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

What happened to z fighting?

Discussion in 'General Discussion' started by Tomnnn, Mar 9, 2015.

  1. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I just noticed some of my walls are overlapping and occupying the same space, but there's no z fighting in the editor or the game view. What sorcery is this?

    I'm sure the application is minor, but is there a way for re-enable z fighting? Could be valuable for some people.
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,381
    How?
     
  3. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    because if you are building something like a wall with quads and accidentally put multiple quads over each other and you don't want the extra quads there, Z fighting helps to locate these places.
     
  4. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I don't know really, @drewradley gave the one example I could think of. I noticed there's still z fighting with different textures, but I could swear in unity 4.x that similar textures had z fighting.
     
  5. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Adjust your camera clip distances. If your near clip distance is really small, and your far clip distance is really big, your z-buffer precision will be lower, and you should see z-fighting...

    Most people will want to be doing the opposite, keeping the far plane as close to the camera as possible, and avoiding making the near distance too tiny, to minimize the effect.
     
  6. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Oh. My near is 0.1 but my far is only 30, since the environment is inside a building only like 20 units wide and long. I guess that's what stopped the z fighting... kind of.

    I've made my walls overlap because in the past, if 2 walls were connected by just the corners, occasionally a raycast would go between them lol. I guess I'll have to take the extra steps in the future and manually extend just the colliders.
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    If you use primitive colliders for your walls (ie: box colliders) you'll most likely end up with some overlap anyway.


    I don't recall this in Unity 4, but in earlier versions of Unity something like this could happen as a result of something to do with the lighting system - overlapping geometry would be over bright.

    Aside from that, if you've got the same texture (and it's aligned with itself) on two bits of overlapping geometry z-fighting wouldn't be visible because regardless of which face ended up 'in front' at rasterisation it would look identical.

    Perhaps where you saw this happening they weren't lined up? So the z-fighting would show different parts of the same texture. Or other things that would effect the look of the texture would also make it show up - different vert colours, material properties, being effected by different lights, etc.
     
  8. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    @angrypenguin the textures were just solid colors, maybe that's why there wasn't any overlap. Same texture, solid color. I saw more z fighting than ever when I put an untextured plane against the wall lol.

    Nice to see the performance increase of Unity5 allows for even more rapid and crazy z fighting ;)