Implementing shadow maps for real-time shadows
As the name implies, shadow maps are used to simulate shadows. The goal of shadow mapping is to determine which parts of a scene are in shadow and which parts are illuminated by a light source by first rendering the scene from the light’s perspective, generating a depth map.
This depth map (also known as a shadow map) serves as a spatial record, storing the shortest distance from the light source to any point in the scene. By encapsulating the scene from the vantage point of the light source, the depth map effectively captures the areas of the scene that are directly visible to the light source and those that are occluded.
This depth map is then used during the main render pass to determine if the fragment can’t be reached from the light by comparing its depth value with the one in the depth map. For each fragment in the scene, we perform a test to evaluate whether it lies in shadow. This is achieved by comparing the...