Search Unity

How to avoid Z-fighting

Discussion in 'Editor & General Support' started by blackMasoon, Aug 4, 2010.

  1. blackMasoon

    blackMasoon

    Joined:
    Jul 23, 2010
    Posts:
    11
    Hello :) I have my terrain water very close to each other so there is a z-fighting all the time on edges of the coast. How can I avoid it? For example to tll the terrain to be drawn always before water or sth like that?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    reduce the view distance, ensure that far clip plane / near clip plane is never larger than 30000
     
  3. blackMasoon

    blackMasoon

    Joined:
    Jul 23, 2010
    Posts:
    11
    Yes... I thought about that but where can I set that for built-in FPSwalker prefab?
     
  4. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    The values Dreamora refers to are properties of the camera. So unless the FPSWalker prefab is or includes a camera, it won't be there, it will be on the main camera in your scene.

    Remember that the key to Z-fighting is the ratio between the near and far planes.

    For example:

    Near: 0.1, Far: 1000
    Near: 0.5, Far: 1000

    You've only offset your near plane by 0.4 world units. It's not a huge distance. The ratio between your near and far planes just improved 5 fold, however.

    So don't just automatically crank down the far plane, as you can often get more mileage cranking up the near plane. Often without much/any noticeable difference too!

    Also, you should remember that the z-buffer is not linear. So you inherently get greater precision closer to the camera than you do further away. This is logical and helpful, but it makes it even more important not to needlessly set your nearplane too low or you're wasting a huge proportion of your z-precision on things you don't need/won't see.

    Hope that helps.
     
    Alverik likes this.
  5. blackMasoon

    blackMasoon

    Joined:
    Jul 23, 2010
    Posts:
    11
    Ok... so I've added a Camera component to the built-in FPS walker prefab and now I can't move mouse vertical... Why that happened?
     
  6. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    I didn't suggest adding a camera component. Your camera should be a separate gameobject.
     
  7. pixelthis

    pixelthis

    Joined:
    Nov 5, 2008
    Posts:
    120
    The FPS prefab contains a camera already (in the 'head' of the walker). Sorry, beyond that I don't know how to access it.
     
  8. blackMasoon

    blackMasoon

    Joined:
    Jul 23, 2010
    Posts:
    11
    Ok :) thanks a lot everyone ;) I found fixed it.
     
  9. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    427
    thanks for the info @sybixus2.

    I am tweaking my near/far clip planes and this is useful to know.

    I'm trying to find the ideal setting that doesn't allow the player to see through walls they are touching while also providing a clear non-Zfighting view into the distance.