Search Unity

Huge Terrains with lots of foliage

Discussion in 'World Building' started by SaphiBlue, Jun 11, 2020.

  1. SaphiBlue

    SaphiBlue

    Joined:
    Apr 18, 2016
    Posts:
    43
    Hello There,

    I noticed a massive CPU impact if I add more Trees to the Terrain

    Ok the objects are Trees for the Terrain but not really trees. Things such as gras, bushes, ferns and so on cannot be placed as 'detail' object to the Terrain when using HDRP.

    My map is a little big bigger 8x8 tiles. So there are many objects placed as Trees on the Terrain.

    How can I fix the huge cpu impact (I think because of the distance checks for the Objects LOD's).

    Is there a better way to place huge ammount of foliage to a terrain without having such a big impact on the cpu?
     
  2. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    What is your amount of batches in the scene? They are usually the first thing to check in cases such as your.
     
  3. SaphiBlue

    SaphiBlue

    Joined:
    Apr 18, 2016
    Posts:
    43
    There are about 8000 to16000 batches, depending on the view direction.

    Sounds quite a lot, but the whole world is far from finished.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    That is indeed quite a lot. You need to get that down to a few hundred if possible.
     
  5. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    So thats the cause of the low fps. Here is short explanation of what batch is

    https://docs.unity3d.com/Manual/DrawCallBatching.html

    Try to also learn about stuff such as:
    - GPU instancing in material setting (turn It on and huge part of the rendering will be moved to the GPU)
    - SRP Batcher, I couldn't find information about where It is in their terrible documentation so you are on your own.
    - Static batching, which is really average. You will have to try to mix this solution with gpu instancing and check which one works the best.

    This should fix the issues you have with the fps. Average AAA game for current generation (ps4/xbox one) doesn't go above 2-4k batches.
     
  6. SaphiBlue

    SaphiBlue

    Joined:
    Apr 18, 2016
    Posts:
    43
    I was able to optimize the LOD's a bit and reduce the batches to somweher between 4000 and 8000

    I attached a Screenshot of the Profiler expandet to the biggest point, PrepareSceneCulling.
     

    Attached Files:

  7. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    This is still way too much bathes and your game is still partly suffering from that. You are using over 600 materials and at the same time have some strange spikes which Im not sure If are from the editor or GC spikes. You still have around 65 LOD levels around your level which means they are really bad too or you have done too much variety.

    Something you should remember, profiling your game and running It in unity takes a lot of ms by default, especially in 2019.3 with hdrp installed. Plus standard oclussion culling provided by unity is actually rather bad and scales really badly with larger scenes. This engine isn't really made for big, open world games.
     
  8. SaphiBlue

    SaphiBlue

    Joined:
    Apr 18, 2016
    Posts:
    43
    I was able to Reduce the Batches (baked onclusion) below 1000, for some view directions. But still PrepareSceneCullingParameters took most of the CPU.

    Currently the Terrain and it's trees are the only Objects in the Scene. How can I handle open worlds in Unity, without having a huge dependency on the Assetstore?
     
  9. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    You can always become dependent on the free, open sourced GitHub projects, check the page unitylist.com. Someone made a bot that gather all public unity projects on GitHub.

    I recommend checking these:
    https://github.com/xraxra/IMP - Its a good way tool limit amount of lods. Worked in HDRP in 2019.2 but with few warnings about outdated API, still should work. Every single profesionall 3D engine I know of have this pre installed.
    https://github.com/andydbc/unity-texture-packer - one of the most basic tool unity should have pre installed. In my opinion required If you are working with terrains and don't want to switch between unity and photoshop. Usefull for HDRP
    https://github.com/Madgvox/unity-scene-groups - don't even try to make any slight bigger level without tool like that. Another thing that every single engine does have but unity.
    https://github.com/keypax/object-pooling-in-unity-demo - this is working replacement of standard scene and culling workflow. Im planning to implement something similar to this.


    and also something you might like:
    https://github.com/Siccity/xNode - free, open sourced visual scripting. Im trying to implement it into my project and I can tell you that Its not the best thing I have ever seen but still good enough.


    Also, something you have to understand. Not all assets on the store are good quality, It is chaotic place in which everyone can upload whatever they want to, no matter how bad It is. Plus the problem is with your problem that every single case is a bit different and It is rather hard to fix this exact issue without looking directly into your project.

    Try to compile the project and test How does It work. Projects with HDRP works terrible in the editor. In my case I'm achieving on average 20-40 fps in in the and 150+ once compiled (with mono).
     
  10. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    681
    If each item of foliage is a gameObject this will have a very large overhead.
    I think from the profiling you’ve done it implies a lot of time is actually being spent calculating what LOD level to use for each object.

    Coding support for GPU Instancing isn’t a trivial task, but that’s really what you need here I think.
    This allows you to draw thousands of identical objects (eg grass) very quickly on GPU and remove the CPU bottleneck.

    “GPU Instancer” is very good (if you are considering third party asset) and I think does support HDRP, although I’ve only used built-in with it.
     
  11. SaphiBlue

    SaphiBlue

    Joined:
    Apr 18, 2016
    Posts:
    43
    One of the Important things is, that the a thrid Party addon has to work with the already existing stuff €67 for one teammember is at the momment very expensive.

    Even a Standalone Build has at the momment the same performance issue PrepareSceneCulling is eating all the CPU-Time.

    Is somthing known about if Unity will do something about this in the near future? This colud be a real selling point.
     
  12. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    Can you give us a name of this third party addon? I can tell you that sometimes stuff form the unity asset store (especially tools) have a really little value and can be easily replaced.

    The last resort I do recommend is simply lowering when and what is going to dissapear. Considering you have took literally all ways to resolve this issue noted in this thread and your scene is perfect there isn't really that much you can do.
     
  13. SaphiBlue

    SaphiBlue

    Joined:
    Apr 18, 2016
    Posts:
    43
    https://assetstore.unity.com/packages/tools/utilities/gpu-instancer-117566
    This looks very promissing, but I have no idea if this really helps. The Second point is the pricing 67€ per teammember.

    But if the world gets more bigger (also gpu's have a limit), then I sholud consider using some kind of level-streaming technology.
     
  14. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    275
    You should always do level streaming in an big, open wolrd. Tools like the one you posted can definitely help, however I believe you can achieve similar results without It, or at least solid fps with HDRP with properly made scene.
     
  15. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    681
    Basically the way to achieve fast rendering of lots of the same object is through GPU Instancing. Unity supports this, it’s just whether you want to code your own implementation of it, or use a third party asset (like GPU Instancer).

    Likewise with world streaming. Unity supports asynchronous scene loading. The question is whether you code your own implementation or use a third party solution.
     
  16. AndersModen

    AndersModen

    Joined:
    Nov 19, 2019
    Posts:
    51
  17. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    Is instancing working on your trees? Do you have instancing enabled on the tree materials and use light probes disabled? If you have a lot of trees, you probably will be need to have some sort of spacial partitioning where parts of your world are turned off when far enough away. This way, your lods and culling are not even checked when far away. Anyways, Unity isn't really built for these kind of open world games. Have you considered a different game engine?
     
  18. chanfort

    chanfort

    Joined:
    Dec 15, 2013
    Posts:
    641
    I guess we need to keep reminding Unity to update billboarding system in HDRP and URP which is capable of rendering millions of trees.