#version 330 core

layout(location = 0, index = 0) out vec4 outcol;

uniform sampler2DRect tex0;

uniform vec4 levels_inout;
uniform vec4 gamma;

in vec2 texcoord0;

void main()
{
	vec4 sample_col = texture( tex0, texcoord0 );

	vec3 inBlack  = levels_inout.xxx;
	vec3 inWhite  = levels_inout.yyy;
	vec3 gamma    = gamma.xxx;
	vec3 outBlack = levels_inout.zzz;
	vec3 outWhite = levels_inout.www;

	//note: sakset fra gpu-gems1, s.364
	//TODO: fjern normaliseringer - de er der kun for at matche værdier fra ps
	outcol.rgb = ( pow( max(vec3(0,0,0),(sample_col.rgb * vec3(255.0f)) - inBlack) / (inWhite-inBlack), gamma) * (outWhite-outBlack) + outBlack) / vec3(255.0f);
	outcol.a = sample_col.a;
}
