Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1)

expp

Provides exponential 2x partial support.

expp 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 by the expp instruction.

float w = src.w;
float v = (float)floor(src.w);

dest.x = (float)pow(2, v);
dest.y = w - v;
    
// Reduced precision exponent
float tmp = (float)pow(2, w);
DWORD tmpd = *(DWORD*)&tmp & 0xffffff00;
dest.z = *(float*)&tmpd;
dest.w = 1;

The expp instruction produces undefined results if fed a negative value for the exponent (src.w).

This instruction provides exponential base 2 partial precision. It allows for a more accurate determination of dest.x*function(dest.y), where function is a user approximation to 2*dest.y over the limited range where dest.y is between 0.0 and 1.0.

Reduced precision arithmetic is used to evaluate the destination z component (dest.z). However, the approximation error must be less than 1/(211) (the absolute error for 10-bit precision) and between 0.0 and 1.0.

Example

// This example changes the value of the vertex color.

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

mov r0, c5  		; load gray into register r0
mov r1, c4.y		; load 1's into register r1
expp r1.x, c6.y		; change r1.x only
			        ; c6.y = 0.5 so r1.x = 20.5 = 1.4
mul r2, r0, r1		; scale r0 by r1

mov oD0,  r2		; output 

// The exp instruction causes the red component to increase about 40%. 
// The resulting color is a dim red 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 colorGray[] = {0.5f,0.5f,0.5f,0.5f};
m_pd3dDevice->SetVertexShaderConstant(5, &gray, 1);

// set register c6
float exp[] = {0.24f, 0.48f, 0.96f, 1.92f};
m_pd3dDevice->SetVertexShaderConstant(6, &exp, 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 for the color green. The next SetVertexShaderConstant 
// method binds the C5 register with the data for the color gray. The 
// last SetVertexShaderConstant method binds the C6 register with the 
// data for the exponent values.