Custom Depth Stencil Value Makes Items Visible Through Walls

I’m currently working on a black and white game and I’m making specific objects color with custom depth stencil pass. All is well except my color objects are visible though walls. Is there a way to fix this? I’m not sure if it matters but this is a fixed camera project.

I have two images attached to show what I mean.


Capture2

You need to compare the regular depth pass to the custom depth pass to detect if the object is being covered up by something else or not. If the custom depth value is nearer or equal to the regular depth, then you know it is unobstructed. If the regular depth is nearer than the custom depth, then an object is blocking it and you can mask out the color.