Why texture atlas has gap?

Hi~ I’m generating a building with procedural.
The texture is a atlas.
8524943--1137263--WeChat Image_20221019201250.jpg


When camera near the building, it looks profect.

But when camera far away from the building, texture has lots of gap.

I was set a tiny distance when get UVs to prevent cropping beyond UV cells.

public const float uvGap = 0.001f;
public const float uvUnit = 0.0625f; //(1/16)

How can I fix this? Thank you!~

It’s not looking “profect” at all even at close range. :wink:
8524982--1137278--upload_2022-10-19_14-36-22.png

The most likely culprit is that your texture atlas has no padding, instead a gray-brown-ish grid is next to each image:
8524982--1137281--upload_2022-10-19_14-37-42.png

That is the color that is shining through. If the grid is from the UI and not actually in the texture, then the 1px wide gap between textures simply isn’t enough.

Make sure to have at least a 2px wide padding of black/alpha between each texture because texture filtering looks at the surrounding pixels as well. You can test if that’s the issue by setting the texture filtering mode to point, the artifacts should be gone or not nearly as visible.

See: Edge padding - polycount

Thank you!
Actually,the grid you have seen is Photoshop UI(Show Grid). The texture did not have that. Texture cells side by side,no space between of them.

I set UV like this. Even sliced more inside, the gaps still visiable.
![8525972–1137446–G}{YC$@DF}XTS{ICLL`JBW.png|412x218

I have no idea~

It is pretty hard to atlas like that. If you have mipmapping on, you will get bleeding between tiles like you show, unless you have large gaps between.
Try looking at texture arrays instead or if you want an unfiltered retro look, just turn on point filtering and disable or hand craft the mipmaps.
But this is a question for graphics forum.

1 Like

Thanks!
I disabled the mipmap on texture, and set UV more inside(a little bit).
Now looks better.8526803--1137656--WeChat Image_20221020111415.jpg

Cool! :slight_smile:

Just FYI since this looks like it’s made solely out of cubes, keep in mind that this won’t perform/scale well unless you combine the cubes into a single mesh (possibly separated by material, or one submesh per material) and also use cube marching algorithm to reduce polycount (ie a flat surface x by y number of cubes would be a single quad rather than x*y quads).

1 Like

There’s a thing called mipmapping.

Mipmapping means texture stores several lower resolution versions of it. Because of that nearby tiles can leak into each other.

Disabling mipmapping will reduce performance slightly and is not really recommended.

1 Like

Yes, the building is a single mesh now. I’ll try make submeshes with every material(not use texture atlas). Maybe it will reduce performance , but I can use more materials and shaders in this way.
Thanks again , bro~