- Home /
Use the stencil buffer in multiple passes in a single shader
Hello, this shader wants do display Green whenever the stencil is filled with the reference value and red whenever it isn't. However, I allways have the color of the first pass but never the other. Am I doing something wrong ?
Shader "Stencil/StencilOutline" {
SubShader{
Pass{
Stencil{
Ref 1
Comp Equal
}
CGPROGRAM
#pragma fragment frag
#pragma vertex vert_img
#include "UnityCG.cginc"
float4 frag(v2f_img i) : COLOR{
return float4(1,0,0,1);
}
ENDCG
}
Pass{
Stencil{
Ref 1
Comp NotEqual
}
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 diff : COLOR;
};
float4 frag(v2f i) : COLOR{
return float4(0,1,0,1);
}
ENDCG
}
}
}
Comment