1 // Earth vertex shader computes lighting coefficients.
\r
3 // Note: For optimal light animation set the RenderMonkey cycle time
\r
4 // for predefined variables to 20 seconds. (Found in the Edit->Preferences).
\r
6 // predefined variables used to animate light direction
\r
7 uniform float cos_time_0_2PI, sin_time_0_2PI;
\r
9 // artist variable to control season
\r
10 uniform float season;
\r
12 // varying variables passed to fragment shader
\r
13 varying float Diffuse;
\r
14 varying vec3 Specular;
\r
15 varying vec2 TexCoord;
\r
19 // calculate vertex position in eye coordinates
\r
20 vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
\r
22 // compute the transformed normal
\r
23 vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
\r
25 // compute the light vector pointing toward the sun, in model coordinates
\r
26 // x,y compose the longitude and z the (seasonal) lattitude of the nadir point.
\r
27 vec3 lightVec = normalize(gl_NormalMatrix * vec3(cos_time_0_2PI, season, sin_time_0_2PI));
\r
29 // compute the reflection vector
\r
30 vec3 reflectVec = reflect(-lightVec, tnorm);
\r
32 // compute a unit vector in direction of viewing position
\r
33 vec3 viewVec = normalize(vec3 (-ecPosition));
\r
35 // Calculate specular light intensity, scale down and
\r
36 // apply a slightly yellowish tint.
\r
37 float specIntensity = pow(max(dot(reflectVec, viewVec), 0.0), 8.0);
\r
38 specIntensity = 0.3 * specIntensity;
\r
39 Specular = specIntensity * vec3 (1.0, 0.941, 0.898);
\r
41 // Calculate a diffuse light intensity
\r
42 Diffuse = dot(lightVec, tnorm);
\r
44 // Pass texture coordinates fragment shader
\r
45 TexCoord = vec2 (gl_MultiTexCoord0);
\r
47 // output final vertex information
\r
48 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
\r