Graphics Reference
In-Depth Information
Terrain Bump-Mapping
Terrain mapping is a visualization use of the height-field bump-mapping
we've seen before. Like the ripple bump-map shader we saw before, the idea
is to create the illusion of lots more geometry detail than we really have. In
fact, like the ripple example, the entire geometry is typically a single quad.
The geometry is a square quad, scaled to match the aspect ratio of the real
terrain area. That part of the .glib file looks like this:
Scale 1.2569 1. 1.
QuadXY .1 1.
This code shows the vertex shader. It sets up two variables for the frag-
ment shader: the texture coordinates and the model coordinate position. The
texture coordinates will be used to look up the terrain heights in a texture map.
The model coordinates will be used for lighting. (We use model coordinates
for lighting because we assume that, in the case of terrain, the light moves, but
the geometry doesn't.)
out vec3 vMCposition;
out vec2 vST;
void main( )
{
vST = aTexCoord0.st;
vMCposition = aVertex.xyz;
gl_Position = aModelViewProjectionMatrix * aVertex;
}
This code shows the fragment shader. The heights are sampled from a data
texture. Like the ripple shader, it generates a normal by taking the cross prod-
uct of two tangent vectors. It uses the normal in a lighting model that applies
to a color that is selected based on elevation. The results of this shader, with
two different height exaggerations, are shown in Figure 15.27.
uniform float uLightX, uLightY, uLightZ; // light pos
uniform float uExag; // height exaggeration
uniform sampler2D uHgtUnit; // where to find heights
uniform float uLevel1; // green-to-brown
uniform float uLevel2; // brown-to-white
uniform float uTol; // soften the transition
in vec3 vMCposition;
Search WWH ::




Custom Search