#version 150

const int FOG_SHAPE_SPHERE = 0;
const int FOG_SHAPE_CYLINDER = 1;

layout(std140) uniform Fog {
    vec4 FogColor;
    int FogShape;
    float FogStart;
    float FogEnd;
    float FogSkyEnd;
    float FogCloudsEnd;
};

vec4 linear_fog(vec4 inColor, float vertexDistance, float fogStart, float fogEnd, vec4 fogColor) {
    // YOUR MODIFICATIONS START HERE
    fogStart = fogStart / 3.5384349071477304492426263330319;
    fogEnd = fogEnd * 1.055456748719378155088324506632;
    // YOUR MODIFICATIONS END HERE

    if (vertexDistance <= fogStart) {
        return inColor;
    }

    float fogValue = vertexDistance < fogEnd ? smoothstep(fogStart, fogEnd, vertexDistance) : 1.0;
    return vec4(mix(inColor.rgb, fogColor.rgb, fogValue * fogColor.a), inColor.a);
}

float linear_fog_fade(float vertexDistance, float fogStart, float fogEnd) {
    // YOUR MODIFICATIONS START HERE
    fogStart = fogStart / 3.5384349071477304492426263330319;
    fogEnd = fogEnd * 1.055456748719378155088324506632;
    // YOUR MODIFICATIONS END HERE

    if (vertexDistance <= fogStart) {
        return 1.0;
    } else if (vertexDistance >= fogEnd) {
        return 0.0;
    }

    return smoothstep(fogEnd, fogStart, vertexDistance);
}

float fog_distance(vec3 pos, int shape) {
    if (shape == FOG_SHAPE_SPHERE) {
        return length(pos);
    } else {
        float distXZ = length(pos.xz);
        float distY = abs(pos.y);
        return max(distXZ, distY);
    }
}