Jump to content
  • Advertisement
Sign in to follow this  
n00body

OpenGL [SOLVED] Copying depth to a texture (D3D & OGL)

This topic is 3463 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

OpenGL: Info Firstly, I'm targeting SM 3.0 hardware with my current method, and would prefer answers that would work at that level. Thus far, I have been using the following approach to get at the contents of the depth buffer for deferred shading:
  1. Make two FBOs, one with a depth_stencil renderbuffer, and one with a depth texture.
  2. Do all my rendering to the first.
  3. Blit contents of first to second.
  4. Use depth texture attached to second.
Questions:
  • Is this the optimal method for getting at the contents of the depth buffer, without using MRT?
  • Does this introduce significant performance penalties?
  • Will this trick work on any GPU that supports FBO Blitting?
Direct3D Questions:
  • Is there an equivalent of the method I am using in OpenGL?
  • Is there a better method?
  • Are either of them reasonably cross-platform, or limited to specific GPUs?
Thanks for any help you can provide. [Edited by - n00body on March 30, 2010 4:42:31 PM]

Share this post


Link to post
Share on other sites
Advertisement
I don't know much about OpenGL, so I can't comment on the method you're currently using. Direct3D9 doesn't support any sort of readback of a depthstencil buffer, but there are vendor-specific "extensions" that let you sample them directly. Nvidia has RAWZ for their 6 and 7-series, and INTZ for 8-series and above. You can read about those here. ATI has their own extensions that are similar, which you can read about here. I would imagine that these are also exposed in OpenGL as extensions.

D3D10/D3D11 natively support sampling a depthstencil buffer, if you create the buffer using a TYPELESS format and create an appropriate shader resource view.

Share this post


Link to post
Share on other sites
Quote:
Original post by n00body
Is this the optimal method for getting at the contents of the depth buffer, without using MRT?

Certainly not, since it involves a copy. Why don't you just attach a depth(-stencil) texture to your FBO and render directly to that texture ?

Share this post


Link to post
Share on other sites
I guess I should have mentioned before that because I need to share it between multiple FBOs for depth testing. This presents the issue that I need it for testing and position recovery for my lighting pass. So I need it as both a renderbuffer and a texture.

So that leaves me with two options. I could use MRT with an fp16 buffer to store linear depth. Otherwise, I have to copy the contents of the depth buffer to a texture to avoid MRT.

Originally, I was trying to be minimalist and avoid MRT + fp16, since SM 3.0 OpenGL is limited to RGBA16F. Unfortunately, it is looking like that is the only option that will work consistently between the two APIs. :(

Unless someone can suggest something else?

Share this post


Link to post
Share on other sites
In OpenGL you can render to a depth texture, then attach that texture to another FBO, and use it from there. No copying needed.

Also, i don't get why you need depth as RB and texture to read and test against it.

Share this post


Link to post
Share on other sites
To the best of my knowledge, you can't share and read a depth-stencil texture between FBOs. It has to be one or the other. So that is why I needed the renderbuffer to be shared between FBOs, and the texture for reading in the lighting shader.

Anyway, I have concluded that the most cross-API-safe method will just be using an RGBA16F RT so I can output depth during rendering. This way, I can avoid MRT or the extra copy step. Not exactly ideal, but it will work in a pinch.

Thanks for the help everyone.

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!