Platform SDK: DirectX

Diffuse Light Maps

When illuminated by a light source, matte surfaces display diffuse light reflection. The brightness of diffuse light depends on the distance from the light source and the angle between the surface normal and the light source direction vector. The diffuse lighting effects simulated by lighting calculations produce only general effects.

[C++]

Your application can simulate more complex diffuse lighting with texture light maps. Do this by adding the diffuse light map to the base texture, as shown in the following C++ code fragment.

// This example assumes that lpD3DDev is a valid pointer to an
// IDirect3DDevice7 interface.
// lptexBaseTexture is a valid pointer to a texture.
// lptexDiffuseLightMap is a valid pointer to a texture that contains 
// RGB diffuse light map data.
 
// Set the base texture.
lpD3DDev->SetTexture(0,lptexBaseTexture );
 
// Set the base texture operation and args
lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP,
       D3DTOP_MODULATE );
lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE );
lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG2, D3DTA_DIFFUSE );
 
// Set the diffuse light map.
lpD3DDev->SetTexture(1,lptexDiffuseLightMap );
 
// Set the blend stage.
lpD3DDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE );
lpD3DDev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
lpD3DDev->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT );
[Visual Basic]

Your application can simulate more complex diffuse lighting with texture light maps. Do this by adding the diffuse light map to the base texture, as shown in the following code Visual Basic fragment.

' This example assumes that d3dDev is a valid reference to
' a Direct3DDevice7 object.
' texBaseTexture is a valid reference to a texture.
' texDiffuseLightMap is a valid reference to a texture that contains
' RGB diffuse light map data.
 
' Set the base texture.
Call d3dDev.SetTexture(0, texBaseTexture)
 
' Set the base texture operation and args
Call d3dDev.SetTextureStageState(0, D3DTSS_COLOROP, _
 D3DTOP_MODULATE)
Call d3dDev.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE)
Call d3dDev.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE)
 
' Set the diffuse light map.
Call d3dDev.SetTexture(1, texDiffuseLightMap)
 
' Set the blend stage.
Call d3dDev.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE)
Call d3dDev.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE)
Call d3dDev.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT)