Material Layers Optimization

Im started on a project and want to set up a good foundation for the Material Layer system, but i can’t find much information about it. One performance question i have is:

What is the best (in terms of performance) way of doing the Material Layer Blends?
A library of smaller restricted Layers Blends, so you choose what Layer Blend you want to use for your specific case. OR is it better to have a “Master” Layer Blends that contains a lot of different blend methods and take advantage of switches, so you always use the same Blend Layer no matter how you want to blend?

If someone has an answer or just a hunch of what probably would be the best way to go id be grateful!

1 Like

I hope somebody else can pitch in here. I jumped into it a while a go but then abandoned it. The library of layer blends seemed like the way to go. But it was frustrating because there seemed to be no way to measure the performance… In the epic videos they say that it only compiles the necessary nodes in the final material but in the shader stats it jumps up really high to like 16 Texture Samples/Lookups with just one lightweight layer. And in the shader optimization viewmode it seems to just display the same dark green color regardless of complexity. To me it just ended up being faster to just alter an existing material and use instances than to try and do everything with a bunch of premade bend nodes. If you make a bunch of nodes at the beginning of a production you are kind of locked into that bc if you want to alter anything it will change all the already existing materials and it just got really confusing

I would try 2d texture array for storing textures and store blend info in vertex color. This is how is it done in AAA games, you can easily texture walls in whole town with one array (material). If I remember well, Witcher 3 was using this technique quite a lot. Also it is probably only way how to do performant multilayer terrain material. But I am not sure, how far is UE with this. I ve seen tool for 2d texture array creation in 5.0EA, but never tried.

Got the similar question. Any ideas how material layers are constructed internally - are they run separate shaders for each material layers and then blend them (basically having 1 draw call for each material layer) or unreal is compiling all layers and layer blends into 1 shader and it’s somewhat optimized?

This same question came to my mind, I was planning to go with this approach by creating a unique Material Blending Layer and decide the channels I want to blend with static switches. This way the shader complexity would be reduced as it does not calculate the “branches” generated by the switches, however, and I am not really sure about this, as far as I know static switches generate a lot of shader permutations (I think up to 2^n, n → number of static switches in the worst case) that the engine needs to compile when releasing a build, and cause long loading times or ingame stuttering.

However, as I say, I am not 100% sure if Material Layers are handled this way by Unreal and I would appreciate so much if someone shed some light on this topic.