Uninomicon

Documenting the dark corners of the Unity Engine.

User Tools

Site Tools


static_batching

This is an old revision of the document!


Renderer Batching

There are a few different ways that Unity can combine meshes together, for optimization: - “Static Batching” - The checkbox in the Unity Player Settings - “Dynamic Batching” - A now-outdated mode of runtime batching. Not recommended. 1) - “SRP Batching” - A new runtime batcher for the SRP.

  • See StaticBatchingUtility.Combine to batch meshes at runtime.

Static Batching in Unity creates a Read-Only mesh named “Combined Mesh (root: <root-game-object>)”, with a Submesh for each batched renderer. Unity invokes a separate draw call for each range of indices within the combined mesh buffer.

Note that this means Unity does not actually render the entire batch in a single draw call. As they mention, truly merging all meshes would make culling vastly less effective.

Instead, the performance comes from issuing fewer material / mesh change state operations (in OpenGL at least). In a lot of ways, this ends up being more similar to SRP Dynamic Batching.

Lightmap UV Coordinates

The lightmap coordinates from Lighting Data Asset are baked into the Combined Mesh UV coordinates when the scene loads2). Afterwards, querying meshRenderer.lightmapScaleOffset will return the old scale and transform, even though it has been baked into the mesh. Technically, in the render pipeline, all of these meshes have a lightmapST (scale/transform) of '(1,1,0,0)'. 3)

1)
I can no longer find a player settings checkbox to even enable this feature
2)
I think this also happens during standalone build, not at runtime, but I'm not sure
3)
It shows the scale and transform it loaded from the LightingDataAsset file for that renderer.
static_batching.1616279072.txt.gz · Last modified: 2021/03/20 22:24 by 73.95.178.156