Fragment Shader question ...


Wild Coder
First of all, I did not read and decode the fragment shader extension specs right now, I first want to know if they can do what I need ...

Here is the layout :
I have a landscape with two textures : grass and rock.
The way I use these two textures depend on the slope of the terrain. When the terrain is flat, I use the grass texture. The higher the slope is, the more I use the rock texture. On extreme slopes, only the rock texture would be use. So the question is : can this be done with fragment shaders ? The system will have more than two texures, e.g. low altitudes (near the sea) would use a sand texture.
The idea is to enhance a landscape rendering engine to dynamically generate it's textures from a set of base textures and properties (look at the terragen system :, all this realtime of course.

Any ATI input is welcome ;)

PS : This dev. board is a great idea !
Not sure if a fragment shader is what you're looking for here... Sounds more like an application for a vertex shader. However, you could try to linearly interpolate (lerp) between the two textures depending on, say the current vertex color (height).
The terrain in the island demos uses a technique similar to what you describe. Basically, the vertex normal dotted with "up" determines the blend factor between the vertical and horizontal textures. This does a surprisingly good job of breaking up the apparent repetition of what are essentially tiled textures (one projected vertically and one projected horizontally in the art tool). The blend factor is computed at the vertices during preprocessing and an interpolator component (diffuse alpha, say) is used as the blend factor when multitexturing/pixel shading.



Thank you Jason !
Can't wait to see the island demo to have a visual example of this.