/* RENDERTARGETS: 11 */

#include "/lib/all_the_libs.glsl"   

varying vec2 texcoord;

// Gaussian Bell Curve weights
const float weights[5] = float[5](0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);

void main() {
    vec2 texelSize = 1.0 / vec2(viewWidth, viewHeight);

    float depth = texture2D(depthtex1, texcoord).r;

    
    // Start with the center pixel
    vec3 blurResult = texture2D(colortex10, texcoord).rgb * weights[0];
    
    // The Horizontal Blur Loop
    for(int i = 1; i < 5; i++) {
        // Multiply by 3.0 to spread the light out wider!
        vec2 offset = vec2(texelSize.x * float(i) * 3.0, 0.0); 
        
        blurResult += texture2D(colortex10, texcoord + offset).rgb * weights[i];
        blurResult += texture2D(colortex10, texcoord - offset).rgb * weights[i];
    }
    
    // Write the result to colortex11 (mapped to Index 0 by the RENDERTARGETS at the top)
    gl_FragData[0] = vec4(blurResult, 1.0);
    
   
}