Direct3D (DirectX 9.0) Code Samples - Page 4

Multi-Texturing
 

This sample demonstrates how to perform multi-texturing under Direct3D by either modulating or adding two textures together in one rendering pass. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: SetTextureStageState, SetSamplerState, D3DTSS_TEXCOORDINDEX, D3DTSS_COLOROP, D3DTSS_COLORARG1, D3DTSS_COLORARG2, D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE, and D3DPT_TRIANGLESTRIP.

 

Dot3 Per-Pixel Bump Mapping
 

This sample demonstrates how to perform Dot3 per-pixel bump mapping using a normal map and the D3DTOP_DOTPRODUCT3 texture-blending operation. This technique is sometimes referred to as per-pixel lighting or per-pixel attenuation, but Dot3 per-pixel bump-mapping is what most programmers know it as. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

This sample also demonstrates how to create tangent, binormal, and normal vectors, for each vertex of our test geometry (a simple cube). These vectors are used during rendering to define an inverse tangent matrix for each vertex. This has to be done because a normal-map stores its normals in tangent-space. Therefore, we need an inverse tangent matrix so we can transform our scene's light vector from model-space into tangent-space. Once transformed, we then encode this new light vector as a DWORD color and pass it into the texture blending stage as the vertex's Diffuse color.

Relevant Keywords: GetDeviceCaps, TextureOpCaps, SetTextureStageState, SetSamplerState, D3DTSS_TEXCOORDINDEX, D3DTSS_COLOROP, D3DTSS_COLORARG2, D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE, D3DPT_TRIANGLESTRIP, D3DTA_TFACTOR, D3DRS_TEXTUREFACTOR, and D3DTOP_DOTPRODUCT3.

 

Alpha Texture Blending
 

This sample demonstrates how to perform alpha blending using the alpha channel of a standard .tga texture. For proper alpha blending, the sample uses a cull-mode sorting trick to ensure the sides of the textured cube get rendered in back-to-front order. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: SetRenderState, D3DRS_ALPHABLENDENABLE, D3DRS_ZENABLE, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA, D3DRS_CULLMODE, D3DCULL_CCW, D3DCULL_CW, and D3DCULL_NONE.

 

Alpha Blending in the Frame buffer
 

Demonstrates how to perform alpha-blending in the frame-buffer. The sample renders a textured cube which is alpha-blended into the frame-buffer in such a way as to create a translucent effect. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: SetRenderState, D3DRS_ALPHABLENDENABLE, D3DRS_ZENABLE, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA, D3DRS_DESTBLEND, D3DBLEND_ONE, D3DRS_CULLMODE, and D3DCULL_NONE.

 

Alpha Blending With Materials
 

This sample demonstrates how to perform alpha-blending using a material. This alpha-blending technique is widely used to make entire objects fade out of existence over some amount of time.

Relevant Keywords: SetRenderState, D3DRS_ALPHABLENDENABLE, D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1, D3DRS_SRCBLEND, D3DRS_DESTBLEND, D3DBLEND_SRCALPHA, and D3DBLEND_INVSRCALPHA.