Skip to content

Latest commit

 

History

History
111 lines (66 loc) · 9.36 KB

Shadows-in-HDRP.md

File metadata and controls

111 lines (66 loc) · 9.36 KB

Shadows in the High Definition Render Pipeline

The High Definition Render Pipeline’s Lights can cast shadows from one GameObject onto another. They emphasize the position and scale of GameObjects, which adds a degree of depth and realism to a Scene that could otherwise look flat.

Shadow map resolution

The resolution of a Light’s shadow map determines the size of its shadow maps. The larger the shadow map, the more precise the shadows can be, and the better the High Definition Render Pipeline (HDRP) can capture small details in the shadow casting geometry. Rendering shadow maps at higher resolutions make them look sharper.

Set the resolution of a specific Light’s shadow map in the Shadows section of the Light component.

The number of shadow maps HDRP renders per Light depends on the Type of the Light:

  • A Spot Light renders one shadow map.
  • A Point Light renders six shadow maps (the number of faces in a cubemap).
  • A Directional Light renders one shadow map per cascade. Set the cascade count of Directional Lights from the HD Shadow Settings of your Scene’s Volumes. The default value is four cascades.

Shadow atlases

HDRP renders all real-time shadows for a frame using a shadow map atlas for all punctual light shadows, and another shadow map atlas for Directional Light shadows.

Set the size of these atlases in your Unity Project’s HDRP Asset. The atlas size determines the maximum resolution of shadows in your Scene.

For example, the default size of an atlas is 4096 x 4096, which can fit:

  • Four shadow maps of 1024 x 1024 pixels.
  • Two shadow maps of 1024 x 1024 plus four shadow maps of 512 x 512 plus 16 shadow maps of 256 x 256.

Controlling the maximum number of shadows on screen

In addition to the atlases, you can also set the maximum number of shadow maps HDRP can render in a single frame. To do this, open your Unity Project’s HDRP Asset, navigate to the Shadows section, and enter a Max Shadows on Screen value. If the number of shadow maps on screen is higher than this limit, HDRP does not render them.

Shadow Bias

Shadow maps are essentially textures projected from the point of view of the Light. HDRP uses a bias in the projection so that the shadow casting geometry does not self-shadow itself.

In HDRP, each individual Light component controls its own shadow biasing using the following parameters:

  • Near Plane
  • ShadowMask Mode
  • View Bias Scale
  • View Bias
  • Normal Bias
  • Edge Leak Fixup
  • Edge Tolerance Normal
  • Edge Tolerance

Find these settings under the Shadows section. If some of the property fields are missing, click the Advanced Properties button to expose them. For details on how each property controls the shadow biasing, see the Light documentation.

Using high shadow bias values may result in light "leaking" through Meshes. This is where there is a visible gap between the shadow and its caster and leads to shadow shapes that do not accurately represent their casters.

Shadow filtering

After HDRP captures a shadow map, it processes filtering on the map in order to decrease the aliasing effect that occurs on low resolution shadow maps. Different filters affect the perceived sharpness of shadows.

To change which filter HDRP uses, change the Filtering Quality property in your Unity Project’s HDRP Asset. There are currently four filter quality presets for directional and punctual lights.

Filtering Quality Algorithm
Low Point/Spot Lights: Percentage Closer Filtering (PCF) 3x3 (4 taps).
Directional Lights: PCF Tent 5x5 (9 taps).
Medium Point/Spot Lights: PCF 5x5 (9 taps).
Directional Lights: PCF Tent 5x5 (9 taps).
High Point/Spot/Directional Lights: Percentage Closer Soft Shadow (PCSS). You can change the sample count to decrease the quality of these shadows. This decreases the resource intensity of this algorithm. To change the sample count for shadows cast by that Light, set the Filter Sample Count in the Inspector of each Light component.
Very High Point/Spot: Use High for their Filtering Quality.
Directional Lights: Improve Moment Shadows.

The PCF algorithm applies a fixed size blur. PCSS and Improved Moment Shadows algorithms apply a different blur size depending on the distance between the shadowed pixel and the shadow caster. This results in a more realistic shadow, that is also more resource intensive to compute.

Shadowmasks

HDRP supports two Mixed Lighting Modes:

Enabling shadowmasks

To use shadowmasks in HDRP, you must enable shadowmask support in your Unity Project’s HDRP Asset and then make your Cameras use shadowmasks in their Frame Settings :

  1. Under Render Pipeline Supported Features, tick the Shadow Mask checkbox. This enables support for shadowmasks in your Unity Project.
  2. Next, you must make your Cameras use shadowmasks. In your HDRP Asset, navigate to Default Frame Settings > Lighting and tick the Shadow Mask checkbox to make Cameras use shadowmasks by default.

Specific settings in HDRP

For flexible lighting setups, HDRP allows you to choose how you want the shadowmasks to behave for each individual Light. You can change the behavior of the shadowmask by changing a Light’s Shadowmask Mode. Set the Light’s Mode to Mixed to expose Shadowmask Mode in the Shadow Map drop-down of the Shadows section.

Shadowmask Mode Description
Distance Shadowmask Makes the Light cast real-time shadows for all GameObjects when the distance between the Camera and the Light is less than a punctual light’s Fade Distance. See below for the alternative distance property that Directional Lights use. When the distance between the Light and the Camera is greater than the Fade Distance, HDRP stops calculating real-time shadows for the Light. Instead, it uses shadowmasks for static GameObjects, and non-static GameObjects do not cast shadows.
Shadowmask Makes the Light cast real-time shadows for non-static GameObjects only. It then combines these shadows with shadowmasks for static GameObjects when the distance between the Camera and the Light is less than the Fade Distance. When the distance between the Light and the Camera is greater than the Fade Distance, HDRP stops calculating real-time shadows for the Light. Instead, it uses shadowmasks for static GameObjects and non-static GameObjects do not cast shadows.

Directional Lights do not use Fade Distance. Instead they use the Max Distance property located in the HD Shadow Settings of your Scene’s Volumes.

Distance Shadowmask is more GPU intensive, but looks more realistic because real-time lighting that is closer to the Light is more accurate than shadowmask textures with a low resolution chosen to represent areas further away.

Shadowmask is more memory intensive because the Camera uses shadowmask textures for static GameObjects close to the Camera, requiring a larger resolution shadowmask texture.

Contact Shadows

Contact Shadows are shadows that HDRP ray marches in screen space, inside the depth buffer, at a close range. They provide small, detailed, shadows for details in geometry that shadow maps cannot usually capture.

For details on how to enable and customize Contact Shadows, see the Contact Shadows documentation.

Only one Light can cast Contact Shadows at a time. This means that, if you have more than one Light that casts Contact Shadows visible on the screen, only the dominant Light renders Contact Shadows. HDRP chooses the dominant Light using the screen space size of the Light’s bounding box. A Direction Light that casts Contact Shadows is always the dominant Light.