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

Bug Depth texture is a frame behind

Discussion in 'Universal Render Pipeline' started by PixelDough, May 22, 2022.

  1. PixelDough

    PixelDough

    Joined:
    Apr 27, 2018
    Posts:
    45
    So I've found that using the depth texture in shaders is always one frame old. Take a low lying planar fog example shown here.
    FogIssueExample1.png
    As you can see, the laser ball has left an imprint in the fog from the frame before. The blue ship is moving backwards slightly, and you can tell that there is a "hole" in the fog in it's shape in front of it, and its back end is covered by the fog from the previous frame. All static objects look perfectly fine.

    I've replicated this with depth implementations in both orthographic and perspective projection modes, as well as using Shader Graph and Amplify Shader Editor, using built in scene depth nodes and fetching the global depth texture manually. All of these combinations have had the same result.

    Is this a problem with how URP handles the depth texture? Is there some option tucked away somewhere in a render pipeline asset or in the project settings? This artifact is quite annoying looking in game, but completely ditching all use of the depth texture for shaders like this doesn't really seem like the right thing to do... :confused:
     
    Pruthin likes this.
  2. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    Just to clarify, you're pulling in the depth texture data from somewhere like a Depth Node in Shader Graph, or sampling from _CameraDepthTexture in a shader, rather than/instead of sampling a camera's DepthTexture with ReadPixels in a script, and passing that in?
     
  3. PixelDough

    PixelDough

    Joined:
    Apr 27, 2018
    Posts:
    45
    Correct