uniform sampler2D tex0;

//.param float window; 0.01; 1.0; Window; 1.0
//.param float level; -0.5; 1.5; Level; 0.5

uniform float window;
uniform float level;
uniform float amount;
uniform vec3 channels;

void main(void)
{
	vec4 a = texture2D(tex0, gl_TexCoord[0].st);
  
  float bw = dot(a, channels);

  float bwc = mix(step(level + window / 2.0, bw),
                  step(level - window / 2.0, bw),
                  (bw - (level - window / 2.0)) / window);
    
	gl_FragColor = vec4(mix(a.rgb, vec3(bwc), amount), a.a);
}


