Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1) |
Computes the product of the input vector and a 4x4 matrix.
m4x4 dest, src0, src1
To learn more about registers, see Registers.
The following code fragment shows the operations performed by the m4x4 instruction.
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); dest.w = (src0.x * src4.x) + (src0.y * src4.y) + (src0.z * src4.z);
The input vector is in register src0, the input 3x4 matrix is in register src1 (and the next three higher registers in the same register file--as shown in the expansion below).
This operation is commonly used for transforming a position by a projection matrix. This macro instruction is implemented as a series of dot products as shown below.
m4x4 r5, v0, c3 which is performed as four dot products: dp4 r5.x, v0, c3 dp4 r5.y, v0, c4 dp4 r5.z, v0, c5 dp4 r5.w, v0, c6
The swizzle and negate modifiers are not allowed on this instruction.
// This example transforms the object with the view and projection matrix. // shader file vs.1.0 m4x4 oPos, v0, c0 ; transform vertices by view/projection matrix mov oD0, c4 ; output constant color // The resultant green object 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); // The first SetVertexShaderConstant method binds the c0 register // with the first row of the view/projection matrix (rows 2, 3, and 4 are // bound to registers C2, C3, and 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.