Open topic with navigation
This sample shows two methods of simulating soft shadows with complex casters and receivers. The Percentage-Closer Soft Shadows method includes a convincing impression of the shadow edge (penumbra) sharpening as the shadow caster approaches contact with the shadow receiver.
The OpenGL samples all share a common app framework and certain user interface elements, centered around the "Tweakbar" panel on the left side of the screen, which lets you interactively control certain variables in each sample.
To show and hide the Tweakbar, simply click or touch the triangular button positioned in the top-left of the view.
Other controls are listed below:
This sample demonstrates two techniques for rendering soft shadows: Percentage Closer Filtering (PCS) with a uniform kernel size and Percentage-Closer Soft Shadows (PCSS) with a variable kernel size.
This sample is assuming the shadow map is a regular depth buffer (non-linear depths), and the shadow-map is generated using a perspective projection with the center of projection at the center of the area light simulated by PCSS.
The sample uses a gradient-based depth bias to scale the depth bias based on the uv-space distance from the center of the kernel. To avoid self-shadowing artifacts, an additional depth bias may also been applied while writing depth into the shadow map.
The Percentage Closer Filtering technique uses a uniform size filter kernel, resulting in shadows with a uniformly soft edge. The PCF algorithm is very straightforward and fast, but does not achieve a realistic contact hardening effect. Also, while the kernel size and penumbra width is uniform, the kernel can be scaled to accomodate different sized lights.
Soft shadows are typically rendered in games by using shadow mapping and Percentage Closer Filtering with a uniform kernel size. The Percentage-Closer Soft Shadows (PCSS) algorithm computes a variable kernel size based on the distance between the relative position of the receiver point, an approximation of the blocker, and the area light. It produces perceptually plausible soft shadows that harden on contact (see screenshot above). For more information about PCSS, please refer to the integration guide and other resources listed below.
The "Use Texture" check box renders the ground plane without any shading to show how undersampling artifacts in the shadows are hidden by textures.
The "Visualize Depth" check box outputs the shadow map depths on the screen.
The light source is a square area light. The "Light Size" slider changes the radius of the light.
The shadow technique can be selected in the GUI; this allows comparing variable-size penumbra shadows ("PCSS") with uniform-size penumbra shadows ("PCF"). Shadows can be disabled by selecting "None".
For each shadow technique, the number of samples and their associated sampling patterns used for the blocker search and the PCF filtering can be changed in the GUI. The available presets are:
NVIDIA® GameWorks™ Documentation Rev. 1.0.220830 ©2014-2022. NVIDIA Corporation and affiliates. All Rights Reserved.