DirectX SDK |
Your application will usually render 3-D scenes more realistically if it uses colored light maps. A colored light map uses the RGB data in the light map for its lighting information.
The following C++ code fragment demonstrates light mapping with RGB color data:
// This example assumes that lpD3DDev is a valid pointer to an // IDirect3DDevice7 interface and that lptexLightMap is a valid // pointer to a texture that contains RGB light map data. // Set the light map texture as the 1st texture. lpD3DDev->SetTexture(0, lptexLightMap); lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_MODULATE); lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG2, D3DTA_DIFFUSE);
This sample sets the light map as the first texture. It then sets the state of the first blending stage to modulate the incoming texture data. It uses the first texture and the current color of the primitive as the arguments to the modulate operation.
The following Visual Basic code demonstrates light mapping with RGB color data:
' This example assumes that D3DDev is a valid reference to a ' Direct3DDevice7 object and that texLightMap is a valid reference ' to a DirectDrawSurface7 texture surface that contains RGB light map data. ' Set the light map texture as the 1st texture. Call d3dDev.SetTexture(0, texLightMap) Call d3dDev.SetTextureStageState(0, D3DTSS_COLOROP, _ D3DTOP_MODULATE) Call d3dDev.SetTextureStageState(0, D3DTSS_COLORARG1, _ D3DTA_TEXTURE) Call d3dDev.SetTextureStageState(0, D3DTSS_COLORARG2, _ D3DTA_DIFFUSE)
This sample sets the light map as the first texture. It then sets the state of the first blending stage to modulate the incoming texture data. It uses the first texture and the current color of the primitive as the arguments to the modulate operation.