Help with outline material

I’m struggling to create an outline material that suits my needs.

I’m currently using as a base the material found here, which is very nice.

To show what it looks like, take this image:

With that material on, it looks like this when I activate the custom depth on that circle-thing (don’t mind the yellow-ish thing on the right):

What I would like to do is to REMOVE the outline from the occluded part. You can see exactly what I mean by looking at this topic, that someone with my exact problem wrote.

It was suggested to check the depth and then multiply 1 or 0 in case it passed the check. I’m very new to materials in general, but I think I should use it this way, right?

The part that can’t be seen on the left computes the outline, so if I don’t multiply the clamped result on the left with the depth check it just draws the outline like in the second image.

The result of this is just like the first image, meaning that it looks like nothing happened.

As it was suggested in the topic above, I tried plugging the “if” directly into the output, and it works like it’s supposed to, it only draws the non-occluded parts:

So I don’t understand, what am I doing wrong? I’m struggling with this all day and I’m lost…

This should to the trick:

Actually I’ve already tried that, but the result is the same as the first image I posted… it’s like nothing happened :frowning: