Camera Space Transformation
A version of this page is also available for
4/8/2010
To perform lighting, the transformation pipeline must be configured to transform vertices into camera space. This transformation is accomplished by multiplying model space vertex positions by the Mwv matrix.
V = V<SUB>model</SUB> * M<SUB>VW</SUB>
Vertex normals are also transformed into camera space. This is accomplished by multiplying the normal vectors by the inverse transpose of the Mwv matrix.
N = N<SUB>model</SUB> * (M<SUB>WV</SUB><SUP>-1</SUP>)<SUP>T</SUP>
If the D3DMRS_NORMALIZENORMALS render state (see D3DMRENDERSTATETYPE) is set then vertex normals are normalized after they are transformed.
N = Norm(N)
Light position in camera space is computed by multiplying the light source position by the view transformation matrix.
Lp<SUB>i</SUB> = Lp<SUB>iWorld</SUB> * M<SUB>V</SUB>
The direction to light in the camera space for directional lights, as identified by the D3DMLIGHTTYPE value D3DMLIGHT_DIRECTIONAL, is computed by multiplying the light direction vector by the view matrix. The results are normalized and negated.
Ld<SUB>i</SUB> = - Norm(Ld<SUB>iWorld</SUB> * M<SUB>V</SUB>)
For point lights, the direction to the light is computed as the vector between the vertex and the light position.
Ld<SUB>i</SUB> = Norm(V * Lp<SUB>i</SUB>)