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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Android depth texture precision issue.

Discussion in 'Universal Render Pipeline' started by Antony-Blackett, Apr 14, 2020.

  1. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,760
    Hi, I'm using the depth texture in Shader Graph in URP for water FX. The depth texture on Android seems a lot less precise than on PC or iOS. Have I done something wrong or is there a setting somewhere I'm not aware of?

    I have made sure the shader precision settings are set to Float.

    I'm using Unity 2019.3.6f1
    URP 7.2.1

    PCAndiOSDepthPrecision.png AndroidDepthPrecision.png
    Screenshot 2020-04-14 at 11.50.26 AM.png
     
  2. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    744
    Same issue here, but not with shadergraph. Anyone from Unity ?
     
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,592
    Hi!
    Can you please report a bug?
    Thanks!
     
  4. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,900
    This was fixed some time ago: https://github.com/Unity-Technologi...2e137de#diff-40ff810ada5f915c5fc97a2a6a9acfcf

    For mobile devices depth should always be sampled using a float sampler, for improved accuracy, which is what this fix does. Perhaps this wasn't implemented in Shader Graph yet. If not, my guess is it will be in URP 7.4.x

    @jimmikaelkael For custom shaders, you can add
    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl" then use
    SampleSceneDepth(float 2uv)
    to sample the depth texture, instead of declaring the depth texture yourself.
     
  5. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    744
    Yes I think it's possible to build a repro project.

    Before I do this, there's this PR: https://github.com/Unity-Technologies/Graphics/pull/26
    Might be related ? not sure...
    I let you clarify if this PR is intended to fix this problem first.
     
  6. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    744
    This is what I'm doing already.
     
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,592
  8. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,900
    Hah, well that's strange. That's exactly what should fix the issue :p
     
  9. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    744
    Tim-C likes this.
  10. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,817
  11. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    145
    The problem is that DeclareDepthTexture didn't have _FLOAT in the depth texture declaration. That's what my PR is fixing and solves the depth precision issue.

    The PR you've been linking to is a backport to 7.x.x which means it will be part of the next 7.x.x release. Next one scheduled is 7.4 and should arrive in May.
    https://github.com/Unity-Technologies/Graphics/pull/26
     
  12. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,817
    Thanks. I manually changed the _FLOAT declaration and the issue on Quest seems to persists? Can you confirm if the issue is also fixed on Android VR platform (specifically Quest)?
     
  13. Elvar_Orn

    Elvar_Orn

    Unity Technologies

    Joined:
    Dec 9, 2019
    Posts:
    145
    Oh that's interesting. You might be dealing with a separate issue than what I was addressing.
    Can you file a bug so the XR team can take a look and fix?
     
  14. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,817
    Case 1232794.
     
    Elvar_Orn likes this.
  15. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,760
    Hey, finally got around to updating URP to 7.4.1 and it did fix my issue.

    Thanks.
     
    Kronnect likes this.
  16. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    119
    Hi, we are on 2019.2.7f2
    how can I fix the problem on that version of unity please. iOS seems fine, but android is off...
     
    Last edited: Mar 10, 2021
  17. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,817
    Declare _CameraDepthTexture like this:
    Code (CSharp):
    1. TEXTURE2D_X_FLOAT(_CameraDepthTexture);
    2. SAMPLER(sampler_CameraDepthTexture);
     
  18. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    119
    Thanks very much for your reply, but where do I do that please? I am not defining the depth texture in code... Unity is doing it automatically.
    I just have a small script that tells Camera.main. (or whatever camera) to enable rendering of Depth information.
    e.g.

    Code (CSharp):
    1. GetComponent<Camera>().depthTextureMode = depthTextureMode;
    but unity does not provide a parameter for precision. Its fine on iOS, but on Android... its inaccurate, or possibly needs a z-bias.
     
    Last edited: Mar 25, 2021
  19. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    119
    TEXTURE2D_X doesn't exist in 2019.2.7f2 projects, how do I fix it there please ?
     
  20. RyanTexture

    RyanTexture

    Joined:
    Jun 10, 2020
    Posts:
    16