Microsoft DirectX 8.0 (Visual Basic)

Pixel Shader Texture Addressing

The following diagram illustrates the mechanics of pixel shader texture addressing.

Texture registers t0, t1, t2, and t3 result from sampling the four input textures using the texture coordinates in conjunction with the texture operations. The mapping of texture coordinates set to texture registers is controlled by the D3DTSS_TEXCOORDINDEX texture stage state. By default, all texture stages receive texture coordinates from coordinate set 0. The positions of the instructions are required to be in order because they can use results only from previous texture registers.

When you use dependent textures, any texture can be used to perturb the coordinates of a higher-numbered texture; for example, t1 can be used to perturb the coordinates of t2.

The Direct3DX pixel shader assembler provides both texture address operators and modifiers. For details, see Pixel Shader Assembler Reference.

The following pixel shader code shows a texture address shader by programming a bump environment map on a lit base texture.

ps.1.0              // DirectX8 Version.
tex t0              // Declare the texture.
tex t1              // Declare the bump map.
texbem t3, t1       // Perturb and then sample 
                    // the environment map.
mul r0, v0, t0      // Modulate the diffuse.
add r0, r0, t3      // Add bumped specular environment map.