Draw Calls issues on my first Iphone game

Hi,

I am currently developping my first iphone game (it is a 3D tower defense and RTS game at the same time). This is still at beta stage, so please forgive any discrepancies on the screenshots.

For the draggable units in the UI, I am using the SM2 package.

While the game still runs at reasonable frame rate, I am struggling with the number of draw calls:

  1. All glow effects are using the same material. From the unity iphone editor Emulated Draw Calls, it seems to use a 1 to 1 draw call per instance of the glow. Isn t it weird?

  2. The 3D Text objects used for the prices of towers or mobile units seem to require one draw call each. I thought unity would batch the draw calls for those objects. Am I missing something?

By the way, is it true that Unity 3.x will support a 2D sprite engine?

thanks


  1. well they look differently so are you sure its the same material (same material means no changes to color or anything at runtime, otherwise you create a new material actually)

  2. these objects are “old day functionality”, they are not integrated with the batching.

Thank you Dreamora,

For 2), is ther eanything you would recommend for displaying just characters?
SM2 with a font in an alias (I mean number 1,2,3…)?

if you have just numbers, using SM and a small ui system or something like GUIManager would definitely do their job

Cool thanks!

For 1) I can t figure out what is going on. The UI atlas is 1024x1024. That should be ok right?

Are you sure about the 3D Text objects not being batched?

Our recently released game Word Monkey uses a single 3D Text Mesh object for each block, and those all get batched (we never get above 15 draw calls, and there are easily 60 3D text objects on screen at a time). They should be batched, since they go through the 3D renderer. GUIText, on the other hand, does NOT get batched.

3d text works with regular meshes and should theoretically batch yeah.
My bad, had GUIText in the back of my head again because I use the 3D texts that rarely.

Its only a problem with the gui systems as none of the gui systems, neither the 1.x (guitext / guitexture) nor 2.x (ongui with gui.xx) batch.

@mohydine: a single texture does not mean a single material. Single material really means the one and same material for all in the the editor and not touching any values on it through code at runtime.

This could be an issue related to Unity’s breaking each glow effect into a separate drawcall due to the fact they use a blended shader and are too near to something else depth-wise, causing Unity to think it has to rendering them separately to be blended correctly. This is a little difficult to explain in text, but there’s a visual aid and a lengthy description of this issue, along with some suggestions on how to resolve it, in the latest SM2 docs. Let me know if you have any questions on that.

As for 3.0, yes, it would appear so. No word yet on what exactly it will entail, but I’ll very likely be writing a new version (possibly an SM3, depending on how radical a change it is) to take advantage of the new engine to provide you with even better performance, even MORE features, and an even EASIER workflow. :smile:

or it just breaks it up because there are lights / its a multi pass material

Hmmm I tried to adjust the depth of the glow, no effect. And I am using the standard Transparent/Vertex Colored Shader.
No lights in my scene.

And… I get a 25 FPS for 41-50 draw calls (looking at the internal profiler stats) on my ipod touch. Havent tried on 3GS yet. I thought I was way over the limit of 30, but I can t see any difference… The game is still responding in a fluid manner. Does anyone have any idea? This isnt bad news but I am afraid I went in the wrong design direction and would have to redo everything later on.

and here are my profile stats for 21FPS on ipod touch:
iPhone Unity internal profiler stats:
cpu-player> min: 34.8 max: 56.8 avg: 41.2
cpu-ogles-drv> min: 3.2 max: 5.4 avg: 3.7
cpu-present> min: 1.1 max: 2.9 avg: 1.4
frametime> min: 41.9 max: 63.2 avg: 48.9
draw-call #> min: 49 max: 51 avg: 50 | batched: 22
tris #> min: 4519 max: 4527 avg: 4523 | batched: 61
verts #> min: 1951 max: 1967 avg: 1959 | batched: 122
player-detail> physx: 1.9 animation: 0.0 culling 1.9 skinning: 0.0 batching: 0.1 render: 10.5 fixed-update-count: 2 … 3
mono-scripts> update: 13.2 fixedUpdate: 0.8 coroutines: 12.2
mono-memory> used heap: 6127616 allocated heap: 6623232 max number of collections: 0 collection total duration: 0.0

The frametime seems consistent with my calculation of the FPS, right?

Am I not reading the stats correctly?

It won’t look right, but try the cutout shader that comes with SM2 and see if it changes the draw call count. You won’t actually want to use that, but it’ll at least tell you if that’s what’s going on.

The Sprite Cutout shader?
So I used it on my UI Atlas. It reduces the number of draw calls dramatically (from 44 static to 36 static).

Does it tell you something?

Yep, that would seem to indicate it’s separating the blended glow sprites because of the reasons described in the SM2 docs.

Adjusting the depth to solve the problem can be tricky if there are lots of other things in the scene since it’s based on the distance from the camera, which increases as an object approaches the edge of the screen, even if it has the same ‘Z’ coordinate. For a UI, try rendering the UI on a separate layer using a separate camera set to orthographic. Then you should be able to radically separate the glows depth-wise from other GUI elements, making sure that nothing could possibly be competing for the same depth queue spot.

Another thing to try is to make sure your glow graphic is on the same atlas (and material) as all other sprites being drawn for the UI. This way Unity can depth sort the sprites with regard to eachother, but since they are all on the same material they can be batched together.

Hey cool, yes I read the section you mentioned in the docs.

Very well, tomorrow I will try your options.

thanks !

So yes it woooorks!!!

Adding a second camera seems to reduce the frame rate: so I will postpone it for the moment. Not good for me.

HOWEVER, putting every UI elements into the same alias worked fine and reduced the number of draw calls. However, even in that case I had to manually adjust the depth of each object, so that I can get a very low draw call number.

I will go further into that direction and let you know. Thanks guys !

No problem. :smile: Glad you’re making progress on it.