Page 1 of 1

Artifacts in tiles

Posted: Tue Sep 03, 2013 4:26 pm
by Megail
Hi All,

I have a problem with a tile. You can see it:
Bad screen
Bad screen
bad.png (23.37 KiB) Viewed 3298 times
Artifacts are visible only in rare positions of the camera. This is particularly evident when you move. I tried to set different filters, it does not work. To work with the camera I use a package HUMP. To draw tiles I use SpriteBatch (You can see that in ground.lua).

Thanks.

Re: Artifacts in tiles

Posted: Tue Sep 03, 2013 4:43 pm
by raidho36
I beleive this has to do with aliasing. Try moving camera strictly to integral positions.

Re: Artifacts in tiles

Posted: Tue Sep 03, 2013 4:53 pm
by Boolsheet
When you move your camera to a position that makes the images fall just on the edge of a pixel, OpenGL wants to use the color of the neighbouring pixel (outside of the tile) in the spritesheet. This is expected behaviour.

One solution is to make sure that the images always line up on the pixel. For example, you could change your scene update code to this.

Code: Select all

local sx, sy = love.graphics.getWidth(), love.graphics.getHeight()
camera:move(math.floor(dx/2*sx)/sx, math.floor(dy/2*sy)/sx)
Of course, this is a bit ugly and won't work if you start rotating. The better solution then is to pad each of your tiles with a 1 pixel border with the color of the neighbouring pixel. This will give the expected result in all situations.

Re: Artifacts in tiles

Posted: Tue Sep 03, 2013 7:13 pm
by Megail
Thanks for the answers. Maybe there's another way to draw tiles? When opengl knows what near tile.

Re: Artifacts in tiles

Posted: Tue Sep 03, 2013 7:18 pm
by raidho36
OpenGL draws your tiles as a textured triangles. Due to aliasing, a fragment of a triangle can either occupy a whole pixel, or not occupy it at all. But decimal values of edges' positions and texture coordinates are maintained as decimal, and since there's no aliasing for textures (by default), on the aliased edge it can render slightly beyond desired texture edge, resulting in overlapping with next tile. Think of it as if your tile was a slot in cardboard with a wallpaper beyond it. The wallpaper moves freely, but the slot can only "jump" through 2 inches at once.

Re: Artifacts in tiles

Posted: Tue Sep 03, 2013 7:32 pm
by slime
Tools like http://www.codeandweb.com/texturepacker can automatically add the padding Boolsheet's talking about to your sprite sheet for you.

Re: Artifacts in tiles

Posted: Tue Sep 03, 2013 7:34 pm
by Megail
I understand why. I thought maybe it makes sense to create a texture on the entire screen. So opengl will know which pixel nearby.

Re: Artifacts in tiles

Posted: Tue Sep 03, 2013 7:46 pm
by Megail
slime wrote:Tools like http://www.codeandweb.com/texturepacker can automatically add the padding Boolsheet's talking about to your sprite sheet for you.
thanks :nyu:

Re: Artifacts in tiles

Posted: Sat Sep 21, 2013 8:20 pm
by AntonioModer