fixed: auto_ptr -> unique_ptr
[opensg.git] / Examples / CSM / Shader / Earth / Earth.fp
bloba319eac78f52a66e83724657b37399748f7e2d98
1 // Earth fragment shader blends day/night/cloud/gloss textures based on local time of day.
3 uniform sampler2D EarthDay, EarthNight, EarthCloudGloss;
5 const bool cloudCover = true;
7 varying float Diffuse;
8 varying vec3 Specular;
9 varying vec2 TexCoord;
11 const float Terminator = 0.3;
12 const float InvTerminator = 1.0 / (2.0 * Terminator);
14 void main (void)
16 // separate maps are packed into the color components of this texture
17 // clouds.r = cloud opacity
18 // clouds.g = water glossiness
19 vec2 cg = texture2D(EarthCloudGloss, TexCoord).rg;
20 float clouds = cg.r * float(cloudCover);
21 float gloss = cg.g;
23 // load daytime color, plus a specular component modulated by the gloss map
24 vec3 daytime = texture2D(EarthDay, TexCoord).rgb * Diffuse + Specular * gloss;
26 // mix in diffusely-lit clouds, modulated by the cloud opacity
27 daytime = mix(daytime, vec3(abs(Diffuse)), clouds);
29 // load night image, modulated by cloud opacity
30 vec3 nighttime = texture2D(EarthNight, TexCoord).rgb * (1.0 - clouds);
32 // assume day, to start
33 vec3 color = daytime;
35 // if fully dark, select night
36 if (Diffuse < -Terminator)
38 color = nighttime;
41 // within the twilight zone, mix night/day
42 if (abs(Diffuse) < Terminator )
44 color = mix(nighttime, daytime, (Diffuse + Terminator) * InvTerminator);
47 gl_FragColor = vec4 (color, 1.0);