If I have a scene with some objects all using the same material and only directional lighting, it gets rendered in one batch, one setPass-call, no problem.
As soon as I add a single point or spotlight, batching breaks completely. I’ve tried finding the reason for this, but all sources I could find basically just say “it just does” or “unity can’t batch multi pass shaders”. Even the forward base pass, which should only be using the directional light, now issues a ton of setPass-calls, where previously only a single one was needed, even though the gpu data stays the same for all these calls. I’ve checked the frame debugger of course, which says “objects are affected by different forward lights” as batch-breaking reason, but why is this a thing? The materials, shader, pass, gpu data, vertices, textures, matrices, everything that could be different to the previous draw call and require a setPass-call is the exact same, so what is there to “set”? I don’t understand. Forward base pass doesn’t even use these additional forward lights.
Forward-add-pass draw calls, of course, don’t get batched either - another thing I can’t wrap my head around. These are additive passes, separate from the base pass, and for the same spot or point light, their draw calls again share all gpu data etc between them. Can’t be batched though, instead every draw call needs a setPass-call, to replace the current render state with seemingly the exact same data.
The funny thing is, I can at least “fix” the broken batching for the forward base pass by splitting my passes into two shaders, one only containing the base pass with only directional light support, and one containing only the forward add pass, then rendering all objects with both shaders. Now, the base pass at least gets batched again with a single setPass-call and isn’t disturbed by the additional forward lights. But this seems like a dumb workaround and also doesn’t fix batching of the forward add pass.
If somebody has some insight to share on this topic, either why this can’t ever work or how it could be made working, I’d appreciate it.