const float sunPathRotation = -35;
const int shadowMapResolution = 2048; // [512 768 1024 1536 2048 3172 4096 8192 16384]
const float shadowDistance = 160.0;   // [64.0 80.0 96.0 112.0 128.0 144.0 160.0 176.0 192.0 208.0 224.0 240.0 256.0 272.0 288.0 304.0 320.0 336.0 352.0 384.0 400.0 416.0 432.0 448.0 464.0 480.0 496.0 512.0]
const float shaddist = shadowDistance;

#ifndef DISTANT_HORIZONS
const float shadowDistanceRenderMul = 1;
#else
const float shadowDistanceRenderMul = -1;
#endif

const bool shadowHardwareFiltering = true;

const float ambientOcclusionLevel = 1.0;
// const float shadowIntervalSize = 0.1;
#define PENUMBRA_SHADOWS
#define RSM

#if !defined MC_GL_VENDOR_NVIDIA && !defined MC_OS_WINDOWS
#undef PENUMBRA_SHADOWS
#endif

#define SHADOW_DISTORTION 75

#ifdef DISTANT_HORIZONS

float calcDistortMainDH(vec2 worldpos)
{

    float value = (length(abs(worldpos)) * shadowMapResolution);
    float low2 = 0.4;
    float high2 = 1 + low2;
    float low1 = 0;
    float high1 = shadowMapResolution;
    return low2 + (value - low1) * (high2 - low2) / (high1 - low1);
}
#else
float computeValue(float x)
{
    float a = 0.325;
    float b = 0.3;
    return a * (log(x) / log(10.0)) + b;
}


float calcDistortMainDH(vec2 worldpos)
{
    float test = shadowDistance;
    float value = (length(abs(worldpos)));
    float low2 = DISTORTION_ADJUSTMENT;
    float high2 = computeValue(min(shadowDistance, far));
    float low1 = 0;
    float high1 = 1;
    float final = low2 + (value - low1) * (high2 - low2) / (high1 - low1);


    return final;
}
#endif

// Function to calculate distortion based on world position
float calcDistort(vec2 worldpos)
{

    return 1.0 / calcDistortMainDH(abs(worldpos.xy));
}

// Function to calculate shadow distortion
vec2 calcShadowDistortion(vec3 shadowpos)
{

    return shadowpos.xy / calcDistortMainDH(abs(shadowpos.xy));
}
