Gamasutra: The Art & Business of Making Gamesspacer
"Ups and Downs" of Bump Mapping with DirectX 6
View All     RSS
August 21, 2018
arrowPress Releases
August 21, 2018
Games Press
View All     RSS
  • Editor-In-Chief:
    Kris Graft
  • Editor:
    Alex Wawro
  • Contributors:
    Chris Kerr
    Alissa McAloon
    Emma Kidwell
    Bryant Francis
    Katherine Cross
  • Advertising:
    Libby Kruse






If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

"Ups and Downs" of Bump Mapping with DirectX 6


June 4, 1999 Article Start Previous Page 3 of 7 Next
 

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);


Article Start Previous Page 3 of 7 Next

Related Jobs

Cold Iron Studios
Cold Iron Studios — San Jose, California, United States
[08.21.18]

Infrastructure Engineer
Cold Iron Studios
Cold Iron Studios — San Jose, California, United States
[08.21.18]

Console Gameplay Engineer
Dallas County Community College District
Dallas County Community College District — Dallas, Texas, United States
[08.21.18]

Faculty Full Time- Interactive Simulation and Game Design
Remedy Entertainment
Remedy Entertainment — Espoo, Finland
[08.21.18]

(Senior) Animation Programmer





Loading Comments

loader image