Sampling depth buffer in shader

Started by
3 comments, last by Yann_A 10 years, 7 months ago

Hi there,

I am trying to improve my water shader so i takes into account how deep the water is.

For this i need in the water shader to sample the depth buffer (i render the ground before the ocean, so the depth buffer already has the information i need when i am about to render the ocean).

The problem comes when i need to send it to my ocean shader. I read that i need to unbind the depth buffer from the current render target to be able to sample it. So right before rendering the ocean i call this :

md3dImmediateContext->OMSetRenderTargets(1, &mRenderTargetView, NULL);

But then my ocean grid does not have depth test properly performed, and it looks just wrong.

If i don't unbind the depth buffer, then i only sample the value 0 ...

I googled this a bit, but it's always explained with an engine using differed rendering. I might switch to differed rendering at some point, but for now, i just have a "normal" rendering pipeline. Is this incompatible with the ability to sample the hardware depth buffer ?

Advertisement

You need to make a read-only depth-stencil view for your depth buffer. With a read-only view you can still have it bound for depth testing (but no depth writes), and simultaneously read from it as a shader resource view in a shader.

that's great, i did not know that .. is it working for any resource ?

DirectX 11, C++

No, it's only for depth buffers.

Awesome this works perfectly, sorry for the late answer, i needed to make sure i could reconstruct view position from depth (thanks to your brillant article !).

This topic is closed to new replies.

Advertisement