- Home /
2d artefact gap between tiles
I have issue which u can see on left image when orthographic size of my camera is an integer. If orthographic size is integer+0.5 than its ok: right image.
Size of my camera changes automatically by formula
camera.orthographicSize = camera.pixelHeight / 2.0f;
Width and height of tiles meshes and textures is 16.
1 generate 1 mesh, and for every tile i make quad of 4 new verticles:
for (int i = 0; i < _w; ++i)
{
for (int j = 0; j < _h; ++j)
{
if (data[i,j] != null)
{
SetTile(new XY(i, j), data[i,j].GetId());
}
}
}
public void SetTile(XY pos, int tileId)
{
// ->
// 1 2
// *----*
// | \ |
// | \|
// *____*
// 3 4
int index = (pos.x * _w + pos.y) * 4;
_vertices[index] = new Vector3(pos.x * _tileSize, _depth, pos.y * _tileSize);
_vertices[index + 1] = new Vector3(pos.x * _tileSize + _tileSize, _depth, pos.y * _tileSize);
_vertices[index + 2] = new Vector3(pos.x * _tileSize, _depth, pos.y * _tileSize + _tileSize);
_vertices[index + 3] = new Vector3(pos.x * _tileSize + _tileSize, _depth, pos.y * _tileSize + _tileSize);
_normals[index] = Vector3.up;
_normals[index + 1] = Vector3.up;
_normals[index + 2] = Vector3.up;
_normals[index + 3] = Vector3.up;
Rect uv = _atlas.spriteDefinitions[tileId].uv;
_uvs[index] = new Vector2(uv.xMin, uv.yMin);
_uvs[index + 1] = new Vector2(uv.xMax, uv.yMin);
_uvs[index + 2] = new Vector2(uv.xMin, uv.yMax);
_uvs[index + 3] = new Vector2(uv.xMax, uv.yMax);
int triangleIndex = (pos.x * _w + pos.y) * 6;
_triangles[triangleIndex] = index;
_triangles[triangleIndex + 1] = index + 3;
_triangles[triangleIndex + 2] = index + 1;
_triangles[triangleIndex + 3] = index;
_triangles[triangleIndex + 4] = index + 2;
_triangles[triangleIndex + 5] = index + 3;
}
What am i doing wrong? Help me please.
here is another sample (this time i also have empty squares, its not a bug - just intentional)
Answer by Taza494 · Oct 11, 2015 at 11:43 AM
Edit>Project Settings>Quality, disable antisotopic filtering and anti aliasing is what worked for me.
Answer by Yakov_Ginko · Aug 01, 2013 at 02:45 PM
Well, i tempoprarily fixed it with hack - made orhograthic size be always with .5 floating part. But i'm still looking for my mistake/solution of this problem
Answer by MachindoApps · Aug 01, 2013 at 02:57 PM
Is camera.pixelHeight an even number?
The artifact might be caused by the height being odd, and the division by 2 discarding the remainder.
I think no, for example, when i do have problem: Orthographic size = 455, pixel height = 910, screen height = 910 and i divide by 2.0f, i wrote wrong above
Answer by phocker · Aug 01, 2013 at 07:33 PM
also check your texture to see if you are using POINT versus BILINEAR -- that can cause those gaps as well.