I have to ask about it because I couldn’t find definite answer over internet (I was looking for UE3, it might have been diffrent in UE4 anyway).
Is there any diffrence between MaterialInstance and Material in terms of rendering perfomance (Draw Calls ?).
Let’s say I have two diffrent meshes.
In first case I have appliled to both meshes two diffrent material instances of master material (with diffrent parameters).
In second case I have applied two diffrent materials (or material instaces from two diffrent master materials) also with diffrent textures and parameters.
Is there any perfomance diffrence between these two ? Or the MaterialInstance is more of convenience tool that allow modfifying materials at run time, but doesn’t really affect how fast things are ?
Would it be better to create one super-master material that covers most of the things I have ever needed and reuse it over and over again, or creating smaller but more specialized materials would be better ? (again I’m asking in of performance diffrence).
I can’t really give an estimate of performance comparison, but I do know this: a material instance makes use of the same compiled shader. therefore if you have a scene with 5 MI’s you’re actually just executing one shader, while if using 5 different materials you’re executing 5 shaders.
the way I see it, it’s probably best to re-use as much as possible but within some sense. ie. using your terrain material for static level assets would be a bad idea
from my experience with UE3, making a ‘master’ material with lots and lots of parameters would heavily slow down its editability. ie. changing a single scalar param on an instance would hang my PC for at least 15 seconds. I hope this has changed in Rocket
anyway, you can probably reduce it to the following: a terrain material, one or a few ‘master’ level materials depending on how different they might be, a generic level asset material, a weapon material, a character skin material, a character hair material, and maybe character cloth/eyes/others if you’re going for a lot of detail. then of course one or multiple materials for particles and other effects, and one each for other specific stuff like grass, trees, etc.
I currently have master material with “even I don’t know how many” parameters and I didn’t notice any issues with editing it. I guess is due to deffered compilation of materials.
Anyway my confusion is coming from the way the material system is structured. We have already master material (the thing where we plug textures), and I wondered if the building another shader network on top of it have any real impact on perfomance, because to my knowlegde we always instace the core system and add new things on top of it.
Limiting the number of material shaders can definitely be a boon to performance. Static switch and mask parameters make the distinction a bit unclear so I will try to explain it:
A material with no static switches will generate a set of shaders. All material instances that use the material will use the same set of shaders.
A material with static switches will generate a set of shaders for each unique combination of static switch settings across all material instances that use it. All material instances that use the same set of static switches will use the same set of shaders.
An example, let’s say you have two materials: M_Wood with no static switches and M_Concrete with a single static switch: IsWet. Then say you have a bunch of material instances that use M_Wood, a bunch of material instances that use M_Concrete with IsWet=False, and a bunch of material instances that use M_Concrete with IsWet=True. The engine is going to generate three separate sets of shaders: one set for M_Wood, one set for M_Concrete with IsWet=True, and one set for M_Concrete with IsWet=False. All of the material instances that use the same master material with the same set of static switches will use the same shaders.
My usual recommendation to content teams is that you want to have a simple material with no static switches to use on the bulk of assets in your world, say 90%. You then want to leverage the material editor to make very interesting materials for the other 10%. But it all depends on what you’re trying to achieve, whether you want the performance benefits of material reuse or you are willing to draw fewer meshes but want more variety in materials.
Inrteresting answer.
I’m developing for mobile and obviosly I need my device to work as least as possible. I’m working to create a parent material with parametric texture so i can use istances for wood, metal, plaster, and maybe forniture, too.
So twould this solution help me androud phone to work less and better, maybe pumping up other settngs?
I’m a bit late to the party but you can use LERP’s instead of switches so you can have these options without the internal recompilation of the shader. This does make the main shader a bit heavier but you also only need one shader.