Hello everyone
i want to make a stencil shader to cutout a sphere from a cylinder. The part of the cylinder behind(coverd by) the sphere should be invisible. Only the front arc should be visible. So far the setup is no problem. However i also have other objects in the scene that are opaque and should not be covered by the stencil. Also the cutout part needs to be rendered on top all object.
So what i tried:
Cull Shader (Rendered on layer 2001 therefore ZWrite on won’t block the other objects):
Shader "Custom/Cull"
{
SubShader
{
ColorMask 0
Stencil{
Ref 1
Pass replace
}
ZWrite on
ZTest always
Pass { }
}
}
Top shader (Rendered on layer 2002):
Shader "Custom/Top"
{
Properties {
_Color("Color", Color) = (1,1,1,1)
}
SubShader
{
Color[_Color]
Stencil{
Ref 1
//Only render if pass the stencil buffer test i.e. equal or greater
Comp gequal
}
Pass { }
}
}
I attached a screenshot of the result. Unfortunately if the ring is covered by a scene object it won’t be rendered on top which makes sence, because the Top shader only renderes everything inside the stencil mask and outside only if the ztest succed. So i need some kind of ztest that only tests outside the mask. Else the covered part of the cylinder will be visible, too. I thought about using a second rendercamera or multiple materials but that sound a bit cumbersome. Any idea on how to get this result? Thank you for reading this