#ifndef CLOUDS_GLSL_
#define CLOUDS_GLSL_

#include "simplex.glsl"

float cloudsSample(vec3 localDir, float extent, float time, float cloudCover)
{
    const vec3 TIME_DIR = vec3(0.754877666, 0.569840296, 0.318309886);

    float n = 0.0;
    float amp = 0.5;
    float freq = 1.0;

    for (int i = 0; i < 5; i++)
    {
        n += amp * simplexNoise(localDir * freq + TIME_DIR * time);
        freq *= 2.7;
        amp *= 0.5;
    }

    n = n * 0.8 + 0.5;

    float threshold = 1.0 - cloudCover;
    float softness  = 0.8;

    return smoothstep(threshold, threshold + softness, n);
}

#endif