2014-04-21 20:29:22 -04:00
|
|
|
// From http://www.ceng.metu.edu.tr/~akyuz/files/hdrgpu.pdf
|
2014-04-20 19:52:44 -04:00
|
|
|
|
|
|
|
uniform sampler2D tex;
|
|
|
|
uniform sampler2D logluminancetex;
|
2014-04-24 11:47:17 -04:00
|
|
|
uniform float exposure = .09;
|
|
|
|
uniform float Lwhite = 1.;
|
2014-04-20 19:52:44 -04:00
|
|
|
|
|
|
|
in vec2 uv;
|
|
|
|
out vec4 FragColor;
|
|
|
|
|
|
|
|
vec3 getCIEYxy(vec3 rgbColor);
|
|
|
|
vec3 getRGBFromCIEXxy(vec3 YxyColor);
|
|
|
|
|
2014-04-24 11:47:17 -04:00
|
|
|
|
2014-04-21 13:39:39 -04:00
|
|
|
float delta = .0001;
|
2014-04-21 20:29:22 -04:00
|
|
|
float saturation = 1.;
|
2014-04-20 19:52:44 -04:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 col = texture(tex, uv);
|
2014-04-21 20:29:22 -04:00
|
|
|
float avgLw = textureLod(logluminancetex, uv, 10.).x;
|
|
|
|
avgLw = max(exp(avgLw) - delta, delta);
|
2014-04-20 19:52:44 -04:00
|
|
|
|
2014-04-21 20:29:22 -04:00
|
|
|
vec3 Cw = getCIEYxy(col.xyz);
|
|
|
|
float Lw = Cw.y;
|
2014-04-25 11:57:10 -04:00
|
|
|
|
2014-04-25 20:00:50 -04:00
|
|
|
/* Reinhard, for reference */
|
|
|
|
// float L = Lw * exposure / avgLw;
|
|
|
|
// float Ld = L * (1. + L / (Lwhite * Lwhite));
|
|
|
|
// Ld /= (1. + L);
|
|
|
|
// FragColor = vec4(Ld * pow(col.xyz / Lw, vec3(saturation)), 1.);
|
|
|
|
|
|
|
|
// Uncharted2 tonemap with Auria's custom coefficients
|
2014-04-25 20:02:16 -04:00
|
|
|
vec4 perChannel = (col * (6.9 * col + .5)) / (col * (5.2 * col + 1.7) + 0.06);
|
2014-04-25 20:00:50 -04:00
|
|
|
perChannel = pow(perChannel, vec4(2.2));
|
|
|
|
FragColor = vec4(perChannel.xyz, 1.);
|
2014-04-20 20:33:12 -04:00
|
|
|
|
2014-04-20 19:52:44 -04:00
|
|
|
}
|