Advertisement

Copy Z-Buffer in DirectX

Started by November 24, 2017 10:47 AM
5 comments, last by KarimIO 7 years, 2 months ago

Hey guys,

I'm trying to work on adding transparent objects to my deferred-rendered scene. The only issue is the z-buffer. As far as I know, the standard way to handle this is copying the buffer. In OpenGL, I can just blit it. What's the alternative for DirectX? And are there any alternatives to copying the buffer?

Thanks in advance!

4 minutes ago, KarimIO said:

What's the alternative for DirectX? And are there any alternatives to copying the buffer?

What's the reason behind copying it in the first place? You can just use the same z-buffer for opaque and transparent objects.

In D3D the equivalent of blitting is CopyResource/CopySubresourceRegion, or for depth buffers you can write a shader that reads from the src texture and outputs the value to the SV_DEPTH semantic (though this generally won't end up copying any magic extra layers of information, like Hi-Z and will force both src/dest buffers to be decompressed).

Advertisement
11 minutes ago, Hodgman said:

What's the reason behind copying it in the first place? You can just use the same z-buffer for opaque and transparent objects.

Are you suggesting sharing an image/texture (specifically the depth buffer) between two framebuffers? I had considered that but I thought it might have issues.

1 hour ago, KarimIO said:

Are you suggesting sharing an image/texture (specifically the depth buffer) between two framebuffers?

Yeah. GL's "framebuffers" are a very thin/lightweight object that is equivalent to the parameters passed into OMSetRenderTargets (i.e. it's just an array of up to 8 render-target-views and up to 1 depth-stencil-view, which themselves are just a pointer to a texture-resource and some format/size info).

7 minutes ago, Hodgman said:

Yeah. GL's "framebuffers" are a very thin/lightweight object that is equivalent to the parameters passed into OMSetRenderTargets (i.e. it's just an array of up to 8 render-target-views and up to 1 depth-stencil-view, which themselves are just a pointer to a texture-resource and some format/size info).

Forgive me if this is marginally off topic, but with OpenGL, is that done this way?


glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);

glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);
On 11/24/2017 at 2:15 PM, Hodgman said:

Yeah. GL's "framebuffers" are a very thin/lightweight object that is equivalent to the parameters passed into OMSetRenderTargets (i.e. it's just an array of up to 8 render-target-views and up to 1 depth-stencil-view, which themselves are just a pointer to a texture-resource and some format/size info).

To clarify to those finding this later, and so someone can correct me if I'm wrong, this is a good solution, but you can not use it with the default depth buffer in opengl. This can be solved by using an fbo in the middle, and simply doing something that doesn't output depth, such as post processing, at the end. 

This topic is closed to new replies.

Advertisement