Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TileMap show artifacts  (Read 4379 times)

0 Members and 1 Guest are viewing this topic.

Kuinox

  • Newbie
  • *
  • Posts: 27
    • View Profile
TileMap show artifacts
« 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:

I know this artifact is a part of the tileset i use, but i dont give any coordinate to these textures. 
Thanks

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: TileMap show artifacts
« Reply #1 on: November 27, 2017, 05:46:19 pm »
that's because you have some errors in your code

Kuinox

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: TileMap show artifacts
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: TileMap show artifacts
« Reply #3 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kuinox

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: TileMap show artifacts
« Reply #4 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: TileMap show artifacts
« Reply #5 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kuinox

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: TileMap show artifacts
« Reply #6 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.

Kuinox

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: TileMap show artifacts
« Reply #7 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. 

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: TileMap show artifacts
« Reply #8 on: November 29, 2017, 02:33:52 pm »

Kuinox

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: TileMap show artifacts
« Reply #9 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

 

anything