Optimising SpeedTree for GPU Instancing in Unity 5.5
I hear a lot of concerns about the poor performance of SpeedTree when you put a lot of them in your scene – and yes SpeedTree can bog your scene down, but at the same time, if you set them up properly they can perform very nicely and they look awesome!
So lets start by describing how your scene typically works when it is rendered – for every object in your scene that object along with all its materials need to be set to the GPU to render it. And when you have relatively high poly things like SpeedTree’s, and lots of them, this can really bog your system down and kill your FPS.
To mitigate this, starting with Unity 5.5, Unity have implemented GPU Instancing on the SpeedTree shader. GPU Instancing is a technique in which you send the object to your GPU just once, and then draw it many times. And for things like tree’s that are replicated many times in your scene this can make a massive performance difference.
So in this tutorial I will show you how to set instancing up on SpeedTrees to get a potentially massive performance and frame rate boost.
In the scene below I am running a lot of SpeedTree instances, at Fantastic Quality, along with Grass and Unity Post FX – Antialiasing, Ambient Occlusion, and Vignetting, and getting 250 frames per second! It’s running on a GTX 1070, but even with a decent graphics card it is pretty easy to bring to its knees unless you do some optimization.
Note – I have raised the camera up a little so you can see the SpeedTree billboards in the distance. For most games this would not be something that you would do. And when you look at the settings below use them as a guide, but tweak them for your game. Every game is different and you will always be managing a trade off between visual fidelity and performance.
So what do we need to do ?
- Go into your terrain settings and disable bake light probes for trees.
- Go into your tree settings and disable light probes for all the LOD’s. Also think about disabling shadows for lower LOD’s as their impact as it can be significant.
Culled – If you drag this setting to the left, this will move the billboards closer, and distant SpeedTree’s will be completely culled, and this can make a big difference as well. Tweak it until the distance is right for your scene.
- You will need to do this for every type of tree in your scene and this alone will provide a significant frame rate boost. However there is more you can do.
- Check your GI / lighting settings. The following settings are generally good settings for an open world. Note that I am not using the SkyBox for my ambient light as this is slower. I have also dropped the resolution on my precomputed GI, and removed baked GI completely.
- Now lets look at your general quality settings. The shadow distance is one of the killer settings here. The lower you make it, the less your graphics card needs to do, and the better the frame rate you will get. Also explore the LOD bias. This will change the distance at which lower LOD’s kick in, and can also significantly improve performance. Note: You can change these settings for each quality level.
- Now look at your Graphics Settings. You will get better performance with deffered lighting.
- And your light – i prefer soft shadows.
- And then your camera. You want HDR for better lighting and you want draw as little as possible. To reduce what you need to draw reduce the Far Clipping Plane. If you draw less then you will increase your frame rate, so its a balance. Use things like fog to ‘artfully hide’ the far distance (and hence not have to draw it).
- Finally, you can also add occlusion culling to your scene : Window / Occlusion Culling. This will stop your trees from being drawn when they are blocked by other things in your scene. With clever level design you can get a dramatic performance boost with this alone.