- Home /
Using stencil buffer with OnRenderImage()/Blit
I am working with a modified version of a shader from this tutorial: https://youtu.be/LnAoD7hgDxw
I've added an option to write to the stencil buffer in the shader
Properties
{
(...)
_SRef("Stencil Ref", Float) = 1
[Enum(UnityEngine.Rendering.CompareFunction)] _SComp("Stencil Comp", Float) = 8
[Enum(UnityEngine.Rendering.StencilOp)] _SOp("Stencil Op", Float) = 2
}
SubShader
{
Tags{ "Queue" = "Geometry-1" }
// No culling or depth
Cull Off ZWrite Off ZTest Always
Stencil
{
Ref[_SRef]
Comp[_SComp]
Pass[_SOp]
}
(...)
}
What I'm trying to achieve is for the shader to hide and reveal certain objects that write to the stencil buffer. This works well when the shader is applied to a material and put on a mesh:
But it doesn't work when I use the material in OnRenderImage() with Graphics.Blit(). I simply get the white color but the spheres are not revealed by the effect (the sphere that is supposed to be hidden gets obstructed by the effect but I assume it's because of depth).
How would I go about making the stencil effect work in OnRenderImage()?
Your answer
Follow this Question
Related Questions
Cutting hole in water plane using stencil buffer.Help making it visible from both sides. 0 Answers
Graphics.CopyTexture and location fo textures 0 Answers
Custom bit size for Stencil buffer 0 Answers
How to use Graphics.DrawProcedural to render a quad over a scene? 0 Answers
Standard Shader Still Visible through Stencil Shader 0 Answers