Light Position, Range and Attenuation

The position, range, and attenuation properties are used to define a light's location in world space, and how the light it emits behaves over distance. Like all light properties, these are carried within a light's D3DLIGHT2 structure.

Position

Light position is described using a D3DVECTOR structure in the dvPosition member of the D3DLIGHT2 structure. The x-, y-, and z-coordinates are assumed to be in world space. Directional lights are the only type of light that don't use the position property.

Range

A light's range property determines the distance, in world space, at which meshes in a scene no longer receive light emitted by that object. The dvRange member contains a floating-point value that represents the light's maximum range, in world space. Most applications set the range to the maximum possible value, D3DLIGHT_RANGE_MAX, which is defined in D3d.h. Directional and parallel-point lights don't use the range property.

Attenuation

Attenuation controls how a light's intensity decreases toward the maximum distance specified by the range property. Light attenuation is represented by three D3DLIGHT2 structure members: dvAttenuation0, dvAttenuation1, and dvAttenuation2. These members contain floating point values typically ranging from 0.0 to 1.0, controlling a light's constant, linear, and quadratic attenuation. Many applications set the dvAttenuation1 member to 1.0 and the others to 0.0, resulting in light intensity that attenuates evenly over distance—from maximum intensity at the source, to zero intensity at the light's range. You can combine attenuation values to get more complex attenuation effects. Or, you might set them to values outside of the normal range to create even stranger attenuation effects; negative attenuation values make a light that gets brighter over distance. For more information about the mathematical model that Direct3D uses to calculate attenuation, see Light Attenuation Over Distance. Like the range property, directional and parallel-point lights don't use the attenuation property.