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

Started by
4 comments, last by n00body 14 years ago
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]

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970

[Websites:] Development Blog | LinkedIn
[Unity3D :] Alloy Physical Shader Framework

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.
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 ?
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?

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970

[Websites:] Development Blog | LinkedIn
[Unity3D :] Alloy Physical Shader Framework

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

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970

[Websites:] Development Blog | LinkedIn
[Unity3D :] Alloy Physical Shader Framework

This topic is closed to new replies.

Advertisement