How to create layered PBR diffuse channel using masks?

Hi everyone,

Please take a look a the attached image.

I would like to create a kind of ‘layer’ in the PBR diffuse channel where I can switch out several textures.

I have additional ‘layer’ textures (1a and 1b) that I want to switch and make them part of the diffuse channel using the masks, by somehow joining them into the base diffuse texture.

Is this possible, and if so, what would be the best way to do it?

For me it doesn’t matter if the layer-texture is ‘stamped/baked’ into the base texture, because I can always start over with a fresh base texture and do the stamping again.

Thank you for any advice!

(By the way, this is a very simple example, the actual application uses hundreds of textures, and we cannot generate all possible combinations upfront.)

The best way is probably to use a node material. For eg:

https://nme.babylonjs.com/#MXERI0

Then you can programmatically change the texture of the detailTexture block whenever you want.

Well that is awesome! Thank you @Evgeni_Popov! Would I be able to stack about 15 of those detail textures blocks on top of each other without any problem (except for performance)?

It may work as I think the minimum textures that can be bound in a fragment shader in WebGL2 is 16 (and quite often it is also the maximum, depending on your GPU - for eg, on my GTX 1080 it is 16 max)… However, stacking 15 textures on top of each other in a single shader seems really a lot to me! You will definitely have some perf hit because it means 15 texture lookups per execution of the fragment shader.

Okay great :+1: :+1: I’m still amazed every time I discover what Babylon.js is capable of and how easy it is to implement, just incredible.

By the way, 15 textures would be a rare case, but super that it will still work. Mostly I’m thinking 4 or 5 combinations.