Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to get the _LastCameraDepthTexture but not draw the camera?

Discussion in 'Shaders' started by dorukeker, Jun 13, 2018.

  1. dorukeker

    dorukeker

    Joined:
    Dec 6, 2016
    Posts:
    37
    Hello All,

    For a very corner case I need some help. Below is the setup.

    There are several cameras in the scene. One of them has the highest depth value.
    In a shader I am using the _LastCameraDepthTexture in a shader. This provides the depth texture of that camera. I use it in the shader calculations.

    The problem is, since the camera has the highest depth value, it is drawn on top of everything else. What I want is not to draw it at all, but still use the DepthTexture in the shader.

    I already tried some solutions. I list them and why they did not work below.
    - Use a lower depth value for the camera so it is not drawn on top: Then the _LastCameraDepthTexture returns form a different camera
    - Render the camera to a render texture: this causes _LastCameraDepthTexture to return the depth texture from a different camera.
    - Change the camera viewport size: This effects the returned render texture's resolution. I don't want that.
    - Use _CameraDepthTexture instead: this return depth texture from a different camera.
    - Create a RenderTexture of type "depth". Render the camera to that texture. Use that texture in the shader instead of _LastCameraDepthTexture: This did not work properly with Linear01Depth

    Any idea / help will be much appreciated.
    Thanks,
    Doruk