Texture atlas and assigning UVs

I’m not really sure how this is done… cant find any info on google for some reason so I must be using the wrong term.

If you have a bunch of quads that you are building procedurally and you want to texture them from one big image split up into different textures (so you can have one material), whats the best way? It’s like a sprite atlas but for 3D quads.

I have been editing the mesh UVs directly like so…

    public static Vector2[] UV4s(Vector2 TL, Vector2 BR, int rotation) {
        Vector2 v1, v2, v3, v4;
        v1 = new Vector2(MathF.Round(TL.x / 1024f, 4), 1 - MathF.Round((BR.y / 1024f), 4)); // 0 0
        v2 = new Vector2(MathF.Round(TL.x / 1024f, 4), 1 - MathF.Round((TL.y / 1024f), 4)); // 0 1
        v3 = new Vector2(MathF.Round(BR.x / 1024f, 4), 1 - MathF.Round((TL.y / 1024f), 4)); // 1 1
        v4 = new Vector2(MathF.Round(BR.x / 1024f, 4), 1 - MathF.Round((BR.y / 1024f), 4)); // 1 0
        Vector2[] r = new Vector2[] { v1, v2, v3, v4 };
        if (rotation == 1) { r = new Vector2[] { v2, v3, v4, v1 }; }
        if (rotation == 2) { r = new Vector2[] { v3, v4, v1, v2 }; }
        if (rotation == 3) { r = new Vector2[] { v4, v1, v2, v3 }; }
        return r;
    }

But one thing I’ve noticed is that there are “seams” where the quads bleed through. I’m pretty sure this is because of when you have a large image like 1024 and you set the UV to a certain slice of it you have to divide it and you wind up with a UV float value like 0.625.

But when I use a small 64x64 texture where the UVs can be just whole numbers like (0, 1) the seams dont appear.

So how have you guys tackled this before? I think I’m just going to create a bunch of different 64x64 materials and use that unless there is a better way.

You should probably make the texture atlas have padding around each one. At least one pixel of padding around each tile in the atlas, with that extra padding being colored with the tile’s border colors. That way when there are any slight steams, it just basically stretches that one tile’s color out over the seam

Disabling texture compression can help.

It feels hacky and it increases my workflow… but it worked. Thanks PixelDough :smile:

Well… it works on textures up close but in the distance the mipmap textures still have the same problem. I’ll try messing around with the mipmap settings.

I feel like this is a common procedure in the gaming industry so its crazy I cant find any info on it…

Edit: Found another thread with the exact same problem where the poster gave up lol, Seams visible in textures, I guess its just not common procedure to sample textures by changing UVs. I’ll just create separate textures for everything but that creates more draw calls/batches. >_<

I wonder how unity samples the sprite atlas feature. You can cut apart the image any way you like without having to pad anything. It’s not using mipmaps but you should be able to do the same with meshes/textures.