Mesh's texture seems to be off by a small amount

I am working on a game inspired by this post on the unity fourms. I have always noticed this odd bug where the texture of each block has a column of pixels from the next block’s texture.

This causes these vertical lines throughout the world.

I have looked through the code used a bit, but I can’t seem to find anything that caused this. Everything seems to be correct, granted I don’t know much about meshes and UV in unity.

All of the code can be found here.

This looks like normal color bleeding due to missing padding between different parts inside the UV space. This happens due to texture filtering So essentially the parts are packed too tight. You also seem to use mipmapping which makes the issue even worse at larger distances. If you use some sort of atlas texture you have to ensure the atlas is an actual power of two texture and the different parts are should be aligned to a power of two with “enough” spacing. Bilinear and Trilinear filtering will sample the neighboring texels and does an interpolation between them. Therefore the neighboring pixels at the border will bleed into the texture.

Mipmaps are downsampled versions of your original texture. So for every 2x2 pixel there will be only one in the next mipmap layer. The mipmaps go down to one pixel. See the example image on the Mipmap wikipedia page below the “How it works” section. If the different parts in your atlas are arranged in a way so at mipmap level x you actually mix pixels of different parts you get the wrong color for the edge region…

Next thing is UV coordinates go from 0 to 1. A value of 0 is the left / bottom border of the image and 1 is the right / top border. However people often forget that a pixel actually has a certain “size”. Just for example in an 8x8 texture the lower left pixel / texel goes from 0,0 to 0.125. The center of the pixel is at 0.0625. Many people actually map the triangles at the outer edge of the pixels which will result in a perfect 50/50 mix between neighboring pixels. You should sample the center of the pixels.