Packed textures "flicker" in distance

Hello,

my game contains a map that is made of tiles of different terrain types. So I figured it might be a good idea to pack the textures and make a texture atlas.

This worked, with two problems:

  1. I now have black lines between my tiles. I assume the PackTextures method added padding despite the 0 parameter. Does anyone have a suggestion on how to fix that? Do I just move the uvs a bit further “into” the texture?
  2. The texture doesn’t get displayed correctly. It kind of shows a dirt texture where there’s meant to be grass, and it turns into grass when I approach. I tried changing the anisoLevel and the filterMode, no success. I’m clueless on how to approach this now. Is this fixable in anyway way or should I go back to single textures?

Thanks everyone for your help.

17502-problem.jpg

I don’t have the time to test this, but this should be the case:

  • Black lines: it doesn’t matter whether you set padding or not. The black border is result of filtering the texture at it’s edge which blends with it’s neighborhood - other textures or empty unused space. (In case of single texture this doesn’t happen because left border is blended with right one and because the texture is meant to be seamless, it works well.)
  • Bad texture in distance: yes, it’s connected to mipmaps. Mipmaps are textures scaled down for different distances so it won’t flicker when rendered far away, but if you use them for atlas, neighbor images will blend at certain level and crate ugly effect you encountered and described. (Search google (“mipmap atlas”) for details and beter understanding what I just wrote.)

Solutions:

  • No - don’t revert back to single textures. It will slow down your game greatly. Atlases are really needed these times. Don’t avoid them.
  • Black border: your texture need some border (1px is enough for bilinear filtering.) so edges can be filtered correctly. How to create the border? Copy left most column of pixels in the original image and put them to right side of the texture (you need to create space for it). Similarly copy right column to left side, top row to bottom and bottom row to top. Finally top-left pixel to bottom-right corner etc.
  • Bad texture in background: this is more problematic. Simplest thing is turn off the mipmaps, but it won’t get you nice results (textures will flicker in distance). Other thing is to make border described above with thickness bigger then 1px. But it will still result in bad texture in from some distance - the thicker the border is, the bigger distance is needed for the problem to appear. Best thing, IMHO, is to setup mipmaps to certain level only (level where different tiles still can be distinguished). Currently I don’t know how to achieve this in Unity. Other solution is to use “Fadeout Mip Maps” option in the texture inspector - tiles in big distances (or under low angles) should fade to gray.

Personally, I would go for custom mipmaps to certain level with borders for each tile. (In this case textures will flicker in really big distance, but I think it’s the most acceptable solution.)