1
\$\begingroup\$

I'm creating a tile based game. The tiles can have different textures. All the textures are loaded at startup and dynamically packed in a texture atlas (this is done to make modding easier). Each tile stores the UVs of it's texture.

Here is an example from the game, in which the terrain is mostly made up of "grass" tiles, and there are also "stone" and "dirt" tiles in the center:

tiles example

As you can see, the edges between different tile types are "hard". I want to make them "soft", so the tiles would blend into each other.

It was suggested to me to create special "edge tile" textures and use them for the edge tiles, but I would rather avoid that because it would require creating an edge tile texture for every 2 possible tile combinations (perhaps more for corners), and would massively bloat up the texture atlas.

Therefore I thought this should be done using a shader. I'm not too familiar with shaders though. I've created simple shaders that make grass sway and such, but I have no idea how to approach this problem. For starters, I'm not even sure how to "tell" the shader what are the UVs in the surrounding tiles (I need the UVs to sample the texture from the Atlas)?

Any help would be appreciated.

Thank you.

\$\endgroup\$
4
  • \$\begingroup\$ Are the tiles separate meshes? \$\endgroup\$
    – Zebraman
    Jan 24, 2018 at 14:38
  • \$\begingroup\$ Check out this previous answer on using a tile index map to specify tile contents. With a technique like that, your shader can "peek" into adjacent tile slot texels to figure out what atlas entry to blend into for its neighbours. \$\endgroup\$
    – DMGregory
    Jan 24, 2018 at 15:13
  • \$\begingroup\$ @Zebraman - the tiles are on the same mesh. \$\endgroup\$
    – user92748
    Jan 24, 2018 at 16:31
  • \$\begingroup\$ You can use opengl blend modes to blend the second texture onto the first, but its messy. If you create 'edge' textures, you can make them look interesting and natural, something you could only achieve in the shader with great difficulty. \$\endgroup\$
    – otoomey
    Jan 24, 2018 at 21:26

1 Answer 1

1
\$\begingroup\$

It was suggested to me to create special "edge tile" textures and use them for the edge tiles, but I would rather avoid that because it would require creating an edge tile texture for every 2 possible tile combinations (perhaps more for corners), and would massively bloat up the texture atlas.

This is the correct way to go, but you don't have to create a separate texture for each combination of 2 blended textures. Just make each floor texture have an edge which is half alpha, and half the desired texture. Then when you place a tile on the floor, make all surrounding tiles have 2 textures, one from the newly placed tile, and one from it's old tile.

Using the same logic, you can also make corner tiles, to support a tile being surrounded by 4 different tiles, or weird shapes.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .