uniform sampler2D Texture;

varying vec2 TexCoord;

uniform vec2 blurVec;
uniform vec2 TextureDivViewport;

void main()
{
	if ((TexCoord.x > 1.0) || (TexCoord.y > 1.0))
		discard;

	vec4 Color = texture2D(Texture, TexCoord);
	float r = Color.r;
	float d = 1.0;

	vec2 bv = (blurVec / TextureDivViewport) * Color.a;

	vec3 Tex = texture2D(Texture, TexCoord + bv).rgb;
	if (Tex.gb == Color.gb)
	{
		r += Tex.r;
		d += 1.0;
	}
	Tex = texture2D(Texture, TexCoord - bv).rgb;
	if (Tex.gb == Color.gb)
	{
		r += Tex.r;
		d += 1.0;
	}
	Tex = texture2D(Texture, TexCoord + bv * 2.0).rgb;
	if (Tex.gb == Color.gb)
	{
		r += Tex.r;
		d += 1.0;
	}
	Tex = texture2D(Texture, TexCoord - bv * 2.0).rgb;
	if (Tex.gb == Color.gb)
	{
		r += Tex.r;
		d += 1.0;
	}

	/*Tex = texture2D(Texture, TexCoord + bv * 3.0).rgb;
	if (Tex.gb == Color.gb)
	{
		r += Tex.r;
		d += 1.0;
	}
	Tex = texture2D(Texture, TexCoord - bv * 3.0).rgb;
	if (Tex.gb == Color.gb)
	{
		r += Tex.r;
		d += 1.0;
	} */
	gl_FragColor.r = (r / d);

	gl_FragColor.gba = Color.gba;
}
