Game Development Reference
In-Depth Information
configure the stencil test to pass only when the value in the stencil buffer is zero
using the following function calls.
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_EQUAL);
glStencilFunc(GL_EQUAL, 0, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
Since the lighting pass adds to the ambient illumination already present in the
color buffer, we need to configure the blending function as follows.
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
After the lighting pass has been rendered, we clean up by resetting a few render-
ing states back to those needed by the ambient pass for the next frame using the
following function calls.
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glStencilFunc(GL_ALWAYS, 0, ~0);
10.3.7 Scissor Optimization
When using an attenuated light source, it is usually convenient to define a range r
beyond which the light source does not contribute any illumination to the world.
Although this is not a physically correct model, using an attenuation function that
vanishes at a distance r from the light's position allows us to quickly cull any
light source whose sphere of illumination does not intersect the view frustum.
When a light source's sphere of illumination is visible, the area within the view-
port that could possibility be affected by the light source may not be the entire
viewport. By projecting the sphere of illumination to the image plane and using
the scissor rectangle to limit our drawing to the projected area of influence, we
can avoid a significant amount of superfluous rendering of both shadow volumes
and illuminated surfaces.
Suppose that we have a point light source whose center lies at the point L in
eye space and whose range is r , as shown in Figure 10.14. We wish to find four
planes, two parallel to the x axis and two parallel to the y axis, that pass through
Search Nedrilad ::




Custom Search