Microsoft DirectX 8.1 (Visual Basic) |
When illuminated by a light source, shiny objects—those that use highly reflective materials—receive specular highlights. In some cases, the specular highlights produced by the lighting module is not accurate. To produce a more appealing highlight, many Microsoft® Direct3D® applications apply specular light maps to primitives.
To perform specular light mapping, first modulate the specular light map with the primitive's existing texture. Then add the monochrome or RGB light map.
The following Microsoft® Visual Basic® code example illustrates this process.
' This example assumes that d3dDevice is a valid reference to an ' Direct3DDevice8 object. ' texBaseTexture is a valid reference to a texture. ' texSpecLightMap is a valid reference to a texture that contains RGB ' specular light map data. ' texLightMap is a valid reference to a texture that contains RGB ' light map data. ' Set the base texture. Call d3dDevice.SetTexture(0, texBaseTexture) ' Set the base texture operation and args. Call d3dDevice.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE) Call d3dDevice.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE) Call d3dDevice.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE) ' Set the specular light map. Call d3dDevice.SetTexture(1, texSpecLightMap) ' Set the specular light map operation and args. Call d3dDevice.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD) Call d3dDevice.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE) Call d3dDevice.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT) ' Set the RGB light map. Call d3dDevice.SetTexture(2, texLightMap) ' Set the RGB light map operation and args Call d3dDevice.SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_MODULATE) Call d3dDevice.SetTextureStageState(2, D3DTSS_COLORARG1, D3DTA_TEXTURE) Call d3dDevice.SetTextureStageState(2, D3DTSS_COLORARG2, D3DTA_CURRENT)