Exercise 2: Vertex Shader Diffuse Lighting
//
// Effect File Workshop Solution for Exercise 2
// Copyright (c) 2001 Microsoft Corporation. All rights reserved.
//
vector lhtR; // Light direction from app
vector matD; // Object diffuse material color
matrix mWld; // World
matrix mTot; // Total
// Load model
string XFile = "f40.x";
// Background color
DWORD BCLR = 0xff000000;
// No pixel shader
pixelshader pNIL;
// Technique names for display in viewer window
string tec0 = "Solution 2: Vertex Shader Diffuse Lighting";
/////////////////////////////////////////////////////////////////////////////
/////// Exercise 2: Vertex Shader Diffuse Lighting //////////
/////// Light the model taking both diffuse material and //////////
/////// diffuse light source into consideration. //////////
/////////////////////////////////////////////////////////////////////////////
technique tec0
{
pass p0
{
//Load matrices
VertexShaderConstant[0] = ; // World Matrix
VertexShaderConstant[4] = ; // World*View*Proj Matrix
//Material properties of object
VertexShaderConstant[9] = ; // Diffuse from object material diffuse
VertexShaderConstant[10] = (0.0f,0.0f,0.0f,0.0f); // Specular from constant color
VertexShaderConstant[11] = (0.0f,0.0f,0.0f,0.0f); // Ambient from constant color
// Light Properties. lhtR is input from the shader app
VertexShaderConstant[13] = (1.0f,0.9f,0.9f,1.0f); // Diffuse
VertexShaderConstant[14] = (0.0f,0.0f,0.0f,0.0f); // Specular
VertexShaderConstant[15] = (0.0f,0.0f,0.0f,0.0f); // Ambient
VertexShaderConstant[16] = ; // Light direction
// Assign diffuse color to be used
ColorOp[0] = SelectArg1;
ColorArg1[0] = Diffuse;
AlphaOp[0] = SelectArg1;
AlphaArg1[0] = Diffuse;
// Only one color being used
ColorOp[1] = Disable;
AlphaOp[1] = Disable;
// Definition of the vertex shader, declarations then assembly
VertexShader =
decl
{
stream 0;
float v0[3]; // Position
float v3[3]; // Normal
float v7[3]; // Texture Coord1
float v8[3]; // Texture coord2
}
asm
{
vs.1.1 // Version number
m4x4 oPos, v0, c4 // Transform point to projection space
dp3 r0,v3,-c16 // Dot product against untransformed light
mul r0,r0,c13 // Modulate against diffuse light color
mul r0,r0,c9 // Modulate against diffuse material
mov oD0,r0 // Put into Diffuse Color output
};
}
}