Search Unity

Random White lines in between tiles

Discussion in '2D' started by Nerevarine, Nov 26, 2014.

  1. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    Im getting white lines in between some tiles when i move the camera.. This issue is really persistent.. I havent found any workarounds other than overlapping 2 tiles.. tried everything, like replacing the tiles entirely with some other etc but the issue is still there
    The strange part is that, it seems to occur in a certain area only as creating the same tiled structure somewhere else doesnt seem to have this problem
    Any help guys,
    thanks in advance
    (sorry for my english)

    Attached ss
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Are the tiles sprites with the default sprite shader?
     
  3. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    Yup, they are
     
  4. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    do you use the pixel snap check box on Sprites/Default shader?
     
  5. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    I tried the default shader and created a new material with base as default shader but enabled pixel snap..
    Both give the exact same result.. Im starting to think this is a bug OR it could be the annoying floating point imperfections i keep hearing about..
    what value do I set the main camera in order to avoid FP imperfections ?
     
    Last edited: Nov 26, 2014
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    with pixel snap it seems you also must have an exact pixel-to-texel ratio set up in your camera, so that e.g. if the resolution is 768 pixels high then the ortho needs to be 384... or work out so that you get `whole pixels`, otherwise it seems the calculations will produce some floating point fluctuations like this.
     
    A_Vrankie likes this.
  7. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    You've hit one of the things that drove me batty for a month or two.

    This is what I ended up doing that resolved the issue. Note that doing any one or the other may solve the issue in specific cases but not in others.

    For 2D, this is what I use:

    1. Locking the camera to pixel positions (if the camera can move then you will need to use code to do the pixel positioning in the update method of an attached script)
    2. Using a sprite renderer material with Pixel Snap enabled (I never saw this make any difference but others said it worked for them).
    3. Point Filtering (this has no effect on the gap issue but definitely want to use it for sharp non-blurred images)
    4. Locking the position of each sprite to pixel coordinates meaning you will need to put code into update to do this for every sprite.
    5. Make sure each tile (and sprite) image has 2 pixels of transparent space on each side.
    For 1 and 4 what I do is use a Vector2D to hold the pixel position which I then use to position the transform in Update.
    I use another Vector2D to hold the "real" position of the objects and this is the one I use to do the actual movement and so forth. The v2PixelPosition is used only in the Update to position the object.

    By doing all of these things I no longer encounter any glitches in the way tiles / sprites are displayed.
     
  8. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    ^2,3 ive already tried, didnt work...
    5 is not possible, im halfway through my work and i cant edit the pixels one by one again
    Ill try 1 and 4, and report asap.. thanks a lot for the help guys, you guys making my life easier :D
     
  9. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    will try, thanks for suggestion
     
  10. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    Currently in all my tiles, the Pixel to Unit is set to 100, i want to change it to 1 without it messing up in distance, is there any way to do it ? im halfway through and remapping all tiles will take days, is there any efficient way that Unity will automatically calculate distance between 2 tiles etc
     
  11. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14

    trying this, it may have solved the issue.. need to test

    bump regarding this ?
     
  12. Nerevarine

    Nerevarine

    Joined:
    Jul 26, 2014
    Posts:
    14
    Update : Im rounding off the maincamera X and Y position to 2 decimal places using a function update

    this seems to have solved most of the white line flickering (some still remains)..

    Update2: Issue fixed, thanks for the help everyone
     
    Last edited: Nov 28, 2014
    GarBenjamin likes this.
  13. Decrofts

    Decrofts

    Joined:
    Jul 9, 2015
    Posts:
    1
    i was in the same problem i discover a way, Edit>Project Settings>Quality and disable antialising
     
  14. luihabl

    luihabl

    Joined:
    Oct 24, 2015
    Posts:
    1
    This fixed the issue for me!
     
  15. Maniak101

    Maniak101

    Joined:
    Feb 16, 2017
    Posts:
    1
    I've been having a similar issue and turning off antialising helped but didn't completely solve the issue. I'm not that a confident programmer so locking the camera to pixel points confused me ... a lot.

    Setting Clear Flags on my camera to Depth Only seems to have done the job - not sure of the knock ons however as I have no idea what that even means...
     
    jokijan and Armynator like this.
  16. chernobyyl

    chernobyyl

    Joined:
    Aug 7, 2019
    Posts:
    6
    Solution for newer Versions ( tested in 2020.3 )
     
    VedTheDead and Infinite-3D like this.
  17. VedTheDead

    VedTheDead

    Joined:
    Apr 21, 2020
    Posts:
    3
    This solved my issue at least for now. Thanks. Last video also seems good. I will try that.