Shadow Casting

High level overview of shadows.

Choose your operating system:

Windows

macOS

Linux

lighting_overview_banner_001.png

Shadows make objects feel grounded in the world and give the viewer a sense of depth and space. Static shadows are free as far as rendering goes, but dynamic shadows can be one of the biggest drains on performance. This document covers the basics of the 4 types of shadow casting you can have in Unreal Engine 4.

Static Lights

Static lights cast completely static shadows and light, meaning they will have no direct effect on dynamic objects (static lights are baked into the Indirect Lighting Cache so they have some effect) like on the bronze men below.

LI_StaticMeansStatic.png

The bronze character on the left is standing in the light of a static light, it does not affect them in any way (lighting or shadows) while the one on the right is in the light of a stationary light .

Directional Light Cascading Shadow Maps (Whole Scene Shadows)

Directional Stationary Lights are special because they support whole scene shadows through Cascaded Shadow Maps at the same time as static shadowing. This is very useful in levels with a lot of animating foliage; you want to have moving shadows around the player but do not want to pay the cost of having many cascades to cover a large view range. The dynamic shadows are faded into static shadows over distance, such that the transition is often

  1. To set this up, just change the Dynamic Shadow Distance StationaryLight of a DirectionalLightStationary to be the range at which you want the fade to happen.

Stationary Light Shadows

Dynamic objects (like StaticMeshComponents and SkeletalMeshComponents with Mobility set to Movable) must integrate into the static shadowing of the world from distance field shadowmaps. This is accomplished with Per Object shadows. Each movable object creates two dynamic shadows from a stationary light: a shadow to handle the static world casting onto the object, and a shadow to handle the object casting onto the world. With this setup, the only shadowing cost for stationary lights comes from dynamic objects that it affects. This means the cost can vary from very little to a large amount, depending on how many dynamic objects there are. With enough dynamic objects, it is more efficient to use a Movable light instead.

In the scene below, the spheres are all movable, and they all receive shadows from the static world and cast their own shadows, which merge with the distance field shadows. The Per Object shadow frustums for each Movable component are also shown.

DynamicObjectShadowFrustums.png

Per Object shadows used by movable components apply a shadowmap to the object's bounds, therefore the bounds must be accurate. For Skeletal meshes this means they should have a physics asset. For particle systems, any fixed bounding box must be large enough to contain all particles.

Dynamic Shadows

Movable lights cast completely dynamic shadows (and light) on everything. None of its light data will get baked into the light maps and it will be free to cast dynamic shadows on everything. Static Meshes, Skeletal Meshes, effects, etc... will all cast and receive dynamic shadows from a movable light.

On average, movable dynamic shadow casting lights are the most expensive.

Preview Shadows

When editing a Stationary or Static Light in such a way that the lighting becomes un-built, Preview Shadowing is enabled to give you an idea of what the shadows will look like when lighting is rebuilt.

These shadows are shown in the editor with the text "Preview" to distinguish them from pre-existing shadows as seen below.

UnbuiltShadows.png

If you test your game in the editor prior to rebuilding lighting, the Preview Shadows will disappear as the preview only exists within the editor and not during Play In Editor.

UnbuiltShadowsPIE.png

In order to generate shadows from the Preview Shadows, you will need to select Build Lighting from the Build option off the Main Editor Tool Bar.

BuiltShadows.png

You can disable Preview Shadows by un-checking the Preview Shadows Indicator option in the Viewport's Show/Visualize menu.

If you wish to tweak the Light Function Material used to project this text, it can be found at: Engine/EditorMaterials/PreviewShadowIndicator

All Together

When all the shadows are brought together, each bringing their strengths to make up for the weakness of the others, impressive and rapidly rendered visuals can be brought to life.

LO_Shadows_Footer.png

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