Using an object as a mask / xray shader

What I’ve read (could be wrong) is that in deferred rendering stencil does not work, so I’m wondering is it possible to get the same effect somehow via shaders?

P.S: I’ve tried this, however like I said, it doesn’t seem to be working in deferred https://forum.unity3d.com/threads/unity-4-2-stencils-for-portal-rendering.191890/

alt text

The stencil buffer does work in deferred rendering and deferred lighting, however the objects need to be rendered in a particular way. To make the stencil objects work in deferred rendering, make sure the shader is set to use the transparent render queue.