//====================================================
// Sunrise
//====================================================

#define SKY_SUNRISE_HORIZON vec3(1., 0.45, 0.25)
#define SKY_SUNRISE_MIDDLE  vec3(0.60, 0.35, 0.65)
#define SKY_SUNRISE_ZENITH  vec3(0.15,0.25,0.55)

//====================================================
// Noon
//====================================================

#define SKY_NOON_HORIZON vec3(0.1922, 0.2549, 0.4196)
#define SKY_NOON_MIDDLE  vec3(0.5098, 0.7373, 1.0)
#define SKY_NOON_ZENITH  vec3(0.4039, 0.5922, 1.0)

//====================================================
// Sunset
//====================================================

#define SKY_SUNSET_HORIZON vec3(1., 0.45, 0.25)
#define SKY_SUNSET_MIDDLE  vec3(0.60, 0.35, 0.65)
#define SKY_SUNSET_ZENITH  vec3(0.15,0.25,0.55)

//====================================================
// Midnight
//====================================================

#define SKY_MIDNIGHT_HORIZON vec3(0.2706, 0.2941, 0.3686)
#define SKY_MIDNIGHT_MIDDLE  vec3(0.1608, 0.1922, 0.2745)
#define SKY_MIDNIGHT_ZENITH  vec3(0.0, 0.0, 0.0039)


const vec3 SKY_RAIN_HORIZON =  vec3(0.0824, 0.0941, 0.1059);
const vec3 SKY_RAIN_MIDDLE  = vec3(0.0745, 0.0863, 0.102);
const vec3 SKY_RAIN_ZENITH  = vec3(0.0902, 0.0902, 0.102);


vec3 GetSkyGradient(vec3 horizon, vec3 middle, vec3 zenith, float h)
{
    
    h = pow(clamp(h, 0.0, 1.0), SKY_GRADIENT_CURVE);

    vec3 sky = mix(horizon, middle, smoothstep(0.0, 0.5, h));
    sky = mix(sky, zenith, smoothstep(0.5, 1.0, h));

    return sky;
}

vec3 GetSkyPalette(vec4 phases, float h){
	vec3 horizon =
    SKY_SUNRISE_HORIZON * phases.x +
    SKY_NOON_HORIZON    * phases.y +
    SKY_SUNSET_HORIZON  * phases.z +
    SKY_MIDNIGHT_HORIZON * phases.w;

	vec3 middle =
    SKY_SUNRISE_MIDDLE * phases.x +
    SKY_NOON_MIDDLE    * phases.y +
    SKY_SUNSET_MIDDLE  * phases.z +
    SKY_MIDNIGHT_MIDDLE * phases.w;

	vec3 zenith =
    SKY_SUNRISE_ZENITH * phases.x +
    SKY_NOON_ZENITH    * phases.y +
    SKY_SUNSET_ZENITH  * phases.z +
    SKY_MIDNIGHT_ZENITH * phases.w;

    horizon = mix(horizon, SKY_RAIN_HORIZON, rainStrength);
    middle  = mix(middle,  SKY_RAIN_MIDDLE,  rainStrength);
    zenith  = mix(zenith,  SKY_RAIN_ZENITH,  rainStrength);

    return GetSkyGradient(horizon,middle, zenith,h);
    



}
