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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Multiple Objects vs Multiple Submeshes performance?

Discussion in 'Shaders' started by mrtkhosravi, Aug 30, 2018.

  1. mrtkhosravi

    mrtkhosravi

    Joined:
    Nov 9, 2014
    Posts:
    198
    Is there a performance difference between these two cases:
    1. 5 meshes each having a single material
    2. One mesh with 5 submeshes each having different materials
    I create many small meshes procedurally each having 50 - 300 tris. Each mesh needs 5 materials. All the meshes are different and static. Batching is considered.

    With these conditions is there a difference in performance between the two options?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    5 meshes means 5 game objects to update, 5 renderer components to cull.
    1 mesh with 5 materials means 1 game object to update, 1 renderer component to cull.

    The benefit of 5 meshes is that each part can be separately culled if necessary, potentially reducing draw calls.
    The benefit of 1 mesh is less CPU overhead.
     
  3. mrtkhosravi

    mrtkhosravi

    Joined:
    Nov 9, 2014
    Posts:
    198
    Thanks Ben. The meshes are large in size and low poly. Culling like 2 of the 5 pieces can't help me here. I'm surprised to see that in my case having submeshes can be faster. So there is no problem with static/ dynamic batching of submeshes? They can be batched just like different meshes?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Yep. Once you're passed the initial gameobject and culling phases, the batching and rendering is identical as best I understand it.
     
    mrtkhosravi likes this.
  5. mrtkhosravi

    mrtkhosravi

    Joined:
    Nov 9, 2014
    Posts:
    198
    Excellent answer. Gave me courage to write a test and see it in action.
     
  6. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,495
    Polycount isn't the only thing to think about. If your use case for example is that the sub-meshes are a huge portion of your surrounding level, this could contribute to significant overdraw due to the singular renderer of them being sorted in a less than ideal way relative to the rest of the objects in the scene, resulting in large portions of these objects being rendered on screen when they otherwise would have either occlusion/frustrum culled or at least had their fragments depth-culled.
     
    mrtkhosravi likes this.
  7. mrtkhosravi

    mrtkhosravi

    Joined:
    Nov 9, 2014
    Posts:
    198
    Good point to consider. Thanks for the info.
     
  8. mrtkhosravi

    mrtkhosravi

    Joined:
    Nov 9, 2014
    Posts:
    198
    I created a test code to see what happens in a simple setup. I can confirm batching works without problems. Each master mesh has 5 submeshes. Each submesh has only two triangles. The test code is attached to this message in case somebody gets curious.

    upload_2018-8-30_7-9-1.png
     

    Attached Files:

    Squize likes this.