(Demo) Earth: Day to Night Transition

GeeXLab demo - Earth: Day to Night Transition - OpenGL

Here is a demo that displays the Earth with two high resolution textures (10k): one texture for the day and one texture for the night (with cities lights).

The demo is available in the OpenGL 2.1 demopack in the following folder:

A smooth transition between day and night textures is the little difficulty of this demo, as shown in the following screenshot:

GeeXLab demo - Earth: Day to Night Transition - OpenGL

One solution is based on the smoothstep function.

GeeXLab demo - Earth: Day to Night Transition using smoothstep

Here is the GLSL code that does the transition in the pixel shader:

  vec3 t0 = texture2D(tex0,uv).rgb; // day
  vec3 t1 = texture2D(tex1,uv).rgb; // night
  float NdotL = dot(N,L); 
  float y = smoothstep(-0.05, 0.05, NdotL);
  vec3 t = t0*y + t1*(1-y);

NdotL is the scalar product between Earth’s normal and Sun’s direction. The transition occurs when NdotL is zero. Using the smoothstep function, we can do a smooth transition from -0.05 (limit of the full night) to 0.05 (limit of the full day). 0.05 is an experimental number. You can use another one.

This demo loads high resolution textures for the day and night: 10800×5400 pixels for each texture. On Raspberry Pi, I limited to 2k maps (not tested,. sorry…). 10k maps requires around 20 seconds to load so be patient when you launch the demo. Earth’s textures come from this page.

GeeXLab demo - Earth: Day to Night Transition - OpenGL

Leave a Comment

Your email address will not be published. Required fields are marked *