const float dx = 1.0 / 1024.0;
const float dy = 1.0 / 768.0;
uniform sampler2D tex;

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

	// center
	vec4 c_c = texture2D(tex, tc);

	// one right
	tc.s = tc.s + dx;
	vec4 c_r = texture2D(tex, tc);

	// one down
	tc.t = tc.t - dy;
	vec4 c_rd = texture2D(tex, tc);

	// one left
	tc.s = tc.s - dx;
	vec4 c_d = texture2D(tex, tc);

	// two up
	tc.t = tc.t + 2.0 * dy;
	vec4 c_u = -texture2D(tex, tc);

	// one left
	tc.s = tc.s - dx;
	vec4 c_ul = -texture2D(tex, tc);

	// one down
	tc.t = tc.t - dy;
	vec4 c_l = -texture2D(tex, tc);

	vec4 col = (c_r + c_rd + c_d + c_u + c_ul + c_l) / 9;

	float grd = (col.r + col.g + col.b + col.a) / 2 + 0.25;

	float k = 0.85;
	float l = 1.0 - k;
	
	float r = k * grd + l * c_c.r;
	float g = k * grd + l * c_c.g;
	float b = k * grd + l * c_c.b;
	vec4 grad_color = vec4(r, g, b, 1.0);

	gl_FragColor = grad_color;
}
