/*
	gaussian blur algorithm - XPeng
*/

#version 130


uniform sampler2D 	inText;		// input sampler
out     vec4 		outText;	// output sampler

const  int GAUSSIAN_SAMPLES = 7;
 
uniform  float texelWidthOffset; 
uniform  float texelHeightOffset;
//uniform  float blurSize;	// default is 1.0
//uniform float blurStrength;		// 0.0 -- 1.0

uniform float kernel0;
uniform float kernel1;
uniform float kernel2;
uniform float kernel3;
uniform float kernel4;
uniform float kernel5;
uniform float kernel6;
uniform float kernel7;
uniform float kernel8;
uniform float kernel9;
uniform float kernel10;
  
void main()
{
	 vec2 inputTextureCoordinate = gl_TexCoord[0].xy;
	 vec2 blurCoordinates[GAUSSIAN_SAMPLES];
 
	// Calculate the positions for the blur
 	int multiplier = 0;
 	 vec2 blurStep;
     vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);// * blurSize;
     
 	for ( int i = 0; i < GAUSSIAN_SAMPLES; i++) 
	{
 		multiplier = (i - ((GAUSSIAN_SAMPLES - 1) / 2));
        // Blur in x (horizontal)
        blurStep = float(multiplier) * singleStepOffset;
 		blurCoordinates[i] = inputTextureCoordinate.xy + blurStep;
 	}

 	 vec4 sum = vec4(0.0);
 	
    sum += texture2D(inText, blurCoordinates[0]) * kernel0;
    sum += texture2D(inText, blurCoordinates[1]) * kernel1;
    sum += texture2D(inText, blurCoordinates[2]) * kernel2;
    sum += texture2D(inText, blurCoordinates[3]) * kernel3;
    sum += texture2D(inText, blurCoordinates[4]) * kernel4;
    sum += texture2D(inText, blurCoordinates[5]) * kernel5;
    sum += texture2D(inText, blurCoordinates[6]) * kernel6;
    /*
    sum += texture2D(inText, blurCoordinates[7]) * kernel7;
    sum += texture2D(inText, blurCoordinates[8]) * kernel8;
    sum += texture2D(inText, blurCoordinates[9]) * kernel9;
    sum += texture2D(inText, blurCoordinates[10]) * kernel10;
    */

    outText = sum;//blurStrength*sum + (1-blurStrength)*texture2D(inText, inputTextureCoordinate.xy);
}

