I’m currently trying to figure out how to get per-instance MaterialPropertyBlocks settings to work with shader variants.
As I see it, MaterialPropertyBlocks has currently no method to set shader variants, e.g. like Enable/DisableKeyword.
What is the correct procedure to switch the shader variant in use, ideally per instance (in this case, a GameObject holding a controller MonoBehaviour)? Where are the pitfalls?
(E.g. cloning the material is going to lead to in-memory copies.)
The correct procedure is to not use keywords / variants, because instancing doesn’t work between variants. Every instance in a GPU instanced draw needs to use exactly the same material, mesh, and shader variant.
The solution is to use if or switch statements in your shader checking against an instanced property.
Ok, but if I do use ifs/switches and have ComputeBuffers that I only set at runtime, the shader doesn’t show in the Editor and I get log spam like this: Metal: Vertex shader missing buffer binding at index 4 (BonePositions / SpheroidNormal/Debug/SpheroidNormal)
This is the core of my issue. What’s the best way to handle this?