Texture morfing?

I’m writing programm - terrain generator for strategic game.
The terrain is described by 2-dimension array of points. Each point have several parameters like heigh or terrain type (grass, water, dessert, etc.).

Now, I’m writing module for terrain visualization in OpenGL. I’m using simplest method: I get 3 points from array and create triangle. At first I used only colors for simulate terrain type and all was OK.
But now I’m trying to use textures and I have conceptual problem. If all vertexes have the same terrain type, everything is OK - I’m using one texture for whole triangle. But if vertexes have different terrain type, I have no idea, how morf 2 or 3 textures on one triangle. :frowning:

Do you heve any suggestions?

Of course, I can prepare special morfed textures, but it is stupid work. :stuck_out_tongue:
I found many information about multitexturing, but I think it is not proper way too…


I’m not really familiar with multitexturing, and I don’t really know how you want to combine the textures, but I’ve got an idea for you.

I might apply all three textures to the triangle. I don’t know what the fixed-functionality for multitexturing is or how it works, but in a fragment shader you could read the colors from each texture and weight that based on the texture coordinates.
Each triangle has three vertices , each with an associated texture coordinate ((0,0),(0,1)(1,0), for instance). For each fragment, read the color from each texture using the coordinates for the fragment. Use the texture coordinates to determine the influence of each vertex at the fragment, then multiply the color from each texture by it’s corresponding influence, and add it up.

If that explanation doesn’t make any sense, I’ll explain differently… I know I can’t always understand these things in plain English…

Pretty much what todayman said… Use some value related to the triangle (height?) to decide the blend level for the textures in a shader. Alternatively stick some height map info into the alpha channel of the texture…

Another method I use is to put the different terrain level textures into a 3D texture.
So, for example the bottom is sand, the next is grass, then more foliage, then rocks, then mountains and then snow…

Use the “height” as the depth for the 3D texture, and map it onto the triangles laterally. Using a few texture packs like this I have fairly nice height blended terrains with two or three different sets of tiles to choose from to also splat around laterally to break up the landscape…

Thanks, all.
The solution with terrain level textures into a 3D texture is very interesting, but not useful in my situation.
On my maps the parameters “height” and “terrain type” are independent - you can design green forest on the peak of snowy mountains. :smiley:

I see, I must use Google with “fragment shader” keywords… :wink: