Microsoft DirectX 8.1 (Visual Basic)

Ambient Lighting

Ambient lighting provides constant lighting for a scene. It lights all object vertices the same because it is not dependent on any other lighting factors such as vertex normals, light direction, light position, range, or attenuation. It is the fastest type of lighting but it produces the least realistic results. Microsoft® Direct3D® contains a single global ambient light property that you can use without creating any light. Alternatively, you can set any light object to provide ambient lighting. The ambient lighting for a scene is described by the following equation.

Ambient Lighting = Mc*[Ga + sum(Lai)] 

The parameters are defined in the following table.

Parameter Default value Type Description
Mc (0,0,0,0) D3DCOLORVALUE Material ambient color.
Ga (0,0,0,0) D3DCOLORVALUE Global ambient color.
Lai (0,0,0,0) D3DVECTOR Light ambient color, of the ith light.
sum N/A N/A Summation of the ambient light from the light objects.

The value for Mc is one of three values: one of the two possible vertex colors in a vertex declaration, or the material ambient color. The value is:

Note  If either AMBIENTMATERIALSOURCE option is used, and the vertex color is not provided, then the material ambient color is used.

To use the material ambient color, use SetMaterial as shown in the example code below.

Ga is the global ambient color. It is set using SetRenderState(D3DRENDERSTATE_AMBIENT). There is one global ambient color in a Direct3D scene. This parameter is not associated with a Direct3D light object.

Lai is the ambient color of the ith light in the scene. Each Direct3D light has a set of properties, one of which is the ambient color. The term, sum(Lai) is a sum of all the ambient colors in the scene.