uniform float nightmix;
uniform float nightmixInv;
uniform vec3 atmosphereUp;



#include "/lib/sky_function.glsl"

vec3 skyLut2(vec3 sVector, vec3 sunVec)
{
    return clamp(GetAtmosphere10(sVector), 0, 1000);

    // return (calcAtmosphericScatter3(normalize(sVector)));
}
vec3 skyLut3(vec3 sVector, vec3 sunVec)
{
    return clamp(GetAtmosphere11(sVector), 0, 1000);

    // return (calcAtmosphericScatter3(normalize(sVector)));
}
vec3 skyLut(vec3 sVector)
{

    return (skyLut2(sVector, vec3(0)));
}

vec3 cosineHemisphereSample(vec2 Xi)
{
    float r = sqrt(Xi.x);
    float theta = 2.0 * PI * Xi.y;

    float x = r * cos(theta);
    float y = r * sin(theta);

    return vec3(x, y, sqrt(clamp(1.0 - Xi.x, 0., 1.)));
}
vec2 sphereToCarte(vec3 dir)
{
    float lonlat = atan(-dir.x, -dir.z);
    return vec2(lonlat * (0.5 / PI) + 0.5, 0.5 * dir.y + 0.5);
}

vec3 skyFromTex(vec3 pos, sampler2D sampler)
{
    vec2 p = sphereToCarte(pos);
    return texture(sampler, p * 0.25 - vec2(0.0005, 0.0005)).rgb;
}

vec2 tapLocation(int sampleNumber, int nb, float nbRot, float jitter)
{
    float alpha = float(sampleNumber + jitter) / nb;
    float angle = (jitter + alpha) * (nbRot * TWO_PI);

    float ssR = alpha;
    float sin_v, cos_v;

    sin_v = sin(angle);
    cos_v = cos(angle);

    return vec2(cos_v, sin_v) * ssR;
}
vec2 sincos(float x)
{
    return vec2(sin(x), cos(x));
}
