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

Author Topic: Sfml multi-textured tile map  (Read 3221 times)

0 Members and 1 Guest are viewing this topic.

Inspector Coarse

  • Newbie
  • *
  • Posts: 4
    • View Profile
Sfml multi-textured tile map
« on: August 17, 2015, 02:40:33 pm »
How would i do multi texturing in sfml?

Since sf::vertex is set, i would have to use the colour channel to carry the texture weights, and then all i need to do is specify the uv somehow to sample the appropriate texture from the texture 'atlas'.
How would/could i do that?

I don't quite understand "gl_TexCoord[0]" here.

Quote
vec4 pixel = texture2D(mapTexture, gl_TexCoord[0].xy);





Any help appreciated.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Sfml multi-textured tile map
« Reply #1 on: August 17, 2015, 02:46:24 pm »
Try to patch as much as possible on one texture without create huge textures that are only supported by the latest high-end GPUs and then use one vertex array per texture.

Not sure what you're trying to ask with the OpenGL code here...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Inspector Coarse

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sfml multi-textured tile map
« Reply #2 on: August 17, 2015, 02:54:49 pm »
So that the overlaying textures blend to produce the multi texture effect ?


I was planning on doing it in the shader, hence that line of code which is from a basic texturing pixel shader.
I just don't know how to go about accessing different parts of the texture(atlas) to draw the right part according to the weight information.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Sfml multi-textured tile map
« Reply #3 on: August 17, 2015, 03:44:29 pm »
Ah I didn't realize you were talking about multi-texturing. I've never done that, so I'm unsure, but I guess you can do all of it in a shader.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sfml multi-textured tile map
« Reply #4 on: August 17, 2015, 04:11:57 pm »
I guess you can do all of it in a shader.
You can pass multiple textures to a shader and use them as you wish, but passing multiple texture-coordinates per vertex (one for each texture) seems impossible (with the current SFML setup).
Sending extra data with vertices would solve that problem. I 'think' I've seen talk of it being considered for SFML but I'm not sure where. It may be for SFML 3 where it'll probably use 'modern' OpenGL.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Inspector Coarse

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sfml multi-textured tile map
« Reply #5 on: August 17, 2015, 05:08:15 pm »
All i need to do is sample the same texture at at-least four different points, so using an offset will do. Using colour channel that gives me 4 different values(uint8 so 0-255) for weights so, four textures.

Tex2pos will be Tex1pos + offset of some kind. etc.


pixel = Tex1Pos * TexWeight.x
pixel += Tex2 Pos * TexWeight.y
...     +=
...     +=


 Is this possible?
 

The tile map will appear smoothly textured as a result, with textures painted according to the weight values which could be a heightmap or any old map.


« Last Edit: August 17, 2015, 05:39:15 pm by Inspector Coarse »

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: Sfml multi-textured tile map
« Reply #6 on: August 17, 2015, 05:49:01 pm »
Yep, totally possible.
I've done something very similar before with no problem.

I did it with 4 different textures, but there's absolutely no reason you couldn't do it using a texture atlas with 4 different offsets passed in as uniform params.
« Last Edit: August 17, 2015, 05:50:33 pm by Jabberwocky »

 

anything