Custom UI material with Mask ?


I’m trying to use a custom material on a Image component. But I need it to work with UI Mask.

I already added this :

_StencilComp ("Stencil Comparison", Float) = 8
        _Stencil ("Stencil ID", Float) = 0
        _StencilOp ("Stencil Operation", Float) = 0
        _StencilWriteMask ("Stencil Write Mask", Float) = 255
        _StencilReadMask ("Stencil Read Mask", Float) = 255
        _ColorMask ("Color Mask", Float) = 15

And this :
ColorMask [_ColorMask]

to the shader I use, but it didn’t work. Even the UIMaterial given by default with Unity didn’t work with mask.

Did I miss something ?

Thanks a lot

The proper - and full - answer is here

In essence you need that “1” set for the mask to work, and the supporting structure in the custom shader.
It was very easy.

I’m having a similar issue right now, did you find a solution? It must be related to the stencil buffer, but I’m not experienced with shaders at all.