uniform sampler2D tex;

const float Luminance = 0.08;
const float fMiddleGray = 0.2;
const float fWhiteCutoff = 0.4;

// High-pass filter
void main() {
	vec4 ColorOut = texture2D(tex, gl_TexCoord[0].xy);

	ColorOut *= fMiddleGray / (Luminance + 0.001);
	ColorOut *= (1.0 + (ColorOut / (fWhiteCutoff * fWhiteCutoff)));
	ColorOut -= 6.0;

	ColorOut /= (10.0 + ColorOut); //25.0;

	gl_FragColor = ColorOut;
}