Unlocking Performance: 
Shadow Optimization Techniques
Kai Moosmann, 24/02/20

Unreal Engine 5 is a force to be reckoned with – a veritable Swiss army knife of game development. But here's the thing: with great power comes great responsibility – and knowing your way around such tools is key to unlocking their full potential.

So, what's optimization all about? Picture this: you've crafted a breathtaking game world filled with stunning visuals and heart-pounding action. But wait, why is it stuttering on your friend's ancient laptop - or worse, even the new rig they just bought? That's where optimization swoops in to save the day – making sure your game not only looks incredible but runs like a dream on as wide an array of devices imaginable.

In Unreal Engine 5, real-time shadow casting can be a vital aspect of creating immersive and realistic scenes. UE5 employs advanced rendering techniques to generate high-quality shadows efficiently, but this process can also increase the polycount in the scene. Unreal Engine 5 utilizes Cascaded Shadow Maps to render shadows dynamically. CSM divides the camera frustum into several cascades, each with its own shadow map resolution and distance range. This technique allows for accurate shadows across varying distances, ensuring consistent shadow quality throughout the scene. However, rendering multiple shadow maps for each cascade can increase the polycount, especially in complex scenes with many objects.

Cube objects casting realtime shadows.

One trick developers use is disabling shadow casting for objects that are already in shadow, and it's not necessarily about aesthetics – it's all about performance. When an object is already within the shadow cast by another object, there's no need to render its shadow separately. By skipping this redundant step, developers can lighten the load on your computer's graphics card and CPU, allowing for smoother gameplay and higher frame rates. 

But manually checking each actor to determine if it should cast a shadow requires time and effort. In a scene with let's say 7000 actors, that's a lot of checking! Not only does this process consume valuable development resources, but it also introduces the potential for human error. Disabling shadows for just one actor can disrupt the visual consistency of the scene tremendously if you're not careful.

Red cubes = shadow casting disabled

Red cubes: Shadow casting disabled.

At Mirebound, our innovative shadow management tool employs ray casts to efficiently determine shadow optimization. First, we capture pertinent objects into an array for evaluation, establishing a reference for shadow frustum analysis. Then, leveraging ray casts, our tool systematically tests individual light sources capable of casting shadows against this array. By tracing rays from the light source to potential shadow-receiving objects, we accurately assess whether an object lies within the shadow frustum of another. This automated process enables us to swiftly identify candidates for shadow optimization, ensuring optimal performance without compromising visual fidelity or gameplay immersion.

Raycasts check for shadow overlaps

Raycasts (projected from the main light source) check for overlapping shadow casts. All cubes are part of an array that, after the raycast is complete, determines if the object should or shouldn't be casting a shadow.

Implementing our shadow management tool has greatly expedited the optimization process at Mirebound, enabling us to work more efficiently. By automating shadow analysis with ray casts and object arrays, we've simplified the identification of areas for optimization, freeing up valuable time for our team. This approach not only improves the performance of our game environments but also allows us to focus on creating engaging experiences without unnecessary distractions. If you're interested in learning more about this, don't hesitate to reach out to us. We're always eager to share our knowledge and insights with fellow developers and enthusiasts.

Wir benötigen Ihre Zustimmung zum Laden der Übersetzungen

Wir nutzen einen Drittanbieter-Service, um den Inhalt der Website zu übersetzen, der möglicherweise Daten über Ihre Aktivitäten sammelt. Bitte überprüfen Sie die Details in der Datenschutzerklärung und akzeptieren Sie den Dienst, um die Übersetzungen zu sehen.