// 3ds max effect file // Simple Lighting Model // This is used by 3dsmax to load the correct parser string ParamID = "0x0"; //DxMaterial specific // light direction (view space) float3 lightDir : Direction < string UIName = "Light Direction"; string Object = "TargetLight"; > = {-0.577, -0.577, 0.577}; // light direction (view space) float3 cam_pos : Position < string UIName = "Light Position"; string Object = "OmniLight"; > = {0,0,100}; // light intensity float4 I_a = { 0.1f, 0.1f, 0.1f, 1.0f }; // ambient float4 I_d = { 1.0f, 1.0f, 1.0f, 1.0f }; // diffuse float4 I_s = { 1.0f, 1.0f, 1.0f, 1.0f }; // specular // material reflectivity float4 k_a < string UIName = "Ambient"; > = float4( 0.47f, 0.47f, 0.47f, 1.0f ); // ambient float4 k_d < string UIName = "Diffuse"; > = float4( 0.47f, 0.47f, 0.47f, 1.0f ); // diffuse float4 k_s < string UIName = "Specular"; > = float4( 1.0f, 1.0f, 1.0f, 1.0f ); // Specular int n< string UIName = "Specular Power"; string UIType = "IntSpinner"; float UIMin = 0.0f; float UIMax = 50.0f; > = 15; // transformations float4x4 World : WORLD; float4x4 View : VIEW; float4x4 Projection : PROJECTION; float4x4 WorldViewProj : WORLDVIEWPROJ; float4x4 WorldView : WORLDVIEW; float3 g_CamPos : WORLDCAMERAPOSITION; struct VS_OUTPUT { float4 Pos : POSITION; float4 col : COLOR0; float4 Z_Dep : TEXCOORD0; float3 Normal : TEXCOORD1; float3 ViewDir : TEXCOORD2; }; VS_OUTPUT VS( float3 Pos : POSITION, float3 col : COLOR, float3 Norm : NORMAL) { VS_OUTPUT Out = (VS_OUTPUT)0; float3 L = lightDir; float3 P = mul(float4(Pos, 1),(float4x4)World); // position (view space) float3 N = normalize(mul(Norm,(float3x3)World)); // normal (view space) float3 R = normalize(2 * dot(N, L) * N - L); // reflection vector (view space) float3 V = normalize(P); // view direction (view space) Out.Pos = mul(float4(Pos,1),WorldViewProj); // position (projected) float4 Diff = I_a * k_a + I_d * k_d * max(0, dot(N, L)); // diffuse + ambient float4 Spec = I_s * k_s * pow(max(0, dot(R, V)), n/4); // specular Out.col = Diff + Spec; Out.Normal=Norm; float3 ViewDir = g_CamPos - P.xyz; Out.ViewDir = ViewDir; float distC=(255.0f-distance(P*2,cam_pos))/255.0f; float finalC=(distC>=0.0?distC:0.0f); Out.Z_Dep=float4(finalC,finalC,finalC,1); return Out; } struct PSIn { float4 Diff : COLOR0; float4 Spec : COLOR1; float4 Z_Dep : TEXCOORD0; float3 Normal : TEXCOORD1; float3 ViewDir : TEXCOORD2; }; float4 PS_Z( PSIn psIn) : COLOR { float4 color= psIn.Z_Dep; //float4 color =float4(Normal,1); //float4 color = Diff + Spec; return color ; } float4 PS_norm(PSIn psIn ) : COLOR { float4 color =float4(psIn.Normal,1); //float4 color = psIn.Diff + psIn.Spec; color += psIn.Diff + psIn.Spec; return color ; } float4 PS_Pixel(VS_OUTPUT psIn ) : COLOR { float3 BottomCol = k_d.rgb; float4 TopCol = k_d; float3 LightCol = float3(1.0,1.0,1.0); float3 Normal = normalize(psIn.Normal); float3 LightDir = normalize(lightDir); float3 ViewDir = normalize(psIn.ViewDir); float3 Ambient = k_a.rgb; float3 SpecLevel = float3(1.0,1.0,1.0); float Alpha; float4 newCol; Alpha = TopCol.a; newCol.rgb = TopCol * Alpha; newCol.rgb += BottomCol * (1.0f - Alpha); float4 finalCol; finalCol.rgb = (Ambient + saturate(dot(Normal, LightDir))) * newCol.rgb; float3 H = normalize(LightDir + ViewDir); float Specular = pow(saturate(dot(Normal, H)), n); finalCol.rgb += (k_s.rgb * Specular) * SpecLevel.rgb; finalCol.a = 1.0f; return finalCol; } float4 PS(PSIn psIn ) : COLOR { float4 color = psIn.Diff + psIn.Spec; return color ; } technique DefaultTechnique { pass P0 { // shaders CullMode = None; VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_2_0 PS(); } } technique DisplayNormal { pass P0 { // shaders CullMode = None; VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_1_1 PS_norm(); } } technique DisplayZDepth { pass P0 { // shaders CullMode = None; VertexShader = compile vs_2_0 VS(); PixelShader = compile ps_2_0 PS_Z(); } } technique PerPixel { pass P0 { // shaders CullMode = None; VertexShader = compile vs_2_0 VS(); PixelShader = compile ps_2_0 PS_Pixel(); } }