# Attenuation and Spotlight Factor (Direct3D 9)

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

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 equations.

Atten = 1/( att0_{i} + att1_{i} * d + att2_{i} * dÂ²)

Where:

Parameter | Default value | Type | Description | Range |
---|---|---|---|---|

att0_{i} |
0.0 | FLOAT | Constant attenuation factor | 0 to +infinity |

att1_{i} |
0.0 | FLOAT | Linear attenuation factor | 0 to +infinity |

att2_{i} |
0.0 | FLOAT | Quadratic attenuation factor | 0 to +infinity |

d | N/A | FLOAT | Distance from vertex position to light position | N/A |

- Atten = 1, if the light is a directional light.
- Atten = 0, if the distance between the light and the vertex exceeds the light's range.

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

The distance between the light and the vertex position is always positive.

d = | L_{dir} |

Where:

Parameter | Default value | Type | Description |
---|---|---|---|

L_{dir} |
N/A | D3DVECTOR | Direction vector from vertex position to the light position |

If d is greater than the light's range, that is, the Range member of a **D3DLIGHT9** structure, Direct3D makes no further attenuation calculations and applies no effects from the light to the vertex.

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 Attenuation1 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 Factor

The following equation specifies the spotlight factor.

Parameter | Default value | Type | Description | Range |
---|---|---|---|---|

rho_{i} |
N/A | FLOAT | cosine(angle) for spotlight i | N/A |

phi_{i} |
0.0 | FLOAT | Penumbra angle of spotlight i in radians | [theta_{i}, pi) |

theta_{i} |
0.0 | FLOAT | Umbra angle of spotlight i in radians | [0, pi) |

falloff | 0.0 | FLOAT | Falloff factor | (-infinity, +infinity) |

Where:

rho = norm(L_{dcs})^{.}norm(L_{dir})

and:

Parameter | Default value | Type | Description |
---|---|---|---|

L_{dcs} |
N/A | D3DVECTOR | The negative of the light direction in camera space |

L_{dir} |
N/A | D3DVECTOR | Direction 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.

## Related topics