D3D Soft Shadows Sample

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

Description

This sample demonstrates three different techniques for soft shadows on complex geometry: Percentage Closer Filtering (PCS) with a uniform kernel size, Percentage-Closer Soft Shadows (PCSS) with a variable kernel size, and Contact Hardening Shadows (CHS) with a dynamically generated fixed size kernel

APIs Used

App-Specific Controls

This sample has the following app-specific controls:

Device Input Result
mouse Left-Click Drag Rotate the scene
Middle Button Scroll Zoom the scene
Right-Click Drag Rotate the light
keyboard W/S Translate the view forward/back
  A/D Translate the view left/right
  F2 Change rendering device
F3 Toggle reference rasterizer

Technical Details

Overview

This sample demonstrates three techniques for rendering soft shadows: Percentage Closer Filtering (PCS) with a uniform kernel size, Percentage-Closer Soft Shadows (PCSS) with a variable kernel size, and Contact Hardening Shadows (CHS) with a dynamically generated fixed size kernel.

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 due. 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.

Contact Hardening Shadows (CHS)

The Contact Hardening Shadows technique uses a fixed size kernel, but the kernel coefficients are dynamically generated to accomodate a variable width penumbra. The PCF algorithm relies on gather4 instructions for sampling the shadow map, so while it can be performant, the width of the penumbra is limited by the size of the filter kernel.

Running the Sample

The left button controls the light position and the right button the camera position. The mouse wheel zooms in and out. The light source is a square area light. The "Light Size" slider changes the radius of the light.

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:

The Shadow Technique dropdown allows us to compare using PCSS (variable-size penumbra) with non-PCSS (fixed-size penumbra), and CHS (limited variable-size penumbra).

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.

See Also

 

 


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