Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1) |
Multiplies and adds sources.
mad dest, src0, src1, src2
To learn more about registers, see Registers.
The following code fragment shows the operations performed.
dest.x = src0.x * src1.x + src2.x; dest.y = src0.y * src1.y + src2.y; dest.z = src0.z * src1.z + src2.z; dest.w = src0.w * src1.w + src2.w;
// This example combines three colors. vs.1.0 m4x4 oPos, v0, c0 ; transform vertices by view/projection matrix mov r0, c4 ; green mov r1, c6 ; off white mov r2, c7 ; gray mad r3, r0, r1, r2 ; combine all three colors mov oD0, r3 // The resultant vertex color is a combination of all three colors. // The mad instruction multiplies green and off-white to produce a // slightly darker shade of green. Then gray is added to the result // which yields a shade of green that has non-zero red and blue // components. The resulting shade 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 color[4] = {0, 1, 0, 0}; m_pd3dDevice->SetVertexShaderConstant(4, &color, 1); // set register c6 float colorOffWhite[] = {0.9f, 0.9f, 0.9f, 0.9f}; m_pd3dDevice->SetVertexShaderConstant(6, &colorOffWhite, 1); // set register c7 float colorGray[] = {0.5f, 0.5f, 0.5f, 0.5f}; m_pd3dDevice->SetVertexShaderConstant(7, &colorGray, 1); // The c0 register is loaded with the view and projection matrix using the // m4x4 instruction (the m4x4 instruction also uses the c1, c2 and c3 // registers). The last three methods set the constant color registers // c4, c6 and c7.