Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using sprites-diffuse material breaks batching

Discussion in 'Editor & General Support' started by Etabubu, Jun 27, 2014.

  1. Etabubu

    Etabubu

    Joined:
    Jun 1, 2014
    Posts:
    1
    Hi,

    I'm a noob, so this might be totally my fault. I searched a lot on the interwebs for a solution, but I didn't find anything.
    I'm using Unity Pro 4.5.0f6.
    I'm working on a 2D game and I created a simple scene with 20 or so sprites.
    They're all flagged as "static" and they are packed in the same atlas using Sprite Packer.

    Initially I was using the Sprites-Default material for all of them and the whole scene was being drawn in just 2 draw calls (and about 15 calls saved by batching).
    Then I decided to add a point light and I created a new material that is using the Sprites-Diffuse shader.
    I assigned the new material to all the sprites in the scene.
    That's the only thing I did and now the batching is broken: 34 draw calls, saved by batching 0.

    I did all kind of tests, repacked the atlas, recreated the material... but nothing. If I simply select the Sprites-Default shader the batching is completely restored.

    So... is this a bug? Is it by design? Do I have to forget about using the sprites-diffuse shader with batching?

    Thank you!
     
  2. 8bitCartridge

    8bitCartridge

    Joined:
    Feb 26, 2014
    Posts:
    144
    I got the same problem, sprite diffuse material gives me extra 50 draw calls and saved by batching drops to 0.
    Did you find a solution for this?
     
  3. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    This is not a problem with the sprite diffuse shader - it is functioning 100% as intended.

    In the following example I have 55 sprites on the screen using a material which uses the sprite diffuse shader and everything is batching as expected. The issue, if you will, that you are seeing is with the addition of a dynamic light each sprite is receiving and passing the shader unique information.

    A good read on how Unity handles batching can be found here: http://docs.unity3d.com/Manual/DrawCallBatching.html

    You're going to have to get creative with your lighting solution if you are looking to take advantage of batching, be it with an additive sprite overlaying the areas requiring lighting, or with a 3rd party package such as 2D Volumetric Lights by @reveriejake

    2DLighting.gif