- Home /
Why combine meshes that share the same material?
The documentation indicates that combining meshes provides performance benefits. However, after doing some tests, it seems like meshes with the same material are auto-batched and result in 1 draw call.
Questions:
So why combine meshes that share a single material?
Is there a frame rate performance benefit to combining the meshes even though it's the same number of draw calls for combined or uncombined meshes with the same material? (is that what this post is essentially indicating?)
Are any of my conclusions incorrect?
Test Results:
1 Mesh with 1 Material = 1 Draw Call, Batched 1
2 Meshes, Uncombined, with the same material = 1 Draw Call, Batched 2
2 Meshes, Combined, with the same material = 1 Draw Call, Batched 0
2 Meshes, Uncombined, with separate materials each = 2 Draw Calls, Batched 0
2 Meshes, Combined, with separate materials for each mesh = 2 Draw Calls, Batched 0
Conclusions:
Mesh draw calls are directly related to the number of materials applied to the meshes being drawn.
If two meshes share the same material, whether they are combined or are separate, will be batched and result in a single draw call.
Combining two objects with separate materials doesnt give you any performance benefit, so dont do it because you can then apply the two materials inside Unity to either mesh instead of having to apply the materials in Maya, combining and then exporting (i.e. you can't separate a mesh in Unity to apply materials to each mesh and then combine the mesh again).
I think your conclusions are premature; I'd recommend a wider sample of meshes. You're meshes seem to be very batch friendly, but not all meshes are so. We certainly have meshes sharing the same material that do not draw-call-batch until after they are combined.
Answer by Jessy · Jan 29, 2011 at 04:22 AM
Conclusions 1 and 3 are good. A material equates to at least one draw call. (Shader passes and pixel lights in forward rendering result in a draw call each.)
Conclusion 2 is a bit incomplete. Meshes may be batched dynamically in non-Pro Unity, if they have fewer than 300 vertices and share the same material (I say may be because the actual requirements for batching have never been disclosed, and those guidelines alone do not always result in a dynamic batch). Dynamic batching is inferior to static batching, and static batching is superior to combining meshes. However, static batching requires a Unity Pro license.
When you have a choice between dynamic batching and combining meshes, that's a pickle, and I suggest you don't combine meshes, and instead, suffer a performance cost until you can afford Unity Pro. Seriously. Combining meshes is a boring and tedious operation best left to Unity, who does not experience ennui.
This video offers relevant details.
I'm targeting PC Standalone. Does that change any of your advice, Jessy? Your advice to not combine meshes is in stark contrast to the Unity docs, but maybe the docs are poorly worded?: "If you care about performance, combine meshes." (http://unity3d.com/support/documentation/$$anonymous$$anual/Optimizing%20Graphics%20Performance.html)
Thanks, Brad
Does the Auto-Batching in Unity 3 (was previously only on iPhone) basically mean you don't need to combine meshes manually and the docs just haven't been updated?
That documentation is several years old, and batching only became available on the desktop in 3.0. I think an update is in order. Combining static meshes might make sense, but not for a Pro user.
Sorry, I think I get it now. Seems dynamic geometry batching was a feature rolled from iOS into all platforms but never documented for other platforms. $$anonymous$$y tests on PC show the max number of verts for auto-batching two or more meshes to be around 225 verts, even lower than iOS!