Search Unity

Fighting Z Fighting

Discussion in 'General Graphics' started by G33RT, Jul 16, 2019.

  1. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    Hi all,

    I'm struggling with a nasty case of z-fighting. I've no control over de meshes being imported in my app (dynamic), and in many cases they are overlapping, resulting in horrible flickering.

    I would like to know if there would be a way to "blend" the colors of overlapping polygons. I'm no shader guru, but I understood there is no straight forward way of achieving this. I've experimented with vertex offsets, but that only solves it partially ...

    I wonder if there is a way to render the whole scene multiple times (say 3 for example) independently with different vertex offsets and average those in a single blended result. I imagine that in worst case that would slow down all 3x, but I'd like to try. And oh, it should work in VR.

    I'm wondering if this could somehow be achieved with a Custom Rendering Pipeline …

    Any ideas?

    Geert
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    While yes, this is technically plausible, I'm a little surprised the vertex offsets help at all. Two surfaces that are z fighting should continue to z fight after they've been offset, unless you're able to apply different offsets to each of the overlapping surfaces.

    Unfortunately, when I say "technically possible", it won't be remotely performant. Plausible to use for situations where framerate doesn't matter much, but basically impossible for VR while maintaining decent framerates. I mean you could certainly render out the scene 3 times and average the results, but that really means rendering the entire scene 6 times due to VR.


    However I wonder if the issue is one that can be solved in another way. What happens if you slightly increase the near clip on your camera?
     
  3. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    I experimented a bit with using offsets based on the color, that helped a little bit. But didn't solve it obviously … that's why I wanted to do that like 3 times with different color offset "modes".

    Changing the near clip of the camera doesn't really help if the surfaces are overlapping exactly (and not just near each other).