Jump to content

  • Log In with Google      Sign In   
  • Create Account


Sampling depth buffer in shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Yann ALET   Members   -  Reputation: 219

Like
0Likes
Like

Posted 12 September 2013 - 08:56 PM

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 ?



Sponsor:

#2 MJP   Moderators   -  Reputation: 10025

Like
0Likes
Like

Posted 12 September 2013 - 09:06 PM

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.



#3 wh1sp3rik   Members   -  Reputation: 248

Like
0Likes
Like

Posted 13 September 2013 - 12:59 AM

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


DirectX 11, C++


#4 MJP   Moderators   -  Reputation: 10025

Like
0Likes
Like

Posted 13 September 2013 - 11:34 AM

No, it's only for depth buffers.



#5 Yann ALET   Members   -  Reputation: 219

Like
0Likes
Like

Posted 18 September 2013 - 06:17 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS