[FP overlay]

vec4 Overlay (vec4 cBase, vec4 cBlend)
{
	vec4 cNew;
	if (cBase.r > 0.5) { cNew.r = 1.0 - (1.0 - 2.0 * (cBase.r - 0.5)) * (1.0 - cBlend.r); }
	else { cNew.r = (2.0 * cBase.r) * cBlend.r; }
	
	if (cBase.g > 0.5) { cNew.g = 1.0 - (1.0 - 2.0 * (cBase.g - 0.5)) * (1.0 - cBlend.g); }
	else { cNew.g = (2.0 * cBase.g) * cBlend.g; }
	
	if (cBase.b > 0.5) { cNew.b = 1.0 - (1.0 - 2.0 * (cBase.b - 0.5)) * (1.0 - cBlend.b); }
	else { cNew.b = (2.0 * cBase.b) * cBlend.b; }
	
	cNew.a = cBase.a * cBlend.a;
	return cNew;
}

uniform sampler2D colormap;

void main( void ) {
	// texel color
	//float val = gl_TexCoord[0].s;
	vec4 bcolor = texture2D(colormap, gl_TexCoord[0].st);//vec4(val, val, val, 1);
	// overlay color	
	vec4 ocolor = gl_Color;
	// result
	gl_FragColor = Overlay(bcolor, ocolor);
}