Microsoft DirectX 8.1 (C++)

Attenuation and Spotlight Terms

The diffuse and specular lighting components of the global illumination equation contain terms that describe light attenuation and the spotlight cone. These terms are described below.

Attenuation Term

The attenuation of a light depends on the type of light and the distance between the light and the vertex position. To calculate attenuation, use one of the following three equations.

ParameterDefault value TypeDescription
att0i(0,0,0,0) FLOATLinear attenuation factor
att1i(0,0,0,0) FLOATSquared attenuation factor
att2i(0,0,0,0) FLOATExponential attenuation factor
di(0,0,0,0) FLOATDistance from vertex position to light position

The att0, att1, att2 values are specified by the Attenuation0, Attenuation1, and Attenuation2 members of the D3DLIGHT8 structure.

The distance between the light and the vertex position is always positive.
di = ||Ldir||
where:
ParameterDefault value TypeDescription
Ldir0.0 D3DVECTORDirection vector from vertex position to the light position

If di is greater than the light's range, that is, the Range member of a D3DLIGHT8 structure, Direct3D makes no further attenuation calculations and applies no effects from the light to the vertex. The dvAttenuation0, dvAttenuation1, and dvAttenuation2 values are the light's attenuation constants as specified by the members of a light object's D3DLIGHT8 structure. The corresponding structure members are Attenuation0, Attenuation1, and Attenuation2.

The attenuation constants act as coefficients in the formula—you can produce a variety of attenuation curves by making simple adjustments to them. You can set Attenuation0 to 1.0 to create a light that doesn't attenuate but is still limited by range, or you can experiment with different values to achieve various attenuation effects.

The attenuation at the maximum range of the light is not 0.0. To prevent lights from suddenly appearing when they are at the light range, an application can increase the light range. Or, the application can set up attenuation constants so that the attenuation factor is close to 0.0 at the light range. The attenuation value is multiplied by the red, green, and blue components of the light's color to scale the light's intensity as a factor of the distance light travels to a vertex.

Spotlight Term

 

ParameterDefault value TypeDescription
rho0.0 N/AAngle
phi0.0 FLOATPenumbra angle of spotlight in radians. Range: [thetaI, p)
theta0.0 FLOATUmbra angle of spotlight in radians. Range: [0, p)
falloff0.0 FLOATFalloff factor. Range: (-infinity, +infinity)

where:

rho = norm(Ldcs).norm(Ldir)
ParameterDefault value TypeDescription
Ldcs0.0 D3DVECTORDirection vector from origin to the light position in camera space
Ldir0.0 D3DVECTORDirection vector from vertex position to the light position

After computing the light attenuation, Direct3D also considers: spotlight effects if applicable, the angle that the light reflects from a surface, and the reflectance of the current material to calculate the diffuse and specular components for that vertex. For more information, see Spotlight Model.