Article directory
Preface
In the previous article, we learned that SRP Betcher can be allowed only by using the constant register CBUFFER.
In this article, we take a look at what SRP Batcher is.
1. What is SRP Batcher?
-
The SRP Batcher is a render loop that speeds up CPU rendering in a scene with many materials using the same shader variant.
2. Conditions of use of SRP Batcher
1. Programmable rendering pipeline
- URP
- HDRP
- Custom SRP
2. Let’s use URP as an example
- Ensure the project uses URP
3. Use SRP Batcher is turned on in URP settings.
- Turn on the Debug mode of the Inspect panel
- Make sure Use SRP Batcher is turned on
4. Enable the SRP Batcher code path to render objects
- Rendered objects must be meshes or skinned meshes. The object cannot be a particle.
- Shaders must be compatible with SRP Batcher. All lit and unlit shaders in HDRP and URP comply with this requirement (except for the "particle" versions of these shaders).
- Rendering objects must not use MaterialPropertyBlocks.
5. Make shaders compatible with SRP Batcher:
- All built-in engine properties must be declared in a CBUFFER named "UnityPerDraw". For example: unity_ObjectToWorld or unity_SHAr.
- All material properties must be declared in a CBUFFER named UnityPerMaterial. That is, the constant buffer of the previous article
CBUFFER_START(UnityPerMaterial)
half4 _Color;
CBUFFER_END
3. Differences between different batches
BuildIn Render Pipeline下:
- Static Batching (static batching)
- Static batching optimized for Batching in Unity
is usually used in scene baking.
Needs to be met: the same material ball can use different meshes, and static batching must be checked
- Dynamic Batching
- Dynamic batching of Batching optimization in Unity
needs to meet: the same material ball, different meshes can be used, and the limit of the number of vertices of a single model with 225 vertices
- GPU Instancing (GPU instantiation)
- A summary of GPU instantiation optimization for Batching in Unity
Needs to be met: must have the same mesh, different shader attributes can be used, and must be the same Shader
Universal Render Pipeline下:
SRP Batcher (SRP batch)
Need to meet: the conditions for the use of SRP Batcher mentioned above
4. Compare the differences between each batch of renderings between BRP and SRP
1. Under BRP
2. Under SRP (the CPU part is the core of SRP)
5. In Unity, test the effect of turning on and not turning on SRP Batcher.
- In Unity, prepare a scene like this for testing. Four objects use different shaders of the same Shader.
1. Do not turn on SRP Batcher (HDR needs to be turned off)
4个对象用了4个批次
2. Enable SRP Batcher
只用了一个批次