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

Question How to access the camera Depth Texture on URP

Discussion in 'Shader Graph' started by nicfio, Sep 20, 2022.

  1. nicfio

    nicfio

    Joined:
    Feb 12, 2017
    Posts:
    7
    Hi!
    I was trying to make some camera effects based using the camera depth texture using the shadergraph.
    (simply as an initial experiment, render the depth texture converted to a gradient instead of b/w).
    However, how can I retrieve the depth texture from the camera and use it in the shadergraph?
    I saw there is the Scene depth node but i'm not sure this is what I am looking for.

    Secondly: how can I "apply" the shader to the rendered camera? I tried attach a script to the camera and use the "OnRender" function, but it does not seem to be overriding the default camera. What am I missing?

    Thanks!
     
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    631
    Hi, I think Scene Depth Node is the thing you are looking for.

    Do you mean a custom post-processing effect? I remember that in 2022.2b/2023.1a URP, you are able to create custom post-processing effects with zero code.

    If you cannot use 2022.2b/2023.1a by now, you'll have to create custom post-processing effects with custom Renderer Features.

    If it's not something that the coming custom post-processing can do (such as you need to modify Scene Depth), you can follow this URP Renderer Features docs to perform a full screen blit (using your own shader and set render target to depth, not the color blit shader) in URP.
     
    Last edited: Sep 30, 2022
    nicfio likes this.
  3. nicfio

    nicfio

    Joined:
    Feb 12, 2017
    Posts:
    7
    Thanks a lot for your reply! That's exactly what I meant. I though it could've been scene depth node, but for some reason (even trying to render the scene depth node on a simple material, as a test) when i try to use it I end up with a black "texture" only which made me guess I was doing something wrong.

    Thanks a lot for the link and the directions! I'll dig into it! Really appreciate!!
     
    wwWwwwW1 likes this.