Game Development Reference
In-Depth Information
In code a light source is represented with the D3DLIGHT9 structure.
typedef struct _D3DLIGHT9 {
D3DLIGHTTYPE Type;
D3DCOLORVALUE Diffuse;
D3DCOLORVALUE Specular;
D3DCOLORVALUE Ambient;
D3DVECTOR Position;
D3DVECTOR Direction;
float Range;
float Falloff;
float Attenuation0;
float Attenuation1;
float Attenuation2;
float Theta;
float Phi;
} D3DLIGHT9;
Type —Defines the type of light that we are making and can be one
of the following three types: D3DLIGHT_POINT , D3DLIGHT_
SPOT , D3DLIGHT_DIRECTIONAL
Diffuse —The color of diffuse light that this source emits
Specular —The color of specular light that this source emits
Ambient —The color of ambient light that this source emits
Position —A vector describing the world position of the light
source. This value is meaningless for directional lights.
Direction —A vector describing the world direction that the light
is traveling. This value is not used for point lights.
Range —The maximum range that the ligh t can travel b efore it
“dies.” This value cannot be greater than FLT MAX
_
and has no
effect on directional lights.
Falloff —This value is used only for spotlights. It defines how
the light's intensity weakens from the inner cone to the outer cone.
This value is generally set to 1.0f.
Attenuation0 , Attenuation1 , Attenuation2 —The attenua-
tion variables are used to define how the intensity of light weakens
over distance. These variables are only used for point and spot
lights. The attenuation0 variable defines a constant falloff,
attenuation1 defines the linear falloff, and attenuation2
defines the quadratic falloff. Calculated using this formula, where D
is distance from light source and
A 0 ,A 1 ,A 2 correspond to Attenu-
ation 0 , 1 , and 2 .
1
Attenuation =
AADAD
2
0
1
2
Theta —Used for spotlights only; specifies inner cone angle in
radians.
Phi —Used for spotlights only; specifies outer cone angle in radians.
Search WWH ::




Custom Search