So, I’ve been reading the Unity iPhone forums for a while now, and have recently bought myself a license and amd working on “stuff”.
One thing that does scare me a bit, though, is the consistent theme that pops up here talking about “keeping your draw calls to a minimum”. Perhaps I’m not far enough into my Unity learning oddysey yet, but I haven’t actually seen a draw call yet!? I’m a professional coder and artist, and I’m working on some of my own stuff in XCode so I’m aware of draw-calls in OpenGL ES, but how do I affect their use when using an asset driven environment like Unity?
Sorry - I know this is probably really dull stuff to all the Unity hardcore out there, but I’d sooner get off on the right foot with the stuff I’m doing!
The actual amount of draw calls are visible inside the editor in the game window if you press the little “stats” button on the top-right corner of the game window. If displays then a half-transparent overlay with some gfx stats as well as the draw call count.
For example switch a material with a vertex lit shader and a diffuse shader and see the difference in draw calls in the stats window (vertex lit = 1 DC, diffuse = 2 DCs).
Well, kinda - it’s good to know where I can see how many draw-calls I’m making, but how do I effect them? Is it down to the structure of my models, or just which shaders I’m using? Or is there something else to it?
Less objects visible = less draw calls.
Less objects that use multiple materials = less draw calls.
Less shaders that use multiple passes = less draw calls.
Combine spatially close objects into larger ones = less draw calls.
I’d suggest a Performance Optimization talk from Unite 2007 (it was not iPhone specific, but lots of concepts apply)
Every shader pass on a mesh/material/object instance is a draw call.
That means if you have 50 instances of a single mesh, each using a single material using a shader with a single pass, you will have 50 draw calls.
If you have 50 instances of a mesh using two materials, the first using a shader of a single pass, the second using a shader of two passes, you will have 150 draw calls.
For things that have many instances in the world, you would be wise to arrange it so they use one material and a single pass shader. Better yet, try to combine many meshes into few meshes. (see the SpriteAnimator class, for example).
For things that have few instances in the world (e.g. one), its possible to consider the possibility of using more than one material or shader pass.
As I understand it, however, each material or shader pass will require the vertices to be re-processed, so your multipass shader will count as extra draw calls AND extra vertices.
The common wisdom of this forum is that, to achieve 30fps, you have a budget of around 30 draw calls and 8000 or so vertices to play with.