

uniform sampler2D colortex5;

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;
    float density = 0;
    vec3 refractedSunVec = refract(lightPos, -vec3(0.0, 1.0, 0.0), 0.9);

    float SdotV = dot(sunVec, normalize(fragpos));
    vec3 dVWorld = mat3(gbufferModelViewInverse) * (fragpos - vec3(0.0));

#ifdef OVERWORLD

    if (isEyeInWater == 1)
    {

        rayLength = 32;
    }
    else
    {
        rayLength = gbf(fragpos, dhFarPlane, 0) * 1028;
    }
#endif
    float dither = noise_standard(gl_FragCoord.xy);
    bool noWater = (isEyeInWater == 0);
    float dY = normalize(mat3(gbufferModelViewInverse) * fragpos).y * rayLength;
    float sh0 = 1.0;

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

    vec3 start = shadowSpace0();
    vec3 end = toShadowSpaceProjected(fragpos);

    vec3 dV = (end - start);

    AtmosphereLoop(6, 11, dither, rayLength, start, dV, dY, phaseg(SdotV, 0.4), phaseRayleigh(SdotV), noWater,
                   estEyeDepth, refractedSunVec, atmosphereUp, sunLight, sh0, absorbance_w, vL_w, density, dVWorld);
    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) * sh0;

    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;
}