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.

Screenshot

APIs Used

  • GL_EXT_shadow_samplers
  • GL4.0

Shared User Interface

The Graphics 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.

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:

  • "25/25 Poisson": 25 samples for the blocker search, 25 samples in the PCF filtering, all samples using a Poisson disk
  • "32/64 Poisson": 32 samples for the blocker search, 64 samples for the PCF filtering, all samples using a Poisson disk
  • "100/100 Poisson": 100 samples for the blocker search, 100 samples for the PCF filtering, all samples using a Poisson disk
  • "64/128 Poisson" 64 samples for the blocker search, 128 samples for the PCF filtering, all samples using a Poisson disk
  • "49/225 Regular": 49 samples for the blocker search, 225 samples for the PCF filtering, all samples using regular sampling (faster than Poisson disk)