Unity3d Shader Z testing question, ZTest Greater but keep behind

381 Views Asked by At

I'm rather new with shaders in Unity and I'm trying to create something but all my attempts failed. The scenario is this, I have the following objects: A,B,C.
A is a sprite, B is a Textmesh (not GUI) and C is a depth mask rectangle.
I wanted to take the text and scroll it over the "A" sprite, but since just scrolling the text over the sprite will result in the text going out of the sprite bounds, I wanted to create a depth mask that only while rendered on that mask the text will appear, and place that mask on the sprite.
That worked just fine, I put the sprite (A) then the text (B) and I added ZTest Greater to it's shader, and then (C) the depth mask, which is basically a rect with the following shader:

Tags { "Queue" = "Transparent" }
Lighting Off
ZTest LEqual
ZWrite On
ColorMask 0
Pass {}

This makes it so the text only appears on the rect of the mask and once its scrolled out, it vanishes, which is great.
Now for my problem, I have another object, which can appear on top of everything, and should make everything vanish as well (so I used a depth mask like stated above), but since I've already defined the text to be ZTest Greater, when that object goes over, everything disappears correctly except for the text.
My question is as follows, is there a way to differentiate between the two masks, so that the text will appear on one (passing the Ztest), but disappear from the other(failing the Ztest?).
Attaching a screenshot depicting my problem, as you can see, the red masks are showing only part of the text (which is good) but the blue mask which needs to be the end of the screen is not working on the text because the text is ZTest greater which is needed for the red mask.
So what I actually need is a way for the blue mask to cover the text but the red mask reveal it. enter image description here

Any ideas if you can assign specific objects so that they will act differently with each other object, with regards to the shaders' tests? (or a similar solution)

0

There are 0 best solutions below