当被光源照亮时,闪亮的对象-那些使用高度反射材料的对象-接收反射亮点。 在某些情况下,照明模块生成的反射高光不准确。 为了生成更具吸引力的亮点,许多 Direct3D 应用程序将反射光映射应用于基元。
若要执行反射光映射,请将反射光贴图添加到基元的纹理,然后调节(将结果乘以)RGB 光图。
以下代码示例演示了C++中的此过程。
// This example assumes that d3dDevice is a valid pointer to an
// IDirect3DDevice9 interface.
// lptexBaseTexture is a valid pointer to a texture.
// lptexSpecLightMap is a valid pointer to a texture that contains RGB
// specular light map data.
// lptexLightMap is a valid pointer to a texture that contains RGB
// light map data.
// Set the base texture.
d3dDevice->SetTexture(0, lptexBaseTexture );
// Set the base texture operation and arguments.
d3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
d3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
// Set the specular light map.
d3dDevice->SetTexture(1, lptexSpecLightMap);
// Set the specular light map operation and args.
d3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD );
d3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT );
// Set the RGB light map.
d3dDevice->SetTexture(2, lptexLightMap);
// Set the RGB light map operation and arguments.
d3dDevice->SetTextureStageState(2,D3DTSS_COLOROP, D3DTOP_MODULATE);
d3dDevice->SetTextureStageState(2,D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3dDevice->SetTextureStageState(2,D3DTSS_COLORARG2, D3DTA_CURRENT );
相关主题