Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Scene Optimization with "Combine Children"

Discussion in 'Editor & General Support' started by Cybexx, Feb 10, 2009.

  1. Cybexx

    Cybexx

    Joined:
    Dec 4, 2008
    Posts:
    23
    I'm trying to optimize a scene in Unity by using the "Combine Children" script. I create an empty object, parented all the objects with the same materials under the empty object, then attached the "Combine Children" script to the empty object.

    This seems to improve performance. I notice that my draw calls are reduced, however the Tris and Verts seems to jump up when I do this. I read that reducing your Tris and Verts is important for integrated graphics cards.

    I assume that when I use the "Combine Children" script it basically creates one big mesh to send to the graphics card. If I, for example, parent all the rocks in my scene, would all mesh data for all the rocks in my scene get sent to the graphics card even if only one rock is in the the view frustrum?

    If so, would it be better to only parent rocks that are near each other. My scene could essentially be split in to four areas, so would parenting only objects near each other be better than parenting all the, for example, rock objects in the scene?
     
  2. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
  3. Cybexx

    Cybexx

    Joined:
    Dec 4, 2008
    Posts:
    23
    Sorry, I wasn't thinking I should have posted my question in there.

    Though that topic pertains to how to how to merge the vertices of similar objects, I think what they probably want is instancing, which is what I originally thought the "Combine Children" script did.

    Of course that is a stupid assumption considering that instancing is a shader based rendering technique, while the "Combine Children" script basically is just used to push all the verts for objects sharing materials, thus shaders, into the same draw call, which would of course increase performance, though not as much as instancing. Of course instancing doesn't work on integrated graphics cards.

    My question is a bit different, I was wondering how, on an engine level, does Unity handle culling?

    According to the Rendering Statistics it looks like as long as one of the combined meshes is the the view frustrum, Unity will attempt to rendering all the objects, since they are combined. This tells me that Unity does Object-based culling and not vertex, based culling.

    Therefore if I'm right, trying to combine two objects that are a world apart, just results in me trying to draw a bunch of verticies I'm not seeing, which could affect older graphics cards. Thus, if I split up my combined stuff per-area I would still benefit from less draw calls, but I also wouldn't be drawing excess vertices. I assuming draw calls = #(object * #shaders_on_object * #lights_on_object).

    I could be completely wrong about about this, I of course didn't write the Unity Engine, so I was wondering if someone who is more knowledgeable than me could correct me.
     
  4. Lucas Meijer_old

    Lucas Meijer_old

    Joined:
    Apr 5, 2008
    Posts:
    436
    culling happens per meshrenderer component.

    merging too much stuff (especially stuff that is far away from eachother) will lead to your objects not being culled most of the time, even when they are not visible.

    merging too little stuff will lead to excessive drawcalls and statechanges.

    It's a careful balance, and from all the different Unity projects I've seen from other people, probably the hardest one for people to get right. It's hard to make a rule "do it like this". it also depends on where you expect your camera to be, where you expect your camera to point at, etc etc.

    Bye, Lucas
     
  5. Cybexx

    Cybexx

    Joined:
    Dec 4, 2008
    Posts:
    23
    Cool, alright I guess I will combine objects that are near each other. In our game the camera is usually in one of 4 fixed spots. So I have the advantage of knowing what the player is looking at.

    Thanks for the response Lucas :)