float getVPSSigma(in vec3 pos, float cd, float distortion) {
    const float lightSize   = 0.04;
    const int samples   = 4;
    const float minSigma = 0.00006;
    float zcoord    = pos.z;
    float dist      = 0.0;
    float sigma     = 0.0;
    float shadowDepth = 0.0;
    float blockers  = 0.0;

    float searchArea = lightSize/zcoord;
        searchArea  *= 1.2;

    for (int i = -samples; i<samples; i++) {
        for (int j = -samples; j<samples; j++) {
            vec2 searchCoord     = pos.xy + (vec2(i, j)*searchArea / (20.0*samples));
            shadowDepth         = textureLod(shadowtex1, searchCoord, 2.0).x;

            dist    += shadowDepth;
            blockers += 1.0;
        }
    }

    if (blockers>0.0) {
        dist /= blockers;
        sigma = (zcoord-dist)*lightSize / zcoord;
    }

    return clamp(sigma*10+minSigma, minSigma, searchArea/20)*distortion;
}