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

const float asmooth = 2.0;
const float damping = 0.975;

uniform sampler2D wbuffer;
uniform int swap_state;

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

	vec4 buffer_old_color = texture2D(wbuffer, tc);

	tc.s = tc.s - dx;
	vec4 cl = texture2D(wbuffer, tc);

	tc.s = tc.s + 2.0 * dx;
	vec4 cr = texture2D(wbuffer, tc);

	tc.s = tc.s - dx;
	tc.t = tc.t + dy;
	vec4 cd = texture2D(wbuffer, tc);

	tc.t = tc.t - 2.0 * dy;
	vec4 cu = texture2D(wbuffer, tc);

	if (swap_state==0)
	{
		buffer_old_color.g = ((cl.r + cr.r + cd.r + cu.r) / asmooth) * damping - buffer_old_color.g;
	}
	else
	{
		buffer_old_color.r = ((cl.g + cr.g + cd.g + cu.g) / asmooth) * damping - buffer_old_color.r;
	}

	gl_FragColor = buffer_old_color;
}
