Search Unity

Prefabs vs Combined Geometry - What is best?

Discussion in 'General Graphics' started by WimB, Dec 12, 2019.

  1. WimB

    WimB

    Joined:
    Sep 23, 2014
    Posts:
    35
    Hi

    We are building a reasonably complex scene of a small industrial city. We have export X amount of buildings and created prefabs from them to populate the scene. Most of the textures/materials are shared which we are planning on putting into an atlas.
    The question is to keep them as prefabs and use the "static batching" which is working to keep the draw calls down, OR to combine them into groups of single meshes which also is keeping the draw calls down. We will also use the occlusion bake.
    It is for PC but also IPAD.
    The confusion I run into is keeping them as prefabs which is good for updating the meshes and using the static batching, or should we combine them say using "mesh baker" as both seem to give similar results in the stats window.
    The only draw back I find with using tools such as mesh baker is that the data is stored in the scene which creates a very large scene file which is not great when using Collaborative. E.g scene file went from a few mbs to 800mb when testing combing meshes.
    Any advice on which way to go..

    Another question.
    Is it best to keep the parts of the meshes which have alpha/material as a separate mesh ( e,g building_1 and building_1_alpha ) or to keep it combined as one mesh with two materials? as I think unity at run time will separate the mesh anyhow?

    Many thanks
     
  2. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    501
    I would definitely let Unity's static batching do the heavy lifting for you here. While a merged mesh is slightly faster to render than several instanced meshes, you will render into issues when merging them. For instance, if you look at several buildings simultaneously, the batched version can batch together the parts of the different buildings. If you merged them together, this is no longer going to be the case. You also have a much higher memory footprint, as you noticed yourself. All these big building meshes also have to be sent to the GPU, instead of the just the small parts which are instanced. On top of that, the workflow is a lot more complex. Unity's static batcher is a great tool, use it!

    As for several materials: when Unity instructs the GPU to render something, it does so per material. So yes, your mesh is "separated" automatically when you have multiple materials. Just do whatever is easiest to work with in the editor. You should be aware however that translucent objects are sorted based on their position within the scene. If you for instance merge all windows in a single mesh, it's likely that windows from the rear of the building will be drawn on top of the ones in front. Best to keep these apart, at least per side of the building.
     
  3. WimB

    WimB

    Joined:
    Sep 23, 2014
    Posts:
    35
    Hi Thomas, many thanks for the reply.
    Useful to hear, and as you say prefab/batching is an easier workflow, so I will try sticking to this. Curious does it make a difference for mobile/tablet performance, as in combining or static batching is better or its generally the same?
    And thanks for the material info, again very helpful :) much appreciated
     
  4. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    501
    As with all things in graphics, it's a balancing act. It's faster to render a merged mesh than rendering with instancing (but I'm not sure from what amount of instanced meshes that it would actually be noticeable), but there are caveats. For instance, if you merge too much, you will have large meshes that always have to be rendered. With modular pieces, Unity will only ask the GPU to draw the geometry that is actually visible. Or, as I mentioned, there is a larger memory overhead with unique merged meshes versus instances.

    You have to do profiling to be able to compare which approach yields better performance in your use case. Still, because the instancing is automatic and allows you to work with modular pieces, I would only consider the manual merging approach if you really find that your FPS is struggling because of the instanced meshes. (and first you'll have to make sure that the meshes are definitely being batched)
     
    WimB likes this.
  5. WimB

    WimB

    Joined:
    Sep 23, 2014
    Posts:
    35
    Thank again Thomas, useful info :)