# UV mapping. Texture blurry and overlapping. Unity3d

In my voxel game, this is how I'm calculating UV coordinates for my cubes' faces:

public static Vector2[] faceUVs(Direction dir)
{

Vector2[] sideUV = new Vector2[4]{
new Vector2(0, 1),
new Vector2(1f/3, 1),
new Vector2(1f/3, 0),
new Vector2(0, 0)
};
Vector2[] topUV = new Vector2[4]{
new Vector2(1f/3, 0),
new Vector2(1f/3, 1),
new Vector2(2f/3, 1),
new Vector2(2f/3, 0)
};
Vector2[] bottomUV = new Vector2[4]{
new Vector2(2f/3, 0),
new Vector2(2f/3, 1),
new Vector2(1, 1),
new Vector2(1, 0)
};
if ((int)dir == 4)
{
}
if ((int)dir == 5)
{
return bottomUV;
}

return sideUV;
}


Then depending on which face is being generated, I return appropriate UV coordinates for it.

This is the texture itself(pretty clean, each block is exactly 16 pixels wide and 16 pixels tall. Total length of picture is 48 pixels):

But the result is terrible(Faces are almost correctly aligned with appropriate texture part, but the annoying keyword here is "almost"):

As you can see, edges of side faces contain few pixels of what should have been the texture of top face.

I've set filter mode to point too.

If I instead use 16x16 pixel texture, for example only side, then I get good result:

I suspect the problem here could be floating point precision. In that case, how do i resolve this error?

• It looks like your texture's import settings are scaling it to a power of 2 size since your input was a different size. Additionally, 1/3 isn't exactly representable as a decimal, let alone binary floating point. Have you tried making your image a power of two width and adding padding between the tiles, so the pixel edges you want to reference fall on representable floating point numbers? Mar 4, 2020 at 12:14
• @DMGregory Epic! Thanks. Changed image width to 64, didn't even need additional padding between tiles. Works seamlessly!
– Nick
Mar 4, 2020 at 12:35
• If this solved your problem, please post it as an Answer below. Mar 4, 2020 at 12:37