#version 330 core

in float vertexAlpha;
in vec3 worldPos;

uniform vec3 cameraPos;
uniform bool fogEnabled;
uniform float fogStart;
uniform float fogEnd;
uniform vec3 fogColor;
uniform float visibility;

out vec4 color;

void main() {
    vec3 rainColor = vec3(0.62, 0.82, 1.0);
    float alpha = vertexAlpha * visibility;

    if(fogEnabled) {
        float distanceToCamera = length(worldPos - cameraPos);
        float fog = smoothstep(fogStart, fogEnd, distanceToCamera);
        rainColor = mix(rainColor, fogColor, fog);
        alpha *= 1.0 - fog;
    }

    color = vec4(rainColor, alpha);
}
