Search Unity

Weird glitches with cubes, random black lines at given camera positions.

Discussion in 'Editor & General Support' started by NeverGod, Jun 2, 2013.

  1. NeverGod

    NeverGod

    Joined:
    Nov 8, 2012
    Posts:
    2
    Hello Unity community,
    So, I've asked on Unity Answers about this, but eventually I figured that those black lines are impossibly the work of inaccurate block placement.

    The Problem so far:

    To simplify it as much as possible, a grid of primitive cubes in Unity will produce rendering artifacts at random camera positions that look like shading errors between 2 cubes that should be snapped next to each other but aren't.

    Of course a lot of people on Unity Answers were very kind and offered a lot of possible solutions, the problem persists though and after some investigation yesterday I am almost certain that this is not an issue of shading.
    Why? Well, mainly because the artifacts keep appearing when the cube meshes have casting and recieving shadows off, but there are more things that make me think that its my Unity messing with me, as other people on UA didn't experience the same kind of problem.

    Reproduction of the problem:

    Basically I am spawning a grid of primitive cubes and clone them to another grid of clones of primitive cubes, just to make sure that the error is not caused by the cloning of prefabs, using this code.
    Code (csharp):
    1.  
    2. for (int i = 0 ; i < 10 ; i++)
    3.         {
    4.             for (int j = 0 ; j < 10; j++)
    5.             {
    6.                 GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    7.                 cube.transform.localScale += new Vector3(0.2f,0.2f,0.2f);
    8.                 cube.transform.position = new Vector3(i,j,-5f);
    9.                 Instantiate (cube,new Vector3(i+11,j,(-5f)),Quaternion.identity);  
    10.             }
    11.                
    12.         }
    13.  
    Next, I've set up a camera that I can move by a very little using the arrow buttons and is directly facing my grid (meaning no rotation) .

    I moved the camera around a little bit and of course those artifacts appeared again. Carefully I moved into a position where one of the artifacts simply stayed on screen. (For me that meant that its not a random artifact that appears for a single frame because rendering screwed up, but I'm new to Unity so I wouldn't know)

    Now, the common workaround that was recommended to fix the minute gap error was to make the cubes a bit larger so they overlap. But as I stated before this is probably not a matter of gaps between blocks, I exaggerated a bit and made the cubes 1.2 large (after trying very small values at first of course.)

    Screenshot Attached as Overlap.png

    (It's too large to be shown properly here, please open the screenshot in a new tab.)

    As you can see, even though both blocks overlap by a fair bit, the black line is getting rendered.

    I tried around a bit and those are further results.

    Marking BOTH blocks and pulling them right or left even by a tiny bit would make the line disappear at the place those blocks were located. Pulling them back at their original position would make the line reappear.


    Screenshot Attached as Pull right.png

    (It's too large to be shown properly here, please open the screenshot in a new tab.)

    Marking only the left block and pulling it further into the direction of the right block would cause the line to disappear at it's position (It's too large to be shown properly here, please open the screenshot in a new tab.)


    Screenshot Attached as pull left into right.png

    (It's too large to be shown properly here, please open the screenshot in a new tab.)

    But Marking the right block and pulling it into the left block to further overlap it would not give the same effect.


    Screenshot Attached as pull right into left.png

    (It's too large to be shown properly here, please open the screenshot in a new tab.)

    Making an actual gap of course would create a black line, being the shadow between the two. Funny thing, even if those two blocks don't overlap with nearby blocks but are only snapped there is no artifact, unless the rendering decides to create one after camera movement.


    Screenshot Attached as Actual gap.png

    (It's too large to be shown properly here)


    Now this is as much information as comes to my mind right now, note that I tried to turn of the Cast and Recieve shadows in the Mesh Renderer for the cubes, and while all shadows disappeared, the black line did not.

    I hope someone will know why Unity tries to make me go insane, or will enlighten me about how stupid my mistake is.

    Have a nice day,
    Alex
     

    Attached Files:

  2. NeverGod

    NeverGod

    Joined:
    Nov 8, 2012
    Posts:
    2
    bump();
    Sorry but I am quite desperate here.
     
  3. farzher

    farzher

    Joined:
    May 9, 2013
    Posts:
    9
    Same issue here.
    Is anyone able to make a grid of cubes without having this issue? Or are we doing something wrong.
    Those lines popup all the time. (All I had to did to get this image was play my game and press printscreen a few times)


    $unity grid artifact.PNG
     
  4. dyox

    dyox

    Joined:
    Aug 19, 2011
    Posts:
    619
    It's due to Float limitation. Try to scale your cube with an offset like this : Scale = 1.0001f, 1.0001f, 1.0001f.
    Or add an offset directly on the position
    Code (csharp):
    1.  
    2. float Scale = 1f;
    3. for(int x=0;x<10;++x)
    4. GameObject.Instanciate(Obj,new Vector3(x*(Scale -0.0001f),y,z));
    5.  
    Be careful , scaled mesh take more time to apply an Collider. If you need realtime colliders modification , use the position offset.
     
    Last edited: Sep 16, 2013
  5. farzher

    farzher

    Joined:
    May 9, 2013
    Posts:
    9
    This didn't work for me.

    What did work was turning off lighting. I'm pretty sure I'm seeing a tiny bit of the front face of the cube in back, so if all face are the same color I don't notice it. That's not a solution at all though.
     
  6. farzher

    farzher

    Joined:
    May 9, 2013
    Posts:
    9
    Also, changing my cubes to planes (only rendering the top face) removes the lines too.
     
  7. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,433
    dyox was correct, in that there is a limitation in the resolution of numbers. Imagine three polygons, seen from the side, forming a T. The vertical polygon should not be seen from above the two horizontal polygons, but due to number roundoff, a hair of it can be seen above the two horizontal surfaces.

    If your game knows that the two objects are butted against each other, and this is a very common occurrence, consider culling the polygons yourself somehow. For example, Minecraft culls every side of every cube separately, based on whether one opaque block is adjacent to another opaque block, because it's an essential aspect of performance as well as accurate drawing.
     
  8. farzher

    farzher

    Joined:
    May 9, 2013
    Posts:
    9
    Wouldn't I then just see through to the bottom of the world?

    I'm curious why it doesn't help when I make the tiles bigger so that they overlap.
     
  9. scorp2007

    scorp2007

    Joined:
    Aug 17, 2014
    Posts:
    54
    Exactly the same problem, someone please help what to do !!!
     

    Attached Files:

  10. vutruc80

    vutruc80

    Joined:
    Jun 28, 2013
    Posts:
    57
    Exactly the same problem, someone please help what to do !!!
     
  11. kobyle

    kobyle

    Joined:
    Feb 23, 2015
    Posts:
    92
    Still exists today! anyone solved it?
     
  12. w0nche0l

    w0nche0l

    Joined:
    Feb 21, 2015
    Posts:
    4