How to do edge detection with scene depth

I’m trying to modify Tom Loomans post process ouline material so it can draw and outline at the edge of where they object is being occluded. I would have thought this would have worked:

But I guess I’m missing some logic as to whether the pixel is really hidden or not.

I have modified it such that the outline is not drawn if the pixel is hidden from forum post. I just need to now figure out how to get it to detect the edge of where the object is being hidden.

Here’s the logic for the not drawing if hidden.

I’m thinking that I need to add some of the logic from there to first image.

So I managed to figure out a technique to get what I was after. It might not be the most efcient way but it works.
Heres the overall graph

Heres one of the textel nodes they are all the same with the exception of the inputs to pick the pixel

and finally the end of the graph

Here’s the results