float fog_correction;
#if V_CLOUDS > 0
    fog_correction = mix(1.0, 1.35, final_sun_factor);
    #if VOL_LIGHT > 0
        fog_correction /= mix(1.0, 1.35, final_sun_factor);
    #endif
#elif VOL_LIGHT > 0
    fog_correction = mix(1.0, 1.275, final_sun_factor);
#else
    fog_correction = 1.0;
#endif


float fog_adj2 = mix(fog_adj, clamp(fog_adj * 1.75, 0.0, 2.0 - final_sun_factor), final_sun_factor);


#if defined THE_END
    #ifdef FOG_ACTIVE
        if(isEyeInWater == 0 && FOG_ADJUST < 15.0) {  // In the air
            // Balanced lavender distance fog keeps silhouettes legible and
            // avoids the saturated blue veil from the previous End palette.
            vec3 end_fog_color = mix(
                ZENITH_DAY_COLOR, HORIZON_DAY_COLOR, 0.62)
                * vec3(1.08, 1.02, 1.00);
            block_color.rgb = mix(
                block_color.rgb, end_fog_color,
                clamp(fog_adj * 0.72, 0.0, 0.78));
        }
    #endif
#elif defined NETHER
    #ifdef FOG_ACTIVE
        if(isEyeInWater == 0 && FOG_ADJUST < 15.0) {  // In the air
            block_color.rgb = mix(block_color.rgb, mix(fogColor * 0.25, vec3(0.5), 0.025), fog_adj);
        }
    #endif
#else
    #ifdef FOG_ACTIVE  // Fog active
        vec3 gaux4_fog_sample = texture2D(gaux4, gl_FragCoord.xy * vec2(pixel_size_x, pixel_size_y)).rgb;
        float gaux4_fog_valid = (max(max(gaux4_fog_sample.r, gaux4_fog_sample.g), gaux4_fog_sample.b) > 0.002 || day_mixer < 0.05) ? 1.0 : 0.0;
        vec3 safe_fog_color = mix(skyColor, gaux4_fog_sample, gaux4_fog_valid) * fog_correction;

        #if MC_VERSION >= 11900
            vec3 fog_texture;
            if(darknessFactor > .01) {
                fog_texture = vec3(0.0);
            } else {
                fog_texture = safe_fog_color;
            }
        #else
            vec3 fog_texture = safe_fog_color;
        #endif
        #if defined GBUFFER_ENTITIES
            if(isEyeInWater == 0 && entityId != 10101 && FOG_ADJUST < 15.0) {  // In the air
                block_color.rgb = mix(block_color.rgb, fog_texture, fog_adj);
            }
        #else
            if(isEyeInWater == 0) {  // In the air
                block_color.rgb = mix(block_color.rgb, fog_texture, fog_adj);
            }
        #endif
    #endif
#endif

#if MC_VERSION >= 11900
    if(blindness > .01 || darknessFactor > .01) {
        block_color.rgb = mix(block_color.rgb, vec3(0.0), max(blindness, darknessLightFactor) * gl_FogFragCoord * 0.2);
    }
#else
    if(blindness > .01) {
        block_color.rgb = mix(block_color.rgb, vec3(0.0), blindness * gl_FogFragCoord * 0.2);
    }
#endif
