| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
"Ups and Downs" of Bump Mapping with DirectX 6
Listing 1. Code to implement the embossing technique. For sake of brevity, some of the renderstates and texturestagestates that are less relevant to the sample are omitted, but some of them, such as those to implement filtering, can be found in the sample code that accompanies this article. // Rendering Pass #1 lpD3DDevice->SetTexture( 0, lpBumpTexture ); //ignore FB color, just use the output of the SRC (the triangle we are about to render) lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); lpD3DDevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE); lpD3DDevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO); //set up the bump texture lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP ); lpD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); lpD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); hr = lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, pVertices, 6, D3DDP_DONOTLIGHT);
// Rendering Pass #2 lpD3DDevice->SetTexture( 0, lpInvBumpTextureRaw ); //using the D3DBLEND_ONE for both SRC and DEST blend factors results in an // additive blend. FB = (Src * 1) + (Dest * 1) lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); lpD3DDevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE ); lpD3DDevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE ); // inverted bump texture lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); hr = lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, pVertices, 6, D3DDP_DONOTLIGHT);
// Rendering Pass #3 lpD3DDevice->SetTexture( 0, lpBaseTexture ); //The default blending mode with the frame buffer (D3DRENDERSTATE_TEXTUREMAPBLEND) is modulate // so by picking the src and dst blend factors below, we get: // Framebuffer color = (SrcColor*DestColor) + (DestColor*SrcColor), or 2*Dst*Src // this is why the heightmap needs to be from 0 to 0.5 only, and not above 0.5 lpD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); lpD3DDevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_DESTCOLOR ); lpD3DDevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR ); // base texture lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); lpD3DDevice->SetTextureStageState( 0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP );
hr = lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, pVertices, 6, D3DDP_DONOTLIGHT); |
|
|