View Full Version : Multitexturing a heightmapped terrain

08-15-2002, 02:55 AM
Does anyone know how to use multiple textures to fade into one another as the height of the terrain changes? I have a terrain engine that is subdivided into distinct nodes so I can cull the ones that are not in the viewing frustum. Each node has a vertex array containing its respective vertex data to draw gl_triangles. I also pass the pointers to the normals and texture coordinates. So, right now I have only one texture for the entire terrain. I would like to slowly go from a grass texture to a mountainous texture and finally, cap the highest parts of the terrain with snow.

08-15-2002, 04:56 AM
For every triangle you should check height of vertices, then decide which texture you want to use. I have somethink like that, but I am using second texture unit for lightmap, so I can't use another texture unit to fade textures. And I don't think it is good idea.
BTW how do you want to make lighting?

08-15-2002, 04:59 AM
I am using OpenGL lighting by passing in the normals for each vertex in the triangle. By the way, how would you go about fading the 1st texture to the second?

One of the problems I'm encountering is being able to check the height of the triangles because I am using glDrawElements. How would I know to change textures when doing things in vertex arrays? Here is the piece of code that sends the triangles in the node to opengl (coding is in Delphi):

glVertexPointer(3, GL_FLOAT, 0, @pNode.Terrain);
glTexCoordPointer(2, GL_FLOAT, 0, @pNode.TexCoordArray);
glNormalPointer(GL_FLOAT, 0, @pNode.NormalArray);

glDrawElements(GL_TRIANGLES, pNode.TriangleCount*3, GL_UNSIGNED_INT, @pNode.g_IndexArray[0]);

[This message has been edited by Ganymede (edited 08-15-2002).]

08-15-2002, 05:48 AM
The interpolate combiner of the GL_ARB_texture_env_combine extension will do the trick of blending textures this way. However you will lose lighting with this method if you have only 2 texture units. In that case you will need to do the lighting in a previous pass, and blend in the beauty pass. Otherwise with 3 or more texture units, you should have no problem blending the textures and lighting the polygons in the same pass. Also, this techique assumes no triangle in the terrain spans more than 2 terrain types.

08-15-2002, 09:37 AM
And if a triangle can have more than two terrain types, you have some more problems. You will most cetrainly have to do it in multiple passes, which involves blending, and separate interpolation factors for each terrain type. Not going too deep into the problems, but let's say it like this: if you must ask how to interpolate two textures, you are not yet ready to deal with tree or more textures on a triangle.