1 uniform extern float4x4 mRotation;
2 uniform extern float4x4 mTranslation;
3 uniform extern float4x4 mView;
4 uniform extern float4x4 mProjection;
5
6 uniform extern float4x4 gWorldInverseTranspose;
7 uniform extern float4 gAmbientMtrl;
8 uniform extern float4 gAmbientLight;
9 uniform extern float4 gDiffuseMtrl;
10 uniform extern float4 gDiffuseLight;
11 uniform extern float3 gLightVecW;
12
13 // vertex shader output structure
14 struct OutputVS {
15 float4 position : POSITION0;
16 float4 color : COLOR0;
17 };
18
19 OutputVS AmbientDiffuseVS(float3 input : POSITION0, float3 normalL : NORMAL0)
20 {
21 OutputVS outVS = (OutputVS)0;
22
23 // multiply world with view and proj matrix
24 float4x4 mWorld = mul(mTranslation, mRotation);
25 float4x4 mViewProj = mul(mView, mProjection);
26 float4x4 mCombined = mul(mWorld, mViewProj);
27
28 // Transform to homogeneous clip space
29 outVS.position = mul(float4(input, 1.0f), mCombined);
30
31 //calculate normal for the diffuse light
32 float3 normalW = mul(float4(normalL, 0.0f), gWorldInverseTranspose).xyz;
33 normalW = normalize(normalW);
34
35 //calculate diffuse color based on light direction
36 float s = max(dot(gLightVecW, normalW), 0.0f);
37 float3 diffuse = s * (gDiffuseMtrl * gDiffuseLight).rgb;
38
39 //calculate ambient color
40 float3 ambient = gAmbientMtrl * gAmbientLight;
41
42 //combine ambient and diffuse colors for final output color
43 outVS.color.rgb = ambient + diffuse;
44
45 //copy the alpha level
46 outVS.color.a = gDiffuseMtrl.a;
47
48
49 return outVS;
50 }
51
52 float4 AmbientDiffusePS(float4 c : COLOR0) : COLOR
53 {
54 return c;
55 }
56
57 technique technique1
58 {
59 pass P0
60 {
61 vertexShader = compile vs_2_0 AmbientDiffuseVS();
62 pixelShader = compile ps_2_0 AmbientDiffusePS();
63 }
64 }