Shadow Mapping Techniques
CSC 472 Final Project - Christopher Gibson
Premise:
The focus of this project is to learn more about depth buffers and their role in hardware-accelerated shadows as well as the various techniques used in shadow mapping. Frame Buffer Objects were also involved, and different techniques at building, handling and utilizing FBOs were also researched in order to handle the depth buffers gathered from the light source.
Technology:
- Hard Shadows
- Dithered Shadows
- Soft Shadows (Variable Resolution and Size)
- Projected Textures
- Dynamic Lights
- Complex and Simple Scenes
Techniques:
Hardware-accelerated Shadows:
An FBO is constructed to take in the depth values from the perspective of the light. Once the scene is rendered from the camera's view, the depth texture is passed into a shader during the regular render phase. Utilizing shadow2DProj to project the depth value using a stored light matrix, the GPU returns whether or not the current point is in shadow.
Dither/Soft Shadows:
In order to 'soften' the edges of the shadows being cast, we must look past the current point being drawn and check surruonding points in the light's depth buffer. Averageing the results we get helps us determine how dark or light to make the pixel, causing a blurred effect on the shadow's silhouette. Dithered shadows are done similarly, modulating using the fragment's x and y values to offset the test points.
Projected Textures:
Projected textures are done similarly to the shadow projections, the current vertex is multiplied by the stored light matrix, and a texel from the texture is grabbed using texture2Dproj, literally 'projecting' the texture into space.
Application:
Controls:
- SPACE - Change render view (normal, shadowed, depth representation)
- S - Start/Stop light spin
- X - Start/Stop camera spin
- C - Change scene complexity
- T - Change shadowing method
- H - Increase Blur Kernel Size
- Y - Decrease Blur Kernel Size
- J - Increase Blur Kernel tests
- U - Decrease Blur Kernel tests
Known Bugs:
- In some machines, the first 'render state' only renders white, no shading and no materials.
- Sometimes materials will not render correctly, making every object in the scene with a white diffuse.
Code References:
- The ShadowHelper.h file is based off of the code from http://fabiensanglard.net/shadowmappingPCF/index.php
- OpenGL SuperBible
- OpenGL "Orange Book" Shader Language References
References:
http://www.cescg.org/CESCG-2009/papers/VUT-Schwaerzler-Michael.pdf
http://fabiensanglard.net/shadowmappingPCF/index.php
PCSS Reference:
http://http.download.nvidia.com/developer/presentations/2005/SIGGRAPH/Percentage_Closer_Soft_Shadows.pdf
http://developer.download.nvidia.com/shaderlibrary/docs/shadow_PCSS.pdf