static_batching
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
static_batching [2021/05/02 16:11] – old revision restored (2021/02/11 23:28) 167.114.64.97 | static_batching [2025/01/15 04:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | | + | There are a few different ways that Unity can combine meshes together, for optimization: |
+ | | ||
+ | * " | ||
+ | * "SRP Batching" | ||
+ | |||
+ | |||
+ | Note that none of these options actually combine meshes together. They will all result in the same number of graphics API drawcalls. Instead, the purpose of batching is to optimize the order of drawcalls to avoid changing state between calls. | ||
+ | |||
+ | ===== Static Batching ===== | ||
Static Batching in Unity creates a Read-Only mesh named " | Static Batching in Unity creates a Read-Only mesh named " | ||
Line 9: | Line 17: | ||
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]]. | 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]]. | ||
- | ===== Baking | + | Static batching is done at build-time, so mobile developers should be aware that static batching can unexpectedly increase your build size. Static Batching can result in significantly more mesh data being generated, if many batch meshes are created. |
+ | |||
+ | ==== Lightmap UV Coordinates ==== | ||
+ | |||
+ | The lightmap coordinates from [[lightingdataasset|Lighting Data Asset]] are baked into the Combined Mesh UV coordinates when the scene loads((I think this also happens **during** standalone build, not at runtime, but I'm not sure)). Afterwards, querying '' | ||
+ | |||
+ | Static batching can actually work with manually provided lightmap scale/ | ||
+ | |||
+ | ===== Batching and MaterialPropertyBlocks ===== | ||
+ | |||
+ | Static and SRP batching is incompatible with MaterialPropertyBlocks, | ||
+ | |||
+ | This is the data sent by the SRP batcher for each draw call: | ||
+ | |||
+ | {{ :: | ||
+ | |||
+ | This data is efficiently managed by the engine and uploaded to the GPU as fast as Unity can. The idea is to abuse some of these built-in values to pass custom data. Good candidates are '' | ||
+ | |||
+ | An example, when using SRP batching: | ||
+ | |||
+ | <code csharp> | ||
+ | renderer.realtimeLightmapIndex = 0; // forces " | ||
+ | renderer.realtimeLightmapScaleOffset | ||
- | The lightmap coordinates from LightingDataAsset are baked into the Combined Mesh UV coordinates when the | + | // For custom SRPs: |
- | scene loads((I think this also happens during standalone build, not during standalone runtime, but I'm not sure)). Afterwards, querying '' | + | // (Only relevant for custom SRPs; in existing RPs it should likely just work as is, as they all support lightmapping in the main pass) |
+ | drawingSettings.perObjectData = ...; // PerObjectData.Lightmaps or otherStuffYouNeed; | ||
+ | </ | ||
+ | On the GPU you should have a '' |
static_batching.1619971893.txt.gz · Last modified: 2025/01/15 04:35 (external edit)