Object Culling In Unreal Engine
Culling is the process of excluding rendering objects to optimise performance. There’s a wide range of culling options with a few coming as standard with Unreal Engine. When done correctly objects should be culled aggressively but in a way that the player will never notice.
One thing to bear in mind with object culling is that Nanite works on an entirely different system and as such they will not be culled by traditional means, however, Nanite has its own improved culling built in, which is mostly automatic and doesn’t require much though. See the Nanite section for more information.
Note: When testing culling, hit ‘G’ to enter ‘Game Mode’ to see an accurate view of what you are looking at.
Tip: You can freeze the rendering in place by typing ‘freezerendering’ into the console. This allows you to easily see what is and isn’t being rendered outside of what the camera can see. To unfreeze it simply type the command in again.
Object Bounds
Rather than a potentially costly check to see if an object is visible by checking if any of its potentially millions of polygons are peaking around another object, Unreal uses ‘Bounds’. Each object has an automatically generated box and sphere around it that it will use for culling queries. Both of these will completely cover the object but are often bigger than it, especially the sphere.
The bounds sphere is used for a faster test to check the distance of an object. This allows for a cheap and simple Cull Distance check, one of the cheapest and most effective ways of culling objects.
The bounds box will normally fit much closer to your mesh and is used for more accurate culling queries such as occlusion and frustum culling. Allowing these forms of collision to be more accurate means it is still able to cull things as early as possible but also ensures that you won’t have any popping in of assets as players walk around corners or spin the camera around.
You can manually change the bounds of an object by opening the asset and changing the ‘Positive Bounds Extension’ and ‘Negative Bounds Extension’ settings under ‘General Settings’ > ‘Advanced’. You can also change the bounds on individual actors in a scene by changing the ‘Bounds Scale’ setting under ‘Rendering’ > ‘Advanced’.
Frustum
Frustum culling describes the act of hiding anything that the player is not currently looking at. It does this by creating a frustum shape (like a pyramid with the top cut off) that extrudes from the camera. This accurately describes what is within view from the player’s camera. Anything that is within this frustum is rendered as usual, anything outside of this is hidden.
Frustum culling has been one of the staples of culling and optimisation as a whole since the advent of 3D games due to how cheap and effective it is. As such it should always be used in a game unless there’s a very good reason not to. For this reason, it’s enabled by default in Unreal Engine.
Cull Distance
Cull distance culling is the cheapest of all the culling options. The reason for this is that it only has to query each object against a single figure, the distance from the player’s camera, which in itself is a very cheap calculation. It works by taking a value that you wish to be the minimum or maximum range that you want the objects to be visible at. There are a few ways of doing this, the first is to set the ‘Min Draw Distance’ and ‘Desired Max Draw Distance’ on an actor in the scene. The ‘Min Draw Distance’ will ensure that anything closer to the camera than this will not be rendered. The ‘Desired Max Draw Distance’ sets what you want the maximum draw distance to be, but is considered the ‘desired’ distance as any other culling that is more aggressive than this will cull it sooner.
Cull Distance Volumes
In a game with many assets it can be unrealistic to go through every actor, work out when they should no longer be visible and then set custom distance culling settings for each. For this we have a specific volume that we can add to a scene to handle this for us, the Cull Distance Volume. We can place this volume into a scene and everything within this area will have the settings applied.
The Cull Distance Volume allows you to set value pairs that check the size of an asset and determine the distance that it should be culled based on it. For instance you could set a value of the Size setting to 500 and the Cull Distance value to 50000. As the default unit scale in Unreal Engine is centimeters, this means anything smaller than 500cm will be culled when they are more than 500m away.
It is good practice to set an upper limit to culling by setting a size and leaving the Cull Distance setting as 0 (doesn’t cull). This means that any very large objects that are bigger than this size, such as skyscrapers or mountains, will not get culled at distance and you will still be able to see them.
View Distance Settings
View Distance scalability settings (covered earlier) affect the cull distance. This is done by using a multiplier to change the setting entered either as part of the actor’s ‘Desired Max Distance’ or the settings from the Cull Distance Volume. These settings can be changed by editing the DefaultScalability.ini file found in the Engine > Config folder. Below is a table of the scalability settings and the default percentage distance it uses for each.
View Distance Scalability Setting | View Distance Percentage |
---|---|
Near | 40% |
Medium | 60% |
Far | 80% |
Epic | 100% |
Cinematic | 1000% |