- Home /
uv does't apply correctly
Hey I've programmed a procedudural mesh generation like minecraft. At the moment I use 2 Textures on 1 material for some testig stuff. So currently I have 2 different types of blocks in my game but the textures won't apply correctly. It looks like this:
It looks like there's a pixel missing. (the white stripes) The textures wrap mode is set to clamp and in Photoshop are no missing pixels in the texture.
This is the texture I use:
And here is my code to apply them to the mesh:
public void GenerateFace(byte block, Vector3 vert1, Vector3 vert2, Vector3 vert3, Vector3 vert4)
{
int index = vertices.Count;
vertices.Add (vert1);
vertices.Add (vert2);
vertices.Add (vert3);
vertices.Add (vert4);
triangles.Add (index + 0);
triangles.Add (index + 1);
triangles.Add (index + 2);
triangles.Add (index + 3);
triangles.Add (index + 2);
triangles.Add (index + 1);
Vector2 uvWidth = new Vector2(0.5f, 0.5f);
Vector2 uvCorner = new Vector2((block - 1f)/2, 0.5f); //the left bottom corner of the tile
uv.Add (uvCorner);
uv.Add (new Vector2(uvCorner.x + uvWidth.x, uvCorner.y));
uv.Add (new Vector2(uvCorner.x, uvCorner.y + uvWidth.y));
uv.Add (new Vector2(uvCorner.x + uvWidth.x, uvCorner.y + uvWidth.y));
}
Maybe I'm doing something wrong here? If you have some ideas pleas let me know ;)
As a test, I would recommend trying this with a 4-by-4 pixel texture in which each pixel is assigned a different color. In the texture import settings, set wrap mode to "clamp" (as you've already done) and filter mode to "point".
Also, make sure your texture doesn't have an alpha channel (I've seen this "white lines" effect a few times when images with transparency aren't imported properly) and that it's saved using a loseless format (e.g., PNG).