SFML community forums

Help => Graphics => Topic started by: Kuinox on November 27, 2017, 04:57:27 pm

Title: TileMap show artifacts
Post by: Kuinox on November 27, 2017, 04:57:27 pm
Hi,
I coded a tilemap using the VertexArray like many tutorial show. 
The problem is i get some artifacts:
(https://i.imgur.com/1LQ4BFt.png)
I know this artifact is a part of the tileset i use, but i dont give any coordinate to these textures. 
Thanks
Title: Re: TileMap show artifacts
Post by: achpile on November 27, 2017, 05:46:19 pm
that's because you have some errors in your code
Title: Re: TileMap show artifacts
Post by: Kuinox on November 27, 2017, 05:51:17 pm
When i put the texture coordinate it never put the coordinate of this purple and black texture.
It's actually the missing texture
Title: Re: TileMap show artifacts
Post by: eXpl0it3r on November 28, 2017, 08:51:49 am
And when does this occur? When you move or zoom the tilemap? Or when it's static? Or?
Title: Re: TileMap show artifacts
Post by: Kuinox on November 28, 2017, 09:48:28 am
They are "static" if i don't move the View, but they disapear or appear when i zoom, dezoom to a certain point. 
They are more frequent when i dezoom. 
The line are not between the vertex array, but appear between the quads of the vertex array, they does not appear when i zoom in, they appear only when i zoom out a bit.
Title: Re: TileMap show artifacts
Post by: eXpl0it3r on November 28, 2017, 11:20:08 am
That's texture bleeding. There's no nice/easy fix for it, but it can be minimized with some adjustments.
So the issue is that the neighboring part of the texture you've "selected" with a texture rect/texture coordinates is bleeding into your selection. This happens because the coordinate falls on a none integer position, thus OpenGL has to decide which part of the texture it should now display, which can lead to OpenGL using the part of the neighboring texture to fill the gap.

One thing you can do to minimize the visual effect is to have a 1px wide border around each of your tile, that way if it bleeds, it doesn't bleed the next tile.
Then you need to make sure your vertex array is positioned at integer positions and not in between "pixels".
Other than that you need to make sure that you zoom at round multiples, so the entity positions remain integers.

An alternative that shouldn't cause bleeding is to render to a render texture and use that texture for zooming and translating.
Title: Re: TileMap show artifacts
Post by: Kuinox on November 28, 2017, 11:46:44 am
Thanks ! 
So, i think its the view getting a Vectorf position, i'm wrong ? Because the tiles get a position that is an integer and the VertexArray position are a multiple of 16.
Title: Re: TileMap show artifacts
Post by: Kuinox on November 29, 2017, 01:40:34 pm
So, i checked, all textures coordinate and Quads are Vector2i casted in a Vector2f. 
Also, the tile width is 1, is this causing a problem ? 
There is only the camera that is a float. 
You said there is no easy fix, but i didn't saw this problem in other tile engines using SFML. 
Title: Re: TileMap show artifacts
Post by: fallahn on November 29, 2017, 02:33:52 pm
This is quite a common problem and there are a few other posts about it:

https://en.sfml-dev.org/forums/index.php?topic=15338.0
https://en.sfml-dev.org/forums/index.php?topic=6665.0
https://en.sfml-dev.org/forums/index.php?topic=19821.0

The most effective fix I've found is to use a shader to draw the tiles, which is explained here:

https://github.com/SFML/SFML/wiki/Source%3A-ShaderTileMap
http://www.the2dgame.com/index.php?page=articles&ref=ART8
Title: Re: TileMap show artifacts
Post by: Kuinox on November 29, 2017, 04:19:08 pm
Thanks !
Also, i figured that this problem is not happening when i use the intel chipset, but only happen when i use the nvidia iGPU