开发者

Texture coordinates for dynamic terrain - OpenGL

开发者 https://www.devze.com 2023-03-17 20:02 出处:网络
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 a

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. C开发者_如何学编程an I use glTexGen for something like this??


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号