Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Accessing Depth rendertexture in HDRP and pass it to Compute Shaders

Discussion in 'Shaders' started by TerraUnity, Jul 4, 2018.

  1. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,274
    We used to obtain the Depth rendertexture from the camera and pass it to a compute shader for later processing as follows:

    Code (CSharp):
    1. currentRT = RenderTexture.GetTemporary(rows, columns, 32, RenderTextureFormat.Depth);
    2.  
    3.         cam.targetTexture = currentRT;
    4.         cam.Render();
    5.         RenderTexture.active = currentRT;
    6.  
    7.         computeCloud.computeShader.SetTexture(computeCloud.mComputeShaderKernelID, "_DepthTexture", currentRT);
    Or directly pass the rendered depth from the main camera using the following line of code:

    Code (CSharp):
    1. computeCloud.computeShader.SetTextureFromGlobal(computeCloud.mComputeShaderKernelID, "_DepthTexture", "_CameraDepthTexture");

    None of these codes work in the HD Render Pipeline and the produced Depth-map is all black! I guess there are some customization needed to get the depth from camera in HDRP!
     
  2. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,274
    I know HD Render Pipeline is still in shadows but anyone can help in this?
     
  3. Ehredt

    Ehredt

    Joined:
    Jun 20, 2018
    Posts:
    79
    I'm having trouble getting a RenderTexture to work at all with the HD Render Pipeline. Were you able to figure this issue out?
     
  4. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,274
    I've opened and issue on SRP's Github page and got a response that some customization needed in the Render() function in HDRP source but all issues have been removed from there. My problem was that I can not get the depth rendertexture from the 2nd camera in scene.

    Also it has been mentioned that "RenderTexture.GetTemporary" is removed in HDRP.

    @SebLagarde I still couldn't get my head around customizing the Render() function in order to include the Depth in the rendertexture from camera! Your help and real code example is really appreciated.
     
  5. Untitled_Tools_Projects

    Untitled_Tools_Projects

    Joined:
    Nov 9, 2016
    Posts:
    10
    I know I'm reopening an older thread but I also haven't figured out this problem, although RenderTexture.GetTemporary is working in HDRP for me.