Jump to content
  • Advertisement
Sign in to follow this  
KarimIO

DX11 Copy Z-Buffer in DirectX

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!