Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1)

dp3

Computes the three-component dot product of the source registers.

dp3 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 dp3 instruction.

dest.w = (src0.x * src1.x) + (src0.y * src1.y) + (src0.z * src1.z);
dest.x = dest.y = dest.z = dest.w = the scalar result of dp3

Example

// This example adds two constant colors. This combines the rgb 
// components of each color to produce the final color

// shader file
vs.1.0
m4x4 oPos, v0, c0	; transform vertices by view/projection matrix

mov r0, c5		    ; load pink
mov r1, c6	    	; load off-white
dp3 r2, r0, r1		; combine c5 and c6 using a dot product
mov oD0, r2		    ; output color

// The resultant vertex color is a shade of gray because the output scalar 
// value is copied to all components
// 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 c5
float colorPink[] = {0.75,0,0,0};
m_pd3dDevice->SetVertexShaderConstant(5, &colorPink, 1);

// set register c6
float colorOffWhite[] = {0.9f,0.9f,0.9f,0.9f};
m_pd3dDevice->SetVertexShaderConstant(6, &colorOffWhite, 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 two methods set the constant color registers