RayTraced Distance Field Soft Shadows

​In this How-to we will cover how to setup and use dynamic Ray Traced Soft Shadows with Mesh Distance Fields enabled for our project. This page will cover how to enable Distance Field Shadows within your light sources and explore the various settings and options to improve shadow quality for your game.

How to Enable Distance Field Soft Shadows

1. Navigate to the Modes panel, in the Light section, click on a Directional, Spot, or Point Light and then drag it into the Viewport.

2. With the light source selected, look at its properties in the Details panel. In the Transform section set the Mobility to Movable.

3. Now in the Distance Field Shadows section, place a checkmark in the box next to RayTraced Distance Field Shadows.

Directional Light

Point/Spot Light

​If this option is grayed out make sure you have first enabled the option for Generate Mesh Distance Fields in the Project Settings.

4. At this point Ray Traced Distance Field Soft Shadows will be enabled for your scene. Try dragging in a few Static Meshes from the Content Browser to see Distance Field Shadows working in your scene.

When using a Directional Light it can be helpful to set Dynamic Shadow Distance Movable Light property to 0 in the Details panel. This will disable Cascaded Shadow Maps so that you will only see the shadow casts from the Mesh Distance Field. This can be helpful for testing in your scene and diagnosing any potential Mesh Distance Field issues.

Light Source Settings

Dependnig on whether you select to use a Directional Light source or Point/Spot Light source you will have different options that are available to be adjusted relative to that light type.

Directional Light

Properties

Description

Distance Field Shadow Distance

Distance at which the ray traced cascade should end. Ditsance Field shadows will cover the range between Dynamic Shadow Distance and this distance.

Light Source Angle

This is the light source angle in degrees.

RayTraced Distance Field Shadows

Whether to use ray traced distance field area shadows.

Ray Start Offset Depth Scale

Controls how large of an offset ray traced shadows have from the receiving surface as the camera gets further away. This can be useful to hide self-shadowing artefacts from low resolution distance fields on huge static meshes.

Comparison of Cascaded Shadow Maps vs Distance Field Shadows

Point/Spot lights

Properties

Description

Source Radius

Size of the light source sphere. Larger values result in larger penumbras, but also cost more performance.

RayTraced Distance Field Shadows

Whether to use ray traced distance field area shadows.

RayTraced Distance Field Shadows

Controls how large of an offset ray traced shadows have from the receiving surface as the camera gets further away. This can be useful to hide self-shadowing artefacts from low resolution distance fields on huge static meshes.

Comparison of Default Shadow Maps vs Distance Field Shadows

Light Properties

​The settings for RayTraced Distance Field Shadows is located in the Details panel in the Distance Field Shadows section of the selected light source. This setting is off by default.

Source Radius

​In this demonstration you can see how adjusting the Source Radius of a Point or Spot light will directly affect the area shadows. Lower values provide crisp sharp shadows based on the Mesh Distance Fields resolution while higher values will allow for softer edges at further distances from the light source. When adjusting the Source Radius think of this as the size of the light itself, so for instance, if this were a household light bulb you would want to use a lower value like 5 or 10 as the Source Radius.

Light Source Angle

In this demonstration you can see that adjusting the Light Source Angle of your Directional Light will result in softer or sharper shadows depending on the distance the shadow is from the source mesh. By using a value of 0 the shadows will be sharp, while higher values will soften the shadow at further distances.

Ray Start Offset Depth Scale

In this demonstration for Ray Start Offset Depth Scale you can adjust where the ray that is traced to generate the shadow will start from. This can be helpful in reducing small artifacts with lower resolution Mesh Distance Fields on larger meshes. By default this property has a very low value, and by using minimally higher values you can reduce the artifacts like in the below. The higher the value the further the ray trace will be from the surface of the Mesh Distance Field which will cause inaccurate shadow representation.

Static Mesh build Settings

In each Static Meshes Editor there are multiple settings that can be adjusted that can be used specifically with Mesh Distance Fields. You can access these settings via the Build Settings in LOD0 of the Static Mesh Editor.

​Currently Mesh Distance Fields will only generate for LOD0. If you are using 4.9 or later Distance Fields are optimized by using the Global Distance Field to combine them at further distances. For further reading on Global Distance Fields see this page here.

Distance Field Resolution Scale

The setting for Distance Field Resolution Scale will allow you to increase the resolution of the Mesh Distance Field that is generated for your static mesh. It may be necessary to sometimes adjust value for larger or more complex static meshes.

In the images below you will see that the status does not a high enough Mesh Distance Field resolution to fully block the light. Increasing the resolution minimally can help get the resolution needed to provide a more accurate shadow and block the light that is passing through.

​When increasing the Distance Field Resolution Scale adjust the value incrementally until you're are happy with the resolution quality. Some meshes will only get to a certain level before they cannot be any more accurate than they already are.

By increasing the Distance Field Resolution Scale you will also increase the volume texture size used for the distance field of this static mesh which will in-turn use more memory.

Generate Distance Field as if Two-Sided

In this demonstration you can see the difference that Generate Distance Field as if TwoSided can make. This is ideal for use with foliage, but it will cost more since the resulting shadows are not fully opaque. For additional notes using this method and how it was used in the Kite Demo created by Epic Games here.

Distance Field Replacement Mesh

This setting will use any selected static meshes distance field mesh in the place of the static meshes own distance field mesh. In the example below the Material Sphere's Distance Field Mesh has been replaced with that of SM_Pillar_Frame from the Starter Content pack.

You will find this setting available in the Static Mesh Editor in the Build Settings under LOD0. From the drop-down next to Distance Field Replacement Mesh you will be able to select any Static Mesh that is currently located in the Content Browser.

Conclusion

​By using Distance Field Soft Shadows in your game you can get nice area shadows along with shadows that can be used a farther distances for a minimal cost compared to Cascaded Shadow Maps. This method of shadowing was used extensively in the Kite Demo and in Fortnite that are made by Epic Games. Using the properties and settings detailed in this How-to you should be able to create nice dynamic shadows and tweak the settings that fit your games style.