• Advertisement
Sign in to follow this  

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
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By d3daywan
      【DirectX9 Get shader bytecode】
      I hook DrawIndexedPrimitive
          HookCode(PPointer(g_DeviceBaseAddr + $148)^,@NewDrawIndexedPrimitive, @OldDrawIndexedPrimitive);    
          function NewDrawIndexedPrimitive(const Device:IDirect3DDevice9;_Type: TD3DPrimitiveType; BaseVertexIndex: Integer; MinVertexIndex, NumVertices, startIndex, primCount: LongWord): HResult; stdcall;
          var
              ppShader: IDirect3DVertexShader9;
              _Code:Pointer;
              _CodeLen:Cardinal;
          begin
              Device.GetVertexShader(ppShader);//<------1.Get ShaderObject(ppShader)
              ppShader.GetFunction(nil,_CodeLen);
              GetMem(_Code,_CodeLen);
              ppShader.GetFunction(_Code,_CodeLen);//<----2.Get bytecode from ShaderObject(ppShader)
              Result:=OldDrawIndexedPrimitive(Self,_Type,BaseVertexIndex,MinVertexIndex, NumVertices, startIndex, primCount);
          end;
      【How to DirectX11 Get VSShader bytecode?】
      I hook DrawIndexed
          pDrawIndexed:=PPointer(PUINT_PTR(UINT_PTR(g_ImmContext)+0)^ + 12 * SizeOf(Pointer))^;
          HookCode(pDrawIndexed,@NewDrawIndexed,@OldDrawIndexed);
          procedure NewDrawIndexed(g_Real_ImmContext:ID3D11DeviceContext;IndexCount:     UINT;StartIndexLocation: UINT;BaseVertexLocation: Integer); stdcall;
          var
              game_pVertexShader: ID3D11VertexShader;
                  ppClassInstances: ID3D11ClassInstance;
                  NumClassInstances: UINT
          begin
              g_Real_ImmContext.VSGetShader(game_pVertexShader,ppClassInstances,NumClassInstances);    //<------1.Get ShaderObject(game_pVertexShader)
              .....//<----【2.Here's how to get bytecode from ShaderObject(game_pVertexShader)?】
              OldDrawIndexed(ImmContext, IndexCount, StartIndexLocation, BaseVertexLocation);
          end;

      Another way:
      HOOK CreateVertexShader()
      but
      HOOK need to be created before the game CreateVertexShader, HOOK will not get bytecode if the game is running later,I need to get bytecode at any time like DirectX9
    • By matt77hias
      Is it ok to bind nullptr shader resource views and sample them in some shader? I.e. is the resulting behavior deterministic and consistent across GPU drivers? Or should one rather bind an SRV to a texture having just a single black texel?
    • By Affgoo
      This is a rev share team. (payment based on a % of profits of the game/software/app)
      About us:
      We are a team of 16 developers developing multiple mid scope games. We polish all of our games. We have released one title so far, which will be linked below. We have 6 products in development currently. 4 games 1 tool set and 1 app. We are a very friendly and active team. 

      looking for:
      3d/2d Artist that can hand paint textures.  
      highly motivated game developers.

      ^ requirement for all positions: A true love of game development and to be very self motivated.
      We are a very active team, you must be too. 


      If interested or for more information add me on skype: nicholas.boucher4


      Atlas Sentry art style: (art complete)(code complete)
      https://play.google.com/store/apps/details?id=com.NE.Alien&hl=en

       
    • By revolverolver
      This is a snippet from my first ever 3D game. It's about doing flips & tricks down stuff. It's made with Unity and models made in Blender. I'm a total beginner in 3D graphics so I chose a low poly style because it is a lot simpler and also looks pretty good. 
      Here is a trailer for the game: 
       
  • Advertisement