Applying one texture on another using a mask texture

So i was trying to do the same thing that was described in this guide before animation: Texture masks using a shader | Playing in Canvas
However as I may see (even looking at the example project) this doesn’t work anymore.
To try to understand this I am trying this on simple cube model

Then I have a white and black / rgb mask texture and another texture I want to apply to the cube by the white / red pattern on respective mask.
image

How can I achieve this nowadays?

In this case, use the opacity channel of the material to do the ‘masking’

Oh, it helped, thank you

Is there a way I could add this mask material over some other material on the same mesh instance?

No, you would need to use stenciling for something like that or a custom shader

Thank you. Is there a guide or something for these methods? I’m kinda new to Playcanvas so there are many things I don’t know yet.

For these specific methods or in general? Between the forum, user manual and tutorials, it covers quite a few areas.

Is there something specific that you are looking for?

Here’s one for using a the stencil buffer: Stencil Buffer - 3D Magic Card | Learn PlayCanvas

Well, I have a model of a character. It has a mesh for a face texture, but there is going to be a customization of the character where we can change eyes, lips etc. So I need to find a way to mix two textures using one as a “background” and others being texture masks overlaying it.

I’m not sure what your face looks like but this is going to require something custom.

Some people have used the detail map on a material (eg StandardMaterial | PlayCanvas API Reference) to have a secondary texture on top of the primary like a decal.

But that is potentially going to be limited as you want something that works for eyes/nose/lips. :thinking:

@Leonidas, any ideas on this one? I was thinking about using multiple materials on a single mesh so you can do eyes, nose and lips per material with the same face texture as the base.

Either that, or use a custom shader chunk that would take the multiple textures for the base face, eyes, nose and lips and then blends/overrides them together which actually sounds easier to do in theory

For example, the eyes texture would be pink expect for the eyes and it would only apply the pixel to the final diffuse color if it’s non-pink?

So is it possible to use multiple materials on the same mesh? How can I do that?

This is one method and you will have to do this via code as it’s not exposed via the Editor. With the detail channels, you can set a separate UV offset/tiling to position if need be.

Otherwise:

1 Like

I don’t understand any of these :sob:.
I tried both methods some way, but the shader method was old and doesn’t work anymore and at multiple materials on the same mesh I just didn’t come up with anything that worked the way I expected.
Is there an example for any of those methods?

I’m afraid there aren’t any examples. I might be able to put together a detail channel material example if I have time

That would be awesome, thank you.

In the meantime, the simplest workaround is to have separate meshes that on top of the face for the face features that you can swap out the materials for.

The detail channel didn’t work as I expected it to unfortunately but here’s a small example of using a custom shader to add a decal on top of an existing diffuse texture:

https://playcanvas.com/project/1058547/overview/detail-map

You may also want to look at: Spray/Decal Script

Thank you, it seems to be what I needed.