Hi, as the title says i was wondering if someone could clear up just how expensive material instances really are?
My general understanding was that a “Master” material would take up 1 draw call per how many times its used and
material instances would be “combined” into a single draw call no matter how many were used in the world (like instanced static meshes).
When searching for how expensive Mat-Inst really were i read that if the Mat-Inst had unique parameter values then they would
each use 1 draw call similar to regular “non-inst” materials, so now i’m confused and there is no documentation on
material instance expense.
Material instances don’t work that way–what they are for is modifying the value of a material without changing the original material. For example, say you had a wall material that you use on a bunch of meshes but you want to highlight one particular wall, normally if you change the color in the material then it will change for every objects that uses that material. Instead if you use a material instance you can change the value in the instance without having to make a new material. A material instance will still cost a draw call.
The engine cannot combine multiple material instances that have different parameters.
(And for any dynamic actor, the engine has a hard time combining them anyway.)
However, “draw call” is one kind of cost. There is also the “shader switching cost” cost. When you have multiple material instances, they all re-use the same shader on the card, so it’s still faster to render a bunch of instances of the same material, than rendering a bunch of different materials where the shader switching cost is higher. Material instances also don’t need to store the additional shader code, so they save a bit of space, too.
The only way to group meshes into one draw call is by using instanced meshes. Meshes using the same material/instance will still take one draw call each. However, they are drawn in an order that is grouped by material/instance, to reduce the number of render state changes, kinda like this:
3 meshes using the same material:
set shader, draw mesh #1, draw mesh #2, draw mesh #3
3 meshes using a different material each:
set shader #1, draw mesh #1, set shader #2, draw mesh #2, set shader #3, draw mesh #3
Right now my materials are basic. Just textures for albedo/normal/rough/metal/occlusion plugged in. So I’ve set them as texture parameters and then created a lot of instances for the different texture sets. I assume this is cheaper than just creating a tonne of materials with different textures. But what is the memory cost of an instance? Is it the same as the base material or does it come at no, or at less, cost?