Light Color
A version of this page is also available for
4/8/2010
Lights in Microsoft® Direct3D® Mobile emit three colors that are used independently in the system's lighting computations: a diffuse color, an ambient color, and a specular color. Each is incorporated by the Direct3D Mobile lighting module, interacting with a counterpart from the current material, to produce a final color used in rendering. The diffuse color interacts with the diffuse reflectance property of the current material, the specular color with the material's specular reflectance property, and so on. For specifics about how Direct3D Mobile applies these colors, see Lighting Equations.
In a C++ application, the D3DMLIGHT structure includes three members for these colors — Diffuse, Ambient, and Specular — each one is a D3DMCOLORVALUE structure that defines the color being emitted.
The type of color that applies most heavily to the system's computations is the diffuse color. The most common diffuse color is white (R:1.0 G:1.0 B:1.0), but you can create colors as needed to achieve desired effects. For example, you could use red light for a fireplace, or you could use green light for a traffic signal set to Go.
Generally, you set the light color components to values between 0.0 and 1.0, inclusive, but this is not a requirement. For example, you might set all the components to 2.0, creating a light that is brighter than white. This type of setting can be especially useful when you use attenuation settings other than constant.
Note that although Direct3D Mobile uses RGBA values for lights, the alpha color component is not used. For more information, see Color Values for Lights and Materials.
Color Vertices
Usually material colors are used for lighting. However, you can specify that material colors — ambient, diffuse, and specular — are to be overridden by diffuse or specular vertex colors. This is done by calling IDirect3DMobileDevice::SetRenderState and setting the device state variables listed in the following table.
Device state variable | Description | Type | Default |
---|---|---|---|
D3DMRS_AMBIENTMATERIALSOURCE |
Defines where to get ambient material color. |
D3DMMCS_MATERIAL |
|
D3DMRS_DIFFUSEMATERIALSOURCE |
Defines where to get diffuse material color. |
D3DMMATERIALCOLORSOURCE |
D3DMMCS_COLOR1 |
D3DMRS_SPECULARMATERIALSOURCE |
Defines where to get specular material color. |
D3DMMATERIALCOLORSOURCE |
D3DMMCS_COLOR2 |
D3MDRS_COLORVERTEX |
Disables or enables use of vertex colors. |
BOOL |
TRUE |
The alpha/transparency value always comes only from the diffuse color's alpha channel.
The fog value always comes only from the specular color's alpha channel.