Graphics Reference
In-Depth Information
treated in almost the same way as positional lights, except that the direction to
the light is always the same, regardless of the position of a point. This simpli-
ies the light direction in any lighting computation by leting you use the light
direction directly, instead of computing the direction between the point and
the light position. Conceptually, for a directional light, you simply treat the
light as a homogeneous point at infinity.
Spot Lights
Spot lights include speciications for the direction, cutof, and atenuation. To
use a spot light, you must compute the angle between the light direction and
the direction from the light to the vertex. By comparing that to the light's cutoff
angle and using the light's atenuation, you can then determine the value of
the light at the vertex. This requires the vertex shader to send both the light
position and the light direction to the fragment
shader, and the fragment shader must calculate
the angle between the light direction and the
vector from the light to the point in order to see
whether to use the light in the color computa-
tion.
In the vertex shader example below, you
can see the kind of computation that is needed
to compute the light intensity for a spot light.
The color always includes the ambient light, and
it uses diffuse and specular light for the particu-
lar light source only if the point is close enough
to the light direction. The effect of spot lighting
is shown in Figure 6.2, where the light shines
on only part of the geometric primitive, but we
omit the specular contribution in this case to
simplify the computation.
A vertex shader for lighting with a spot
light or directional light (or both) requires us
to manage that lighting function ourselves. The
fixed-function OpenGL spot light on the stan-
dard teapot is shown in Figure 6.2 (top), while
we can use the capabilities of GLSL and the ver-
tex shader to create the “fuzzy” spot light shown
in Figure 6.2 (botom). The vertex shader for this
example has only three things to do:
Figure 6.2. The effect of a spot light on a teapot
that lies on the edge of the light's illumination
area. Traditional OpenGL spot light (top) and a
spot light with a fuzzy edge (botom).
Search WWH ::




Custom Search