Game Development Reference
In-Depth Information
input.normal.w
= 0.0f;
LightDirection
= mul(LightDirection, ViewMatrix);
input.normal
= mul(input.normal,
ViewMatrix);
//
// Compute cosine of the angle between light and normal.
//
float s = dot(LightDirection, input.normal);
//
// Recall that if the angle between the surface and light
// is greater than 90 degrees the surface receives no light.
// Thus, if the angle is greater than 90 degrees we set
// s to zero so that the surface will not be lit.
//
if( s < 0.0f )
s = 0.0f;
//
// Ambient light reflected is computed by performing a
// component-wise multiplication with the ambient material
// vector and the ambient light intensity vector.
//
// Diffuse light reflected is computed by performing a
// component-wise multiplication with the diffuse material
// vector and the diffuse light intensity vector. Further
// we scale each component by the shading scalar s, which
// shades the color based on how much light the vertex received
// from the light source.
//
// The sum of both the ambient and diffuse components give
// us our final vertex color.
//
output.diffuse = (AmbientMtrl * AmbientLightIntensity) +
(s * (DiffuseLightIntensity * DiffuseMtrl));
return output;
}
Now that we have looked at the actual vertex shader code, let's shift
gears and look at the application code. The application has the following
relevant global variables:
IDirect3DVertexShader9* DiffuseShader = 0;
ID3DXConstantTable* DiffuseConstTable = 0;
ID3DXMesh* Teapot
= 0;
D3DXHANDLE ViewMatrixHandle = 0;
D3DXHANDLE ViewProjMatrixHandle = 0;
D3DXHANDLE AmbientMtrlHandle
= 0;
D3DXHANDLE DiffuseMtrlHandle
= 0;
D3DXHANDLE LightDirHandle
= 0;
D3DXMATRIX Proj;
Search WWH ::




Custom Search