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
110559-screenshot-1.png

And this is what we want:
110560-result.png

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

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