Microsoft DirectX 8.0 (Visual Basic) |
When your application has created a bump map and set the contents of each pixel, you can prepare for rendering by configuring bump mapping parameters. Bump mapping parameters include setting the required textures and their blending operations, as well as the transformation and luminance controls for the bump map itself.
To configure bump mapping parameters in Visual Basic
The following code example sets three textures—the base texture map, the bump map, and a specular environment map—to the appropriate texture blending stages.
' Set the three textures. d3dDevice.SetTexture(0, d3dBaseTexture) d3dDevice.SetTexture(1, d3dBumpMap) d3dDevice.SetTexture(2, d3dEnvMap)
After setting the textures to their blending stages, the following code example prepares the blending operations and arguments for each stage.
' Create the bump map texture. ' Set the color operations and arguments to prepare for bump mapping. ' Stage 0: the base texture. Call d3dDevice.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE) Call d3dDevice.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE) Call d3dDevice.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE) Call d3dDevice.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1) Call d3dDevice.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE) Call d3dDevice.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 1) ' Stage 1: the bump map - Use luminance for this example. Call d3dDevice.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1) Call d3dDevice.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BUMPENVMAPLUMINANCE) Call d3dDevice.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE) Call d3dDevice.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT) ' Stage 2: a specular environment map. Call d3dDevice.SetTextureStageState(2, D3DTSS_TEXCOORDINDEX, 0) Call d3dDevice.SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_ADD) Call d3dDevice.SetTextureStageState(2, D3DTSS_COLORARG1, D3DTA_TEXTURE) Call d3dDevice.SetTextureStageState(2, D3DTSS_COLORARG2, D3DTA_CURRENT)
Once the blending operations and arguments are set, the following code example sets the 2×2 bump mapping matrix to the identity matrix, by setting the D3DTSS_BUMPENVMAT00 and D3DTSS_BUMPENVMAT11 texture stage states to 1.0. Setting the matrix to the identity causes the system to use the delta-values in the bump map unmodified, but this is not a requirement.
' Set the bump mapping matrix. Call d3dDevice.SetTextureStageStateSingle(1, D3DTSS_BUMPENVMAT00, 1#) Call d3dDevice.SetTextureStageStateSingle(1, D3DTSS_BUMPENVMAT01, 0#) Call d3dDevice.SetTextureStageStateSingle(1, D3DTSS_BUMPENVMAT10, 0#) Call d3dDevice.SetTextureStageStateSingle(1, D3DTSS_BUMPENVMAT11, 1#)
If you set the bump mapping operation to include luminance (D3DTOP_BUMPENVMAPLUMINANCE), you must set the luminance controls. The luminance controls configure how the system computes luminance before modulating the color from the texture in the next stage. For details, see Bump Mapping Formulas.
' Set luminance controls. This is only needed when using a bump map ' that contains luminance, and when the D3DTOP_BUMPENVMAPLUMINANCE ' texture blending operation is being used. Call d3dDevice.SetTextureStageStateSingle(1, D3DTSS_BUMPENVLSCALE, 0.5) Call d3dDevice.SetTextureStageStateSingle(1, D3DTSS_BUMPENVLOFFSET, 0#)
After your application configures bump mapping parameters, it can render as normal, and the rendered polygons receive bump mapping effects.
Note The preceding example shows parameters set for specular environment mapping. When performing diffuse light mapping, applications set the texture blending operation for the last stage to D3DTOP_MODULATE. For more information, see Diffuse Light Maps.