Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1)

m4x3

Computes the product of the input vector and a 4x3 matrix.

m4x3 dest, src0, src1

Registers

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

To learn more about registers, see Registers.

Remarks

The following code fragment shows the operations performed by the m4x3 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);

The input vector is in register src0, the input 3x4 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 a position vector by a matrix that has no projective effect, such as occurs in model-space transformations. This macro instruction is implemented as a pair of dot products as shown below.

m4x3   r5, v0, c3

which is performed as three dot products:
dp4   r5.x, v0, c3
dp4   r5.y, v0, c4
dp4   r5.z, v0, c5

Note that the w-component in c3, c4, and c5 is ignored in this computation unless the input vector has a w-value of 1.0. If this w-value is 0.0, then no translation of the input vector will occur; that is, the translation elements of the matrix will not be applied.

The swizzle and negate modifiers are not allowed on this instruction.

Example

// This example scales the object in the y direction.

// shader file
vs.1.0
mov r0, v0	    	; load vertex position
m4x3 r1, r0, c5		; scale in y
m4x4 oPos, r1, c0	; transform vertices by view/projection matrix

mov oD0, c4	    	; output constant color

// The resultant green object is 3/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)
// 4 rows x 3 cols
float scale4x3[][4] = {{1, 0, 0, 0},{0, 0.75, 0, 0},{0, 0, 1, 0},{0, 0, 0, 1}};
m_pd3dDevice->SetVertexShaderConstant(5, &scale4x3, 4);


// 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. The last SetVertexShaderConstant method 
// binds the c5 register with the first row of the scale matrix (rows 2, 3 and 4 
// are bound to registers C6, C7 and c8 also). The m4x3 instruction (in the 
// shader file) loads the data.