Setting the Z Range
- Last UpdatedAug 22, 2023
- 1 minute read
The first optimization is to decide a maximum Z range for the pixels to receive shadows.
zFarLimit parameter
By using the parameter csm/params/zFarLimit, you can set a maximum Z value manually.
All the scene pixels inside this value (in View Space) have shadows.
nearFarComputation parameter
By enabling the parameter csm/sample_distribution/nearFarComputation, the code automatically calculates the range of pixels inside the scene that gets shadows.
This is the most precise way to decide which pixels in the current view get shadows.
Note: This can introduce artifacts, such as shimmering. Because each time the Camera moves (or rotates) the Z Range is slightly different from the previous frame.
This function also takes into account the csm/params/zFarLimit parameter.
Scenario example
In this example, some parts of the world are empty. However, if they were completely filled, you should improve the correlation between the Shadow map pixels and the Scene pixels by selecting a maximum range.
The image on the left uses the full Camera Frustum (from Camera near to Camera far) for the shadowed pixels.
The image on the right has reduced the maximum Z for shadowed pixels to about a third. The result is a better usage of the Shadow maps and a better precision for the final shadows.
