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
;
11 const
float Terminator
= 0.3;
12 const
float InvTerminator
= 1.0 / (2.0 * Terminator
);
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
);
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
35 // if fully dark
, select night
36 if (Diffuse
< -Terminator
)
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);