poeticsunset
#define PI 3.14159265359

vec3 colorA = vec3(0.39, 0.26, 0.31);
vec3 colorB = vec3(0.71,0.733,0.82);
vec3 colorC = vec3(0.19, 0.06, 0.11);
vec3 colorD = vec3(0.71,0.733,0.82);
vec3 sunColorA = vec3(0.97,0.,0.);
vec3 sunColorB = vec3(0.97,0.92,0.3);

// makes a pseudorandom number between 0 and 1
float hash(float n) {
  return fract(sin(n)*93942.234);
}

vec4 noise(in vec2 uv)
{
	vec2 r=(456.789*sin(789.123*uv.xy));
	return vec4(fract(r.x*r.y));
}

// smoothsteps a grid of random numbers at the integers
float noise2(vec2 p) {
  vec2 w = floor(p);
  vec2 k = fract(p);
  k = k*k*(3.-2.*k); // smooth it

  float n = w.x + w.y*57.;

  float a = hash(n);
  float b = hash(n+1.);
  float c = hash(n+57.);
  float d = hash(n+58.);

  return mix(
    mix(a, b, k.x),
    mix(c, d, k.x),
    k.y);
}

// rotation matrix
mat2 m = mat2(0.6,0.8,-0.8,0.6);

// fractional brownian motion (i.e. photoshop clouds)
float fbm(vec2 p) {
  float f = 0.;
  f += 0.5000*noise2(p); p *= 2.02*m;
  f += 0.2500*noise2(p); p *= 2.01*m;
  f += 0.1250*noise2(p); p *= 2.03*m;
  f += 0.0625*noise2(p);
  f /= 0.9375;
  return f;
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    float time = iTime*.2;
    vec3 color = vec3(0.0);
    vec2 uv = fragCoord.xy / iResolution.xy;
    float ratio = iResolution.x/iResolution.y;
    uv.x *= ratio;

    vec2 center = vec2(0.5*ratio, (sin(time)+1.)*.4);
    float dist = distance(uv, center);
    float initialRadius = .12;

    // Pick the sky's gradient
    vec3 t = vec3(cos(uv.y)*cos(uv.y),
                  sin(uv.y),
                  sin(uv.y));
    color = mix(colorA, colorB, t);
    color = mix(color, colorC, 1.-center.y);

  	//color.r *= 1.1;

    // add "atmospheric halo""
    color = mix(color, colorD, smoothstep(uv.y+0.4, uv.y+0.8, center.y));

    float radius;

    // add water reflection
    if (uv.y > .0 && uv.y < .2)
    {
        radius = initialRadius+0.02+fbm(uv*40000.)*0.2;
    }
    // add the sun color & distortion
    else
    {
    	radius = initialRadius+fbm(uv*4000.)*0.02;
    }

    float p = 1.-step(radius, dist);
    color += mix(sunColorA, sunColorB, center.y-.1)*p*5.5;

    // add lighting "auras" around the sun
    radius = initialRadius*3.+fbm(uv*center*sin(iTime*.3));
    p = 1.-smoothstep(radius, radius+0.4, dist);;
    color += p*0.08*sunColorA;

    radius = initialRadius*1.+fbm(uv*center*2.*abs(sin(iTime*.6)))*0.12;
    p = 1.-smoothstep(radius, radius+0.4, dist);;
    color += p*0.12*sunColorB;

    color *= 1.4;

    // Body of water
    radius = 0.15+noise(uv).y*0.02;
    p = 1.-smoothstep(radius, radius+0.1, uv.y);
    color = mix(color, colorC, vec3(p*1.1*max(.2, (1.-smoothstep(.1, .9, center.y)))));
    color *= smoothstep(-0.1, .22, uv.y);

    fragColor = vec4(color,1.0);
}