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)
{
return topUV;
}
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?




