How should I go about doing texture blending for my game?

Hi!

My game has a kind of top-down view, similar to most RTS like Starcraft 2 or Warcraft 3. My ground consists of different types of tiles, for example grass tiles, sand tiles, etc. Now I want to have smooth transitions where two different types meet. I believe this is called texture blending, but I’m not sure, I’m a noob when it comes to graphics.

Now, what is the easiest way to achieve this? Is there some ready-made code in JME that helps out with this? I was thinking about things like how many quads/tiles should be used for the transition, how many meshes/textures do I require, etc. Any help would be greatly appreciated. I bet some of you have done this type of thing before. :wink:

Also, another thing: It would be great if I could change the tile type while my game is running, and have this work on-the-fly; for the map editor which will reuse much of the graphics code.

Well there are around 3 main ways to do this. Each with pro an con

-> Back it at construction phase manually, (eg image operations) then use the resulting texture. -> Pro fastest runtime perfomance, con cannot be modified at runtime
-> Create some kind of map that tells what texture where, then let a shader do the rest -> look at the terrain material and how it works for inspiration
-> Hard, make a small border between tiles and a crosspoint as well, then precreate mix textures for everything and apply them correctly. I think wurm online uses this, as it leaves a perfect defined place for stuff like walls, fences and other border objects.

@EmpirePhoenix

I don’t see the difference between approach 1 and 3. And for approach 2: Let shader do what? Please elaborate a little bit on each. Do I need separate meshes? What extra information do I need in the vertices? What kind of shaders should I use? Are those shaders available in JME?

It depends entirely on what you want, but from the information you have given, you could use the terrainlighting matdef with an alphamap that isnt based on height, but based on what material you want. You can use up to three alphamaps I believe, and thus up to 9 different textures for each type of terrain.

You could go even further and dynamically set the textures based on noise. For example, have one noise generator for temperature and one for precipitation. Using the result of those generators you can determine a biome of sorts (hot and wet, hot and dry, cold and wet, etc…) and apply the textures that correspond to that biome to the matdef at runtime.

You can then use the noise generators to determine what texture the player has “hit” on the terrain.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_terrain

@tuffe said: @EmpirePhoenix

I don’t see the difference between approach 1 and 3. And for approach 2: Let shader do what? Please elaborate a little bit on each. Do I need separate meshes? What extra information do I need in the vertices? What kind of shaders should I use? Are those shaders available in JME?

Type 3 I only saw so far in wurm online, basically you add borders between the tiles, and then use pregenerated blend textures on that border, that blends the texture from both sides together. (And use a small quad where the borders meet) Somewhat visible here https://lh5.googleusercontent.com/-A7rzz-RulNg/UeBVsW4PYwI/AAAAAAAAB0w/xMmT1UPl2CQ/s900/wurm.20130712.1512.jpg However keep in mind that this a special concept, it might not make sens in any other game idea.

@EmpirePhoenix @jayfella Thanks guys!