Search Unity

Question Linear depth performs different on mobile

Discussion in 'Shaders' started by Yupsilon, May 22, 2021.

  1. Yupsilon

    Yupsilon

    Joined:
    Apr 22, 2019
    Posts:
    1
    I'm using 2019.4.19f1 and URP 7.1.8, I tried to using depth texture to fade my river and clouds when intersect with opaque objects, the opacity is determined by following code:
    Code (CSharp):
    1. float sceneZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, positionSS.xy/positionSS.w, _ZBufferParams);
    2. float depthdiff = (sceneZ - positionSS.w);
    3. float alpha = depthdiff/10
    while this works perfectly fine on PC, when I pack this game to Android, depthdiff will decrease quickly if I view further(even though I don't change the view direction). This phenomenon makes my water and clouds dissipate.
    At first I checked REVERSE_Z issue, but I switched to GLES3.2 on my PC, and it still worked well;
    And then I checked _ZBufferParams, it's the same at PC and Android.
    If I push my nearclip plane further, this phenomenon will migitate but won't disappear.