Can someone please describe a common technique used to calculate texture coordinates for a terrain that dynamically changes every frame? I have a perlin noise function implemented in a vertex shader and the terrain is animated frame by frame. The terrain is very mountain-like (jagged and very very noisy). I was thinking I can slap a couple large textures linearly over the entire terrain, and multi-texture in fragment shader based on height, but this will cause the textures to looked stretched out in places of large altitude gain/lose, right? I'm having trouble figuring out how to calculate the texture coordinates in the vertex shader so that the texture is nice looking all over the terrain and can be multitextured for detail. I'm looking for pointers as to what kind of techniques exists for this in OpenGL. Can I use glTexGen for something like this??
1 Answers
There is no "common technique" used for doing this, because there's nothing much common about it. You have needs, which are specific to your uses. It's hard to know what you want, because you yourself don't seem to have any particular goal in mind besides "put a texture on this shifting terrain."
glTexGen
isn't going to help you, as it only works on the per-vertex level. If you're concerned about stretching over areas of great change, that won't help.
You should try various things and see what gives an acceptable result. Use shaders to blend textures based on the slope of the triangle (you'll have to find a way to calculate that in the fragment shader, or use a geometry shader to get it) as well as the height of any particular pixel. That way, for areas of higher slope, you can start bringing in a rocky texture or something.

- 449,505
- 63
- 781
- 982
-
I was able to achieve the exact multi-texturing effect I was after by manually blending the textures together in the fragment shader. Because it's perlin noise, the slopes are never so dramatic that texture steching occurs, so my original concern for asking this question didn't matter anyway. I'm going to also try your suggestion of texturing based on slope rather than height to make a more realistic terrain. thanks! – Nitrex88 Jul 06 '11 at 21:46