Distance Field Soft Shadows

An overview of using Mesh Distance Fields to create dynamic soft area shadowing.

Choose your operating system:

Windows

macOS

Linux

Shadowing from movable light sources is provided using object Distance Fields for each rigid mesh to compute efficient area shadowing from dynamic light sources. In Unreal Engine 4 (UE4), this is called Distance Field Shadows (DFS). To calculate shadowing, a ray is traced from the point being shaded through the scene's Signed Distance Fields (SDF) toward each light. The closest distance to an occluding object is used to approximate a cone trace for about the same cost as the ray trace. It allows for high-quality area shadowing from spherical light source shapes.

Scene Setup

This feature requires that Generate Mesh Distance Fields be enabled in your Project Settings in the Rendering section. See the Mesh Distance Fields page for more information.

To enable Distance Field Shadowing, start by dragging a Light into the scene and set its Mobility to Movable and then from the Light Details panel, enable Distance Field Shadows .

DirectionalLightDFSettings1.png

For a step-by-step guide, follow the Using Distance Field Shadowing How-To guide to learn more.

Area Shadowing Settings

Each Light type can use Distance Fields shadows to create soft area shadows. These shadows simulate real-world shadows by retaining sharp contact shadows closer to the base and softening the farther the shadow stretches away

Traditional Shadow Map

Distance Field Shadow

For additional information about Light source settings and additional examples, see the Mesh Distance Fields Reference page.

Point and Spot Light Source Radius

For Point and Spot Lights, the Source Radius is used to determine how large shadow penumbras are on a light. Area shadows are computed with sharp contacts that get softer over long distances. On a Point and Spot Light, it is represented by a yellow sphere.

LightSourceVis.jpg

The Editor draws the source shape of the light with yellow lines.

The Light's source radius sphere should not be intersecting the scene, or it will cause lighting artifacts.

Source Radius: | 0

Source Radius: | 50

The Distance Field shadows are from a Point Light using a Source Radius to soften the shadows cast by the doorway, bench, and piano on the surrounding geometry.

A demonstration of a Point Light moving through the scene casting area shadows from each shadow casting mesh.

For additional information about Point and Spot Light settings, see the Mesh Distance Fields Reference page.

Directional Light Source Angle

For Directional Lights, the Light Source Angle is used to determine how large shadow penumbras are on a light. Distance Field Shadows have very few self-intersection problems and therefore avoid the leaking and over-biasing problems in the distance that traditional shadow mapping would have.

Light Source Angle: | 1

Light Source Angle: | 3

Distance Field Shadows from a Directional Light with a Light Source Angle adjusted for softer shadowing.

In most cases, Cascaded Shadow Maps (CSM) are used to provide dynamic shadowing of a Directional Light. These require rendering the meshes in the scene into several cascade shadow maps (levels of detail for shadowing). The cost of shadowing increases at large shadow distances because of how many meshes and triangles are being rendered into the shadow maps.

Distance Field Shadows work much more gracefully in the distance, doing shadowing work only for visible pixels. Cascaded Shadow Maps can be used to shadow an area near the camera while RTDF shadows will shadow farther regions up to the Distance Field Shadow Distance that is set.

Cascaded Shadow Maps Only

Cascaded Shadow Maps & Distance Field Shadows

When Distance Field Shadows are enabled, anything beyond the set value for Cascaded Shadow Map Distance will be shadowed using Distance Fields. In the comparison using both CSM and RTDF shadowing, the CSM shadow is set to 1,000 CM (centimeters), which allows for sharp shadowing near the camera with lots of added detail. In the shadowing distance beyond 1,000 CM, RTDF shadowing is used, which shadows objects up to 1.2 KM (kilometers) away. This enables the trees in the far distance to cast shadows when this would be too costly for Cascaded Shadow Maps.

A demonstration of changing time of day using Distance Field Shadowing with a Directional Light.

For additional information about Directional Light settings, see the Mesh Distance Fields Reference page.

Scene Representation

Each level that you create is made up of all these Mesh Distance Fields for your placed Actors. When Mesh Distance Fields are generate, they are done so "offline" using triangle raytracing that stores the results in a volume texture. Because of this, mesh distance field generation cannot be done at runtime. This method computes the Signed Distance Field rays in all directions to find the nearest surface and stores that information.

You can visualize the Mesh Distance Fields that represent your scene by using the viewport and selecting Show > Visualize > Mesh Distance Fields .

Menu to Enable Visualization

Mesh Distance Field Visualization

Click images for full size.

When you see areas that are more white than gray, it means that many steps were needed to find the intersection of the mesh surface. Rays at grazing angles to surfaces took many more steps to intersect than would have for a simpler mesh.

Mesh Distance Field Quality

Distance Field shadow fidelity has a significant impact on shadow accuracy, more so than Distance Field Ambient Occlusion . Increased Mesh Distance Field resolution will improve the shadows cast by Static Meshes. Use the Mesh Distance Field Visualization to inspect the quality.

Distance Field Resolution: | 1

Distance Field Resolution: | 5

Distance Field Resolution: | 1

Distance Field Resolution: | 5

Scene View with Distance Field Shadowing

Mesh Distance Field Visualization

Shadows for Mesh Distance Fields are computed at half-resolution with a depth-aware upsample. Temporal Anti-Aliasing (TAA) does a good job of helping reduce the flickering that can happen with half-resolution but jagged edges can still appear sometimes.

For additional information about Mesh Distance Field quality, see the Mesh Distance Fields page.

Performance

The following GPU times were done on a Radeon 7870 at a resolution of 1920x1080 in a full game scene:

Test

Cascaded/Cuebmap Shadow Maps Cost (ms)

Distance Field Shadows Cost (ms)

Percentage (%) Faster

Directional Light with distance of 10k units, 3 Cascaded Shadow Maps

3.1

2.3

25%

Directional Light with distance of 30k units, 6 Cascaded Shadow Maps

4.9

2.8

43%

One Point Light with a large radius

1.8

1.3

30%

Five Point Lights with a small radius

3.2

1.8

45%

Optimizations

Below are some things you can do or should consider to optimize Distance Fields shadowing:

  • On a Directional Light, a larger Light Source Angle increases cost as more objects have to be considered for each point being shadowed.

  • Larger values for Distance Field Shadow Distance reduce the culling efficiency.

  • Shadows from meshes with Two-Sided Distance Field Generation (enabled in the Build Settings ) will cost more as the resulting shadows are never fully opaque.

With Unreal Engine 4.16, the following optimizations can be enabled:

  • Enable these from the Project Settings > Rendering :

    Click image for full size.

    • Compress Mesh Distance Fields can be enabled to store the Distance Fields volume texture compressed in memory. It will reduce how much memory they use, however, if you're using level streaming, they will cause hitches in your gameplay when these levels are streamed in.

    • Eight Bit Mesh Distance Fields can be enabled to store the Distance Fields volume texture in an 8-bit fixed point format instead of the default 16-bit floating point. It will only use half the memory previously used but can introduce some artifacts when you have a large or thin mesh.

  • Global Distance Field caches mostly static primitives with their mobility set to Static or Stationary. The full Global Distance Field inherits from mostly static cache, so when a Movable primitive is modified only other Movable primitives in the vicinity need to be recomposited into the Global Distance Field.

Limitations

Distance Field Shadowing shares the general limitations of the Mesh Distance Fields technique. For more information about these limitations, see the Mesh Distance Fields page.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss