Hello Guest

Author Topic: Z Depth Draw Calls  (Read 3647 times)

Majicpanda

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Z Depth Draw Calls
« on: July 14, 2013, 01:35:19 am »
I've got 3 atlases that make up a player in my game.  Armor, Weapons and Characters. 

Each Adventurer contains child objects for each of these sprites on different z depths to create a layering effect.  If the player animated sprite is at Z = 1, the helmet GO with tk2dsprite on it is at -.1 and the chest -.1 and weapon is .1 so that it is behind the "hand" and everything else. 

This workflow works great as it's only 3 DCs for a character, but the problem comes when I put one at Z=20 in the world, one in Z=21, 22, 23.. this creates 3 MORE draw calls per character even though the sprites are in the same texture.

Can you please tell me why this is happening or suggest another way to create depth?  Each player has to be able to pass the other creating a "this guy is behind this one" type effect when they walk behind, so I need some way to make that happen when they walk over to attack an enemy on the right side of the screen.

Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Z Depth Draw Calls
« Reply #1 on: July 14, 2013, 12:21:41 pm »
Unity is sorting these with the worst case. i.e. assuming that these objects are overlapping in screen space. Lets say A B C are sprites from different collections/atlases. Z is going into the screen from left to right, assuming constant overlap.

A A A = 1 drawcall
A A B = 2 drawcalls
A B A = 3 drawcalls

This in itself explains why you're getting 6 drawcalls with objects laid out the way you have them, which is more or less like this:

A B C     a b c = 6 draw calls

The easiest option is to reorganize in such a way that there is a large gap between A, B and C per character, and the offset between characters should be lower. i.e.
    A a            B b            C c            = 3 draw calls
Eg. each part is separated by 10 units, but each character is separated by 0.1 units.