cristims
Community Member

Posts: 116
|
 |
« on: April 30, 2008, 12:31:00 AM » |
|
I am using a plugin for max to create shaders. While in 3ds max works just fine, this shader doesn't work in tv3d.
Please help. Thank you. Here is the code:
#define DCC_MAX
texture TextureMap_9148 : DiffuseMap < string Name = "D_cobblestones.dds"; string UIName = "Diffuse Texture"; string ResourceType = "2D"; >; sampler2D TextureMap_9148Sampler = sampler_state { Texture = <TextureMap_9148>; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; };
/************** light info **************/
float4 light1Pos : POSITION < string UIName = "Light 1 Position"; string Object = "PointLight"; string Space = "World"; #ifdef DCC_MAX int refID = 1; #endif > = {100.0f, 100.0f, 100.0f, 0.0f};
float4 light1Color : LIGHTCOLOR < #ifdef DCC_MAX int LightRef = 1; string UIWidget = "None"; #endif > = { 1.0f, 1.0f, 1.0f, 1.0f};
//---------------------------------- float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; float4x4 worldI : WorldInverse < string UIWidget = "None"; >; float4x4 viewInv : ViewInverse < string UIWidget = "None"; >; float4x4 world : World < string UIWidget = "None"; >;
// input from application struct a2v { float4 position : POSITION; float2 texCoord : TEXCOORD0; float2 texCoord1 : TEXCOORD1; float2 texCoord2 : TEXCOORD2; float3 vertcol : TEXCOORD3; float vertalpha : TEXCOORD4; float3 tangent : TANGENT; float3 binormal : BINORMAL; float3 normal : NORMAL; };
// output to fragment program struct v2f { float4 position : POSITION; float4 color : COLOR; float2 texCoord : TEXCOORD0; float2 texCoord1 : TEXCOORD1; float2 texCoord2 : TEXCOORD2; float3 eyeVec : TEXCOORD3; float3 lightVec : TEXCOORD4; float3 worldNormal : TEXCOORD5; float3 worldTangent : TEXCOORD6; float3 worldBinormal : TEXCOORD7; };
// blinn lighting with lit function float3 blinn2(float3 N, float3 L, float3 V, uniform float3 diffuseColor, uniform float3 specularColor, uniform float shininess ) { float3 H = normalize(V+L); float3 lighting = lit(dot(L,N), dot(H,N), shininess); return diffuseColor*lighting.y + specularColor*lighting.z; }
//Diffuse and Specular Pass Vertex Shader v2f v(a2v In, uniform float4 lightPosition) { v2f Out = (v2f)0; Out.position = mul(In.position, wvp); //transform vert position to homogeneous clip space //this code was added by the standard material float3x3 objTangentXf; //build object to tangent space transform matrix #ifdef DCC_MAX //swap tangent and binormal, but only for 3ds Max objTangentXf[0] = In.binormal; objTangentXf[1] = -In.tangent; objTangentXf[2] = In.normal; #else objTangentXf[0] = In.tangent; objTangentXf[1] = -In.binormal; objTangentXf[2] = In.normal; #endif //this code was added by the standard material float4 osLPos = mul(lightPosition, worldI); //put world space light position in object space float3 osLVec = osLPos.xyz - In.position.xyz; //object space light vector Out.lightVec = mul(objTangentXf, osLVec); //tangent space light vector passed out
//this code was added by the standard material float4 osIPos = mul(viewInv[3], worldI); //put world space eye position in object space float3 osIVec = osIPos.xyz - In.position.xyz; //object space eye vector Out.eyeVec = mul(objTangentXf, osIVec); //tangent space eye vector passed out
//this code was added by the texture map Node Out.texCoord = In.texCoord; //pass through texture coordinates from channel 1
return Out; }
//Diffuse and Specular Pass Pixel Shader float4 f(v2f In, uniform float4 lightColor) : COLOR { float3 ret = float3(0,0,0); float3 V = normalize(In.eyeVec); //creating the eye vector float3 L = normalize(In.lightVec); //creating the light vector
float4 TextureMap_9148 = tex2D(TextureMap_9148Sampler, In.texCoord.xy); float3 input2 = TextureMap_9148.rgb;
float3 diffuseColor = input2; //using the Diffuse Color socket float specularColor = 0.0; //the Specular Color and Specular Level sockets were empty float glossiness = 20; //the Glossiness socket was empty - using default value float3 N = float3(0.0, 0.0, 1.0); //the Normal socket was empty - using default value
//the lighting equation ret += lightColor * blinn2(N, L, V, diffuseColor, specularColor, glossiness); float4 done = float4(ret, 1); return done; }
technique Complete { pass light1 { VertexShader = compile vs_1_1 v(light1Pos); ZEnable = true; ZWriteEnable = true; CullMode = cw; AlphaBlendEnable = false; PixelShader = compile ps_2_0 f(light1Color); }
}
|