1

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.

user92748
  • 15
  • 5

1 Answers1

1

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.

Tom Tsagkatos
  • 4,761
  • 16
  • 26