Latest  | Search | Go
Edit this page   |   Attach file 

  Home | Tutorials | Technical Reference | Runtime | API Documentation | ContentCreation > ShaderWriting > ShaderUsage  

Using HLSL Shaders With 3dsmax and Reality Builder

Loading a DirectX Shader File Into 3d Studio Max

Step 1

Setup the directory paths. It is found under Customize -> Configure Paths

SettingThePaths.JPG

Step 2

Make a simple shader. Here is a small clip of a very basic shader. The more specific options are commented.

The file is called NewShader?.fx

#include "Types.h"

//-----------------------------------------------------
// Our Basic Settings
//-----------------------------------------------------
texture tNewDiffuse <
    string TextureType = "2D";
>;

float      NewDiffuseUTile<string UIDesc = "Diffuse U-Tile"; > = 1;
float      NewDiffuseVTile<string UIDesc = "Diffuse V-Tile"; > = 1;

sampler sNewDiffuse = sampler_state
{
   SRGBTexture   = (useSRGB);
   Texture       = (tNewDiffuse );
   AddressU      = Wrap;
   AddressV      = Wrap;
   MinFilter     = (texFilter);
   MagFilter     = (texFilter);
   MaxAnisotropy = (maxAnisotropy);
};

texture tNewBump <
    string TextureType = "2D";
>;

float      NewBumpUTile<string UIDesc = "Diffuse U-Tile"; > = 1;
float      NewBumpVTile<string UIDesc = "Diffuse V-Tile"; > = 1;

sampler sNewBump = sampler_state
{
   SRGBTexture   = (useSRGB);
   Texture       = (tNewBump );
   AddressU      = Wrap;
   AddressV      = Wrap;
   MinFilter     = (texFilter);
   MagFilter     = (texFilter);
   MaxAnisotropy = (maxAnisotropy);
};
//-----------------------------------------------------------------------------
// Our New Shader
//-----------------------------------------------------------------------------
struct NewShader_Point_Pixel
{
    float3 LightTangent : TEXCOORD0;
    float3 LightDist    : TEXCOORD1;
    float4 BaseAndBump  : TEXCOORD2;
    float4 Pos          : TEXCOORD3;
    float4 Position     : POSITION;
    float  Fog          : FOG;
};   

NewShader_Point_Pixel   V_NewShader_Point( Vertex IN)
{
    NewShader_Point_Pixel OUT;
    
    OUT.BaseAndBump.xy = Transform(IN.TexCoord0,float2(NewDiffuseUTile, NewDiffuseVTile));
    OUT.BaseAndBump.zw = Transform(IN.TexCoord0,float2(NewBumpUTile, NewBumpVTile));
   
    CalculateLighting(IN,OUT.LightTangent,OUT.LightDist);
   
    OUT.Position   = mul(IN.Pos,mWorldViewProjection);
    OUT.Fog         = 1;
    OUT.Pos         = OUT.Position;
    return OUT;   
}  
  
float4  P_NewShader_Point( NewShader_Point_Pixel   IN ) : COLOR 
{
   float4 Diffuse = tex2D(sNewDiffuse, IN.BaseAndBump.xy);
   float4 Bump    = tex2D(sNewBump, IN.BaseAndBump.zw);
   float3 L   = normalize(IN.LightTangent);
   float3 N    = GetNormal(Bump);
   float  NL   = saturate(dot(N,L));
   
   float4 color = float4(Diffuse.rgb*LightColor.rgb*NL*GetAttenuation(IN.LightDist),1);
   
   if(bHDRBlend)
      color = color + GetColorBuffer(IN.Pos);
      
   return color;
}                          

technique NewShaderPoint
{
   pass p0
   {
      alphablendenable = (0);
      AlphaTestEnable    = (0);
      SrcBlend      = (SourceBlend);
      DestBlend      = (DestBlend);

      vertexshader    = compile vs_2_0 V_NewShader_Point();
      pixelshader     = compile ps_2_0 P_NewShader_Point();
    }
}  

Step 3

Set the Reality Shader Material Settings. They can be found under the DirectX part of the Materials Properties.

SetRealityShaderMaterial.JPG

Step 4

Now more settings should have opened up under the Materials. You will hit connection editor (fig a) and click and select your new Shader (fig c).

(fig a) NewOptions.JPG

(fig c) SelectShader.JPG

Setting up Shaders Under The Reality Builder

This can be done with just a few simple steps. Under the right bar you will have tab “Material Library”. If you click on that you see a few important buttons that does all the work for you “Get Material From Selection” and “Apply to Selection”.

BuilderSettings.JPG

So depending on whether you want to set a new shader or change a current one’s settings it can all be done easily through reality builder. So for now I loaded one of the previously created .xml files. I select an object and click on “Get Material From Selection”. So now I will set it too our newly created shader.

BuilderSetShader.JPG

And now you're done! You should be able to load shader with 3d studio max as well as Reality Builder.

ShaderUsage   Edit | Attach | Ref-By | Printable | Diffs | r1.3 | > | r1.2 | > | r1.1 | More