UE4: Optimizing Foliage-Heavy Scene

  • Requirement: Unreal Engine 4
  • Difficulty: Easy
  • Written By: Lee Zhi Eng
  • Last Update: 15 Jul 2019


Unreal Engine is one of the top-notch game engines that is capable of rendering beautiful scenes like the one shown below:

However, developers may get too excited with its capability and gone overboard when designing their game levels. This may result in poorly-optimized scenes that can affect the overall performance of your game and leave your players a bad taste.

There are many ways to optimize your scene, but before that we must understand the main reasons why your game lags and how we can solve these issues.

Level of Details (LOD)

One common problem with scenes like this is that the polygon count increases whenever you add an extra foliage or prop into the scene. To solve this issue, we use something called Level of Details (or LOD for short) to eliminate the extra polygonal details when an object is located far away from the game camera.

LOD in action

LOD is an effective method to reduce the on-screen polygon count by replacing your model with a lower level (lower polygon count) mesh when it reaches a specific distance from the camera. The further away the model is from the game camera, the lower polygon version of the model is used for rendering on the screen.

The image below illustrates the different LODs of a foliage model by showing its wireframe:

Different LOD levels

Depending on what tool you use, you may or may not need to manually build these different meshes for your models. Professional tools like SpeedTree handles this automatically for you but might come at a cost.

Once you have prepared the different meshes for your 3D object, it’s time to apply it in Unreal Engine. You can open up the Static Mesh Editor by double-clicking on a 3D model in the Content Browser:

Static Mesh Editor in UE4

Under the Details tab, you can set the different LOD settings for your model and determine when the particular LOD will be used for rendering by changing the Screen Size attribute.

LOD 0 is the highest polygon count mesh, follow by LOD 1, LOD 2, LOD 3 and so on… each level has a lower polygon count than its preceding level. There is no limit to how many LODs you can apply to your model, but bear in mind that the more LODs you have for each and every 3D model in your game, the larger the size of your game will become. You can limit the number of LODs at the LOD Settings section in the static mesh editor:

LOD Settings

Foliage Overdraw

Let’s go back to the scene below for a second.

You may not notice any issues in the screenshot above, but there are in-fact many minor issues going on that may add up to cause a bigger performance problem eventually.

To open up the can of worms, click on the Lit button located at the top left corner of your viewport and select Shader Complexity. Your viewport will then change into something like this:

Forest on fire?

As you can see, the scene has many issues especially on the tree leaves. This is because the leaves have transparent areas that need to be culled and hence increased the complexity of the rendering process. This turns into snowball effect when many leaves are stacking on top of each other and resulting in the red-colored mess you see above.

One common way to create leaves for our foliage model is to use quads and apply textures with transparency to the model, as shown in the image below:

Too much overdraw!

While there is nothing wrong with this approach, the white area (i.e. the transparent area) of the texture has to be tested by the GPU, fragment-by-fragment, to determine its z position before getting culled. This process requires extra computing power to execute — which means, the more transparent area there is, the more computing power is wasted for the unnecessary z-testing and culling.

To solve this issue, we can sacrifice the polygon count a little bit and add more corners to our leaf model so that we can minimize the transparent area. The image below illustrates the result of this method:

Adding polygons to reduce overdraw

Early Z-Pass

Other than the methods above, we can also ask Unreal Engine to generate the z-pass at the beginning of the rendering process. This will allow you to avoid expensive shading operations on pixels that do not contribute to the final image.

You can enable early z-pass by going to Edit Project Settings…

After that, the Projects Settings window will pop open. Look for Optimizations section and change its settings to the values shown below:

After you have changed the settings, Unreal Engine will ask you for a restart. It may take some time to restart the game engine before opening the scene, as all the shaders have to be recompiled.

Once the scene has been opened again, you may notice it looks exactly the same as before:

However, if you open up the Shader Complexity rendering again, the trees are now all displayed in green!

However, do note that the early z-pass method is a combination of forward rendering and deferred rendering. It might cause visual artifacts or even affect the performance if your game is heavily relying on deferred rendering and uses a ton of post processing effects.

There is no one-size-fit-all method, so pick the one that suit your project the most. Cheers!

Leave a Reply