Hello Guest

Author Topic: Many draw calls for only one sprite collection  (Read 6116 times)

Raganork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Many draw calls for only one sprite collection
« on: November 23, 2014, 07:51:31 am »
Hi.. I am using 2D Tookit for some time now. I have built some games (for mobile platforms).

Coming to the problem, I am making a HUD screen for my game, with all the sprites are in a single Sprite Collection. I should get only 1 draw call. But after placing sprites on their positions, I am getting around 11 draw calls, I have checked other threads too, but still no use. I have already done below things-

-> No Gizmo is turned on
-> Sprites are in different z levels (by approx 0.1 difference)
-> There are some sprites overlapping, but I am sure they are not in same z.
-> I am absolutely sure there is only one sprite collection at a time. I have disabled main camera. (my HUD screen is shown by HUD Camera)

I am not sure if I can try Sprite Static batcher (I was unaware of that till now, but I done my research on it), since I have Anchored the sprites and also, some are in different layers.

I am using Unity Free v4.5.5 and 2dToolkit v2.5.0. If anyone could help me or support me in solving this problem I will be truly grateful.
Thank you.

Edit: I was just doing some RnD work and find out that, if I duplicate a sprite, it is increasing a  draw call. This happens with only few little big sprites (450x450 in my case)
« Last Edit: November 23, 2014, 03:05:38 pm by Raganork »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #1 on: November 23, 2014, 09:19:43 pm »
Is the sprite / any sprites diced?
What is your poly count?

Raganork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #2 on: November 24, 2014, 06:28:19 am »
Hi, Thanx for quick reply.

Yes, there are some sprites which are diced. Do you want to know polycount of the whole scene ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #3 on: November 24, 2014, 09:09:15 am »
There are rules to dynamic batching, which you can read about here.
http://docs.unity3d.com/Manual/DrawCallBatching.html

Basically, if you dice too much you will lose the ability to dynamically batch as your vertex count will exceed the allowed limit. This isn't necessarily an issue if you use it for a background, etc. but you dont want to mix it up all over the place.

Raganork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #4 on: November 24, 2014, 10:25:48 am »
Well, I have a image of approx 450x450 (target height is 1080). I have diced it by 32x32. Making it less diced (or no diced), will it reduce draw call ?

I read the documents (and from other threads), that if vertex count is greater than 300, then that object is not eligible for dynamic batching.

Can you please provide me the some more reasons for getting more draw calls for this scenario ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #5 on: November 24, 2014, 10:33:29 am »
450x450 diced by 32x32 = 15x15 = 225 quads = 900 verts. It is not going to batch.

Raganork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #6 on: November 24, 2014, 11:38:30 am »
Thanks. I got it now very clear now. Its now showing the draw calls which there should actually be.

But then, for textmesh, why for every text mesh, there is 1 draw call. I mean, if there are 3 textmesh on screen, it is showing 3 draw calls. (Font is same).

Also, will you help me in understand in 'simple words', how z values can affect draw calls ? I mean, if there are sprites overlapping, will it increase draw calls. How much gap should be there between two sprites (if i want to show them overlapped).

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #7 on: November 24, 2014, 11:56:26 am »
If you put the font into a sprite collection it will batch with the rest of the sprite collection, unless it exceeds the vertex count.
The gap between things doesn't affect sorting, as long as there IS a gap.

Raganork

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #8 on: November 24, 2014, 01:59:28 pm »
Ok. I got the point. But still, is there no other way to batch the large sprites ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Many draw calls for only one sprite collection
« Reply #9 on: November 24, 2014, 02:10:14 pm »
If you really care about batching, reduce the poly count, or use a static sprite batcher for static sprites. At the end of the day you dont wanna go > 4k polys per draw call, and if its a large (screen filling) sprite, dedicating one draw call to it isn't a problem. If you had more than 1 of them stacked on top of each other you'd have a bigger problem with fill rate.