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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Why mesh is flickering while moving the camera?

Discussion in 'General Graphics' started by iobagglivepeplaja, Oct 20, 2022.

  1. iobagglivepeplaja

    iobagglivepeplaja

    Joined:
    May 29, 2020
    Posts:
    4
    Hello,

    I have a problem with my 3d model that is being loaded from a .bpb file. Whenever i am close to some meshes, they start to flicker (i will try to post a GIF/video). I tried fixing it using some answers regarding the far near clip pane on the camera but i got no result. Could you give me some solutions?

    Unity version: 2021.3.6f1
    Build: WebGL

    Link for video: https://imgur.com/a/jlYZTwd
     
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    637
    Hi, this common flickering is called Z-fighting. (click the link for detailed explanation)

    I suggest keeping a very small gap between two faces (something like 0.0001).
     
  3. iobagglivepeplaja

    iobagglivepeplaja

    Joined:
    May 29, 2020
    Posts:
    4
    Thanks for the link, now i know what is causing this issue.
    Is there a way to set the small gap using the shader?
     
  4. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    637
    Theoretically you can move these vertices in vertex shader, but it's hard to identify the faces which have z-fighting.

    You can try editing the ".bpb" file.

    For example, assume there's a paper z-fighting with the floor, just move the paper up a little bit.
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,019
    there is Offset:
    https://docs.unity3d.com/Manual/SL-Offset.html

    adding this line helps in many cases:
    Offset -1, -1

    but of course requires you to then use that separate custom shader..

    if its easy to modify that model, could fix it there (either remove overlapping areas, or move one up/down)
     
  6. iobagglivepeplaja

    iobagglivepeplaja

    Joined:
    May 29, 2020
    Posts:
    4
    Offset worked on some cases but didn't cover all, i will try to modify the bpb file and come back.