Artifacts in tiles

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Megail
Prole
Posts: 4
Joined: Tue Sep 03, 2013 3:06 pm
Location: RF, Novokuznetsk

Artifacts in tiles

Post 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 3290 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.
Attachments
gtp1.love
source
(252 KiB) Downloaded 115 times
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Artifacts in tiles

Post by raidho36 »

I beleive this has to do with aliasing. Try moving camera strictly to integral positions.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Artifacts in tiles

Post 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.
Shallow indentations.
User avatar
Megail
Prole
Posts: 4
Joined: Tue Sep 03, 2013 3:06 pm
Location: RF, Novokuznetsk

Re: Artifacts in tiles

Post by Megail »

Thanks for the answers. Maybe there's another way to draw tiles? When opengl knows what near tile.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Artifacts in tiles

Post 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.
User avatar
slime
Solid Snayke
Posts: 3170
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Artifacts in tiles

Post by slime »

Tools like http://www.codeandweb.com/texturepacker can automatically add the padding Boolsheet's talking about to your sprite sheet for you.
User avatar
Megail
Prole
Posts: 4
Joined: Tue Sep 03, 2013 3:06 pm
Location: RF, Novokuznetsk

Re: Artifacts in tiles

Post 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.
User avatar
Megail
Prole
Posts: 4
Joined: Tue Sep 03, 2013 3:06 pm
Location: RF, Novokuznetsk

Re: Artifacts in tiles

Post 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:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests