keywords:UE4, Shadow Optimization, Scene Optimization, 阴影, 场景, 优化

The latest article: UE5 Shadow Notes

Shadow Optimization

Enable Dynamic Shadow Distance

Testing Case: 500 Actors are rendering in screen, Camera height is 4000, DirectionalLight’s property Dynamic Shadow Distance StationaryLight (Default value is 0, which means disabled) should be larger than the straight-line distance from Camera to Actor (Beacause the distance need to cover all Actors, so the distance would be better be larger ), otherwise frame rate would drop down from 200 fps to 100 fps.

How to Cast Shadow by Camera Distance

Tow factors

  • RayTraced Distance Field Soft Shadows
  • Scalability of Shadow
RayTraced Distance Field Soft Shadows
  1. Project Settings -> Engine -> Rendering -> Lighting -> enable Generate Mesh Distance Fields (Need to restart Editor)

  2. Modify DirectionalLight’s properties: DistanceField Shadow Distance and RayTraced DistanceField Shadows

    Effect

Relationship between DistanceField Shadow Distance & Dynamic Shadow Distance
  • Stationary

  • Moveable

Reference:RayTraced Distance Field Soft Shadows
https://docs.unrealengine.com/en-us/Engine/Rendering/LightingAndShadows/RayTracedDistanceFieldShadowing

Scalability of Shadow
  • Cinematic

  • Medium

  • Low

Scalability Reference
https://docs.unrealengine.com/en-US/engine/performance/scalability/scalabilityreference

Cast shadow by level of detail (LOD)

Console command:

//LOD level to force for the shadow map generation only, -1 is off.
r.ForceLODShadow

It works only for non-dynamic lights.

ShadowMap Memory Size

Testing case:
Place 1024 cubes in an empty level, casting shadow by stationary DirectionalLight, and check the memory cost of shadow map. (console cmd:stat rhi)

Shadows quality: Low

Shadows quality: Cinematic

Conclusion:
The higher the shadow quality, the larger the light map resolution, and the larger the memory cost of shadow map .

How to cast character shadow on mobile device

1st way: Movable Directional Light

How to Enable Dynamic Shadows & Correct Reflection Maps on Mobile
https://forums.unrealengine.com/development-discussion/android-development/41661-tip-how-to-enable-dynamic-shadows-correct-reflection-maps-on-mobile

Lighting for Mobile Platforms
https://docs.unrealengine.com/latest/INT/Platforms/Mobile/Lighting/

4.7 release mobile shadows
https://answers.unrealengine.com/questions/180482/47-release-mobile-shadows.html

2nd way: Stationary Directional Light

Enable Cast Modulated Shadows:

Casting Shadow (Common questions)

How to Cast Shadow for SkeletalMesh

Constructor:

UPrimitiveComponent->CastShadow = true;

Run-time:

UPrimitiveComponent->SetCastShadow(true);

UPrimitiveComponent->CastShadow = true; would not work out of Constructor.

How to cast shadow when Actor hidden in game
USkeletalMeshComponent->SetHiddenInGame(true);
USkeletalMeshComponent->bCastHiddenShadow = true;
How to prevent mesh from receiving shadows

Set material’s Shading Model to Unlit, then set you base color to go to the emissive(so its not totally black), but Matellic and Specular lost.

Reference
https://answers.unrealengine.com/questions/258748/how-to-disable-receiving-shadows-on-a-particular-m.html

Reference

Documents

Dynamic Scene Shadows
https://docs.unrealengine.com/en-us/Resources/ContentExamples/DynamicSceneShadows

Cascaded Shadows
https://docs.unrealengine.com/en-us/Platforms/Mobile/Lighting/HowTo/CascadedShadow

RayTraced Distance Field Soft Shadows
https://docs.unrealengine.com/en-us/Engine/Rendering/LightingAndShadows/RayTracedDistanceFieldShadowing

Shadow Casting
https://docs.unrealengine.com/en-us/Engine/Rendering/LightingAndShadows/Shadows

Unreal Engine 4 的 光和影
https://www.unrealengine.com/zh-CN/blog/chn-unreal-engine-4-light-and-shadow

[UE4] Introduction to Shadow Rendering function
https://qiita.com/EGJ-Yutaro_Sawada/items/2a8a1467ebaaa9795fe0

Shadow Casting: High level overview of shadows. (Recommended)
https://docs.unrealengine.com/4.27/en-US/BuildingWorlds/LightingAndShadows/Shadows/

Fake Dynamic Lighting

Using modulate blend material to make a light
https://twitter.com/klemen_lozar/status/1033409819116359681

How to Create Blob Shadows in Unreal Engine 4 (Part 1)
https://www.youtube.com/watch?v=qMYpAFGpNv0

Capsule Shadows

Capsule Shadows
https://docs.unrealengine.com/en-US/Engine/Rendering/LightingAndShadows/CapsuleShadows/Overview/index.html


人会长大三次。第一次是在发现自己不是世界中心的时候。第二次是在发现即使再怎么努力,终究还是有些事令人无能为力的时候。第三次是在,明知道有些事可能会无能为力,但还是会尽力争取的时候。