Question by
Heroes_Fall · Apr 08, 2018 at 12:59 AM ·
c#shaderstencil
Stencil Shader not working with Raw Image UI
I have a stencil shader that hides other gameobjects based on Ref
values and it works perfectly fine when applied to a gameobject such as a plane. However I want to apply this to a UI element, specifically a Raw Image and nothing works.
Shader
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
}
SubShader
{
Tags {
"RenderType"="Opaque"
"Queue"="Overlay"
}
ColorMask 0
ZWrite off
Cull off
Stencil
{
Ref 1
Comp always
Pass replace
}
CGINCLUDE
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 pos : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag(v2f i) : COLOR
{
return half4(1,1,0,1);
}
ENDCG
Pass
{
ZTest Less
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}
[Full credits to Breakfast with Unity for code]
I've tried converting the code to an Unlit Shader with no results (and I'm aware that I could use a plane object to cover the camera but that introduces some clipping problems near walls). I'm not familiar with shaders so sorry if this is a dumb question.
Comment
Your answer
Follow this Question
Related Questions
WebRequest in unity 1 Answer
Unexpected symbol error in shader script 0 Answers
Efficient passing variable from Unity script to shader 0 Answers
C# Editable Gradient sky in the Shader Graph. 1 Answer
Default stencil code 0 Answers