uniform sampler2D texture0;

void main()
{

	float blurMag = 0.01 * (1.0 - gl_Color.a);
	float lodBias = (1.0 - gl_Color.a) * 3.0;
	float threshold = mix (0.45, 0.5, gl_Color.a);
	float width = clamp(gl_Color.a * gl_Color.a * gl_Color.a * gl_Color.a, 0.0, 1.0);
	
	
	vec2 blur = vec2(blurMag * 7.0, blurMag);
	
	//Simple passthrough, outputs interpolated vertex colours.
	vec4 textureColour = vec4(0.0,0.0,0.0,0.0);//texture2D(texture0, gl_TexCoord[0].xy, lodBias);
	
	
	
	//Poisson blur taps taken from ATI paper "Efficient Shader Tricks" by Chris Oat
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(-0.840144,-0.07358) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(-0.326212,-0.40581) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(-0.203345,0.620716) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(-0.695914,0.457137) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(0.473434,-0.480026) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(0.96234,-0.194983) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(0.185461,-0.893124) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(0.519456,0.767022) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(0.89642,0.412458) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(0.507431,0.064425) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(-0.791559,-0.59771) * blur, lodBias);
	textureColour += texture2D(texture0, gl_TexCoord[0].xy + vec2(-0.32194,-0.932615) * blur, lodBias);
	
	textureColour /= 12.0;
	//textureColour = 1.0 - textureColour;
	
	textureColour -= (threshold - width / 2.0);
	textureColour /= width;
	
	gl_FragColor = vec4(gl_Color.r, gl_Color.g, gl_Color.b, 1.0) * textureColour;
	gl_FragColor = vec4(gl_Color.rgb, textureColour.a);
	
	//gl_FragColor = vec4(gl_TexCoord[0].xy, 0, 1);
}