In this lesson, you will learn how to identify, analyze, and optimize shadow-related bottlenecks to maintain high performance in complex outdoor environments.
Shadows are often the most expensive component of an outdoor scene, especially when using Virtual Shadow Maps (VSM) or traditional Cascaded Shadow Maps (CSM). When your frame rate dips, the GPU Visualizer (accessible via Ctrl+Shift+Comma) is your best friend. Look specifically for the ShadowDepths or VirtualShadowMap passes. If these bars are wide, your shadow rendering is likely bottlenecking your frame time.
Profiling Shadow Cost
To diagnose the issue, use the console command r.Shadow.Virtual.ShowDebugVisualizer 1. This allows you to see the "page" distribution of your Virtual Shadow Maps. If you see an overwhelming number of pages being invalidated or updated every frame, it usually means you have too many dynamic objects or high-detail geometry moving near the camera, forcing the GPU to re-render shadow maps constantly.
Optimization Strategies
If you identify shadow rendering as the primary performance cost, consider these three adjustments:
- Adjust Shadow Bounds: Select your light source and check the
Dynamic Shadow Distance. If it is set too high, you are rendering shadows for distant objects that the player can barely see. Reduce this value to focus rendering budget on the immediate foreground. - Use Shadow Proxies: For complex meshes, create simplified collision or proxy meshes to act as the shadow caster. You can set this up via the
Cast Shadow As Two Sidedor by adjusting theShadow Proxysettings in the static mesh asset editor. - Optimize Light Setup: Multiple overlapping dynamic lights are a performance killer. Ensure you are using
Light Channelsto limit which lights affect specific geometry, reducing the number of shadow-casting primitives the engine must process per frame.
By narrowing the scope of what casts a shadow and ensuring that the shadow map resolution is appropriate for the camera's distance, you can significantly reclaim GPU headroom.
Key Takeaway: Profiling shadow performance is about balancing visual fidelity with the cost of updating shadow maps; prioritize shadow resolution for near-field objects and reduce the complexity of distant shadow casters.