#version 150

uniform sampler2D t0;
uniform float exposure;

float tA = 0.15;
float tB = 0.50;
float tC = 0.10;
float tD = 0.20;
float tE = 0.02;
float tF = 0.30;
float tW = 11.2;

vec3 Uncharted2Tonemap(vec3 x) {
	return ((x*(tA*x+tC*tB)+tD*tE)/(x*(tA*x+tB)+tD*tF))-tE/tF;
}

void main(void) {
	//qgl_FragData[0].rgb = texelFetch(t0, ivec2(gl_FragCoord.xy), 0).rgb;
	//return;
	vec3 inColor = texelFetch(t0, ivec2(gl_FragCoord.xy), 0).rgb;
	inColor *= exposure / 1.45;
	float ExposureBias = 1.;
	vec3 curr = Uncharted2Tonemap(ExposureBias*inColor);
	vec3 whiteScale = 1. / Uncharted2Tonemap(vec3(tW));
	vec3 color = curr * whiteScale;
	vec3 retColor = color;//pow(color, vec3(1 / 1));
	qgl_FragData[0].rgb = retColor;
}
