Limiting batches in HDRP

I’m currently working on a rather large top down scene for a personal project of mine, and I’ve decided to try out HDRP for the first time. I’m using realtime lighting with almost exclusively static objects, using very few materials so far. Despite this, I’m getting a ton of batches.

There are 2 factors I don’t understand. One is why unity doesn’t seem to batch static objects using the same material, another is that the camera seems to render way more objects than are actually in view.

For an example, here is my entire scene seen from above


It has roughly 11k batches

Now here is the scene much closer to the ground… a rough estimate is that you’re probably seeing 5% of the same scene


We’re at 5,7k batches… that’s half despite the fact that we’re looking at nowhere near half the scene here.

So that’s the camera issue I’m wondering about… With regards to the bathcing static objects question; I was under the impression that if i marked objects static and they use the same material unity will batch them together… Each building in the scene is built frmo wall parts, explaining the high number of objects, but the vastly majority of them are using the same 8-9 materials.

Hi, hard to tell without access to the project. HDRP have SRP batcher enable by default and should batch material.
cc @arnaud-carre

I’m not entirely against giving access to the project somehow, obviously I’m not gonna be posting it publically on the forum.

Do you have any input on why the camera appears to be rendering way more than it logically ought to?

Hi!
I see two questions here:

  1. “why my objects aren’t static batched together because they use the same material”. I think they are probably static batched. “static batching” in unity doesn’t reduce the number of drawcalls, it just avoid some GPU setup between drawcalls ( set new vertex buffer, set new material, set viewworld matrice etc).
  2. “why is there still so many drawcalls when the camera is really close”. I can’t tell for sure but my guess is probably a culling issue.
    If your scene contains many similar static houses, better create a merged house mesh and do a test, it should improve the rendering time.
    Btw if you need better rendering profiling metrics, use SRPBatcherBenchmark/Assets/Scripts/SRPBatcherProfiler.cs at master · Unity-Technologies/SRPBatcherBenchmark · GitHub script in your scene and press PLAY.

The SRPBatcherProfiler.cs script you linked to throws the following error in Unity 2019.3.11f1 using HDRP v7.4.3:

Assets\Scripts\SRPBatcherProfiler.cs(26,20): error CS0118: ‘Recorder’ is a namespace but is used like a type

Either swap line 26 to

            public UnityEngine.Profiling.Recorder recorder;

or just get rid of the namespace (lines 8-9 and last line).