- Home /
Stencil inside Stencil? (Multiple masks on same object)
Hello
So please take a look at what I want to achieve
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?
Answer by shellash · Jun 21, 2016 at 09:24 PM
Hello, and Sorry for my English in advance :)
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).
Hope this helps :)
Your answer
Follow this Question
Related Questions
UI/Default stencil buffer for only parent? 0 Answers
Stencil Buffers With SpriteRenderer 1 Answer
Multiple sprite mask 0 Answers
Stencil on iOS 0 Answers