How to make use of a RenderTargets DepthStencilBuffer

Hello

I have a postprocess where I would like to calculate a fragments viewposition from the fragments depth and the inverse projection matrix.
I would prefer not to have to enable “enableDepthRenderer”, which will make a separate render pass to only write depth, and RenderTargetTexture has a method called: createDepthStencilTexture which I would assume creates DepthStencilTexture for the render target, which brings me to the first question:
When creating a RenderTargetTexture, there is a parameter that is called: generateDepthBuffer
What would be the difference between having this parameter enabled (which it is by default), from manually calling createDepthStencilTexture?
Are they two entire different things?
What I’ve assumed is that createDepthStencilTexture makes it so that the depth buffer can be sampled from later, is this correct?
And if so my second question is: how do I actually sample it?

I’ve tried sending it to the post process effect with:
effect.setDepthStencilTexture(‘currentFrameDepth’, current_frame)
where currentFrameDepth is a texture sampler in glsl, and I’ve made sure that ‘currentFrameDepth’ is included in the list of samplers.
When I try to sample currentFrameDepth in the glsl shader, it’s always black on all channels except for w, which is always white.
Is this not how you’re to sample previously written depth values?

No playground for now, might put one in later

Thanks for reading
Quack quack

In one case, the parameter, a depth/stencil buffer is used for depth testing. You won t be able to read from it. In the other one, texture is created making it possible to query. This is actually what we are using for shadows.

You can then sample it like any textures which is amazing, you can have a look at our shadowGenerator for examples of usage.

The playground would definitely help :slight_smile:

Thanks for the reply!
Which case is the first you described, I assume it’s the one where you just say that the rendertarget should be created with a depthbuffer?

Yup :slight_smile: sorry for the confusion.