3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Shadow mapping 179<br />
In order to test a point against the depth map, its position in the scene<br />
coordinates must be transformed into the equivalent position as seen by the<br />
light. This is accomplished by a matrix multiplication. The location of the<br />
object on the screen is determined by the usual coordinate transformation, but<br />
a second set of coordinates must be generated to locate the object in light<br />
space.<br />
The matrix used to transform the world coordinates into the light's viewing<br />
coordinates is the same as the one used to render the shadow map in the first<br />
step (under OpenGL this is the product of the modelview and projection<br />
matrices). This will produce a set of homogeneous coordinates that need a<br />
Visualization of the depth map projected<br />
onto the scene<br />
perspective division (see <strong>3D</strong> projection) to become normalized device coordinates, in which each component (x, y,<br />
or z) falls between −1 and 1 (if it is visible from the light view). Many implementations (such as OpenGL and<br />
Direct<strong>3D</strong>) require an additional scale and bias matrix multiplication to map those −1 to 1 values to 0 to 1, which are<br />
more usual coordinates for depth map (texture map) lookup. This scaling can be done before the perspective<br />
division, and is easily folded into the previous transformation calculation by multiplying that matrix with the<br />
following:<br />
If done with a shader, or other <strong>graphics</strong> hardware extension, this transformation is usually applied at the vertex level,<br />
and the generated value is interpolated between other vertices, and passed to the fragment level.<br />
Depth map test<br />
Once the light-space coordinates are found, the x and y values usually<br />
correspond to a location in the depth map texture, and the z value corresponds<br />
to its associated depth, which can now be tested against the depth map.<br />
If the z value is greater than the value stored in the depth map at the<br />
appropriate (x,y) location, the object is considered to be behind an occluding<br />
object, and should be marked as a failure, to be drawn in shadow by the<br />
drawing process. Otherwise it should be drawn lit.<br />
If the (x,y) location falls outside the depth map, the programmer must either<br />
decide that the surface should be lit or shadowed by default (usually lit).<br />
Depth map test failures.<br />
In a shader implementation, this test would be done at the fragment level. Also, care needs to be taken when<br />
selecting the type of texture map storage to be used by the hardware: if interpolation cannot be done, the shadow will<br />
appear to have a sharp jagged edge (an effect that can be reduced with greater shadow map resolution).<br />
It is possible to modify the depth map test to produce shadows with a soft edge by using a range of values (based on<br />
the proximity to the edge of the shadow) rather than simply pass or fail.<br />
The shadow mapping technique can also be modified to draw a texture onto the lit regions, simulating the effect of a<br />
projector. The picture above, captioned "visualization of the depth map projected onto the scene" is an example of<br />
such a process.