DirectX SDK |
Direct3D determines the distance between a light source and a vertex being lit by taking the magnitude of the vector that exists between the light's position and the vertex. This is represented by the following formula:
In the preceding formula, D is the distance being calculated, V is the position of the vertex being lit, and L is the light source's position. If D is greater than the light's range (dvRange), no further attenuation calculations are made and no light effects from the light are applied to the vertex. If the distance is within the light's range, Direct3D then applies the following formula to calculate light attenuation over distance for point lights and spotlights (directional lights don't attenuate):
In this attenuation formula, A is the calculated total attenuation and D is the distance from the light source to the vertex. The dvAttenuation0, dvAttenuation1, and dvAttenuation2 values are the light's constant, linear, and quadratic attenuation factors as specified by the members of a light object's D3DLIGHT7 structure. (Not surprisingly, the corresponding structure members are dvAttenuation0, dvAttenuation1, and dvAttenuation2.) The system normalizes D to be within the range [0.0,1.0], where 0.0 indicates no light at the vertex, and 1.0 indicates full light intensity at the vertex.
The constant, linear and quadratic attenuation factors act as coefficients in the formula—you can produce a wide variety of attenuation curves by making simple adjustments to them. You could set the constant attenuation factor to 1.0 to create a light that doesn't attenuate (but will still be limited by range), or you can experiment with different values to achieve various attenuation effects.
The attenuation formula used by Direct3D computes an attenuation value that typically ranges from 1.0 at the light source to 0.0 at the maximum range of the light. The attenuation value is multiplied into 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. After computing the light attenuation, Direct3D also considers spotlight effects (if applicable), the angle that the light reflects from a surface, as well as the reflectance of the current material to come up with the diffuse and specular components for that vertex. For more information, see Spotlight Falloff Model and Reflectance Model.
Direct3D determines the distance between a light source and a vertex being lit by taking the magnitude of the vector that exists between the light's position and the vertex. This is represented by the following formula:
In the preceding formula, D is the distance being calculated, V is the position of the vertex being lit, and L is the light source's position. If D is greater than the light's range (range), no further attenuation calculations are made and no light effects from the light are applied to the vertex. If the distance is within the light's range, Direct3D then applies the following formula to calculate light attenuation over distance for point lights and spotlights (directional lights don't attenuate):
In this attenuation formula, A is the calculated total attenuation and D is the distance from the light source to the vertex. The attenuation0, attenuation1, and attenuation2 values are the light's constant, linear, and quadratic attenuation factors as specified by the members of a light object's D3DLIGHT7 type. (Not surprisingly, the corresponding structure members are attenuation0, attenuation1, and attenuation2.) The system normalizes D to be within the range [0.0,1.0], where 0.0 indicates no light at the vertex, and 1.0 indicates full light intensity at the vertex.
The constant, linear and quadratic attenuation factors act as coefficients in the formula—you can produce a wide variety of attenuation curves by making simple adjustments to them. You could set the constant attenuation factor to 1.0 to create a light that doesn't attenuate (but will still be limited by range), or you can experiment with different values to achieve various attenuation effects.
The attenuation formula used by Direct3D computes an attenuation value that typically ranges from 1.0 at the light source to 0.0 at the maximum range of the light. The attenuation value is multiplied into 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. After computing the light attenuation, Direct3D also considers spotlight effects (if applicable), the angle that the light reflects from a surface, as well as the reflectance of the current material to come up with the diffuse and specular components for that vertex. For more information, see Spotlight Falloff Model and Reflectance Model.