


vec3 fogAtmosphereDH(vec3 solid, vec3 fragpos)
{

    float estEyeDepth = clamp((14.0 - eyeBrightnessSmooth.y * (16.0 / 255.0)) * (1.0 / 14.0), 0.0, 1.0);
    estEyeDepth = estEyeDepth * estEyeDepth * estEyeDepth * 34.0;

    vec3 absorbance_w = vec3(1.0);
    vec3 vL_a = vec3(0.0);
    vec3 vL_w = vec3(0.0);
    vec3 transmittance;
    float rayLength;

    vec3 refractedSunVec = refract(lightPos, -vec3(0.0, 1.0, 0.0), 0.9);

    float SdotV = dot(sunVec, normalize(fragpos));

#ifdef OVERWORLD

    if (isEyeInWater == 1)
    {

        rayLength = 32;
    }
    else
    {
        rayLength = gbf(fragpos, dhFarPlane, 0) * 1028;
    }
#endif

    if (!(isEyeInWater == 0))
        AtmosphereNoLoop(6, 11.0, rayLength, normalize(mat3(gbufferModelViewInverse) * fragpos).y * rayLength,
                         phaseg(SdotV, 0.4), phaseRayleigh(SdotV), estEyeDepth, refractedSunVec, atmosphereUp, sunLight,
                         absorbance_w, vL_w);

    vL_a = vL_a + (vL_a - dot(vL_a, vec3(0.299, 0.587, 0.114))) * 0.1;

#ifdef OVERWORLD

    float rayLengthGround = pow(length(fragpos), 1.75) * 1 * fogAmount1 * mix(1, 10, rainStrength);
#else
    float rayLengthGround = pow(length(fragpos), 2.5);

#endif

    vL_a = fogAtmosphere2(mat3(gbufferModelViewInverse) * fragpos, rayLengthGround, rayLengthGround, transmittance);

    switch (isEyeInWater)
    {
    case 0:

        solid *= transmittance;
        solid += vL_a;

        break;
    case 1:

        solid *= 0;
        solid += vL_w;

        break;
    case 2:
    case 3:
        solid *= exp(-length(fragpos) * 1);
        solid += fogColor;
        break;
    }

    return vec3(solid);
}

float GetBorderFogMixFactorDH(in vec3 eyePlayerPos, in float far)
{

    float eyeDist = length(eyePlayerPos.xz);
    float borderFogFactor = smoothstep(0.0, dhRenderDistance, eyeDist);
    borderFogFactor *= borderFogFactor * borderFogFactor;
    return (eyeDist > 0.0) ? borderFogFactor : 0.0;
}