I tried to set the stencil quad’s ‘Zwrite’ set to ‘on’, then the culled object’s ‘ZTest’ to ‘GEqual’.
ZTest is working as excepted, only objects behind the quad are rendered but faces are mixed up.
I don’t think you can achieve it this way. Problem is that in order to render triangles of object in correct order it uses ZTest. But you need inverted ZTest for the trick that you’re doing. I don’t think you’ll be able to combine these two things.
Maybe you can achieve it by using multiple passes and Stencil buffer (Unity - Manual: ShaderLab command: Stencil). It’s allows you to write and read bit-mask per pixel.
Something like this:
Your window object must be rendered first (make sure it’s Queue value in shader is less than in the shader of the cullable object)
Render your cullable objects with multiple passes
In first pass do what you do now and write 1 into Stencil buffer for objects which are rendered
In second pass set ZTest to normal one and check that 1 is written in Stencil buffer
Anyway I’m sure you will have some issues with this, because Unity batches objects with multiple passes in a weird way (at least that was my experience) and I was having problem with this approach, but maybe you can figure something out in this direction.