#vertexshader

void main()
{
	gl_Position = ftransform();
	gl_TexCoord[0] = gl_MultiTexCoord0;
}

#fragmentshader

uniform vec2 offsets[8];
uniform float ths[8];
uniform sampler2D color_texture;

//uniform float thresholds[8];
//const vec4 threshold0 = vec4(1.0, 0.9, 0.8,0.7);
//const vec4 threshold1 = vec4(0.6, 0.5, 0.3,0.1);
//const float totalweight = 1.0/ (1.0 + (0.9+0.8+0.7+0.6+0.5+0.3+0.1)*2.0);

vec4 calctap(vec4 tap, int i)
{
	/*const float ths[8];
	
	ths[1] = 0.1;
	ths[2] = 0.3;
	ths[3] = 0.5;
	ths[4] = 0.6;
	ths[5] = 0.7;
	ths[6] = 0.8;
	ths[7] = 0.9;	
	*/
	float w = clamp(tap.a-ths[i],0.0,1.0);
	return vec4(tap.rgb * w, w);
}

void main()
{

	// center tap
	vec4 c = texture2D(color_texture, gl_TexCoord[0].xy);
	float d = c.a;
	float tw = 1.0;
	
	for(int i = 1; i < 8; i++)
	{
		vec4 t;

		t = calctap(texture2D(color_texture, gl_TexCoord[0].xy+offsets[i]), i);
		c += vec4(t.rgb, 1.0);
		tw += t.w;
		
		t = calctap(texture2D(color_texture, gl_TexCoord[0].xy-offsets[i]), i);
		c += vec4(t.rgb, 1.0);
		tw += t.w;
	}
	
	c /= tw;
	
	gl_FragColor = c;
}

/*
uniform vec2 offsets[8];
uniform vec2 offsets_depth[8];
uniform sampler2D color_texture;
uniform sampler2D depth_texture;

uniform float thresholds[8];

//const vec4 threshold0 = vec4(1.0, 0.9, 0.8,0.7);
//const vec4 threshold1 = vec4(0.6, 0.5, 0.3,0.1);
//const float totalweight = 1.0/ (1.0 + (0.9+0.8+0.7+0.6+0.5+0.3+0.1)*2.0);
void main()
{
	vec4 c = vec4(0.0, 0.0, 0.0, 0.0);
	vec4 a;
	float d = texture2D(depth_texture, gl_TexCoord[0].xy+offsets[0]);
	float w = 1.0;
	
	c += texture2D(color_texture, gl_TexCoord[0].xy+offsets[0]);
	
	for(int i = 1; i < 8; i++)
	{
		if(texture2D(depth_texture, gl_TexCoord[0].xy+offsets_depth[i]).x > d)
		{
			c += texture2D(color_texture, gl_TexCoord[0].xy+offsets[i]) * thresholds[i];
			w += thresholds[i];
		}

		if(texture2D(depth_texture, gl_TexCoord[0].xy-offsets_depth[i]).x > d)
		{
			c += texture2D(color_texture, gl_TexCoord[0].xy-offsets[i]) * thresholds[i];
			w += thresholds[i];
		}		
	}
	
	c /= w;
	
	gl_FragColor = c;
}*/
