Just 1 spotlight breaks static batching?

I’m prototyping a mobile horror game and so far I have a test environment and a flashlight working.

As this is mobile, the whole environment is on 1 texture atlas with the same shader, legacy diffuse and everything is set to static batching.

I have a spotlight attached to the player/camera which works well as a flashlight and the whole environment is light mapped.

I noticed that if I turn off the spotlight I get 1 draw call because everything is the same material etc. but as soon as the spotlight is on (no shadows) my draw call count is a lot more and possibly 1 draw call for every object on screen?

Is this correct and a good reason to not use real time lights on mobile or am I missing something?

If this is the case, I was thinking going back to the old school mesh combine might work better for this project?
I can’t seem to find that script in the standard assets anymore though?

I’m preparing (procrastinating) on the same task as you @Gnimmel with a similar setup (totally different genre). :wink:
From all the research I’ve performed - I believe your assessment is correct, but I thought this would be due to shadows, even though you stated no shadows. Possibly because the light is not static. Hmm.

Is the draw call count causing frame rate dips?

Thanks for the reply, it’s good to know it’s not something I’m doing.

I don’t think it is causing frame rate dips yet, but I still have a lot to add so it might soon.

1 Like

It’s due to the light itself, not necessarily the shadow. With forward rendering each object gets the first four brightest realtime lights that affect it. If two objects that are part of a batch have different lights, they can’t be batched.

That makes sense, but I only have 1 real time light, all the rest are baked. If I understand correctly, shouldn’t this be 2 draw calls, objects that the real time light touches and objects it doesn’t

That would certainly be a logical conclusion, but batching tends to not be quite so logical. :slight_smile:

The way Unity renders real time lights tends to trip people up and cause confusion, but each light is rendered as a separate additive pass of the geometry. So in the basic case of two static objects with baked lighting and a single spot light on one this will be at least two “batches”; one of both objects with the baked lighting, one of the one object with the light hitting it, plus at least one more for shadows if the spot light has then enabled. If the spot light is hitting multiple objects add one or two more for each object.

And that all assumes there’s not another reason the shader properties for each object in the batch isn’t changing causing the first staticly lit batch to but get broken apart either intentionally or from a bug.

2 Likes

Thanks for the explanation, it makes a lot more sense now.

From this, it looks like a mesh combine script would be beneficial for situations like this, baked lighting with 1 real time light.