Fixing Interference Between Opacity Mask and Outline

In a small project I’m working on, I have two visual effects I’m trying to use: an opacity mask that uses dithering to fade away objects near the camera, and a simple outline post-process effect. The problem is that, since the opacity mask discards the depth of pixels that are masked out, outlines are being drawn between the pixels that aren’t masked, causing the faded objects to turn black.

My first attempt to solve this problem was to have the faded objects render to custom depth, and then exclude pixels with custom depth from the outline, but this caused the outlines to noticeably disappear once an object started to fade away. I want the objects that are faded to have fully visible outlines, or, even better, outlines that fade away with the objects.

If I could access the depths of pixels before they are masked away, I could easy use that to get the outlines at once, but even with early Z pass enabled, this doesn’t seem to be possible. Is there any way I could get this depth, or any other way I could prevent outlines from being drawn between these pixels?

Faded object without outline:

230630-outline-problem-1.png

Faded object with outline:

230641-outline-problem-2.png

I have the same problem as you :frowning: did you find an answer?