lhyanor.org

  • Increase font size
  • Default font size
  • Decrease font size

Simple Shadow Mapping

E-mail Print PDF

Shadow Mapping is a simple technique to archive dynamic shadows in realtime rendering. The idea is to render a geometry that will possibly occlude itself or another geometry in a first pass from the viewpoint of the light source. The vertex shader has to transform the vertices into light-projection space and the pixel shader has to store the z-value of the projected fragments into a depth buffer.

Depth Map

In the following real rendering pass, each fragment's coordinates are again transformed into the shadow map space, and their depth values are compared. To avoid artefacts, there has to be an adjustable bias that avoids self shadowing of lit fragments.

This way, the decision if a certain fragment is lit by the light source reduces to one simple branch:

if ((shadowPos.z / zMax - zBias) > tex2D(ShadowMap, hom_to_texcoords(shadowPos)).r) lit = false;

If the fragment is lit, we draw the lambertian term, otherwise, only ambient light is rendered.

Shadow Mapping

Last Updated on Sunday, 03 January 2010 11:15