uniform sampler2D tex1;
varying vec2 texC;

uniform float blackTer;
uniform float whiteTer;

uniform float scroller;
//colors larger than whiteTer is turned to black.
//colors smaller than blackTer is turned to black.

//other colors are white.

uniform vec4 col;

void main()
{
	vec4 color =  texture2D(tex1,vec2(texC.x,1.0-texC.y + scroller));
	float lumi = color.r + color.g + color.b;
	lumi*=0.33333;
	lumi = clamp(lumi,0.0,1.0);
	//lumi*=lumi;
	float cal = 1.0;
	
	if(lumi>whiteTer)
	 cal = 0.0;
	if(lumi<blackTer)
	 cal = pow(lumi,3.0 + sin(scroller*6.0 + texC.x*0.3 - texC.y*0.2)*2.2)*0.8;
	color.rgb = vec3(cal);
	gl_FragColor = color*col*1.5;
}