Optimising performance with terrain

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Wallace99

I have a terrain model exported from blender(it was generated from a heightmap and has about 16k faces), in my scene there are also 1400 trees which are 140 faces each. So all up about 220k faces. When adding the trees and terrain to my scene, the framerate drops from 60 to 40ish which lead to my thinking I must either be doing something wrong or need to do some optimising. I have heard Godot is not well suited to this sort of thing currently but I’d like to try optimise where I can.

Should I be trying to reduce the faces in my terrain? Or using MultiMesh? I have clumps of tree models in forests so perhaps each forest should be in a MultiMesh? Then I have also read about whether I should be trying to load parts of the terrain in chunks.

16k faces per se is basically “nothing” even on mobile devices. But if you use some specific shader for the terrain (i.e. a splatmap shader) that could be part of the performance degradation.

The trees most certainly would profit from LOD. But you’d have to script it yourself. Make sure that the script won’t worsen the performance though (i.e. 1400 scripts with a _process handler each is a bad idea).
LOD would mean either just toggling the visibility of the trees or replacing them with lower detailed meshes, maybe even with a simple billboard texture (using alpha or alpha scissors transparency). Also using MultiMesh might simplify the LOD approach as you will have less nodes to process (transition might be more noticable though).

Anyway I’d evaluate each step one by one.

wombatstampede | 2020-03-30 10:09

:bust_in_silhouette: Reply From: rpggeek

Please take a look at Occlusion Culling

Optimization techniques are another big area of graphical programming.

Cheers I will have a read of that. I’ve noticed that regardless of whether the trees are in the scene, the terrain model still seems to result in low frame rate. I tried re exporting in blender with the vertices reduced by 80% but still poor frames which doesn’t make sense to me. In the profiler the number of vertices drawn gets up to 1 million occasionally which I assume is quite high? I’m going to try look at what I could be doing wrong with my terrain model in blender

Wallace99 | 2020-03-30 05:30

The lack of occlusion culling is most likely not what’s slowing down things here. (When you have a depth prepass like Godot does in GLES3, there’s not much else you can occlude in a terrain-based game. LOD, however, is essential to have.)

Calinou | 2020-03-30 07:14

:bust_in_silhouette: Reply From: Calinou
  1. Find a way to use LOD for the terrain. For instance, you could design the terrain using the Godot Heightmap plugin. If you plan on using Blender anyway, you’ll have to find a way to chunk the terrain and export it with several detail levels so the face count is more reasonable.

  2. Look at using MultiMeshes to decrease the number of draw calls. You want to batch small groups of trees together rather than batching all trees in the same MultiMeshInstance. Otherwise, view frustum culling won’t be able to cull any trees since MultiMesh culling works in an “all or nothing” fashion.

Ah thanks I’ll check out the plugin and multimeshes too. So you think the face count could be a significant factor in dropping framerate?

Wallace99 | 2020-03-30 07:58

Yes, but it may not be the only bottleneck (or even the main bottleneck). While polygon count isn’t important on desktop as it used to be, you should still strive to avoid unnecessarily dense polygons (which is a recurring problem with terrains that don’t use LOD).

Calinou | 2020-03-30 08:31

I’ve switched to using the heightmap plugin you suggested and been quite impressed by its results. Still trying to decide how to approach trees. I’m wondering if perhaps I even need to have each tree collideable as with multimesh it seems it’s just the mesh with no collision info. Perhaps I could add multimesh forests and manually lay out collision shapes for the areas where the player can’t go

Wallace99 | 2020-04-02 00:48