/*
   Super2xGLSL shader
   
   Copyright (C) 2007 guest(r) - guest.r@gmail.com

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/


uniform sampler2D OGL2Texture;

void main()
{
	vec3 c11 = texture2D(OGL2Texture, gl_TexCoord[0].xy).xyz; 
	vec3 c00 = texture2D(OGL2Texture, gl_TexCoord[1].xy).xyz; 
	vec3 c20 = texture2D(OGL2Texture, gl_TexCoord[2].xy).xyz; 
	vec3 c02 = texture2D(OGL2Texture, gl_TexCoord[4].xy).xyz; 
	vec3 c22 = texture2D(OGL2Texture, gl_TexCoord[3].xy).xyz; 
	vec3 dt  = vec3(1.0,1.0,1.0);

	float m1=dot(abs(c00-c22),dt);
	float m2=dot(abs(c02-c20),dt);
	float w2=dot(abs(c02-c11),dt);
	float w1=dot(abs(c22-c11),dt);
	float w3=dot(abs(c00-c11),dt);
	float w4=dot(abs(c20-c11),dt);

	m1= min(w1,m1);m2= min(w2,m2);
	w1*=m2;w2*=m1; w3*=m2; w4*=m1;

	gl_FragColor.xyz=(w1*c00+w2*c20+w3*c22+w4*c02+0.001*c11)/(w1+w2+w3+w4+0.001);
}
