The following code maps the texture from a texture atlas to a UV. The problem is I'm having texture tearing issues.
Does anyone know how to overcome this problem and have any suggestions? Here is the code I have, all images are point filtered and no mipmapping is used.
for (int i = 0; i < mesh.uv.Length; i++)
{
UVs.Add(GetUVTextureFromAtlas(mesh.uv[i].x, mesh.uv[i].y, voxel, 0));
}
[...]
Vector2 GetUVTextureFromAtlas(float x, float y, ushort voxel, Facing side)
{
Rect rect = GetVoxelTextureRect(voxel, side);
float xout = UVLerp(rect.x, rect.x + rect.width, x);
float yout = UVLerp(rect.y, rect.y + rect.height, y);
return new Vector2(xout, yout);
}
float UVLerp(float from, float to, float t)
{
float difference = to - from;
return from + (difference * t);
}