Microsoft DirectX 8.0 (Visual Basic) |
Provides lighting partial support.
lit vDest, vSrc0
The following code fragment shows the operations performed by the lit instruction to write a result to the destination.
SetDestReg(); SetSrcReg(0); m_TmpReg.x = 1; m_TmpReg.y = 0; m_TmpReg.z = 0; m_TmpReg.w = 1; float power = m_Source[0].w; const float MAXPOWER = 127.9961f; if (power < -MAXPOWER) power = -MAXPOWER; // Fits into 8.8 fixed point format else if (power > MAXPOWER) power = -MAXPOWER; // Fits into 8.8 fixed point format if (m_Source[0].x > 0) { m_TmpReg.y = m_Source[0].x; if (m_Source[0].y > 0) { // Allowed approximation is EXP(power * LOG(m_Source[0].y)) m_TmpReg.z = (float)(pow(m_Source[0].y, power)); } } WriteResult();
The lit instruction produces undefined results if fed a negative value for the exponent.
This instruction calculates lighting coefficients from two dot products and a power. The source vector is assumed to contain the values shown in the following pseudocode.
vSrc0.x = N*L ; The dot product between normal and direction to light. vSrc0.y = N*H ; The dot product between normal and half vector. vSrc0.z = ignored ; This value is ignored. vSrc0.w = power ; The power, this value must be in the range from –128.0 through 128.0.
Reduced precision arithmetic is acceptable in evaluating vDest.z. An implementation must support at least 8 fraction bits in the power argument. Dot products are calculated with normalized vectors, and clamp limits are -128 to 128.
Error should correspond to a logp and expp combination, or no more than approximately 1 least significant bit (LSB) for an 8-bit color component.
The following example illustrates how the lit instruction might be used.
lit r0, r1