Sunteți pe pagina 1din 4

Shadows make an image much more realistic.

The problem is to compute the shape of the shadow that is cast.
The shape of the shadow is determined by the projections of each of the
faces of the box onto the plane of the foor using the source as the center of
projection. The shadow is the union of the projections of the six faces.
fter drawing the plane using ambient! difuse! and specular light
contributions! draw the six projections of the box"s faces on the plane using
only ambient light.
This will draw the shadow in the right shape and color.
#inally draw the box. \$%f the box is near the plane parts of it might obscure portions
The projection of a &ertex ' on the original object is gi&en by '( ) S * \$' + S,
\$-n\$ + S,./-n\$' + S,.,! where S is the position of the light source! is a point
on the plane! and n is the normal to the plane.
This method works for non+planar surfaces.
The general idea is that any point hidden from the light source is in shadow.
second depth bufer \$the shadow bufer, is used. %t contains depth
information about the scene from the point of &iew of the light source.

each element! the largest pseudo depth possible.
Then! using a camera positioned at the light source! each of the faces in the
scene is scan con&erted! but only the pseudo depth of the point on the face is
tested.
3ach element of the shadow bufer keeps track of the smallest pseudo depth
seen so far.
3xample4 Suppose point P is on the ray from the source through shadow
bufer 5pixel6 d-i.-j.! and that point B on the pyramid is also on this ray. %f the
pyramid is present! d-i.-j. contains the pseudodepth to B7 if it happens to be
absent! d-i.-j. contains the pseudodepth to P.
The shadow bufer calculation is independent of the eye position.
%n an animation where only the eye mo&es! the shadow bufer is loaded
only once.
The shadow bufer must be recalculated7 howe&er! whene&er the
objects mo&e relati&e to the light source.
Render the scene
3ach face in the scene is rendered using the eye camera as usual.
Suppose the eye camera sees point P through pixel p-c.-r.. 8hen rendering
p-c.-r. we must 0nd
the pseudo depth D from the source to P7
the index location -i.-j. in the shadow bufer that is to be tested7
the &alue d-i.-j. stored in the shadow bufer.
%f d-i.-j. is less than D, the point P is in shadow! and p-c.-r. is set using only
ambient light.
9therwise P is not in shadow and p-c.-r. is set using ambient! difuse! and
specular light.
OpenGL Pipeline with GLSL
The pipeline begins with a collection of polygons \$&ertices, as input! followed by a
ertex processor which runs ertex shaders