Unable to use stencil buffer in combination with DepthTexture

Hello everyone,

I am writing a post-processing shader that should be masked by a stencil buffer, but needs depth information. Unfortunately it seems impossible to combine these things on a render target. I created a fiddle for an example (line 50 to uncomment the DephTexture).

If it’s really impossible to combine the two, it should be stated somewhere.
And of course I’d be happy if someone could point me in the right direction to solve this problem.

Thanks in advance!

Edit:
I tried copying the depthBuffer directly instead of using a depthTexture.
But to do that I have to disable the dephtBuffer on the target I want to use the stencil on,
and it turns out that also brreaks the stencil buffer.

It seems like you need a dephtBuffer but no dephtTexture for the stencil to work.

1 Like