This is an OpenGL implementation of the stencil shadow volume technique in C++. The project was developed for a computer graphics course as a school project. Stencil shadows are a reliable method for generating dynamic and real-time shadows. The technique supports point lights, self-shadowing, and utilizes a geometry shader to create shadow volumes and triangles with adjacency information. In addition to the shadows, the application includes an environmental map projected to infinity and a functional camera for navigating the scene.
The rendering process involves four passes:
- Depth pass: This pass fills the z-buffer and is essential for the Z-fail algorithm to ensure accurate shadows, even when the camera is inside the shadow volume.
- Environmental pass (optional): This pass displays the environmental map projected to infinity.
- Shadow pass: During this pass, the shadow volumes are created and rendered to the stencil buffer.
- Lighting pass: This pass illuminates the scene using the stencil buffer as a mask to apply lighting effects.
Mesh conditions to support functionnal stencil shadows:
- Shadow casting mesh must be a crack free surface.
- It must be a topological 2 manifold, i.e. a topological space whose points all have open disks as neighborhoods.
- It must be homeomorphic to the sphere.
- It must look locally like the plane everywhere.
- It must be able to find the silhouette edges of every shadow caster and build the corresponding shadow volume.
To code this whole project, I had to watch and read many sources. Here are some important ones that really helped me:
- Understanding of the stencil buffer - https://learnopengl.com/Advanced-OpenGL/Stencil-testing
- Creating silhouettes with the geometry shader - https://ogldev.org/www/tutorial39/tutorial39.html
- Stencil Shadow Volume by OGL - https://ogldev.org/www/tutorial40/tutorial40.html