| Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1) |
Provides exponential 2x with full precision to at least 1/220.
exp dest, src0
To learn more about registers, see Registers.
float v = src0.w; dest.x = dest.y = dest.z = dest.w = (float)pow(2, v);
// 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
exp 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.