#if (WATER_MODE == 1 || WATER_MODE == 3) && !defined SKY_VANILLA && (!defined NETHER || !defined NETHER_VANILLA)
uniform vec3 fogColor;
#endif

vec4 GetWaterFog(vec3 viewPos) {
    float fog = length(viewPos) / waterFogRange * GetWaterStyleValue(0.22, 0.30);
    fog = 1.0 - exp(-GetWaterStyleValue(2.6, 3.1) * fog);
    
    #if WATER_MODE == 0 || WATER_MODE == 2
    vec3 waterFogColor = waterColor.rgb * waterColor.a;
    #elif  WATER_MODE == 1 || WATER_MODE == 3
    vec3 waterFogColor = fogColor * fogColor * 0.125;
    #endif
    waterFogColor *= WATER_F * WATER_F * GetWaterStyleValue(1.0, 1.06) * (1.0 - max(blindFactor, darknessFactor));
    waterFogColor *= GetWaterStyleValue(
        mix(vec3(0.92, 1.00, 1.04), vec3(0.72, 0.96, 1.08), clamp(fog * 1.1, 0.0, 1.0)),
        mix(vec3(0.86, 0.99, 1.08), vec3(0.58, 0.84, 1.12), clamp(fog * 1.25, 0.0, 1.0))
    );

    #ifdef OVERWORLD
    vec3 waterFogTint = lightCol * eBS * shadowFade * 0.9 + 0.1;
    waterFogTint = GetWaterStyleValue(
        mix(vec3(0.38, 0.62, 0.72), waterFogTint, 0.65 + 0.35 * sunVisibility),
        mix(vec3(0.24, 0.44, 0.56), waterFogTint, 0.52 + 0.48 * sunVisibility)
    );
    waterFogTint *= GetWaterStyleValue(
        mix(vec3(0.80, 0.95, 1.10), vec3(1.0), sunVisibility),
        mix(vec3(0.70, 0.90, 1.12), vec3(1.0), sunVisibility)
    );
    #endif
    #ifdef NETHER
    vec3 waterFogTint = netherCol.rgb;
    #endif
    #ifdef END
    vec3 waterFogTint = endCol.rgb;
    #endif
    waterFogTint = max(waterFogTint, vec3(0.0));
    waterFogTint = sqrt(waterFogTint * length(waterFogTint));

    return vec4(waterFogColor * waterFogTint * GetWaterStyleValue(1.0, 1.08), fog);
}
