Sign in to follow this  

Sampling depth buffer in shader

This topic is 1581 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 !).

Share this post


Link to post
Share on other sites

This topic is 1581 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this