uniform sampler2D target;
uniform sampler2D adder;
uniform float low;
uniform float high;
uniform float bri;


void main(void) {
	vec2 texcoord = gl_TexCoord[0].xy;
  vec4 col1, col2, cout;
  
  col1=texture2D(target, texcoord);
  col2=texture2D(adder, texcoord);


/* 
  if(col2.r < low) col2.r = 0;
  if(col2.g < low) col2.g = 0;
  if(col2.b < low) col2.b = 0;

  if(col2.r > high) col2.r = high;
  if(col2.g > high) col2.g = high;
  if(col2.b > high) col2.b = high;
*/
/*
  cout.r = col2.r*.5+col2.g*.25+col2.b*.25;
  cout.g = col2.r*.25+col2.g*.5+col2.b*.25;
  cout.b = col2.r*.25+col2.g*.25+col2.b*.5;
*/  
  cout.r = col2.r*.95+col2.g*.025+col2.b*.025;
  cout.g = col2.r*.75+col2.g*.025+col2.b*.025;
  cout.b = col2.r*.55+col2.g*.025+col2.b*.025;
  

  gl_FragColor = col1 + (1-(1-cout)*(1-cout)*(1-cout)*(1-cout)*(1-cout)*(1-cout)*(1-cout)*(1-cout)*(1-cout))*bri*0.125*low+(cout*cout)*bri*high;
}
