- Home /
Stencil buffer and transparency
I'm new to shaders in Unity and I'm trying to use the stencil buffer to avoid semi-transparent overlapping triangles to cause additive blending of pixels.
The problem is that also completely transparent pixels stops other pixels from drawing. I would like to threshold this so that completely (alpha < 0.01) transparent pixels don't affect the stencil buffer at all.
I have read this post so it seem to be possible. But how do I modify the shader I have to work like the other post describes. Where do I add the if-statement?
This is my shader:
SubShader {
Tags { "Queue" = "Transparent" }
Pass {
Stencil {
Ref 10
ReadMask 10
Comp NotEqual
Pass Replace
}
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off
ZWrite Off
Cull Off
SetTexture [_MainTex]
{
constantColor (1, 1, 1, [_Opacity])
combine texture * constant
}
}
}
Your answer
Follow this Question
Related Questions
Performance drop with transparent objecs overlying big meshes 1 Answer
Combining two transparent shaders with diffuse lighting 0 Answers
Using stencil buffer with OnRenderImage()/Blit 0 Answers
Standard Shader Still Visible through Stencil Shader 0 Answers
how to remove texture show-through? 0 Answers