Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1) |
Computes the product of the input vector and a 3x3 matrix.
m3x3 dest, src0, src1
To learn more about registers, see Registers.
// m3x3 operates as shown in the following equation. dest.x = (src0.x * src1.x) + (src0.y * src1.y) + (src0.z * src1.z); dest.y = (src0.x * src2.x) + (src0.y * src2.y) + (src0.z * src2.z); dest.z = (src0.x * src3.x) + (src0.y * src3.y) + (src0.z * src3.z);
The input vector is in register src0, the input 3x3 matrix is in register src1 (and the next two higher registers in the same register file--as shown in the expansion below). A 3-D result is produced, leaving the other element of the destination register (dest.w) unaffected.
This operation is commonly used for transforming normal vectors during lighting computations. This macro instruction is implemented as a pair of dot products as shown below.
m3x3 r5, v0, c[3] which is performed as three dot products: dp3 r5.x, v0, c[3] dp3 r5.y, v0, c[4] dp3 r5.z, v0, c[5]
The swizzle and negate modifiers are not allowed on this instruction.
// This example scales the object in both the x and y direction. // shader file vs.1.0 mov r0, v0 ; load vertex position m3x3 r1, r0, c5 ; scale in x and y m4x4 oPos, r1, c0 ; transform vertices by view/projection matrix mov oD0, c4 ; output constant color // The resultant green object is half the width and 1/4 the height // and is shown below.
// Additional code is used to initialize the constant registers. D3DXMATRIX mat, matView, matProj; D3DXMatrixMultiply(&mat, &matView, &matProj); D3DXMatrixTranspose(&mat, &mat); // set C0 with the view and projection matrix m_pd3dDevice->SetVertexShaderConstant(0, &mat, 4); // set register c4 float colorGreen[4] = {0, 1, 0, 0}; m_pd3dDevice->SetVertexShaderConstant(4, &colorGreen, 1); // set register c5 (also sets registers c6 and c7) float scale[][4] = {{0.5f, 0, 0, 0}, {0, 0.25f, 0, 0}, {0, 0, 1, 0}}; m_pd3dDevice->SetVertexShaderConstant(5, &scale, 3); // The first SetVertexShaderConstant method binds the c0 register // with the first row of the view/projection matrix (rows 2, 3, 4 are // bound to registers C2, C3, c4 also). The m4x4 instruction (in the // shader file) loads the data. // The second SetVertexShaderConstant method binds the c4 register // with the data for the color green. The last SetVertexShaderConstant // method binds the c5 register with the first row of the scale matrix // (rows 2 and 3 are bound to registers C6 and C7 also). The m3x3 instruction // (in the shader file) loads the data.