Why aren't 2D Lights _actually_ batched?

For every 2D Light you add the Batches increase by 1

The Light Batching Debugger says the 2D Lights are Batched

But the actual Batches disagree:

The 2D Lights are exactly the same, same layer, no shadows, doesn’t make any difference in changing the 2D Light parameters nor the 2D Renderer Settings. To test this yourself create a new 2D URP project, add some 2D LIghts, and the batches grow.

The Frame Debugger: Couldn’t Batch for ‘Unknown Reason’

Please tell me I am doing something wrong and URP 2D Lighting isn’t this inefficient out of box

@erikabar
@rustum

@erikabar
@rustum

No word on this? It’s been 5 months.

I should add that I tested the latest Unity and URP versions with the same results

Oh, it’s older than that :stuck_out_tongue: :frowning: edit: OH! you’re the next poster in that thread too :frowning: :frowning:

Within 2d light context, “batch” can mean that the sprites that use the resulting light textures are batchable.
What version is this btw? I haven’t checked the latest version to see if they’ve fixed, so might be worth a try.

I just tried it again with a brand new 2D URP project using Unity 2023.2.0f1 and URP 16.0.4
I could try version 17+ but I suspect it will be the same result.

hmm I’m not sure what is meant by sprites that use the resulting light textures are batchable.
each light is the default 2D spotlight, they are all the same.
the sprites that are being lit by these spotlights are default square sprites, they are also all the same.

duplicating either of the 2D spotlights or the square sprites increases the batch count by 1 (as seen in the Stats window, whether or not the Stats windows is accurate is a different question heh)

so I guess we’re out of luck when it comes to using Unity yet again? :stuck_out_tongue:

2 Likes

Bump! It would be awesome, if we could get an explanation for this.

This even happens when using a Light2D in “Sprite” mode with identical settings. In this case we’re just drawing a sprite onto the Light Texture, I don’t see why batching can not be supported there. :frowning:

When you dynamically batch a sprite, it needs the same shader, texture and material properties. Its matrix (position, rotation, scale) can vary.

In contrast, with 2D Lights, the renderer generates light textures. Your light paints to one or more of these textures depending on the sorting layers it targets. These light textures are generated before rendering your sprites.

Step 1: generate light textures. Step 2: render sprites.

In step 2, these sprites now have an additional factor potentially messing up their dynamic batching – the light textures. So when I said the “sprites that use the resulting light textures are batchable” I mean this step of the process. If your SpriteRenderer has a Sorting Layer that uses light textures A, B, C whereas the next sprite uses light textures A & B (no C), then the batch will be broken.

But it’s step 1 that we’re all complaining about here – why can’t Unity use a different API so that its lights, during step 1, are batched…? Last I checked they were just using DrawMesh, likely because that’s simple and they weren’t sure how the renderer might change in the future. Well… now it’s the future and the renderer should be decently mature, so how about Unity eliminates those batches?

Yes, this case specifically is the one that I think could be fixed at least.