Hello, tell me in what way it is better to implement a lot of health bars when switching from embedded rendering to URP. I can have up to 300 characters in my game at the same time. In order to reduce the number of Draw Calls, I used the material property block (and in some places, as there are materials that differ only in color, but there are quite a lot of them). But there is no support for material property block in URP , how to implement such a thing (a lot of health bars) in URP? Or stay on embedded rendering?
Thank you in advance.
Material Property Block will work in URP, but it will not take the fast SRP batcher path. It should work the same as in built-in renderer.
While not quite the same, you can create a material per character instead, which will allow them to go via the SRP batcher fast path. But I do understand that this can be a hassle to manage if it’s only e.g. a color that is different.
Well, for example, I have 200 characters, they have a material that is identical, except for the color. Is it preferable to use the URP feature, which should optimize shaders since only the color is different and there will be a large number of Draw Calls (I’m doing a project including for mobile platforms), or is it better to break the SRP batcher and use the Material Property Block?
In URP it’s okay to have a lot of materials since they batch by shader. The old standard pipeline worked the exact opposite, thus the outdated need for material property blocks.
What justin_sunblink said You should get better performance with the SRP batcher + many materials approach. This also allows the constant buffer memory to be allocated persistently per material, so it should only get re-uploaded to the GPU when you change values in the material.
So what is the best way to approach this in URP 2022 using Shader Graph?
I have about 300 car in the city, and each have 4 unique color properties.
I wouldn’t want to create 300^4 amount of materials on editor.
If batching is per-shader, does that mean I can just modify the material value through script on runtime (Creating a new unique instanced material), and then have it automatically be batched at best performance?
You can instantiate copies of a base material in Start and use those… the lack of a lightweight property override system per object has really been a problem for me in URP for years.
If your cars all have the same shader + geometry + textures (or a reasonably small set) you can look into gpu instancing if you just need multiple color properties (in a best case scenario this might be even faster than srp batching).
Hi, just for clarificaiton, if I understand this right, its alright to create unique instanced material at runtime because it will still be batched with the SRP batcher as long as they’re the same shader?
I want to say yes, but obviously there is a bit of memory cost associated with the additional materials but I guess it is really not that much. The SRP batcher certainly makes this approach relatively light on the cpu though.