Hey all,
For the mobile game we are developing, we would like to implement shadow volumes to allow us to have point lights that cast shadows. Right now I have silhouette detection and shadow volume extrusion working. A separate GameObject is created for each shadow volume - I want to eventually do this all on the GPU, but this seemed like the most straight-forward way to get started.
This has been new territory for me and has left me with a few questions.
-
When “rendering” the shadow volume mesh to perform the stencil operations, do I render this at the same time as the scene, or do I have to render it after the full scene renders?
-
Once the stencil buffer is populated, how do I actually render the shadows? Do I have to use render textures? Do I apply some type of shader to the camera? Something else?
Thank you for any help!
The order is usually as follows:
- Render the scene normally
- Render the shadow geometry with your shaddow shader which usually has two passes if you do “Carmack’s reverse”.
- Render the “shadow” by rendering a fullscreen quad with your shadow colour with a special shader that does a stencil test.
I’ve once implemented stencil shadows in a C++ directX project and it worked pretty well.
ps: If you have trouble understanding how the depth fail algorithm works, i suggest reading this amazing letter of John Carmack where he describes the process of how he discovered it.
edit
The actual rendering can be done using one camera and use a queue offset in your shaders to make sure they are rendered after each other. The fullscreen quad could be rendered the same way or by using the GL class inside OnPostRender in a script attached to the camera. You can use pretty much the sample script that is shown in the docs.