Real Time Shadows With Multitexturing Using GLSL
By Nic Farrell
CSC 473 Winter 2010
Shadow Mapping
Shadow mapping is a technique by which shadows can be generated for a scene independent of the scene geometry, quickly. As it is geometry independent it requires no geometric preprocessing such as hull calculation. Additionally it has hardware support on most modern graphics cards, and can be easily integrated with other common techniques such as multi-texturing and alpha blending.
Steps
The technique involves a few basic steps.
1. Render the scene from the position of the light.
2. Store the depth buffer into a texture.
From here the plan changes based on if it is done in hardware or software. Software steps follow:
3. Render the scene using a dim diffuse light.
4. Enable depth testing against the texture holding the depth buffer.
5. Render the scene using a brighter light.
6. Shadows
For a hardware render:
3. Render the scene using a bright light, with light distance done on the vertex shader, and depth comparisons done on the fragment shader.
4. Shadows.
Additional Information
For my project I started off with a tutorial's code for shadows implemented on the software side, and upgraded it to a Percentage-Closer Filtering (PCF) hardware implementation. PCF is a technique whereby each pixel is multi-sampled against the shadow map in order to generate softer, smoother shadows. This technique is important as Shadow Mapping's primary problem is that small shadow maps can lead to steps in the shadows. By using PCF the steps become soft, and with enough sampling smooth. My project includes several different types of PCF on a variable switch to highlight the differences. Usage note: the shadow PCF mode can be changed by pressing 'm'.
Thanks to the fact that the depth test is done on the hardware side its quite reasonable to do a 4x4 or even 8x8 PCF which results in very nice looking shadows, even with a fairly small shadow map (1024x1024 render, with a 512x512 shadow map).
References
1. OpenGL Shadow Mapping Tutorial - Paul's Projects - base code I used.
2. ShadowMapping with GLUT and GLSL - picked up some tips on fixing various problems.