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

How to Fix Unity Overlapping Textures Problem?

Discussion in 'General Graphics' started by bluevideogame, Dec 31, 2018.

  1. bluevideogame

    bluevideogame

    Joined:
    May 31, 2018
    Posts:
    10
    I have a Unity game where cubes roll from one tile to another, and when the cubes roll a small part of the cubes textures overlap and its messed up looking. I ideally want the cube closest to the players texture to over-ride the cubes texture behind. Here is an image of the problem - (Right hand side, middle height is the problem)

    https://ibb.co/LdhQfR6


     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    927
    Are the shaders/materials transparent?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,255
    This is a basic case of z fighting.

    When rendering opaque objects, modern GPUs use a depth buffer, sometimes called a z buffer, to help sort pixels. The short explanation is when a pixel draws to the screen it checks the depth buffer to see if it is further away from the camera than the value stored. If it's further the GPU skips rendering that object for that pixel, and if it's closer it continues to render and writes that new depth to the depth buffer.

    However there's a limit to the accuracy of the depth buffer, and to the floating point math for determining the depth of each pixel of a triangle. So two faces that overlap can flicker as the math picks one or the other to be closer.

    The solution is to move one closer to the other. This can be done by slightly shifting the objects, or you can use a custom shader on the objects that uses an Offset which can push or pull the depth of each pixel with out changing their position on screen. Or you can try using a transparent shader which doesn't write to the depth buffer. The order will then be totally dependant on the order they're rendered.
     
  4. bluevideogame

    bluevideogame

    Joined:
    May 31, 2018
    Posts:
    10
    I really apprechiate both of your feedback! I set the material rendering mode on my other computer to test it out on some cubes to transparent, and it appears to have fixed the problem on demo cubes???? Does this make sense?? I'm laying in bed so haven't tested changing every object on my main computer to render mode transparent.