Stencil inside Stencil? (Multiple masks on same object)

Hello

So please take a look at what I want to achieve
71995-masks.png

The Red and Blue part is the object I want to mask. The thing is that it will be masked by the green area, and only after that it will be masked by the cyan area, which shall act like a scrollview. Currently I use stencil shader and the first mask works, but I don’t know how to apply the second mask.
Also, I don’t want to use the built-in UI mask system for this. All the objects in the scene are sprites.

Could you please give me a tip about what I should do in this case?

Hello, and Sorry for my English in advance :slight_smile:

I’ve achieved this using reading masks.
In my algohrithm first 5 bytes in Ref parameter of stencil buffer is maskId, and last 3 is depth.

I render sprites if Ref value equals Stencil value.

I render mask only if first 5 bytes of Ref value equals stencil value.
(Using ReadMask 248 = 11111000)

If I encounter nested mask, I’ll increment depth value (was 11111000, became 11111001).

72502-71995-masks.png

Hope this helps :slight_smile: