Modeling specular reflection requires that the system not only know the direction that light is traveling, but also the direction to the viewer's eye. Direct3D uses the inverses of the view- and world-transformation matrices to get this information. The system uses a simplified version of the Phong specular-reflection model, which employs a "halfway vector" that exists midway between the vector to the light source and the vector to the eye to approximate the intensity of specular reflection.
Following the simplified Phong model, Direct3D determines the halfway vector by subtracting the vector to the light source from the vector to the eye. Once it has found the halfway vector, the system uses the following formula to compute specular reflection:
In the preceding formula, Rs is the specular reflectance, N in the vertex normal, H is the halfway vector, and p is the specular reflection power of the material that the vertex uses (as specified by the dvPower member of the material's D3DMATERIAL structure). The N and H vectors are normalized.
Like the diffuse reflectance formula, this formula produces values that range from -1.0 to 1.0, which are clamped to the range of 0.0 to 1.0 and used to scale the light reflecting from the vertex. Also similar to the diffuse reflection model, the remaining light is applied to the specular reflectance property of the vertex's material to derive the specular component at that vertex, as shown in the following formula:
In the preceding formula, Sv is the specular color being computed, A is the attenuated light at the vertex, and the Rs variable is the previously calculated specular reflectance. The Cs variable can be one of two possible colors, the one used depends on the state of the system and the format of the vertex at the time. If the D3DLIGHTSTATE_COLORVERTEX light state is enabled (and specular color is present in the vertex), the system uses the specular vertex color in Cs. Otherwise, the system uses the diffuse material color for Cs.
For more information, see Diffuse Reflection Model.