Soft Shadows Sample


Category: Visuals
Min PC GPU: Fermi-based (GTX 4xx)
Min Tegra Device: Tegra K1

Description

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.

APIs Used

Shared User Interface

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:

Device Input Result
touch 1-Finger Drag Orbit-rotate the camera
2-Finger Drag Move up/down/left/right
2-Finger Pinch Scale the view
mouse Left-Button Drag Orbit-rotate the camera
Right-Button Drag Move up/down/left/right
Middle-Click Drag Scale the view (up:out, down:in)
keyboard Escape Quit the application
  Tab Toggle Tweakbar visibility
gamepad Start Toggle Tweakbar visibility
  Right Thumbstick Orbit-rotate the camera
  Left Thumbstick Move forward/backward. Slide left/right
  Left/Right Triggers Move up/down

App-Specific Controls

This sample has the following app-specific controls:

Device Input Result
keyboard W/S Translate the view forward/back
A/D Translate the view left/right

Technical Details

Overview

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.

Percentage Closer Filtering (PCF)

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.

Percentage-Closer Soft Shadows (PCSS)

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.

Running the Sample

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:

See Also

 

 


NVIDIA® GameWorks™ Documentation Rev. 1.0.200608 ©2014-2020. NVIDIA Corporation. All Rights Reserved.