Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1)

log

Provides log2(x) support with full float precision of at least 1/220.

log dest, src

Registers

dest
Destination register.
src
Input source register.

To learn more about registers, see Registers.

Remarks

The following code fragment shows the operations performed.

float v = ABSF(src.w);
if (v != 0)
{
    dest.x = dest.y = dest.z = dest.w = 
        (float)(log(v)/log(2));  
}
else
{
    dest.x = dest.y = dest.z = dest.w = MINUS_MAX();
}

This instruction accepts a scalar source (src.w) of which the sign bit is ignored. The result is replicated to all four channels.

The input exponent must be in the range –128 to 128. The approximation error must be less than 1/220 in absolute error, and over the range (1.0 <= dest.y < 2.0).

A zero source generates (-infinity, -infinity, -infinity, -infinity).

Example

// This example changes the vertex color.

// shader file

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

mov r0.w, c4.w		; load constant color
log r0,  r0.w		; take the log and copy it to all four components
mov oD0, r0 		; output color

// The constant color loaded in r0 is (0, 0, 0, 1.5). The log of 1.5 is 
// approx. 0.4 which yields a shade of gray since it is copied to all 
// four components(x, y, z, w). The resulting color 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 log[] = {0, 0, 0, 1.5f};
m_pd3dDevice->SetVertexShaderConstant(4, &log, 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 data in the log array. Notice that only the w component is used.