#include <revolution/gx.h>
void GXInitLightAttn(
GXLightObj* lt_obj,
f32 a0,
f32 a1,
f32 a2,
f32 k0,
f32 k1,
f32 k2 );
lt_obj |
pointer to a light object |
a0 |
angular attenuation coefficient |
a1 |
angular attenuation coefficient |
a2 |
angular attenuation coefficient |
k0 |
distance attenuation coefficient |
k1 |
distance attenuation coefficient |
k2 |
distance attenuation coefficient |
None.
This function sets coefficients used in the lighting attenuation calculation for a given light object. The application must allocate the memory for the light object. The arguments a0, a1 and a2 are used for angular (spotlight) attenuation. The coefficients k0, k1 and k2 are used for distance attenuation. The attenuation function is:
atten = clamp0( a2 * aattn^2 + a1 * aattn + a0 )
k2 * d^2 + k1 * d + k0
where aattn is the cosine of the angle between the light direction and the vector from the light position to the vertex, and d is the distance from the light position to the vertex when the channel attenuation function is GX_AF_SPOT. The light color will be multiplied by the atten coefficient when the attenuation function for the color channel referencing this light is set to GX_AF_SPOT (see GXSetChanCtrl).
All coefficients are represented with a 20-bit floating point format (1-bit sign, 8-bit exponent, and 11-bit significand) in the hardware, as for other arguments associated with vertex lighting. Be aware of possible rounding errors as a result.
The function GXInitLightSpot is a convenient way to set the angle attenuation coefficients based on several spotlight types. The function GXInitLightDistAtten is a handy way to set the distance attenuation coefficients using one of several common attenuation functions.
When the channel attenuation function is set to GX_AF_SPEC, the aattn and d arguments are equal to the dot product of the visual space vertex normal and the half-angle vector set by GXInitSpecularDir.
The macro GXInitLightShininess can be easily used to set attenuation parameters for specular lights.
Be aware that this function does not load any hardware registers directly. To load a light object into a hardware light, use GXLoadLightObjImm or GXLoadLightObjIndx.
GXInitLightAttnA
GXInitLightAttnK
GXInitLightSpot
GXInitLightDistAttn
GXInitLightShininess
GXSetChanCtrl
GXLightObj Initialization Flow
03/01/2006 Initial version.