Workshop 2 - Shadow-Mapping
How things start:
Set up the transforms to be able to “draw from the light” - edit:
SetOrthoMatrix with reasonable values and send the matrices to the appropriate shaders.
Once you get the transforms in place - make sure your matrices are right.
First, get the geometric debug to show your scene from the light’s perspective to work.
In the base code
SHOW_LIGHT_COLOR can be set to
true to show the colors of the scene from the light camera’s view.
L key to toggle
There are two shaders used for this debug view:
Correct output should look something like the image below, except with texture colors visible:
SHOW_LIGHT_DEPTH can be used to display the depths of the scene as rendered from the light’s perspective.
K key to toggle
There are depth debug shaders:
that will draw a large quad and texture map on the depth map.
When the light depth’s map view to work, it should look something like:
Now that we have the shadow depth rendered, we need to use this information to shade the objects.
First, we need to do some setup in
render(), provide the shadow map texture to the scene draw call.
Also provide the light matrix.
To complete the shadow mapping, you need to edit the final pair of shaders
shadow_vert.glslto transform the point into Light space per vertex (hint: what matrix do you need)
shadow_frag.glslto complete the shadow depth test:
- shift the coordinates from to
- read off the stored depth (
.) from the ShadowDepth, using the shifted.xy
- compare to the current depth (
.z) of the projected depth
- return if the point is shadowed
You can also implement percentage closer shadows, which blend neighboring depth values to scale shadow intensity.
Final shadow mapped look: