Search Unity

Black lines between tiles after combining them with PackTextures()

Discussion in 'Scripting' started by davvilla, Jul 12, 2012.

  1. davvilla

    davvilla

    Joined:
    Mar 28, 2012
    Posts:
    18
    We have a tile based game (a bunch of 1x1 planes represent the ground) and in a ground of type "Grass" we have 6 variations to make it look less tiled. While trying to reduce draw calls I wrote a script that would grab the 6 different textures and pack them into one bigger one using PackTextures(). I then modified the meshes with the Rect[] I got back from PackTextures() so that all 6 variations use the same material.

    Everything worked fine but now I can see black lines in between the tiles. I'm assuming the black lines are caused by bleeding from the texture atlas, however I'm unsure if this is actually the case and how to fix it. Below are the black lines and the texture atlas for reference. I hope this made sense

    Texture atlas (6 tiles in one texture)


    Black lines


    I really appreciate your time, thanks !
     
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    Did you play with the aniso levels or the texture format? Sometimes that works for me.

    Also you can change the background color of the texture close to the grass color, and that may help too.
     
  3. Krobill

    Krobill

    Joined:
    Nov 10, 2008
    Posts:
    282
    Your assumption is right. The PackTextures method alway gives a black background around the textures you pass as a parameter. Hopefuly someone will realise one day that it would be a lot more usefull if it could generate colored padding around each element or even let you choose the background color...

    For now you have only two solutions if you want to use PackTextures at runtime :
    - feed it some already padded textures and modify the returned UVs to exclude the padding
    - modify the Atlas with the SetPixels method to change the black background entirely or pad your square elements which is not very hard to do.

    If you use PackTextures in the editor and save the atlas output you can modify it in Photoshop to actually add colored padding quite easily.
     
    Last edited: Jul 12, 2012
  4. davvilla

    davvilla

    Joined:
    Mar 28, 2012
    Posts:
    18
    Playing with the aniso levels did not result in any changes but changing the background color did. I just added green into the white areas. This was an easier fix that I thought Thanks a lot for the help!
     
  5. codebeans

    codebeans

    Joined:
    Apr 7, 2014
    Posts:
    79