Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1) |
Computes the reciprocal square root of the source scalar.
rsq dest, src
To learn more about registers, see Registers.
The following code fragment shows the operations performed.
float v = ABSF(src.w); if(v == 1.0f) { dest.x = dest.y = dest.z = dest.w = 1.0f; } else if(v == 0) { dest.x = dest.y = dest.z = dest.w = PLUS_INFINITY(); } else { v = (float)(1.0f / sqrt(v)); dest.x = dest.y = dest.z = dest.w = v; }
The absolute value is taken before processing.
Precision should be at least 1.0/(222) absolute error over the range (1.0, 4.0) because common implementations will separate mantissa and exponent.
If source has no subscripts, the x-component is used. The output must be exactly 1.0 if the input is exactly 1.0. A source of 0.0 yields infinity.
// This example changes the vertex color from dark red to white. // The max instruction clamps the result to 1.0 vs.1.0 m4x4 oPos, v0, c0 ; transform vertices by view/projection matrix rsq r0, c5 ; take the reciprocal square root of 0.2 max r2, r0, c4.y ; clamp the output to max of 1 mov oD0, r2 ; result is white //The resultant vertex color is white 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 colorGreen[4] = {0, 1, 0, 0}; m_pd3dDevice->SetVertexShaderConstant(4, &colorGreen, 1); // set register c5 float colorDarkRed[] = {0.2f, 0.0f, 0.0f, 0.0f}; m_pd3dDevice->SetVertexShaderConstant(5, &colorDarkRed, 1); // The first SetVertexShaderConstant method binds the C0 register // with the first row of the view/projection matrix (rows 2, 3 and 4 are // bound to registers C2, C3 and c4 also). The m4x4 instruction (in the // shader file) loads the data. // The second SetVertexShaderConstant method binds the C4 register // with the color green. The last SetVertexShaderConstant method // binds the C5 register with the color dark red.