I’m working on a project that uses sprite renderers and the sprite-diffuse shader. I can’t seem to get dynamic batching to work. For instance I have bullet shells that are spawned when shooting but they are counted as one drawcall per shell. Even the floor and wall tiles is counted as one drawcall per sprite.
I have even tried creating a new scene and just adding sprites and lights and batching breaks creating one draw call per sprite. If I remove all lights they are batched. Anyone got a solution? Included a screenshot to give you an idea how it looks.
I don’t know if there’s a solution for that sadly… I noticed the same thing when I was playing around with lighting in my game, in the end I chose for a fake/custom light effect ^^’
It’s really odd. But it might be because the sprites are transparent and transparency often breaks batching. Although then a Diffuse-Cutoff shader should work as it then a opaque material. Annyoing as hell since I end up with over 500 draw calls for some simple 2D sprites.
I actually have been but all I could find was that it happened when changing the material in script, which I’m not. I even tried a clean scene without scripts and batching broke.
Do you have any link to a thread where it has been covered that I might have missed?
Thanks
TomasJ: Sorry I’ve been away from the forum for a while and yesterday stumbled onto this issue again. I could send a sample project showing the issue if you want?
Have there been any similar reports where Sprite Diffuse breaks batching even when atlased?
I have the same problem in a simple 2D game. Sprite Diffuse material breaks batching completely and gives me an extra 50 draw calls.
Did anyone find a solution for this?
Default unity lighting is single-pass per light and is not batchable when multiple lights are involved. To improve batching you need to rewrite the shaders to do multiple lights per pass.
8bitCartridge: Did you get this to work? I’m still getting massive amounts of draw calls and nothing seems to help it. Deferred rendering doesn’t do anything, no shader I’m testing improves anything, transparent or not/with or without multipass. I have a lot of lights but 4-8 lights on screen at the same time shouldn’t totally break all batching, right?
Yeah, I tried it but no batching. I didn’t rewrite it to be transparent though. Have tried a bunch of different shaders but batching of sprites just doesn’t want to work for me.
Batching seem to break as soon as I use a lit shader of any kind with the SpriteRenderer.
How does deferred work with sprites, shouldn’t deferred be suggested when using many lights to keep draw calls down or is this something I have misunderstood?
I know this is an old post but for those wondering, batching is working fine atm, at least for me.
The limiting factor is as always the ammount of materials on scene.
So if i have a bunch of sprites with sprite-difuse and some others with transparent-specular whatnot, i still get 2 draw calls, as intended, provided they are all in an altas.
I tested the shader linked above to no avail, and have very clearly arrived at the same result that every sprite affected by lights creates a draw call. I have a scene with 1 spotlight and 1 spritesheet, where all sprites have one of 2 materials, I can still end up with 120 draw calls.
This thread has been cold for a while, wondering if I can revive it. Using Sprite / Diffuse at the moment, it does appear that every sprite (not texture or sprite sheet) hit by a single light source results in a separate Batch. I tried the shader linked above, it changes nothing.
If I have a scene with the hero and a single enemy, all of which use the same Material and Texture I get 110 Batches, with 0 Saved. If I switch the Material to Sprite / Default I get 22 Batch, still 0 Saved.
Switching to diffuse is 5x less performant? Is that right? What is the performant way to use 2D lighting?
Scene stats
Single material (Sprite / Diffuse)
One light source (Spot, Realtime)
One texture atlas
Camera Effects
Noise And Grain +1 Batch
Vignette and Chromatic Aberration +7 Batch
So I’m going to necro this thread again. There is definitely an issue with the SpriteRenderer and dynmaic pixel lights. Here is a list of step to reproduce the issue.
-Create a material and assign the ‘Sprites/Diffuse’ shader
-Create a square sprite using Unity’s built-in tools. Ensure it is entirely opaque.
-Assign the aforementioned material to sprite.
-Duplicate sprite several times (I made 11), leave all sorting settings at default with 0 for sort order.
-Ensure no sprites are overlapping. At this point conditions are ‘perfect’ for batching.
-Add light to scene and set it to ‘Not Important’.
-Ensure light’s range covers all of the sprites.
-Start scene and ensure draw calls are a 2 (1 for screen-clear, 1 for batched sprites).
-Sometimes, depending on light conditions and sprites there may be more batches but never anything unreasonable.
-Change light to ‘Important’ to enable pixel lighting.
-Batching is now completely broken and each sprite is being rendered one at a time with two passes each. Total batches at 1 + (2N) batches - where 1 is the screen-clear and N is the number of sprites.
It is entirely understandable that each pass would be breaking batches, but in this case each sprite both on the ForwardBase and the ForwardAdd is being rendered separately with its own draw call. That’s two draw calls per sprite which is entirely unreasonable.