SRP batcher isn’t working how I thought it would. Am I doing something wrong or are these the intended results?
My setup:
- 3 materials sharing a single shader (Universal Render Pipeline/Lit)
- material_A: color is set to red
- material_B: color is set to blue
- material_C: color is set to green, texture map, normal map, AO map
- Everything is static
- LWRP set
- SRP Batcher is on
I initially thought this would result in a single SRP Batch, but it looks like the keywords are added when I insert textures into the parameters. Are keywords in the shader ignored unless they’re being utilized?
5 SRP Batches, 2 Materials:
I can understand the keyword thing, but I have no idea why I have 5 batches with only 2 materials. Materials A and B batch together fine, it’s only when I introduce material C that everything breaks.
Here is my frame debug:
You have 5 batches because the render state is being set five times due to the different material keywords. Each time the shader variation is changed it breaks the batch and causes the render state to be updated.
_
For example, the second batch has bump map and occlusion map properties which means you are changing the shader - causing the render state to be updated. The third batch has no occlusion or bump properties so you are breaking the batch again.
_
You only have 2 materials but look at the order in which they are called due to the depth test results.
_
[1] Material 1 [2] Material 2 [3] Material 1 [4] Material 2 [5] Material 1
_
You need to remove the CliffJungle normal map and occlusion map, or add a normal map and occlusion map for the “UnityWhite” material.
_
" Are keywords in the shader ignored unless they’re being utilized?"
_
Unity (afaik) strips all shader attributes that are not used. So, because you have no occlusion or normal maps for the “UnityWhite” material you are breaking the batch due to the object render order.