#Question about Material Override with Property Blocks

1 messages · Page 1 of 1 (latest)

errant jay
#

Hey there! I've got a quick question about material handling... Our game has very flat materials with no textures, so we end up getting tons of materials that are only meant for colors. It was getting a little difficult to manage so many colors so I ended up writing a little script where you can set diferent colors with a material property block like:

rend.GetPropertyBlock(s_block,i);
s_block.SetColor(s_color, _colorInfos[i].MatColor);
s_block.SetFloat(s_max, _colorInfos[i].MaxFloat);
rend.SetPropertyBlock(s_block,i);

Now we only have one base material, and we can change the color freely for each object.

My question is... Can this affect badly the render pipeline? I have also activated GPU Instancing as they are all using the same shader/material now. I have done some testing and it seems fine 🤔 But maybe I'm missing some deep knowledge ahaha

Thank you for your time!

lost ginkgo
errant jay
#

Oh! Without?

lost ginkgo
#

But SRP batching is probably better

lost ginkgo
# errant jay Oh! Without?

SRP batching is not compatible with MPBs or with GPU instancing
With it you'd make more materials, or runtime instances of materials
Since you're setting MPBs from code, creating material instances from code would not be a different workflow

#

GPU instancing has an overhead cost so it's best to use it when you have a lot of the same mesh, though in my tests SRP batching beats it even with thousands of meshes

#

Without any of its limitations

errant jay
#

I see, this is actually just to ease the development as there are not a lot of materials lying around now, but If I can have an optimization boost I will take it too ahah

errant jay
lost ginkgo
#

(by variants as materials I don't mean "material variants" which are an editor UX thing that lets materials inherit properties of parent materials with their own overrides, maybe that helps too)

errant jay
lost ginkgo
#

Destroying or unloading the scene they're from sends them to the Garbage Collector, which is better than letting them take up memory but you can re-use material instances as well if you do object pooling to avoid the GC cost