Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1) |
Subtracts sources.
sub dest, src0, src1
To learn more about registers, see Registers.
This instruction performs the subtraction shown in this formula.
dest = src0 - src1
The following example subtracts two colors. // shader file vs.1.0 m4x4 oPos, v0, c0 ; transform vertices by view/projection matrix mov r0, c6 ; load off-white mov r1, c7 ; load gray sub r2, r0, r1 ; subtract gray from off-white mov oD0, r2 ; output darker gray The resultant vertex color is a darker gray and is shown below.
// additional code is required to initialize the constant registers. // c0 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 two methods set the constant color registers c6 and c7. 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 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);