// Diffuse lighting model // I=Aintensity*Acolour + Dintensity*Dcolour * N.L // Where // Aintensity is the ambient light intensity // Acolour is the colour of the ambient light // Dintensity is the Diffuse light intensity // Dcolour is the colour of the Diffuse light // N is the surface normal // L is the light direction // These lines are just for EffectEdit: string XFile = "tiny\\tiny.x"; int BCLR = 0xff202080; float4 vecLightDir < string UIDirectional = "Light Direction"; > = normalize(float4(0.0f, 0.0f, 1.0f,0.0f)); // transformations provided by the app as input: float4x4 matWorldViewProj: WORLDVIEWPROJECTION; float4x4 matWorld : WORLD; // the format of our vertex data struct VS_OUTPUT { float4 Pos : POSITION; float3 Light : TEXCOORD0; float3 Norm : TEXCOORD1; }; // Vertex Shader - carry out transformations VS_OUTPUT VS(float4 Pos : POSITION, float3 Normal : NORMAL) { VS_OUTPUT Out = (VS_OUTPUT)0; Out.Pos = mul(Pos, matWorldViewProj); // transform Position Out.Light = normalize(vecLightDir); // output light vector Out.Norm = -normalize(mul(Normal, matWorld)); // transform Normal and normalize it return Out; } // Calculate the diffuse light component, add it to the ambient // light component and return the colour value float4 PS(float3 Light: TEXCOORD0, float3 Norm : TEXCOORD1) : COLOR { // Intensity of ambient light: float Aintensity=0.2f; // The colour of the ambient light: float4 Acolour=float4(0.1,0.1,0.1,1.0); // Define variable for the intensity and colour float Dintensity=1.0f; float4 Dcolour=float4(1.0,0.6,0.6,1.0); // Calculate the result using the light vector (Light) // and normal (Norm), using the dot product float4 result=Dintensity*Dcolour*(dot(Norm,Light)); // Add the diffuse result to the ambient below for return return Aintensity*Acolour+result; } // Effect technique to be used technique TVertexAndPixelShader { pass P0 { // shaders VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_1_1 PS(); } }