Jump to content
  • Advertisement
Sign in to follow this  
Yann_A

Sampling depth buffer in shader

This topic is 2128 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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!