I have done 2 tests
A) Master material for vert painting with 3 layers. A little complex-ish to make the blending look ok. Instructions count is around ~100. Shader complexity is light green.
B) Master material for online material layering with blending between 4 layers using masks. Instruction count is around ~85. Shader complexity is a little darker than light green (given it has 3 layers more than the vert paint material)
We read everywhere that online layering is very expensive and should avoid using as much as possible. My question is if layering with 4 layers is sitting at 85 instructions and vert paint with 3 layers sitting at 100 instructions and both are still green, where else do I have to look at to see that for “x” reason we have to go with vert painting instead and drop online layering. Since people mostly suggest vert painting over online layering.
Thanks in advance!
Its not about the layers necessarily but the overall material complexity. you can easily make 1 layer that is more expensive than 10 cheap layers.
It sounds like your vertex paint modulation shader is quite expensive compared to the straight up blends.
To test I would remove all modulation and hook up the raw vertex colors as the alphas, then you can see if your layers themselves are too expensive.
Ie, make a new material with only 1 layer and compare that to a single layer from the other material you are saying is so cheap. I bet the other layer is simpler too to explain that much difference.
This time the setup is very simple. Is online layering still considered expensive comparing to vert painting?
Edit: In shader complexity view both are the same light green.
Vertex layers use more instructions on the vertex shader, while texture masks are handled in the pixel shader. Typically, vertices are better to use because there will for the most part be more pixels to render an object than vertices, especially in HD. This is why people say the more you can switch to vertex operations, the better. However, vertex blending doesn’t look good unless you combine it with a pixel texture, so there should be some pixel cost no matter which method you decide to use. Also, vertices are managed all at once, whether the mesh shows up as a single pixel or fills the screen, the cost will be the same. You have to weigh your options to figure out what works well for the look you are trying to achieve.
Of course, just blending one layer isn’t such a huge deal. The more layers you have, the more “tests” the operation has to perform to achieve the final result. Ideally, one would use landscapes to limit the number of layers based on what is painted in the system. You can have 10 different layers set up, but if a landscape component only uses two, then the shader is written only to test between the two layers, not all 10 at the same time. Blending between 3 or 4 materials shouldn’t be too bad, but you will end up with a wide variety of choices doing a linear blend between all of them. See how small you can manage, and if you need more complexity, see if you can find some way to split it up. If not, then see what is the cheapest way you can achieve the result, either simple vertex blending (awful choice, but good on performance), or a basic texture blend (looks much better, but worse on performance).
Normally I wouldn’t stress instruction counts too much because of how incredible modern day GPUs can run, but if gamers demand higher resolutions and performance in 3D with landscape materials that fill the screen, and run it all on a mobile device, you definitely need to watch out!
It doesn’t matter if you blend using separate lerps like the top one or using the matlayerblend node like the bottom. They are exactly identical; the blend node encompasses all the lerps in the function. And since you are only using the basecolor and normal attributes, you are using the same number of lerps in both cases.
The only cost difference above is that in the first you used a vertex color which is a very cheap lookup as the alpha, and in the second you used a texture alpha which adds another texture sample to the material. Texture samples are more expensive than vertex colors. As mariomguy pointed out, you just shifted the 1 instruction difference from the pixel shader to the vertex shader. But you can consider vertex color lookups to be almost free.
So basically if the cost for blending materials using a low res RGB map is only that we’re having a low res RGB map, we can say this isn’t going to noticeably hit the performance in comparison to vertex painting which doesn’t have that RGB map. Am I right?
Yes, and channel packing your masks will save some performance over having separate textures for each alpha. One texture for blending should not be a big deal.
Do you suggest that using this workflow of blending between materials for a wide range of assets is better than having a unique texture set per asset?
We’d be able to reuse materials everywhere and reduce the overall texture memory a lot, but I’m not sure if having 100/150 instructions per material is going to be ok down the line? but it might very well be performing better since we have a lot less textures to render. But since I can’t make a comparison without having 2 game worlds each textured with one of the workflows it’s hard for me to make a guess. Would be appreciated if you can shed some light.
For example for a door we can make unique texture set, shader complexity will be light green.
Or we can reuse materials on it with layering workflow, but shader complexity will be medium/dark-ish green.
I’m stuck between which is more efficient.
No its the opposite, separate textures are better for workflow since the alphas can exist in isolation. Channel packed textures are better for performance. It is up to you to find your ideal balance point between good workflow and optimal performance.
I thought material layers were pretty expensive in comparison to regular materials with just a unique non tileable diffuse roughness normal. Do the channel packed masks replacing the unique textures make up for the performance drop from the shader?
It wouldn’t offset the entire cost, but it would save some instructions.
The point I am trying to make is you can’t simply say “this material with X layers seemed faster than this other material with Y layers”, it all depends on the actual content of the layers as well as what kinds of masks you use. There is no “right way”, everything is a choice and a trade off.
Six years later- I’m new to UE the first tutorial I saw in regards to blending was a Vertex Painting tutorial, now, I’ve also been through a Material Layering tutorial. Requesting an updated answer as to which is considered better. If it depends on circumstances could you please explain what makes one better than the other under the circumstances?