2014-04-20 19:52:44 -04:00
|
|
|
#define AUTO_EXPOSURE
|
|
|
|
|
|
|
|
uniform sampler2D tex;
|
|
|
|
uniform sampler2D logluminancetex;
|
|
|
|
|
|
|
|
in vec2 uv;
|
|
|
|
out vec4 FragColor;
|
|
|
|
|
|
|
|
vec3 getCIEYxy(vec3 rgbColor);
|
|
|
|
vec3 getRGBFromCIEXxy(vec3 YxyColor);
|
|
|
|
|
2014-04-21 13:39:39 -04:00
|
|
|
float exposure = .2;
|
2014-04-20 20:33:12 -04:00
|
|
|
float whitePoint = 1.;
|
2014-04-21 13:39:39 -04:00
|
|
|
float delta = .0001;
|
2014-04-20 19:52:44 -04:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 col = texture(tex, uv);
|
|
|
|
float avgLuminance = textureLod(logluminancetex, uv, 10.).x;
|
2014-04-21 13:39:39 -04:00
|
|
|
avgLuminance = max(exp(avgLuminance) - delta, delta);
|
2014-04-20 19:52:44 -04:00
|
|
|
|
|
|
|
vec3 Yxy = getCIEYxy(col.xyz);
|
|
|
|
float Lp = Yxy.r * exposure / avgLuminance;
|
|
|
|
Yxy.r = (Lp * (1. * Lp / (whitePoint * whitePoint))) / (1. + Lp);
|
2014-04-20 20:33:12 -04:00
|
|
|
FragColor = vec4(getRGBFromCIEXxy(Yxy), 1.);
|
|
|
|
|
2014-04-20 19:52:44 -04:00
|
|
|
}
|