- Home /
Shader - Hide self overlapping mesh
We are creating draw engine in unity, and we are using LineWorks asset for creating lines. Marker pen needs to tint colors behind, and we do this by reducing it's opacity and it works well so far. But the thing is, when one line overlaps itself, we want it not to tint itself, but to tint everything underneath
Example:
This is what we have so far
And this is what we want:
These are both meshes, and we have our custom shader. Is there any way we can just adjust the shader to ignore overlapping parts of the mesh?
Thanks in advance
Answer by Micito · Feb 05, 2018 at 11:22 AM
We have found a solution that works well for our purposes.
Our shader is 2 pass shader now where first pass draws object and sets stencil to:
Stencil {
Ref 0
Comp Equal
Pass IncrSat
}
and second pass actually just clears the stencil so any other lines on top will be drawn:
Stencil{
Ref 0
Comp Always
Pass Replace
}
And since mesh was calculated in shader (LineWorks) we needed to make second pass do same math, just with
ColorMask 0
Which causes it not to render anything, just clear the stencil
Your answer
Follow this Question
Related Questions
How can I make a part of a mesh to be invisible - ie: see through parts of walls... 2 Answers
double-sided plane with texture? 4 Answers
Dynamic Occlusion Flickering in Unity 2020.3.1f1 LTS. How to fix? 1 Answer
Overlapping surfaces problem 0 Answers
Hiding or deleting specific faces of a mesh with a texture or LUT? 2 Answers