Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

terrain vs mesh?

Discussion in 'World Building' started by mellooow9, Apr 15, 2020.

  1. mellooow9

    mellooow9

    Joined:
    Dec 25, 2019
    Posts:
    31
    Is there a difference between using unity's terrain system, vs importing my own mesh to use as terrain with a mesh collider? is one better for performance?
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    866
    It's mostly the ease of use through tools. Unity seems to want to catch up with other engines that already have a non-destructive layering system for terrain modifications and although they haven't yet, if they do, the tooling will be much better compared to the amount of custom tools you'd have to write to achieve the same workflow. If you want to build small architectural or non-organic surfaces the tools to support this are probably better in you favorite modeling app.
    One significant difference though is that heightmap based terrains are by nature not able to model overhangs and similar structures. They also tend to introduce artifacts along very steep height edges as their resolution often just naively uses a regular grid. There are ways to generate more clean meshes but the unity terrain doesn't do this. So using meshes you have the option to manually add detail where needed if this is your case. If you intend to modify your terrain at runtime, heightmap based ones are easier.
     
    Fire9Ball likes this.
  3. mellooow9

    mellooow9

    Joined:
    Dec 25, 2019
    Posts:
    31
    thanks this helped
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,305
    Terrain will be far better performance wise due to it being instanced. They basically take a small set of tile meshes and then instance those all over applying the height in the shader. Plus the built in LOD. If you need 3D terrain though you are stuck with meshes.

    Terrain colliders are optimized also, perform better then regular mesh colliders.
     
    BIGTIMEMASTER likes this.
  5. mellooow9

    mellooow9

    Joined:
    Dec 25, 2019
    Posts:
    31
    is the performance with a mesh something i should worry about for a large open world game? is there anything i can do to improve the performance if i use a mesh?
     
  6. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    530
    Unless Unity's terrain system performance has improved dramatically in the last year, meshes are actually far better for performance. At least this was my conclusion after my research for our large open-world game Eastshade. We used unity terrain for the first two years, then ended up switching to meshes and it was absolutely the right decision. This is mostly because of how many draw calls even a basic blobby Unity terrain creates, due to the way it chunks the pieces. Also the the real-time edge collapsing as you get further away is extremely heavy, much heavier than LODing a large chunk with a simple distance check. Its especially bad when you consider just how many triangles the terrain system uses to give definition, since the topology is even and indiscriminate squares. If the geometry is a regular mesh instead, you can use a good edge collapse optimizer (most 3d packages have one these days) to shave off 75% of the triangles with no visual change, leaving most geometry where its needed. I wrote a big article on foliage optimization, and while most of it is not applicable here, since we're talking about terrain/ground itself, there is a small section on terrain. I'll paste the relevant text:

    Another cool thing about meshes is you can reuse them and arrange them more easily. We have large cliffs in Eastshade that we copied around to make interesting areas quickly. There's also just so many more tools available to make the terrain look good when your authoring regular meshes. So my vote is for meshes :). But every game is different. valley.png
     
  7. ron-bohn

    ron-bohn

    Joined:
    Oct 5, 2015
    Posts:
    216
    I also have found meshes to be much faster, but that's for a well researched, tested, and complicated pipeline. The only savings I see using terrain is the actual memory required for the meshes can be noticeable in a very large world, but it's still not much compared to the overall savings with drawcalls.

    edit: Also, according to some experts, LOD's are not always a good thing and there are often better ways to accomplish more optimized results.
     
  8. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    31
    It would be interesting to have an update on these performance comparisons with URP: from what I understand the performance gained from going from Unity Terrain to a Mesh was due to the reduction in Draw Calls, however the SRP Batcher (used with URP) only slows down when there is a change in shader, not a change in material so maybe the performance gain is now less significant?

    djweinbaum and ron-bohn maybe you have an opinion on this or you might even have tested it?
     
  9. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    530
    I haven't touched the terrain system in years, so I wouldn't know. But I have to imagine the edge collapsing computations are still pretty expensive. I also needed an order of magnitude more triangles for the same definition, since the terrain system made even quads (instead of a software mesh optimizer which puts edges where you need them). The difference was often huge, like 100k triangles vs 6k triangles, and the mesh still had more definition. Idk if the edge collapser is smarter now.
     
    Last edited: Apr 16, 2021
    ron-bohn and nico_st_29 like this.
  10. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,132
    We can debate this for years, its what works for "you", test things out. Mesh as far as "look/definition", is great, but is it right for "your" game/workflow?... Ball in your court...
     
    FlightOfOne, ron-bohn and nico_st_29 like this.
  11. ron-bohn

    ron-bohn

    Joined:
    Oct 5, 2015
    Posts:
    216
    Just conveying my personal findings. There is an easy way for anybody to see for themselves: Put a mesh with one material in a scene, hit play an open up the stats window. Do the same with a terrain, and you'll see the difference. In some cases "my way" might be over-optimization for say a linear game that uses occlusion culling and such, but if you're building an open world of any significant size, every little thing adds up. Some of the more advanced open world tools such as "World Streamer" use meshes as default, for example.

    It absolutely matters with what kind of pipeline you are using, target device(s) etc. However draw calls are draw calls and if you're on a small or solo team, there's several universal concepts that have applied for quite some time. Terrains can much more convenient for some situations.

    Just a use case example of a world that I'm currently working on...I have about 5x5 sq km of buildings using a single atlas that take less of a performance hike that a 1x1 sq km terrain using a single texture.
     
    Last edited: Apr 17, 2021
    warthos3399 and nico_st_29 like this.
  12. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    31
    Thanks to all of you for the comments. I'll try swapping my Unity terrain for a mesh in Cradle of Chaos tonight.
     
  13. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    Thank you for this information, very helpful. Are you using your own solutions for streaming and vegetations?

    And may I say how beautiful your game is, simply gorgeous! HDRP?
     
    Last edited: Sep 4, 2021
  14. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    I am currently using world streamer and it uses mesh terrains for distant terrains (as LOD). Near terrains are Unity terrains. This is their default setup. However with World Streamer (since it has have nothing to do with terrains -streams scenes) you can do whatever you want.

    I am also considering getting rid of all my Unity terrains and just using Mesh terrains. Once you have fooliage (and other detail) over it, it is hard to tell the difference I think
     
    Last edited: Sep 4, 2021
    ron-bohn and warthos3399 like this.
  15. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    Thanks, guys for the info! This made a HUGE improvement for me. My project is a VR project (URP) so everything beyond 50 or so meters looks like crap anyway so don't really care for distant fidelity. And this is with instance checked and in the editor (it would improve more on a build).

    p.s. You have to add about 10 more fps though, for some reason when I use windows snip, I lose about 10 fps. And ignore the ground detail, I just need to move up the rocks.

    Unity
    unity terrain.PNG


    Mesh
    unity mesh terrain.PNG


    EDIT:
    I did a proper build and I can say I am not going back to Unity Terrain any time soon. I gained good 3-6ms ( and over 6ms in some places! I know, hard to believe for me too). For those who only know fps, this is roughly about 20-40fps.

    Another huge thing I noticed was my loading speeds. They went from about 1.5-2 minutes to <5 seconds.

    I should point out that this approach isn't without pain points and will require you to do additional work. But I think this is well worth it.
     
    Last edited: Sep 7, 2021
    pierre92nicot and ron-bohn like this.
  16. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    530
    For streaming just used the regular built-in LoadAdditiveAsync. For the vegetation, well, I give a pretty good rundown of it in the foliage optimization article I linked to there.

    And thank you! No its just the built-in deferred (Unity 2018). I wrote all custom surface shaders, but used Unity's standard spec and lighting model for the most part.
     
    FlightOfOne likes this.
  17. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    I am currently using word streamer (which uses the Unity's Async loading), but been thinking about making my own. WS is fine but I think I can do something simpler (using the same async method) and I like the total control when it comes to extending and troubleshooting.

    Yeah I have been looking at your DevLog, it is a good mine for those of us who are less experienced. Thank you very much for sharing!
     
  18. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,132
    You said "And thank you! No its just the built-in deferred (Unity 2018)", 2018?. My friend you are far behind the times. You should always use a LTS build to begin with. But 2018 is far behind. At least use 2019 LTS version.
     
  19. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    2018 is still under LTS. I am in 2020 LTS and it is far unstable than any other version of Unity I've used. Of course, it has great features but I spend a good chunk of my day staring at progress bars or recovering from crashes. I think 2018 is still the most stable, 2019 was better than 2020 when I used it. I can understand why most of the veterans stick to older LTS versions. Hope things will be better with 2021.
     
  20. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,132
    TBH the 2019 LTS is the best out there... hands down, you should try it, very stable, and compliant... Also your crashes could be due to "version conflicts", due to version used... Dont use 2020 and above, Why?, bugs arent worked out yet, to early of a version...
     
    FlightOfOne likes this.
  21. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    167
    2018 LTS is no longer supported (LTS support has ended)
    2019.4+ is perfectly fine for standard pipeline, all new Unity assets are required to be summited in 2019.4 and or higher so any thing lower than this you will soon have trouble to gain support for assets in older versions

    for HDRP or URP I suggest do not to go below anything lower than api 10x (aka 2020.3 or higher) and save yourself a lot of pain!!!

    back on topic (Terrain vs Mesh)
    historically in unity, mesh has always been a bit better in regards to performance over terrain. however terrain can have more detail closeup, you will find many different ways to deal with this such as mixed mesh and terrain culling terrains replacing with lower poly mesh in distance plus many other tricks.. A good terrain shader is also extremely important as a custom terrain shader will outperform unity shaders. any bench marking should indicate number of layers and shader used. in unity terrain shaders (standard/URP) they use one pass for every four layers and (HDRP) will do 8 layers in one pass..
     
  22. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    530
    We released Eastshade in early 2019. Secondly, I prefer to only upgrade if there is a specific reason, and never during the final leg of a project, or after launch (unless you have a DAMN good reason). Once I pick the engine and version, I tend to just focus on the game and forget about chasing upgrades or what's on the horizon tech-wise. In my experience most successful commercial game developers share that philosophy.
     
    warthos3399 and FlightOfOne like this.
  23. EagleG

    EagleG

    Joined:
    Mar 17, 2018
    Posts:
    88
    How is the number of tris same after u convert the terrain to mesh???? Are u using custom LODs for mesh terrain?
     
  24. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    No way! far less than Unity terrain. I mean I guess you can keep the same resolution but at that point might as well use the Unity Terrain with instanced turned on.


    I am not using LODs for my solo scenes but I am considering them for my open-world map.

    If you do need a greater close-up detail you can do a hybrid/LOD setup with both Unity and Mesh terrain. The tile where the player is on can be unity and everything will be mesh.
     
    Last edited: Sep 7, 2021
  25. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    By the way, did you use any special shaders for the terrain like Microsplat?
     
  26. Shadauwa

    Shadauwa

    Joined:
    Jan 12, 2020
    Posts:
    12
    I am hesitating to go with Mesh vs Terrain, I take Gaia 2 for an esaier way to make Terrain, but i am thinking to convert them on Mesh. Applaying LOD on mesh terrain is like whatever object / creatures, right ?
    I just need to slice my terrain in parts for an efficient, LOD ?

    I would like custom terrain for custom small planet, so having the default Terrain that i can note rotate or shape as i want is not for me. :(
     
  27. EagleG

    EagleG

    Joined:
    Mar 17, 2018
    Posts:
    88
    Unity Terrain has auto LOD so the tris count should have been lower than the the mesh(which means your unity terrain isn't performing any kind of LODs)..... What I want to say is that unity terrain must not perform this worse.... Your batches seem way too high than normal... Tick GPU instancing on the materials of your trees and lower some terrain settings by reading this https://docs.unity3d.com/2021.2/Documentation/Manual/terrain-OtherSettings.html and use LODs and billboards for the trees and don't use unity's paint details for grass if u are not using 2021.2 and later versions because the latest versions have indirect instancing for grass, also make sure u tick static for trees and terrain,enable static batching in URP and occlusion and frustum culling...try changing everything from double sided to single in terrain settings.....Maybe try using a single huge terrain(I don't know whether multiple terrain or single terrain gives better performance) Also if these steps don't help much try reducing terrain resolution and using custom shader for terrain
    Play around with settings and see which one gives best performance and try keeping batch count low
     
    Last edited: Sep 8, 2021
  28. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    530
    I wrote a custom surface shader. It was a three channel vertex splat with a macro overlay and macro normals.
     
    FlightOfOne likes this.
  29. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    Thanks for the info. I am using Instance Indirect (using VSP) for grass, trees and other details and these are also frustum-culled. These were never my problem -I get very good performance even in VR.

    My comparison above was purely for the terrain. One 1kmx1km area (4 chunks).

    I honestly do not see a reason (not speaking for everyone here, just my project) to go to Unity terrain. I use Terrain to Mesh (asset) and I can hardly tell the difference when converted to Mesh. Btw. 512x512 mesh comes out to 4096 vertices and I have about 4-8 tiles active at any given time. I also have other benefits, like being able to bake lights rather quickly -I have 400 tiles. I also have a feeling the texture resolution is also a factor (lower on mesh).

    Because of this now I can hold steady <11.2 ms or around 90fps (target for VR).

    Anyways, no point in going back and forth as to what is better. As @warthos3399 said, do what works for you, your team, and the project. Not all projects are created equal.
     
    Last edited: Sep 8, 2021
    EagleG likes this.
  30. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    I haven't done LODs yet, I think I can do without them as I am already streaming my level and getting good performance. But yeah you would convert your terrain with different quality levels if you want to go the traditional way. Just keep a separate mesh for the collider.

    You might want to look into Curved World Asset (not sure if it works on URP though), might work for your need.
     
    Last edited: Sep 8, 2021
  31. Shadauwa

    Shadauwa

    Joined:
    Jan 12, 2020
    Posts:
    12
    Ok i see thanks for sharing.

    I was gone deeply for the Curved World asset, but it is only a "visual" trick (shader), so a player that would go outside your square mesh terrain he will fall, and can not walk arround all.

    I must to make create sphere terrain and apply gravity on it, like Mario Galaxy in some way.
     
  32. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    565
    You could look at how Kerbal Space Program did it.
     
unityunity