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 Oculus Quest Camera Depth buffer calculations are off

Discussion in 'VR' started by creat327, May 9, 2021.

  1. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    Hi

    I have a water shader that was driving me crazy because it works perfect in most VR systems and PC, but in the Oculus Quest 2 it looks wrong. So I was able to track it down.

    Here is the simple frag code of the shader I used for testing

    Code (CSharp):
    1.  
    2.  
    3. float ori = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos));
    4.         float d = Linear01Depth(ori);
    5.         c.r=  d;
    6.         c.g = d;
    7.         c.b = d;
    8.  
    9.         surfaceEyeDepth = i.scrPos.z;
    10.         sceneDepth = LinearEyeDepth(ori);
    11.         viewDepth = sceneDepth - surfaceEyeDepth;
    12.  
    13.         edgeBlendFactor = saturate(_InvFade * viewDepth);
    14.         c.rgb = lerp(1, c.rgb, edgeBlendFactor);
    15.         return half4(c.rgb, 1);
    This shader, what it does is to render into screen the DepthTexture in gray scale, and then the edges would render as white. Perfect because that´s exactly what I want to get, the shore lines. So here a screenshot working just perfect in the editor. You can see the mountains (depth texture) under the water plane, and the edges in white.

    forum1.jpg


    But, If I compile and run this on the Oculus Quest 2, something completely wrong happens.





    What it seems to do is to render the mountains under (so it seems _CameraDepthTexture has the correct information), but the shore line goes up and down depending on my distance to the water. So if i fly up, the shore line moves up, and if i go down, the shore line goes to its proper position.

    My guess is that LinearEyeDepth is working wrong, but I really don't know if that's the reason. Any ideas?
     
  2. lappnSIRT

    lappnSIRT

    Joined:
    Jan 27, 2021
    Posts:
    1
    Im having similar issue. Have you found a fix?
     
    mpa7ster likes this.
  3. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    nope, report it as a bug
     
  4. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    do you have a project that reproduces it? if so, please submit it as a bug report. I've tried to isolate it to a small project but I can't. It seems to be a combination of things that causes this bug and I haven't been able to pinpoint it yet.
     
  5. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,321
    Instinctively I would say that it seems like the Quest is calculating Z buffer at a very low precision.
    I'm having a similar problem btw, and not even need a special shader: I just have some boulders crossing at about 50 meters distance from world origin.
    This is definitely a precision issue.

    Oh well, and I've just found this: upload_2021-10-3_1-5-51.png

    https://forum.babylonjs.com/t/incor...s-quest-c-using-logarithmicdepthbuffer/7253/4
     
  6. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    Last edited: Dec 1, 2021
  7. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,321
    You can set it at 24 bits.
     
  8. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    you can't set the default camera depth buffer precision in Unity as far as I know. There used to be a checkbox that allowed to put it at 24/32 bits and that is long gone. Unity, any help?