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.
If your hardware support pixel shaders you can use following trick:
tex0 = mask texture
tex1 = rock texture
tex2 = grass texture
tex3 = snow texture
color = mask.rrock + mask.ggrass + 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 2562564) 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.
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)
i tried quite a few thing to max the number of detail textures in one pass.
-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
-up to 6 detail textures
-“fixing” the tex coords is a major pain
-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”