// AA shader v.3.0 - Daisy
// by guest(r)
// license: GNU-GPL

uniform sampler2D OGL2Texture;

float hd(float x)
{ 
  x = x*1.1547-1.0;
  return (sin(x*1.5707963272)+1.1)*0.86;
}

void main()
{
	vec3 c00 = texture2D(OGL2Texture, gl_TexCoord[5].xy).xyz; 
	vec3 c10 = texture2D(OGL2Texture, gl_TexCoord[1].xy).xyz; 
	vec3 c20 = texture2D(OGL2Texture, gl_TexCoord[2].zw).xyz; 
	vec3 c01 = texture2D(OGL2Texture, gl_TexCoord[3].xy).xyz; 
	vec3 c11 = texture2D(OGL2Texture, gl_TexCoord[0].xy).xyz; 
	vec3 c21 = texture2D(OGL2Texture, gl_TexCoord[4].xy).xyz; 
	vec3 c02 = texture2D(OGL2Texture, gl_TexCoord[1].zw).xyz; 
	vec3 c12 = texture2D(OGL2Texture, gl_TexCoord[2].xy).xyz; 
	vec3 c22 = texture2D(OGL2Texture, gl_TexCoord[6].xy).xyz; 
	vec3 dt = vec3(1.0,1.0,1.0); 

	float d1=1.0/(dot(abs(c00-c22),dt)+0.00001);
	float d2=1.0/(dot(abs(c20-c02),dt)+0.00001);
	float hl=1.0/(dot(abs(c01-c21),dt)+0.00001);
	float vl=1.0/(dot(abs(c10-c12),dt)+0.00001);

	c11 = 0.3333*((vl*(c10+c12)+hl*(c01+c21)+d2*(c20+c02)+d1*(c00+c22))/(hl+vl+d1+d2)+c11);

	gl_FragColor.xyz=hd(length(c11))*normalize(c11);
}
