Search Unity

Bug (Why?) All mesh intersections wobble and z-fight in build for VR (Quest2)

Discussion in 'Universal Render Pipeline' started by Ben_at_Work, Jul 5, 2022.

  1. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    83
    I've been working to optimize a scene for VR (Quest 2) which has generally been going predictably. One particular issue, however, has appeared for unknown reasons and only affects the build itself. I'm still trying to understand why and what is happening so that I can address it.

    The problem seems to exist at every mesh intersection across the whole level, and across all assets in it. These meshes don't overlap, so there shouldn't be z-fighting, and they don't tessellate, so the contours of intersections shouldn't be wobbling as I move my head.

    Examples:
    • Where stone steps are inserted into the mesh-based terrain, the edge between the two wobbles as I move my head.
    • Where the water meets the beach, an extended section of something like z-fighting occurs.
    • The crowns of palm trees wobble in and out of the trunk they sit on top of.

    My guess are that it's something to do with the way depth is calculated for the purposes of layering objects. The issues seem to increase with distance, so this is a distance-based problem. Unfortunately, even when I'm standing right where water meets sand, I still see several pixels of artifacting, so at no point does the effect become normal. Since it affects all meshes, it's a generic setting I would assume.

    A last note is that the effect is absent when I run in editor with a VR headset (Quest acting as a Rift). This makes it hard to quickly identify. I tried enabling Depth Texture on my URP asset and the build wouldn't load anymore.

    I've not had issues with mesh intersections before and haven't yet started messing too widely with depth related settings since VR can't make much use of them. I don't know for sure when the issue appeared, either, so I can't pinpoint the change.

    Using XR Interaction Toolkit + Oculus.

    Any idea how I might track this one down to fix it?
     
  2. unity_5cents87

    unity_5cents87

    Joined:
    Dec 15, 2021
    Posts:
    2
    I'm having the exact same issue on my build. Works perfectly fine in editor (rift mode) but literally every mesh is z fighting in the build version. It happens only in one specific level in my scene that the player teleports to.

    Note: we are using no specific render pipeline in our project.

    Edit:
    The area that was giving me trouble was really far away from 0,0,0 (5000+ units away). Placing the area prefab at 0,0,0 and rebaking seems to have solved the issue for me..
     
    Last edited: Jul 11, 2022
  3. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    83
    For scale related issues you can change the near and far clipping planes on the camera if those happen to be set to an excessive range.

    I never found a solution to my issue, it just magically stopped appearing in builds after having been present for far too many. Wish I knew what I'd messed up so I can fix it again if it happens again.
     
  4. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    83
    My team found a stopgap solution that, for us at least, consistently brings an end to the problem at a cost of a chunk of performance.

    We disabled the Auto Graphics API, then forced OpenGLES3. image-20220729-234352.png

    We tried replacing all materials in the scene with the same grey simple Lit material and deleting out all unused objects to be sure something in the background wasn't interfering. We tested the camera's clipping planes, reduced the geometry in the level significantly, removed LODs, and checked for a lot of other possible sources. Nothing made a difference. Even basic primitive geometry like spheres were z-fighting at 50 meters to such a degree that the scene was unusable. We did find that the weirdness was happening specifically where meshes--any meshes--intersected. It behaved like a precision error or a LOD transition, except that the geometry we watched was within 250m of the player and wobbling by like half an inch on screen, and the meshes curved away from one another rather than overlapping to any significant degree.
    intersectionOnly.png

    nonOverlapping.png
    The weird thing to me is that we have another environment in the same exact scene which, when built, doesn't have the issue. If the Graphics API was the problem, we're unsure why the other build from the same scene wasn't affected. Moreover, the performance cost of switching was relatively heavy, bringing my hard won frames back down to the 40s and 50s. I don't get why I was able to build a stable build where intersections look the way you'd expect, then build a second broken wobbling build without changing any settings.
     
  5. Armegalo

    Armegalo

    Joined:
    May 14, 2018
    Posts:
    30
    Same problem here - searching for a solution other than disallowing meshes intersecting at all. Getting constant issues on OpenGLES3. Vulkan is fine but KILLS my frame rate. Going to try going back to SRP - I'll let you know if it fixes

    - edit
    Nope! Same thing in SRP!!!
     
    Last edited: Nov 14, 2022
  6. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    Is your scene far from origin (0,0,0)? If so, you're probably just hitting general precision issues. Are you using the built in URP shaders, shadergraph, or something custom? We're using custom shaders, so we just set the vertex and hclip positions to float precision (32) rather than half precision (16) to avoid general precision issues with positions like this. I don't remember off the top of my head, but maybe URP is using half by default and as a result has these issues.
     
  7. jiaozi158

    jiaozi158

    Joined:
    May 24, 2020
    Posts:
    23
    You can check if it's the case that funkyCoty mentioned.

    (I remember that positions in URP / BIRP shaders are using single precision rather than half.)

    If you are using shaders that provided by Unity (including Shader Graph), I suggest making a bug report with a small project that can reproduce the issue.
     
  8. Armegalo

    Armegalo

    Joined:
    May 14, 2018
    Posts:
    30
    Scene starts at 0,0,0 although z fighting increases a great deal moving towards 100,0,0 - not exactly where you'd expect precision to start dropping out!

    I was using custom shaders but exactly the same effect with built in.
     
  9. Armegalo

    Armegalo

    Joined:
    May 14, 2018
    Posts:
    30
    Fun fact 1
    Reproduced problem in small project.
    Solved problem in small project by fiddling with near clipping plane > 0.125 almost perfect, certainly acceptable. Cannot reproduce fix in main project! Didn't work.

    Fun fact 2
    Rebuilt all from small project. Z fighting issue still solved. Cool. But other parts of project don't work as intended. Exception thrown inside mostly working standalone build :-
    System.DllNotFoundException: Unable to load DLL 'OculusXRPlugin' ... and more.
    This is from calling Unity.XR.Oculus.Performance when the Oculus XR Plugin is definitely installed.

    I realise that the small project has a different version of at least one of the XR packages and I'm pretty sure it's buggy.

    Will continue investigation when more patience presents itself

    I wonder what the record for submitting multiple bug reports in one day is...




     
    Last edited: Nov 15, 2022
    TheSky and jiaozi158 like this.
  10. Armegalo

    Armegalo

    Joined:
    May 14, 2018
    Posts:
    30
    UPDATE : I went back to the old version before I laid into practically every setting I could find and applied the Near Clipping Plane fix and it's fine.
     
    TheSky likes this.
  11. roundyyy

    roundyyy

    Joined:
    Dec 23, 2019
    Posts:
    112
    I have the same problem. It's way worse on OpenGL, vulkan seems to be better. Near clipping plane helps, values like 0.3 or something, but my project can't have such a high value (scope on guns for example become invisible). Seems like I need to use Vulkan.
    I turned of all mesh optimization, compression etc. but still. Even lightmap textures are z-fighting with main tex in distance. Changed shaders precisions for floats etc. no difference. Unity 2022.3.XX