Platform SDK: DirectX

Light Position, Range and Attenuation

[C++]

The position, range, and attenuation properties define a light's location in world space, and how the light it emits behaves over distance. Like all light properties you use in C++, these are contained in a light's D3DLIGHT7 structure.

Position

Light position is described using a D3DVECTOR structure in the dvPosition member of the D3DLIGHT7 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 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. Three D3DLIGHT7 structure members represent light attenuation: dvAttenuation0, dvAttenuation1, and dvAttenuation2. These members contain floating-point values ranging from 0.0 through infinity, controlling a light's attenuation. Some applications set the dvAttenuation1 member to 1.0 and the others to 0.0, resulting in light intensity that changes as 1 / D, where D is the distance from the light source to the vertex. The maximum light intensity is at the source, decreasing to 1 / (Light Range) at the light's range. Typically, an application will set dvAttenuation0 to 0.0, dvAttenuation1 to a constant value, and dvAttenuation2 to 0.0.

You can combine attenuation values to get more complex attenuation effects. Or, you might set them to values outside 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 lights don't use the attenuation property.

[Visual Basic]

The D3DLIGHT7 type includes members that your Visual Basic application uses to define a light's position, range, and attenuation properties. These describe a light's location in world space, and how the light it emits behaves over distance.

Position

Light position is described using a D3DVECTOR type in the position member of the D3DLIGHT7 type. 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 range 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 (18.446+e18). Directional 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. Three D3DLIGHT7 members represent light attenuation: attenuation0, attenuation1, and attenuation2. These members contain floating point values ranging from 0.0 through infinity, controlling a light's attenuation. Some applications set the attenuation1 member to 1.0 and the others to 0.0, resulting in light intensity that changes as 1 / D, where D is the distance from the light source to the vertex. The maximum light intensity is at the source, decreasing to 1 / (Light Range) at the light's range. Typically, an application will set dvAttenuation0 to 0.0, dvAttenuation1 to a constant value, and dvAttenuation2 to 0.0.

You can combine attenuation values to get more complex attenuation effects. Or, you might set them to values outside 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 lights don't use the attenuation property.