Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1)

dp4

Computes the four-component dot product of the sources.

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

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

Example

// This example takes the dot product of two constant colors

// shader file
vs.1.0
dp4 r0.x, v0, c0	; transform vertices by view/projection matrix
dp4 r0.y, v0, c1
dp4 r0.z, v0, c2
dp4 r0.w, v0, c3
mov oPos, r0		; output position

mov oD0, c4 		; output green diffuse color

// The resultant vertex color is green

// 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);

float color[4] = {0,1,0,0};
m_pd3dDevice->SetVertexShaderConstant(4, &color, 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 method sets the constant color register c4 
// with the color green