Skip to content

Shadows

Vladislav Kantaev edited this page Dec 6, 2023 · 6 revisions

Setup

To enable shadows:

  • In the pipeline asset's Shadows section, set Mode to Shadow Mapping;
  • Ensure the Directional toggle in Shadows/Shadow Maps is enabled;
  • Ensure the main (directional) light on the scene is:
    • enabled;
    • Mode is set to Realtime or Mixed;
    • Shadow Type is any mode other than No Shadows.

📝 Note: this page describes the traditional approach for shadow maps. Toon RP also supports Variance Shadow Maps and Blob Shadows.

Common Parameters

📝 Note: a smooth penumbra can be achieved via either Soft Shadows or Variance Shadow Maps.

Shadow Ramp

Shadow receivers use a ramp separate from the global when applying shadows.

Threshold, Crisp Anti Aliased, and Smoothness control the shadow ramp.

Shadow Distance

Increasing Max Distance improves the general draw distance for shadows. However, the larger the distance, the less detailed shadows are.

Distance Fade controls how smooth should the shadows be cut off near the max distance.

Pattern

A stylized pattern can be applied to shadows. The pattern is sampled using world space position. Tiling can be controlled via Pattern Scale.

Example with pattern Pattern Texture and scale (1, 0, 1):

Pattern Example

Directional Shadows

Cascades

Cascaded shadow maps work by splitting the view into several sections, and rendering shadows separately for each of them. While a bit costly, this allows having different pixel densities per-cascade. This means more resolution for closer objects, less for farther ones.

CSM Shadow Quality

Picture taken from learn.microsoft.com.

The maximum number of cascades is 4. The beginning of each cascade relative to the camera can be controlled via Cascade Ratio 1, Cascade Ratio 2, and Cascade Ratio 3 respectively.

Bias

Shadow acne is a very common problem associated with shadow mapping.

A solution is to increase Depth and Slope biases. However, if set too high, they can cause so-called Peter Panning (a shadow disconnected from the object casting it).

No Bias Right Amount of Depth and Slope Bias Too High Bias
Acne No Acne Peter Panning

Another solution is to work around Normal Bias. It offsets the shadow mesh along the geometry normals. Sometimes, however, it causes shadows to be too narrow. Not only it causes incorrect visuals, it can also make the light "bleed" - pass where it shouldn't.

In Toon RP, Normal Bias can be both positive and negative. Positive values "inflate" the geometry, while negative ones "deflate" it.

No Bias Right Amount of Normal Bias Too High Bias
Acne No Acne Light Bleeding