Advertisement Jump to content
Sign in to follow this  
KarimIO

DX11 Copy Z-Buffer in DirectX

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

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!

Share this post


Link to post
Share on other sites
Advertisement
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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. 

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!