Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to blit depth into rendertexture?

Discussion in 'Universal Render Pipeline' started by Markus4Unity, Nov 18, 2020.

  1. Markus4Unity

    Markus4Unity

    Joined:
    Jun 25, 2018
    Posts:
    6
    Hi there,

    Im working on my own ScriptableRenderPass trying to blit the depth of the camera into the depth of a rendertexture. In the Execute function I have the following line:

    cmd.Blit(depthTarget, renderTexture.depthBuffer)


    It copies the depthBuffer of the camera onto the colorBuffer of the RenderTexture. I can see the depth being rendered on the color buffer, however the depthbuffer itsself stays empty.

    Grateful for any ideas!
    Regards
    Markus
     
  2. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    186
    Instead of using blit, try replacing the blit method with the something like the following.
    Code (CSharp):
    1. cmd.SetRenderTarget(colorTexId, renderloadaction, renderstoreaction, depthTexId, renderloadaction, renderstoreaction);
    2. cmd.DrawMesh(fullscreenquad,identity, identity);
    If unsure, use the FinalBlitPass/PostProcessPass as a reference.
     
    Olmi and Markus4Unity like this.
  3. Markus4Unity

    Markus4Unity

    Joined:
    Jun 25, 2018
    Posts:
    6
    Hey, thanks to you I got it working!

    I got DrawMesh rendering the depth now, though I dont seem to get it rendering the Color at all. Is there any specific setup needed to use DrawMesh to render to the colorBuffer?

    Thanks!
    Markus
     
  4. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    186
    Not exactly, you might want to experiment with the material(for the draw mesh) and the render target properties to achieve what you need.
     
    Markus4Unity likes this.