Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Performance of Terrain

Discussion in 'General Graphics' started by Doomchecker, Aug 2, 2021.

  1. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    105
    Going through various Youtube Tutorials and Forum threads I got the logical impression that reducing the Heightmap Resolution and the resolution of the texture being used on terrain should increase performance.

    I tried different setups and run them through the profiler but I really couldn't find any difference at all in FPS.

    Could anyone clarify if it makes sense at all reducing Heightmap and / or Texture resolution to increase performance on Desktop PCs nowadays?

    Using Unity 2020.3 URP

    Thanks.
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    There's your answer right there. Hypothetically those things that you mentioned might help in some situations, but not necessarily.

    Lowering the workload seems like it should logically improve performance over-all, but what actually happens in my experience is that you can keep throwing more and more at the render with careless abandon and it won't make any appreciable difference at all ... up to point. Once you get that point then you start looking for what the problems are.

    The way to increase performance is to identify any specific problems that you're having and address those. Are you getting bad performance? Does the profiler indicate what the problem might be? If you try to optimize too early then you'll waste a lot of time fixing problems that you never would have had.

    Having said that, I'm pretty conservative with my poly-count and texture resolution, but mostly because it's just easier for me to make assets that way.
     
    Last edited: Aug 2, 2021
    BrandyStarbrite likes this.
  3. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    105
    Ok that was basically what I needed to know. First make a project more complete and care about performance later.
    My approach was to try to "test everything" beforehand.

    Thanks a lot for your reply.
     
  4. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    105
    Ignoring my last post I just tested a few setups.

    - Using Terrain with Draw instanced disabled = ca. 250 FPS
    - Using Terrain with Draw instanced enabled = ca. 270 FPS
    - Using Mesh Terrain = ca. 290 FPS

    Honest question:
    Why would I use Terrain at all, considering that the Mesh-Terrain looks basically the same but hast about 1/4 file size and more FPS?
    Or am I missing something here.
     
    tmonestudio likes this.
  5. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    I don't really use terrains all that much, so I'm not really familiar with how they are optimized. I know that if you add trees and grass in the terrain editor, it automatically billboards the trees and distance-culls the grass.
     
  6. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    105
    Hmm after trying out a lot I think I found a good reason (correct me if I'm wrong or if there's a workaround).

    Mesh terrain get's very unsharp when it's not created detailed enough. And when it's created with enough detail, the file size actually get's even bigger than the size of the terrain.

    Although the performance of mesh is still better.

    Does the file size of terrains/meshes in the project folder (of those specific files) reflect the final build size needed for those?
     
  7. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    It depends on what sort of shader and UV unwrap you have on your mesh. There are splat map shaders that you can use on your meshes that work exactly the same as the terrain. Instead of a splatmap, you could also use vertex colors or just ordinary UV coordinates. you could also use tri-planer-projection world-space texturing or something like that.

    With a mesh-based approach, you're basically free to do anything you want, so you could very well create a solution that looks better and is better-optimized than Unity's terrain system if you know what you're doing.

    This I don't really know. you might be able to see this in a build report but I'm not sure whether they are so detailed.
     
    Doomchecker likes this.
  8. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    105
    I assume you do not use an asset from the store for that?

    I have two professional assets which include a terrain to mesh feature but both of them can only use splatmaps (as far as I'm aware)
     
  9. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    Not really.

    For my meshes, I'm just using normal uv -mapped meshes made in Blender. They have a custom shader that applies a second texture in tri-planar world space (The second texture is just to add a low-frequency noise over the primary texture, things like splotches and stains and stuff like that).

    The one thing I'm using from the asset store, is that I'm currently trying to adapt the code from this asset to suit my needs:
    https://assetstore.unity.com/packages/tools/utilities/scene-streamer-38168

    I'm dividing my "overworld" into squares (in separate scebes) so, at any given time, only the square that the player is in and the eight bordering squares are loaded. That way I don't have the entire map loaded at once.
     
  10. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    105
    Do you know if it's a huge performance increase to load seperate scenes instead of just set the tiles inactive?
     
  11. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,791
    Terrain performance is limited for the mobile platform
    You do not need any special optimizations for pc
     
  12. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    Hm. good point.

    If a tile is only inactive it's still in memory, so if your entire world is loaded that could add-up to too much RAM. On the other hand, continually loading and dumping scenes has a certain amount of inefficiency as well. For example, it would be much faster and more efficient to activate an inactive game object than to load it from a scene. So I guess it's really a trade off and neither method is always preferable to the other. That's something I should keep in mind as well, for my project.

    With scene streaming, the size of scenes matter too. You obviously don't want too large of a scene to load at once. On the other hand, too small of a scene may mean loading too frequently.
     
    Doomchecker likes this.
  13. joeysipos

    joeysipos

    Joined:
    Jul 28, 2015
    Posts:
    41
    The difference between using terrain vs mesh is terrain uses splat maps, so you can have very high resolution ground textures. With a mesh you have 1 texture that is spread over the entire terrain, so it will be much lower resolution when near the ground.
     
    Doomchecker likes this.
  14. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    Not necessarily. The texture does not need to be stretched once over the entire mesh because you can UV map the texture to repeat multiple times if you want, or you can also write a shader to do that. You can use splat maps on a regular mesh too, with the right shader. World-space Triplanar projection is another common way to map repeating textures. There are lots of different ways to apply texture to a mesh.
     
    sirleto, angrypenguin and Doomchecker like this.