?/TD>
Microsoft DirectX 9.0

Mathematics of Lighting


The Microsoft?Direct3D?Light Model covers ambient, diffuse, specular, and emissive lighting. This is enough flexibility to solve a wide range of lighting situations. You refer to the total amount of light in a scene as the global illumination and compute it using the following equation.

Global Illumination = Ambient Light + Diffuse Light + Specular Light + Emissive Light 

Ambient Lighting is constant lighting. It is constant in all directions and it colors all pixels of an object the same. It is fast to calculate but leaves objects looking flat and unrealistic. To see how ambient lighting is calculated by Direct3D, see Ambient Lighting.

Diffuse Lighting depends on both the light direction and the object surface normal. It varies across the surface of an object as a result of the changing light direction and the changing surface numeral vector. It takes longer to calculate diffuse lighting because it changes for each object vertex, however the benefit of using it is that it shades objects and gives them three-dimensional (3-D) depth. To see how diffuse lighting is calculated in Direct3D, see Diffuse Lighting.

Specular Lighting identifies the bright specular highlights that occur when light hits an object surface and reflects back toward the camera. It is more intense than diffuse light and falls off more rapidly across the object surface. It takes longer to calculate specular lighting than diffuse lighting, however the benefit of using it is that it adds significant detail to a surface. To see how specular lighting is calculated in Direct3D, see Specular Lighting.

Emissive Lighting is light that is emitted by an object, for example, a glow. To see how emissive lighting is calculated in Direct3D, see Emissive Lighting.

Realistic lighting can be accomplished by applying each of these types of lighting to a 3-D scene. To achieve a more realistic lighting effect, you add more lights; however, the scene takes longer to render. To achieve all the effects a designer wants, some games use more CPU power than is commonly available. In this case, it is typical to reduce the number of lighting calculations to a minimum by using lighting maps and environment maps to add lighting to a scene while using texture maps.

Lighting is computed in the camera space. To see how lighting transformations are calculated, see Camera Space Transformations. Optimized lighting can be computed in model space, when special conditions exist: normal vectors are already normalized (D3DRS_NORMALIZENORMALS is True), vertex blending is not needed, transformation matrices are orthogonal, etc.

Ambient, diffuse, and specular light values can be affected by a given light's attenuation and spotlight factor. The values calculated for ambient, emissive, and diffuse components are stored in the diffuse output vertex color. Terms for both of these are included in the diffuse and specular equations. For more information, see Attenuation and Spotlight Factor.



© 2002 Microsoft Corporation. All rights reserved.