Archive 17/01/2023.

Shadows batches performance problem

Enhex

I’m using shadows causes performance problem because it creates tons of batches.

~25,000 batches, shadows enabled, direct lighting, 124ms frame on a users machine:
i.imgur.com/pfDEx7j.jpg

on my machine:
~29,000 batches, shadows enabled, direct lighting:
i.imgur.com/tDY1CD4.jpg
~4,400 batches, shadows disabled, direct lighting:
i.imgur.com/TRu1ot8.jpg
179 batches, shadows disabled, deferred lighting:
i.imgur.com/gU4BaYD.jpg

I’m using CustomGeometry to create the level models, could it be related to the lack of batching?
It seems like it creates a batch for every visible triangle.

Any idea what might cause it?

cadaver

If you have shadow casting point lights, they will render 6 shadow map faces, so your batch count will explode, particularly if the lights have large radii. Also in forward mode, each object affected by each light (in addition to the first one which is rendered with LitBase) will be a batch.

You can try playing with light and shadow masks in case your lights are “bleeding” to unnecessary objects. But in general, large number of dynamic lights will be a performance loss and you might have to look into some kind of precalculated lighting instead.

If you had models instead of customgeometries, for example 10 nodes each having the same model, same material and LOD, they could be instanced to 1 batch when in the same view (this applies to all of: main camera view, shadow map face, or an additive lighting pass)

Also, try to have as few customgeometries as possible, and within each, as little subgeometries as possible. Do not start a new subgeometry per triangle if it has a different material than the previous, but rather group together the triangles with the same material into the same subgeometry (in case you’re not already doing this…)