Post Process: How to distinguish occluded parts and "endless" parts

Hi everyone,

i have this question.

Here we have Pic1 showing the Scene without the PP Material:

Here is the simple example of the PP Material creating a Alpha Mask depending on visible (white) or non-visible (black) parts:

Here is the result:

As you can see occluded parts (black) are also parts where there is no occlusion, but just “endless” space.
That means that Scene Depth is also smaller than Custom Depth at those parts.

Is there a very generic solution for this to distinguish occluded parts if they are occluded or “endless” space.

Thanks in advance