Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1)

frc

Returns the fractional portion of each input component.

frc dest, src

Registers

dest
Destination register.
src0
Input source register.

To learn more about registers, see Registers.

Remarks

The following code fragment shows the operations performed by the frc instruction.

dest.x = src.x - (float)floor(src.x);
dest.y = src.y - (float)floor(src.y);
dest.z = dest.w = ignored;

Each component of the result is in the range from 0.0 through 1.0.

Example

// This example changes the vertex color.

// shader file

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

mov r0, c5	    	; load white constant color in r0 
frc r0.xy, r0.x		; remove fractional part, store result in (xy)
min r0, r0, c4.y           ; clamp max value at 1
mov oD0,   r0		; output result 

// The frc instruction loads the fractional part in the x and y 
// components of the destination register. This results in r0 
// containing (0.2, 0.2, 6.2, 6.2). After the min instruction, r0 
// contains (0.2, 0.2, 1,1). The resultant vertex color is blue 
// and 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 offWhite[] = {0.9f,0.9f,0.9f,0.9f};
m_pd3dDevice->SetVertexShaderConstant(4, &offWhite, 1);

// set register C5
float superWhite[] = {6.2f,6.2f,6.2f,6.2f};
m_pd3dDevice->SetVertexShaderConstant(5, &superWhite, 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 
// data for the color offWhite. The last SetVertexShaderConstant method 
// binds the C5 register with the data for the color superWhite.