- Home /
Use stencil buffer to hide objects with same shader?
Hey there, I'm very new to shaders,
I have two objects in my scene, both use the same shader to get a transparent affect.
What I want though is that when the two objects are overlapping, I want the top object to hide the object underneath it. So you can see through the first object and not see the second object at all underneath but still see the rest of the scene behind it.
Basically these are UI elements that I want to be able to overlap and hide one another, but still see the game scene behind them.
I've looked into depth mask and stencil buffers but it seems to always assume you are working with two different objects and shaders.
I'm using the Shader from this project here for the "blurry refractions" - https://blogs.unity3d.com/2015/02/06/extending-unity-5-rendering-pipeline-command-buffers/
P.S. I modified the shader by adding a _Transparency prop and setting col.a = _Transparency in the frag function and Blend SrcAlpha OneMinusSrcAlpha
so that I could see through alpha values in the PNGs for the UI, just in case that affects anything
Answer by $$anonymous$$ · Mar 23, 2018 at 04:34 AM
I actually solved this after looking at lots of other solutions for similar tasks by doing the following -
instead of doing col.a = _Transparency
i did if (col.a < _Transparency) discard
Your answer
Follow this Question
Related Questions
Transparent object with look front of all object 0 Answers
UI/Default stencil buffer for only parent? 0 Answers
ui text and quad mesh render priority ? 0 Answers
How to make terrain partially transparent (lower opacity) 1 Answer
Is there a way to have a transparent vertex shader recieve and cast Shadows? 0 Answers