Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Is it possible to grab the custom depth buffer contents in a custom pass?

Discussion in 'High Definition Render Pipeline' started by mgeorgedeveloper, Oct 11, 2023.

  1. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    307
    I have a custom pass that renders to to the Custom Color and Custom Depth buffers. This works fine.

    I then have a subsequent custom pass (stacked in the same custom pass volume) that copies from the Custom Color or Custom Depth to a Render Texture.

    In this subsequent pass, if I blit the contents of the Custom Color buffer to the RT, it works. But if I try to blit the contents of the Custom Depth buffer to the RT, the result seems invalid (just a constant color is all I get).

    My custom pass for grabbing either of custom buffers' contents, looks like this:

    GrabCustomBufferPass.png

    So, is it possible to blit the custom depth buffer to a render texture in this way? Or should I do something else to get the depth buffer contents?

    EDIT:
    Some notes
    - I have ensured that the "grab" custom pass itself does not clear the buffers.
    - I have tried basically all formats for the target RT to make sure this is not the issue.
     
  2. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    249
    Hello,

    The result you have is "expected" as the CommandBuffer.Blit function doesn't support reading or writing to the depth buffer.
    To copy the depth, you either need to use a custom Blit shader or you can use the CustomPassUtils.Copy function that supports copying the depth. The Copy function only takes RTHandle in parameter but you can easily convert those from your RenderTexture like so:
    Code (CSharp):
    1. var handle = RTHandles.Alloc(renderTexture);
     
    mgeorgedeveloper likes this.