Monochrome Light Maps

Some older 3-D accelerator boards do not support texture blending using the alpha value of the destination pixel (see Alpha Texture Blending). These adapters also generally do not support multiple texture blending. If your application is running on an adapter such as this, it can use multipass texture blending to perform monochrome light mapping.

To perform monochrome light mapping, an application stores the lighting information in the alpha data of its light map textures. The program uses the texture filtering capabilities of Direct3D to perform a mapping from each pixel in the primitive's image to a corresponding texel in the light map. It sets the source blending factor to the alpha value of the corresponding texel.

The following code fragment illustrates how an application can use a texture as a monochrome light map:

// This example assumes that lpD3DDev is a valid pointer to an
// IDirect3DDevice3 interface and that lptexLightMap is a valid
// pointer to a texture that contains monochrome light map data.
 
// Set the light map texture as the current texture.
lpD3DDev->SetTexture(0,lptexLightMap);
 
// Set the color operation.
lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP,
                               D3DTOP_SELECTARG1);
 
// Set argument 1 to the color operation.
lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1,
                               D3DTA_TEXTURE | D3DTA_ALPHAREPLICATE);
 

Since display adapters that do not support destination alpha blending usually do not support multiple texture blending, this example sets the light map as the first texture, which is available on all 3-D accelerator cards. The sample code sets the color operation for the texture's blending stage to blend the texture data with the primitive's existing color. It then selects the first texture and the primitive's existing color as the input data.