PDA

View Full Version : Terrain with Multitexturing and Texture Blending



Quarksong
05-03-2004, 10:42 PM
I've seen this posted here before but I didn't find a good answer, so I was hoping someone could help me out.

I would like to render a terrain heightfield, something like a mountainous/desert/canyon scene, where the texture used on the terrain is based on the vertex altitude (height above z=0 plane) and are automatically generated. For instance I Might use three different textures: rocky texture at the top of the hills, sandy at the bottom, and striated in between (for canyon walls). I want to have this texturing generated automatically, and also like to blend between the textures. This might also be used for rendering dynamic water/waves (?), where higher peaks have a foam texture to simulate white caps.

Using a renderer written for the PS2 (for a company I used to work for) this was really easy, just generate texture coordinates from world positions, generate vertex colors also from world coordinates (alpha from altitude), and set the texture to use the vertex colors.

Is this approach possible with OpenGL in a single pass renderer? I guess I could do this in 3 passes, rendering a base layer, then the next two layers with blending enabled, but I was hoping to use multitextures.

Thanks for any help that anyone can provide.

yooyo
05-04-2004, 12:51 PM
If your hardware support pixel shaders you can use following trick:
assume:
tex0 = mask texture
tex1 = rock texture
tex2 = grass texture
tex3 = snow texture

color = mask.r*rock + mask.g*grass + mask.b*snow
(todo: try to add vertexcolor i this expression)
Now... make mask texture using R,G and B colors depending on height or simple open your favorite paint program and draw something...

Using ARB FP or GLSL FS it is very easy task.

Even more... you can use 3x3D textures (for example 256*256*4) instead of 3x2D and in each z-layer of texture put slightly different rock, gras and snow. Using additional vertex attribute or vertex height you can get more detailed terrain (rock texture should have sand, small rocks, bigger rock and huge rocks)

I didn't yet try this approach with 3d textures but with 2d textures work perfectly.

yooyo

azcoder
05-06-2004, 02:26 PM
This might help...
http://www.delphi3d.net/articles/viewarticle.php?article=terraintex.htm

Good Luck!

Chuck0
05-07-2004, 12:09 AM
havent tried the 3d-texture approach, but i see a difficulty arising if you use mipmapping (which would be quite important to avoid aliasing artefacts)... if the terrain is far away everything may look like a mix of the whole 3d-texture....(the only solution for this i could think of would be some kind of anisotropic filtering for 3d textures)

Jared
05-07-2004, 08:30 AM
i tried quite a few thing to max the number of detail textures in one pass.

3d texture:
-potential for a whole lot of different textures
-severe limitations (only transitions between neighboring layers)
-mipmapping will bite you

this might be less of a problem if its only used for variations of one kind of texture as suggested above

cubemap:
-up to 6 detail textures
-"fixing" the tex coords is a major pain

multiple units:
-for some reason accessing more than 4 tex units on my radeon 9800 cuts framerate in half (while multiple lookups in single textures arent making much difference)

multiple textures in one big texture:
-you will learn to hate texture filtering
-either slightly wrong colored edges or seams dont really fit

using base color map and greyscale detail maps:
-4 detail textures (1 per color channel)
-blending is simple dotproduct of a "weight texture" (or color, but doesnt play well with lod) with detail texture
-looking ok, but a little "pale"