#version 330 core

in vec2 cloudUv;
in float cloudShade;
in vec3 worldPos;

uniform vec3 cameraPos;
uniform float cloudStrength;
uniform float lightLevel;
uniform vec3 fogColor;

out vec4 color;

void main() {
    float radius = length(cloudUv);
    if(radius >= 1.0)
        discard;

    float softEdge = 1.0 - smoothstep(0.52, 1.0, radius);
    float centerLight = 1.0 - radius * 0.18;
    vec3 lightCloud = vec3(0.78, 0.81, 0.84);
    vec3 stormCloud = vec3(0.24, 0.28, 0.33);
    vec3 cloudColor = mix(lightCloud, stormCloud, cloudStrength * 0.82);
    cloudColor *= lightLevel * centerLight * cloudShade;

    float distanceToCamera = distance(worldPos, cameraPos);
    float fogAmount = smoothstep(190.0, 390.0, distanceToCamera);
    cloudColor = mix(cloudColor, fogColor, fogAmount);

    float opacity = softEdge * (0.12 + cloudStrength * 0.60) * (1.0 - fogAmount * 0.72);
    color = vec4(cloudColor, opacity);
}
