Week 13 Entry - Shadow Mapping

Shadow Mapping

Shadow mapping is a method to create shadows in a scene, and it critically operates from the perspective of each light in the scene. Conceptually, if a camera with the proper projection is capable of having a direct line of sight to parts of objects in the scene, any other parts of the scene (particularly any objects or parts of objects that are of the same line of projection but with higher z-depth values) will be understood as in shadow. Whatever light can see is in light. What light can't see will be shadowed. Depth maps of the scene are written in shaders to a texture. This buffer will be written off-screen rather than displayed to the screen, but it can be debugged using the Chrome Spector.js extension.

Using a directional light requires the depth map to be represented with orthographic projection. The location of each fragment on the texture space is determined by transforming from world space to view space (of the light), to projection space (of the light), to normalized device coordinates, and finally to texture space. This same step order is followed when checking if a fragment sample from the camera's perspective is to be represented with shadow or as lit.

Bias Offsets, Peter-Panning, and Aliasing

Getting the shadows to work with the camera's perspective render shows issues with offsets. A bias of 0.008 is used to offset the boolean expression of (depth+bias < textureDepth)

Introducing too much bias produces an effect referred to as "Peter-Panning." This problem creates noticible spacing between the object and the initialization of the fragment shader determining that the fragment should be shadowed.

I'm not certain I remember what caused this result to be displayed, but I find it pretty interesting.

As you can see from the specular lighting, the shadow map is currently not being re-rendered relative to the light position (in this case, because this is directional light, the light direction).

Finally rendered with dynamic shadow mapping relative to an adjustable light direction. There is currently a notable amount of aliasing, harsh jagged lines in the shadow's representation in the scene.

Thanks to OGLDEV's tutorial, I've taken advantage of a 9-fragment sampling average by implementing a Percentage Closer Filter (PCF). This adds a notable overhead if too many samples are used, but it reasonably smooths out the edges of the shadows in the scene.


Comments

Popular Posts