vec2 anamorphDirection6[6] = vec2[6] (
    vec2(-1.0, 0.1), vec2(1.0, 0.1),
    vec2(-1.0, 0.0), vec2(1.0, 0.0),
    vec2(-1.0, -0.1), vec2(1.0, -0.1)
);
float anamorphWeight6[6] = float[6] (
    0.25, 0.25,
    0.5, 0.5, 
    0.25, 0.25
);

vec2 anamorphDirection2[2] = vec2[2] (
    vec2(-1.0, 0.0), vec2(1.0, 0.0)
);
float anamorphWeight2[2] = float[2] (
    0.5, 0.5
);

float gradNoise(){
    return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y));
}

void lensAnamorph() {
    float exposure = texture(colortex7, coord).a;
        exposure = 1.0 - exp(-exposure/10);
    vec3 anamorphColor = vec3(0.0);
    const float sigma  = 0.13;
    float threshold = 35.0*max(exposure*1.3+0.15, 0.3);
    const int blurSteps = 6;
    float noise = gradNoise()*0.5-0.25;
    vec2 lensCoord = coord-0.5;
        lensCoord *= 0.9;
        lensCoord  = lensCoord+0.5;
        lensCoord  = clamp(lensCoord, 0.0, 1.0);

    for (int i = 0; i<blurSteps; i++) {
        for (int k = 0; k<2; k++) {
        vec2 blurCoord = anamorphDirection2[k]*vec2(float(i)/blurSteps+noise, 1.0);
        vec3 temp = textureLod(colortex6, lensCoord + blurCoord*sigma, 0).rgb*anamorphWeight2[k];

        #ifdef s_anamLensDiagonal
            vec3 temp2 = textureLod(colortex6, lensCoord + rotateCoord(blurCoord*0.7, -pi*0.3, 0.0)*sigma, 0).rgb*anamorphWeight2[k];
            vec3 color = max(temp, temp2);
        #else
            vec3 color = temp;
        #endif

        float weight = max(1.0+abs(blurCoord.x), 1.0);
            weight = 1.0/weight;
        float alpha = clamp((vec3avg(color)-threshold)/50.0, 0.0, 1.0);
            weight = mix(weight, pow6(weight), alpha);
        float blend = mix(1.0, 0.1, alpha);
        anamorphColor += max(color*weight-threshold, 0.0)*blend;
        }
    }

    returnLens += anamorphColor*s_anamLensInt*0.9;
}