Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1)

dst

Calculates the distance vector.

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

dest.x = 1;
dest.y = src0.y * src1.y;
dest.z = src0.z;
dest.w = src1.w;

The first source operand (src0) is assumed to be the vector (ignored, d*d, d*d, ignored) and the second source operand (src1) is assumed to be the vector (ignored, 1/d, ignored, 1/d). The destination (dest) is the result vector (1, d, d*d, 1/d).

Example

// This example transforms vertices and outputs a constant color 
// These steps are required in all vertex shaders. Once that is done, 
// the sample shows how to set up the inputs to the dst instruction

// shader file
m4x4 oPos, v0, c0	    ; transform vertices by view/projection matrix
mov oD0, c4 	    	; output constant color

// find the distance
mov r0.xyz, v0.xyz		; load vertex position
dp3 r1.yz, r0.xyz, r0.xyz	; put d*d in r1.y and r1.z
rsq r2.y, r1.y			; 1/d
rcp r2.yw, r2.y			; put d in r2.y and r2.w
dst r3, r1, r2			; find the distance from v0 to origin
// The resultant vertex color is green and is shown below
// The dp3 instruction is used to load the src0 register with data 
// in the form of (ignored, d*d, d*d, ignored). The rcp instruction 
// finishes loading register src1 with data in the form of 
// (ignored, d, ignored, d). 

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

// The first SetVertexShaderConstant method binds the C0 register 
// with the first row of the view/projection matrix (rows 2,3,4 are 
// bound to registers C2, C3, C4 also). The m4x4 instruction (in the 
// shader file) loads the data.
// The second SetVertexShaderConstant method binds the C4 register 
// with the color green.