// vert //

void main(void) {
	gl_Position = qgl_ftransform();
}


// frag //

uniform sampler2D tex_0;
uniform float gamma, frame_max;

const vec3 luma = vec3(0.299, 0.587, 0.114);

void main(void) {
	ivec2 tc = ivec2(gl_FragCoord.xy);
	vec4 src = texelFetch(tex_0, tc, 0);
	vec3 res = src.rgb;
	float l = dot(res, luma) * 0.75;
	float g = gamma / frame_max;
	res /= l;
	l = 1 - exp(-l*g);
	res *= l;
	qgl_FragColor = vec4(res, dot(res, luma));
}
