const float n = 1.0;
const float dx = n / 1024.0;
const float dy = n / 768.0;

uniform sampler2D tex;

void main()
{
	vec2 tc = gl_TexCoord[0].st;

	tc.st = tc.st + vec2(dx,dy);
	vec4 sum_dr = texture2D(tex, tc);

	tc.st = tc.st + vec2(-2*dx,0);
	vec4 sum_dl = texture2D(tex, tc);

	tc.st = tc.st + vec2(2*dx,-2*dy);
	vec4 sum_ur = texture2D(tex, tc);

	int sum0 = int(sum_dr.a * 16777216 + sum_dr.b * 65536 + sum_dr.g * 256 + sum_dr.r);
	int sum1 = int(sum_dl.a * 16777216 + sum_dl.b * 65536 + sum_dl.g * 256 + sum_dl.r);
	int sum2 = int(sum_ur.a * 16777216 + sum_ur.b * 65536 + sum_ur.g * 256 + sum_ur.r);

	float sum = (float(sum0) - float(sum1) - float(sum2)) / pow(2*n+1,2);

	float c = sum / 255.0;
	gl_FragColor = vec4(c, c, c, 1.0);
}
