This project is read-only.

Like the google earth, shading the map with different color at different altitude.


Key point to this

  1. The range of altitude. We need a bottom altitude and a top altitude. If the color between top altitude and bottom altitude will be interpolated according to the altitude. otherwise, it should have a fixed color.
  2. The range of color. Take the google earth for example, the top color will be white(for high mountain), yellow(ground), blue(seabed).  The range of color defines how the color varies along with the altitude.
  3. For cliff(both mountain and submarine), the color should be dark.


We need only a vertex shader, no special fragment shader needed.


Here is the vertex shader.

// Terrain depth  vertex shader

// Zhiyong Yang, 2013



uniform vec4 topColor;// 地图最高点颜色

uniform vec4 bottomColor;//最低点颜色

uniform float topCoordinate;//海拔最高点

uniform float bottomCoordinate;//海拔最低点


void main()


gl_Position    = gl_ModelViewProjectionMatrix * gl_Vertex;


    // blender two colors 

    vec4 vertex_color = mix( bottomColor, topColor, (gl_Vertex.y - bottomCoordinate)/(topCoordinate - bottomCoordinate));

    gl_FrontColor = vertex_color * dot(vec3(0.0,1.0,0.0), gl_Normal);// coloring with normal data, the cliff will be in dark.

gl_TexCoord[0] = gl_MultiTexCoord0;



Here is the screenshot with ShaderMaker:



Here is the mesh used for demo:

Snow Terrain 

Last edited Oct 14, 2013 at 10:02 AM by younthu, version 3


No comments yet.