     acc.rgb /= acc.w + 0.0001;
     float alpha = smoothstep( 0.7, 1.0, acc.w );
 
-    acc.rgb -= 0.6 * vec3( 0.8, 0.75, 0.7 ) * alpha * pow( unit, vec3( 13.0 ) );
-    acc.rgb += 0.2 * vec3( 1.3, 1.2, 1.0 ) * ( 1.0 - alpha ) * pow( unit, vec3( 5.0 ) );
+    acc.rgb -= 0.6 * vec3( 0.8, 0.75, 0.7 ) * alpha * pow( vec3( sun_size ), vec3( 13.0 ) );
+    acc.rgb += 0.2 * vec3( 1.3, 1.2, 1.0 ) * ( 1.0 - alpha ) * pow( vec3( sun_size ), vec3( 5.0 ) );
 
     return acc;
 }
 
 void main() {
-    // procedural sky
+    // get the eye lookat vector
     vec3 eye = normalize( vDirection );
 
-    // instead of clamping, we want to extend the range
-    float eye_for_sky = clamp( eye.y, sky_horizon_offset, 1.0 );
+    // we only care about the range of values from sky_horizon_offset to 1.0
+    float sky_h = clamp( eye.y, sky_horizon_offset, 1.0 );
 
-    // now transform to [0, 1.0]
-    eye_for_sky = ( eye_for_sky - sky_horizon_offset ) / ( 1.0 + sky_horizon_offset );
+    // transform from [sky_horizon_offset, 1.0] to [0, 1.0]
+    sky_h = ( sky_h - sky_horizon_offset ) / ( 1.0 - sky_horizon_offset );
 
-    float eye_h = clamp( eye_for_sky, horizon_blueness, 1.0 );
-    float blueness = min( eye_h * sky_blueness, 1.0 );
+    // our blueness depends on how high up we are and how saturated the sky is
+    // blueness should be between 0 and 1.0
+    float blueness = min( sky_h * sky_saturation, 1.0 );
 
-    vec3 sky = vec3( pow( 1.0 - blueness, 2.0 )       // less red as we move up, quadratic
-                   , 1.0 - blueness                   // less green as we move up, linear
-                   , 0.6 + ( 1.0 - blueness ) * 0.4 );            // blue depends on how far up we are
+    // produce the sky color
+    vec3 sky = vec3( pow( 1.0 - blueness, 2.0 )         // less red as we move up, quadratic
+                   , 1.0 - blueness                     // less green as we move up, linear
+                   , 0.6 + ( 1.0 - blueness ) * 0.4 );  // blue depends on how far up we are
 
+    // for everything else, for now, we only care about everything at eye level and above
     eye.y = clamp( eye.y, 0.0, 1.0 );
 
     sky += sun( eye );

uniform vec4 cPosition_World;
uniform float uTime;
varying vec3 vDirection;
const   vec3 unit = normalize( vec3( 1 ) );   // radius of unit sphere, representing the sun
const   float cloudiness = 0.2;
const   float horizon_blueness = 0.02;        // how blue should the sky be at the horizon
const   float sky_bluestep = 1.0;             // how quickly should the sky turn blue when we look up (default = 1.0/1x)
const   float sky_blueness = 0.5;             // how blue should the sky be at the top (if we look straight up)
const   float sky_horizon_offset = -0.2;      // between -1 and 1, if negative, moves horizon down, if positive moves horizon up
const   float sun_flare_size = 0.5;

// noise functions by Inigo Quilez
float hash(float n) { return fract(sin(n) * 1e4); }

}

vec3 sun( vec3 v ) {
    float sun_body = clamp( dot( v, vec3( sun_size ) ), 0.0, 1.0 );
    return vec3( 1.6, 1.4, 1.0 ) * 0.47 * pow( sun_body, 350.0 )
         + vec3( 0.8, 0.9, 1.0 ) * 0.40 * pow( sun_body, ( 1.0 - sun_flare_size ) * 100.0 );
}
