//.template
//.name /*: name*/
//.category Filters; /*: category*/
//.param float amount; 0.0; 1.0; Amount
//.input sampler2D tex0; Input

uniform sampler2D tex0;
uniform float amount;
uniform vec2 size;

void main(void)
{
	float factor = 1.0;
	float stepX = 1.0 / (size.x * factor);
	float stepY = 1.0 / (size.y * factor);

	vec2 offset[9];
	vec3 kernel[3];

	offset[0] = vec2(-stepX, -stepY); offset[1] = vec2(0.0, -stepY); offset[2] = vec2(stepX, -stepY);
	offset[3] = vec2(-stepX,    0.0); offset[4] = vec2(0.0,    0.0); offset[5] = vec2(stepX,    0.0);
	offset[6] = vec2(-stepX,  stepY); offset[7] = vec2(0.0,  stepY); offset[8] = vec2(stepX,  stepY);

	kernel[0] = vec3(-1.0, -1.0, -1.0);
	kernel[1] = vec3(-1.0,  9.0, -1.0);
	kernel[2] = vec3(-1.0, -1.0, -1.0);

	vec3 color = vec3(0.0);
	vec4 texel, original;
	int i;

	original = texture2D(tex0, gl_TexCoord[0].st);

	for (i = 0; i < 9; i++)
	{
		texel = texture2D(tex0, mod(vec2(1.0) + gl_TexCoord[0].st + offset[i], 1.0));
		color += texel.rgb * kernel[i / 3][int(mod(float(i), 3.0))];
	}

	gl_FragColor = vec4(mix(original.rgb, color, amount), original.a);
}
