?/TD>
Microsoft DirectX 9.0

texm3x3spec (Pixel Shader)


Performs a 3x3 matrix multiply and uses the result to perform a texture lookup. This can be used for specular reflection and environment mapping. texm3x3spec must be used in conjunction with two texm3x3pad instructions.

Syntax

texm3x3spec (Pixel Shader) destsrc0src1

Registers

dest
Destination register.
src0
Input source register.
src1
Input source register.

Remarks

Pixel shader versions1_11_21_31_42_02_x2_sw3_03_sw
texm3x3specxxx

This instruction performs the final row of a 3x3 matrix multiply, uses the resulting vector as a normal vector to reflect an eye-ray vector, and then uses the reflected vector to perform a texture lookup. The shader reads the eye-ray vector from a constant register. The 3x3 matrix multiply is typically useful for orienting a normal vector to the correct tangent space for the surface being rendered.

The 3x3 matrix is comprised of the texture coordinates of the third texture stage and the two preceding texture stages. The resulting post reflection vector (u,v,w) is used to sample the texture on the final texture stage. Any texture assigned to the preceding two texture stages is ignored.

This instruction must be used with two texm3x3pad instructions. Texture registers must use the following sequence.

 
tex t(n)                      // Define tn as a standard 3-vector (tn must
                              //   be defined in some way before it is used).
texm3x3pad t(m),   t(n)       //   where m > n
                              // Perform first row of matrix multiply.
texm3x3pad  t(m+1), t(n)      // Perform second row of matrix multiply.
texm3x3spec t(m+2), t(n), c0  // Perform third row of matrix multiply.
                              // Then do a texture lookup on the texture
                              //   associated with texture stage m+2.

The first texm3x3pad instruction performs the first row of the multiply to find u'.

u' = TextureCoordinates(stage m)UVW * t(n)RGB

The second texm3x3pad instruction performs the second row of the multiply to find v'.

v' = TextureCoordinates(stage m+1)UVW * t(n)RGB   

The texm3x3spec instruction performs the third row of the multiply to find w'.

w' = TextureCoordinates(stage m+2)UVW * t(n)RGB  

The texm3x3spec instruction then does a reflection calculation.

(u'', v'', w'') = 2*[(N*E)/(N*N)]*N - E
// where the normal N is given by 
//   N = (u', v', w')
//   and the eye-ray vector E is given by the constant register
//   E = c# (Any constant register--c0, c1, c2, etc.--can be used.)

Lastly, the texm3x3spec instruction samples t(m+2) with (u'',v'',w'') and stores the result in t(m+2).

t(m+2)RGBA = TextureSample(stage m+2)RGBA using (u'', v'', w'') as coordinates.

Examples

Here is an example shader with the texture maps and the texture stages identified.

ps_1_1
tex t0                    // Bind texture in stage 0 to register t0 (tn must
                          //   be defined in some way before it is used).
texm3x3pad  t1,  t0       // First row of matrix multiply.
texm3x3pad  t2,  t0       // Second row of matrix multiply.
texm3x3spec t3,  t0,  c#  // Third row of matrix multiply to get a 3-vector.
                          // Reflect 3-vector by the eye-ray vector in c#.  
                          // Use reflected vector to lookup texture in
                          //   stage 3.
mov r0, t3                // output result

This example requires the following texture stage setup.

Instruction Information

Minimum operating systems Windows 98


© 2002 Microsoft Corporation. All rights reserved.