
uniform float screen_width;
uniform float screen_height;
uniform float layer_scale;
uniform float max_alpha;

varying vec2 v_texCoord;
uniform sampler2D u_texture;  // Texture that will be blurred by this shader

float Gaussian (float x, float deviation)
{
	return (1.0 / sqrt(2.0 * 3.141592 * deviation)) * exp(-((x * x) / (2.0 * deviation)));	
}

void main() {

//	float blurSize_horz = 1.0/(screen_width/5.0f);
//	float blurSize_vert = 1.0/(screen_height/5.0f);
	float blurSize_horz = 1.0/(screen_width/6.0f);
	float blurSize_vert = 1.0/(screen_height/6.0f);  

  vec4 sum = vec4(0.0);
	
	float blur_scale = 1.0f;
	float blur_strenght = 1.0f;

	sum += texture2D(u_texture, vec2(v_texCoord.x - 6.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.045 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x - 5.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.065 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x - 4.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.08 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x - 3.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.09 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x - 2.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.12 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x - blurSize_horz*blur_scale, v_texCoord.y)) * 0.15 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y)) * 0.16 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x + blurSize_horz*blur_scale, v_texCoord.y)) * 0.15 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x + 2.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.12 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x + 3.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.09 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x + 4.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.08 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x + 5.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.065 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x + 6.0*blurSize_horz*blur_scale, v_texCoord.y)) * 0.045 * blur_strenght;

	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y - 6.0*blurSize_vert*blur_scale)) * 0.045 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y - 5.0*blurSize_vert*blur_scale)) * 0.065 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y - 4.0*blurSize_vert*blur_scale)) * 0.08 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y - 3.0*blurSize_vert*blur_scale)) * 0.09 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y - 2.0*blurSize_vert*blur_scale)) * 0.12 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y - blurSize_vert*blur_scale)) * 0.15 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y)) * 0.16 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y + blurSize_vert*blur_scale)) * 0.15 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y + 2.0*blurSize_vert*blur_scale)) * 0.12 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y + 3.0*blurSize_vert*blur_scale)) * 0.09 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y + 4.0*blurSize_vert*blur_scale)) * 0.08 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y + 5.0*blurSize_vert*blur_scale)) * 0.065 * blur_strenght;
	sum += texture2D(u_texture, vec2(v_texCoord.x, v_texCoord.y + 6.0*blurSize_vert*blur_scale)) * 0.045 * blur_strenght;

	if(sum.a > max_alpha) sum.a = max_alpha;
	//if(sum.r == 0 && sum.g == 0 && sum.b == 0) sum.a = 0.0f;
	gl_FragColor = sum;

}