Search Unity

Artifacts when building floor from many cubes

Discussion in 'General Graphics' started by george_playbite, Apr 18, 2019.

  1. george_playbite

    george_playbite

    Joined:
    Sep 27, 2018
    Posts:
    38
    Hello,

    For this game I need to build the floor from many cubes. The box below is a grid of 4x8 cubes. I want it to look completely flat like it's a single object, but some artifacts appear where each cube starts/ends. I've checked that they're positioned correctly. Any idea as to what is causing it and how to fix it?

    Thanks,
    George

    upload_2019-4-18_10-28-35.png

    upload_2019-4-18_11-12-14.png
     
    Last edited: Apr 18, 2019
  2. george_playbite

    george_playbite

    Joined:
    Sep 27, 2018
    Posts:
    38
    bump

    Anyone?
     
  3. KarolisO

    KarolisO

    Joined:
    Feb 2, 2014
    Posts:
    30
    Is the lighting baked?
     
  4. george_playbite

    george_playbite

    Joined:
    Sep 27, 2018
    Posts:
    38
    No, it isn't baked. I just have a single Realtime Directional Light with soft shadows in the scene.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    This could be an artifact of shadow mapping bias (try turning off shadows or set normal bias to 0.0), or MSAA (try disabling MSAA on your camera), or just basic floating point precision issues (try moving everything as close to world 0,0,0 as possible to see if it goes away).

    The real solution too all 3 of these issues: don’t make your floor out of boxes! Ideally you want the ground to be as few meshes as possible, and excluding that remove as many “invisible” faces as possible. For a grid of boxes like this, maybe have only the sides of those boxes that are visible be represented. You could use individual quads for each face, or a set of tile pieces that have the hidden faces removed, or generate a mesh at runtime that includes only those faces that are visible using greedy meshing so each flat surface is a single uninterrupted surface.
     
  6. george_playbite

    george_playbite

    Joined:
    Sep 27, 2018
    Posts:
    38
    Thanks for the thoughts, but it was part of the game's mechanic to make the "floor" out of boxes, like a grid. I ended up using an unlit shader to color all sides of the floor boxes in the same color. That worked out well.

    Here's the game if you're curious: https://itunes.apple.com/us/app/perfect-fit/id1461827778
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    There's a difference between the mechanics and the visual representation. Minecraft is an entire world made out of "boxes", but unless it's a single block floating in mid air, the actual rendered mesh used is never a block. When two blocks are next to each other, the faces that would be in between are removed. If the two blocks are the same material it actually builds a single "block" that's 2 blocks wide, merging the faces. This is the "greedy meshing" I referred to above.