#define s_fogMieD 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.5 5.0 5.5 6.0 7.0 8.0]
#define s_fogRaylD 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0]

#define s_skyLuma 1.0          //[0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0]
#define s_skyR 1.0         //[0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0]
#define s_skyG 1.0         //[0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0]
#define s_skyB 1.0        //[0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0]

#define s_torchlightTemp 2200.0 //[1200.0 1400.0 1600.0 1800.0 2000.0 2200.0 2400.0 2600.0 2800.0 3000.0 3400.0 3600.0 4000.0 4400.0 4800.0 5200.0 5600.0 6000.0 6400.0]
#define s_torchlightLuma 1.0    //[0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0]
#define s_sunlightTempMult 1.0  //[0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5]

flat out float tempSunlight;

flat out vec3 colMoonlight;
flat out vec3 colSkylight;
flat out vec3 colSky;
flat out vec3 colHorizon;
flat out vec3 colSunglow;
flat out vec3 colMoonglow;
flat out vec2 fogDensity;

flat out vec3 colTorchlight;

uniform float rainStrength;
uniform float wetness;

uniform vec2 biomeData;
uniform vec2 fogData;

const float wetnessHalflife = 60.0;
const float drynessHalflife = 150.0;

void nature() {
    tempSunlight    = 3473.0*timeSunrise + 5773.0*timeNoon + 3424.0*timeSunset + 3205.0*timeNight;
    tempSunlight *= s_sunlightTempMult;

    vec3 skylightSunrise;
    skylightSunrise.r    = 0.62;
    skylightSunrise.g    = 0.68;
    skylightSunrise.b    = 1.00;
    skylightSunrise     *= 0.29;

    vec3 skylightNoon;
    skylightNoon.r       = 0.56;
    skylightNoon.g       = 0.85;
    skylightNoon.b       = 1.00;
    skylightNoon        *= 1.00;

    vec3 skylightSunset;
    skylightSunset.r     = 0.74;
    skylightSunset.g     = 0.71;
    skylightSunset.b     = 1.00;
    skylightSunset      *= 0.18;

    vec3 skylightNight;
    skylightNight.r      = 0.6;
    skylightNight.g      = 0.72;
    skylightNight.b      = 1.00;
    skylightNight       *= 0.026;

    vec3 skylightMoon;
    skylightMoon.r      = 0.08;
    skylightMoon.g      = 0.81;
    skylightMoon.b      = 1.00;
    skylightMoon       *= 0.008;

    colSkylight          = skylightSunrise*timeSunrise + skylightNoon*timeNoon + skylightSunset*timeSunset + skylightNight*timeNight;
    colSkylight          = mix(colSkylight, skylightMoon, timeMoon);

    vec3 skySunrise;
    skySunrise.r    = 0.221;
    skySunrise.g    = 0.496;
    skySunrise.b    = 1.0;
    skySunrise     *= 0.24;

    vec3 skyNoon;
    skyNoon.r       = 0.222;
    skyNoon.g       = 0.486;
    skyNoon.b       = 1.00;
    skyNoon        *= 0.81;

    vec3 skySunset;
    skySunset.r    = 0.221;
    skySunset.g    = 0.526;
    skySunset.b    = 1.0;
    skySunset      *= 0.24;

    vec3 skyNight;
    skyNight.r      = 0.14;
    skyNight.g      = 0.58;
    skyNight.b      = 1.00;
    skyNight       *= 0.008;

    colSky          = skySunrise*timeSunrise + skyNoon*timeNoon + skySunset*timeSunset + skyNight*timeNight;
    colSky         *= s_skyLuma*vec3(s_skyR, s_skyG, s_skyB);
    #ifdef s_biomeDynamics
        colSky *= (1.0+(biomeData.x*2.0-1.0)*0.35);
    #endif
    colSky          = mix(colSky, vec3(getLuma(colSky)), wetness*0.95);

    vec3 horSunrise;
    horSunrise.r    = 0.51;
    horSunrise.g    = 1.0;
    horSunrise.b    = 0.421;
    horSunrise     *= 2.80;

    vec3 horNoon;
    horNoon.r       = 0.52;
    horNoon.g       = 0.798;
    horNoon.b       = 1.00;
    horNoon        *= 7.50;

    vec3 horSunset;
    horSunset.r     = 0.51;
    horSunset.g     = 1.0;
    horSunset.b     = 0.521;
    horSunset      *= 2.55;

    vec3 horNight;
    horNight.r      = 0.10;
    horNight.g      = 0.68;
    horNight.b      = 1.00;
    horNight       *= 0.01;

    colHorizon      = horSunrise*timeSunrise + horNoon*timeNoon + horSunset*timeSunset + horNight*timeNight;
    colHorizon      = mix(colHorizon, vec3(vec3avg(colHorizon)), wetness);

    vec3 sunglowSunrise;
        sunglowSunrise.r = 1.0;
        sunglowSunrise.g = 0.14;
        sunglowSunrise.b = 0.00;
        sunglowSunrise *= 0.9;

    vec3 sunglowNoon;
        sunglowNoon.r = 0.56;
        sunglowNoon.g = 0.74;
        sunglowNoon.b = 1.0;
        sunglowNoon *= 0.9;

    vec3 sunglowSunset;
        sunglowSunset.r = 1.0;
        sunglowSunset.g = 0.08;
        sunglowSunset.b = 0.0;
        sunglowSunset *= 0.8;

    vec3 sunglowNight;
        sunglowNight.r = 0.08;
        sunglowNight.g = 0.5;
        sunglowNight.b = 1.0;
        sunglowNight *= 0.004;

    colSunglow = sunglowSunrise*timeSunrise + sunglowNoon*timeNoon + sunglowSunset*timeSunset + sunglowNight*timeNight;


    float mieDensity        = timeSunrise*1.7+timeNoon*0.45+timeSunset*0.6+timeNight*1.6;
        mieDensity          = mix(mieDensity, 4.0, wetness);

    fogDensity.x            = mieDensity;

    float rayleighDensity   = timeSunrise*0.6+1.0*timeNoon+timeSunset*0.6+timeNight*0.7;

    fogDensity.y            = rayleighDensity*2.0+wetness*0.5;
    #ifdef s_biomeDynamics
        fogDensity *= fogData.x;
    #endif

    #ifdef isLightingPass
        colTorchlight   = blackbody(s_torchlightTemp)*3.0*s_torchlightLuma;
    #endif
}