#ifndef OVERWORLD

vec3 calcAmbientLight(vec3 wNormal, vec2 lightmap, vec3 ambientUp, vec3 ambientDown, vec3 ambientRight,
                      vec3 ambientLeft, vec3 ambientB, vec3 ambientF, vec3 RSML, float diffuseSun, vec3 torch)
{
    vec3 ambientCoefs = wNormal / (abs(wNormal.x) + abs(wNormal.y) + abs(wNormal.z));

    vec3 clampedCoefs = clamp(ambientCoefs, 0.0, 1.0);
    vec3 clampedCoefsNeg = clamp(-ambientCoefs, 0.0, 1.0);
    float ambmult = 20;
#ifdef END
    ambmult = 1.0;
#endif

    vec3 ambientCombined =
        (ambientUp * clampedCoefs.y + ambientDown * clampedCoefsNeg.y + ambientRight * clampedCoefs.x +
         ambientLeft * clampedCoefsNeg.x + ambientB * clampedCoefs.z + ambientF * clampedCoefsNeg.z) *
        ambmult;

    vec3 diffuseLight = diffuseSun * vec3(0.01, 0.002, 0.003) + ambientCombined;

    float darknessFactor = darknessLightFactor * darknessLightFactor * darknessLightFactor;

    diffuseLight *= (1.0 - 6.0 * darknessFactor);

    vec3 light = max(diffuseLight + torch + (vec3(0.002, 0.005, 0.006) * (1.0 + screenBrightness * 2.0)), 0.001);

    light *= 1.0 - darknessLightFactor;

    return vec3(light);
}
#else
vec3 calcAmbientLight(vec3 wNormal, vec2 lightmap, vec3 ambientUp, vec3 ambientDown, vec3 ambientRight,
                      vec3 ambientLeft, vec3 ambientB, vec3 ambientF, vec3 RSML, float diffuseSun, vec3 torch)
{
    vec3 ambientCoefs = wNormal / dot(abs(wNormal), vec3(1.0));
    vec3 clampedCoefs = clamp(ambientCoefs, 0.0, 1.0);
    vec3 clampedCoefsNeg = clamp(-ambientCoefs, 0.0, 1.0);
    float mixstrength = clamp(pow(shadowblend, 0.3), 0, 1);
    float skymap = lightmap.y;

    vec3 bounce = (sunLight * 0.25);

    bounce += mix(sunLight * 0.15 * clamp(diffuseSun, 0.5, 1), vec3(0.0), clamp(mixstrength * 1.0, 0, 1));
    bounce *= pow(skymap, 4.0);
    ambientRight = mix(ambientDown, ambientRight, mixstrength);
    ambientLeft = mix(ambientDown, ambientLeft, mixstrength);

    vec3 ambientCombined =
        (ambientUp * clampedCoefs.y + ambientDown * clampedCoefsNeg.y + ambientRight * clampedCoefs.x +
         ambientLeft * clampedCoefsNeg.x + ambientB * clampedCoefs.z + ambientF * clampedCoefsNeg.z) *
            skymap +
        RSML;

    ambientCombined = mix(ambientCombined, bounce, 0.1);

    vec3 diffuseLight = diffuseSun * sunLight + ambientCombined;

    float darknessFactor = darknessLightFactor * darknessLightFactor * darknessLightFactor;

    diffuseLight *= (1.0 - 6.0 * darknessFactor);

    vec3 light = max(diffuseLight + torch + (vec3(0.002, 0.005, 0.006) * (1.0 + screenBrightness * 2.0)), 0.001);

    light *= 1.0 - darknessLightFactor;

    return vec3(light);
}

#endif

vec3 calcAmbientLight(vec3 Normal, vec2 lightmap, vec3 ambientUp, float diffuseSun, vec3 torch)
{

    vec3 ambient = calcAmbientLight(Normal, lightmap.xy, ambientUp, ambientUp, ambientUp, ambientUp, ambientUp,
                                    ambientUp, vec3(0.6 * ambientUp.b * lightmap.y), diffuseSun, torch);

    return ambient;
}