Hello Guest

Author Topic: Lighting and Draw Call Count  (Read 8770 times)

fkassad

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Lighting and Draw Call Count
« on: April 01, 2013, 02:52:07 am »
Started creating a level for a 2d game I'm working on.  The view is a top down perspective and the ground is made up of many many sprites, all in the same sprite collection.  Before I added lighting to the scene, the draw calls were ~30.  Once I added lighting it jumped to ~300. 

The shader used on the sprite collection is tk2d/LitBlendVertexColor.  The scale on each of the sprites has not been altered in the transform component (they have been altered in the tk2dsprite component).  A bunch of the sprites are rotated.  The z values are all different so that draw order of the sprites is handled properly.

Changing the shader instantly drops the draw call count.

Any idea how to get that back down?  Is this unavoidable if I want lit sprites?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lighting and Draw Call Count
« Reply #1 on: April 01, 2013, 03:30:15 am »
Draw call count with Unity lighting is pretty hard to manage. The shader doesn't matter as much as what Unity does internally to batch these. You get different performance depending on the render path in Unity. Eg. you won't get anywhere near as much with deferred rendering, it should be very close to what it was originally. Our upcoming lighting plugin pretty much does deferred rendering in 2D - you will be able to get a large number of simultaneous lights with this technique - the overhead is really minimal.

If you can limit the number of lights affecting a particular sprite, then you can perhaps set it up in such a way that everything batches well. It is really tricky but doable - basically each sprite which is affected by the same number of lights batch, so you wanna make sure that this is the case everywhere.

fkassad

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Lighting and Draw Call Count
« Reply #2 on: April 03, 2013, 05:44:09 am »
With deferred rendering, am I going to run into issues with semi transparent sprites?  I've read that deferred rendering speeds up the rendering of geometry with multiple lights, but is sometimes avoided when dealing with transparency.

I'm fine tuning my scene to see how the lights are affecting the sprites. Each sprite in the scene is taking up 3 draw calls.  Each and every tile in the scene!  I even removed all my lights except for one, and still 3 draw calls per sprite.  I've also tried baking the lights into the level tiles and the number of draw calls per tile goes down to 1, but still 1 per tile is too much.  Trying to get them to batch together.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lighting and Draw Call Count
« Reply #3 on: April 03, 2013, 01:07:00 pm »
What plat form are you targetting?

fkassad

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Lighting and Draw Call Count
« Reply #4 on: April 03, 2013, 01:43:57 pm »
iPad

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lighting and Draw Call Count
« Reply #5 on: April 03, 2013, 03:20:37 pm »
Well deferred rendering is totally out of the question then.
1. It doesn't work on iOS
2. Transparent stuff falls back to forward rendering anyway, which is totally useless in your case.

There is another solution, but its still in development (it works), and it will be a cheap paid add on to 2D Toolkit for lighting.
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,783.0.html

I will be looking for beta testers very soon now (its been in limbo for a while), perhaps you might be interested.
There will be no shadow support in that solution, and no support for normal maps in the initial release.


The normal lighting path isn't THAT bad. It may be 3 draw calls for 1 sprite, but it'll be the same number for all batched sprites which are affected by the same light. So 3 draw calls for 100 sprites using the same material, illuminated by the same number of lights, too. Depending on your needs you could further optimize this using vertex lights only to speed things up further.

fkassad

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Lighting and Draw Call Count
« Reply #6 on: April 04, 2013, 07:24:17 am »
That lighting add-on sounds interesting.  Will definitely look into it when it's ready.

The normal lighting path isn't THAT bad. It may be 3 draw calls for 1 sprite, but it'll be the same number for all batched sprites which are affected by the same light. So 3 draw calls for 100 sprites using the same material, illuminated by the same number of lights, too. Depending on your needs you could further optimize this using vertex lights only to speed things up further.

The problem is that I'm not getting 3 draw calls for 100 sprites.  It's 300 draw calls for 100 sprites.

Do I need to have a pro license to get the batching to work in this case?  I noticed in the player settings it says "Static batching requires Pro License"

Edit: Also, the light I'm using is per-pixel lighting.  When I switch it to vertex lighting it batches.
« Last Edit: April 04, 2013, 05:58:23 pm by fkassad »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lighting and Draw Call Count
« Reply #7 on: April 04, 2013, 08:30:07 pm »
Yeah, the per pixel path won't batch too well.
If you can put up with the quality issues with vertex lighting, then that might be a viable option...