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

Author Topic: Texture atlas tiling  (Read 3087 times)

0 Members and 1 Guest are viewing this topic.

petej

  • Newbie
  • *
  • Posts: 2
    • View Profile
Texture atlas tiling
« on: August 19, 2024, 10:03:52 am »
I am trying to draw a 2D terrain.  I have defined a heightmap, created a VertexArray of type Triangles, and populated it with the vertices of my heightmap.  Specifying vertex colors works great, but I am now trying to use textures instead.

I have a texture atlas (e.g. see attached) that contains sub-textures for the different areas (e.g. grass, rock, etc.).  I need to have those sub-textures tile across the triangles because some triangles are bigger than the sub-texture and most do not align with a texture boundary.  Note that I am using an irregular grid (think something derived from a voronoi diagram) for the heightmap, so using grid-aligned quads is not possible.

When I set the texture to repeat, and specify texture coordinates, it tiles the whole texture atlas, not just a single texture.  I can make this work (e.g. see attached) by breaking the atlas into individual textures, and creating one VertexArray per area (e.g. grass, rock, etc.).  However, this means I must use a single texture across an area, with no ability to vary the texture, unless I create more individual textures and VertexArrays.

Is there another way to accomplish tiling of a sub-texture in an atlas?  Does the question make sense?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Texture atlas tiling
« Reply #1 on: August 19, 2024, 04:09:10 pm »
I don't think it's possible to auto-tile (i.e. repeat) just part of a texture.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

petej

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Texture atlas tiling
« Reply #2 on: August 19, 2024, 09:42:03 pm »
Thanks for the reply!  A little broader research suggests this is possible with OpenGL shaders, so maybe I can do this by using the Shader class and binding a Texture to it.

https://community.khronos.org/t/repeat-tile-from-texture-atlas/104500

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Texture atlas tiling
« Reply #3 on: August 19, 2024, 10:22:00 pm »
Yes, this may be possible indeed.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Texture atlas tiling
« Reply #4 on: August 20, 2024, 10:29:04 am »
Yep, shaders can let you repeat a section of a texture (doing a bit of modulus and stuff with the UV coordinates).
One thing to be careful of though is a sudden jump in UV (like going off one side of the tile and back on the other side) will trip up mip mapping and it will do an edge of 1x1 mipmap, so a solid colour. You need to manually control the mipmapping to avoid it.

 

anything