From b0e56ca2b08d0472810ce3108a43b075b322b55e Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 22 Apr 2014 02:29:22 +0200 Subject: [PATCH] Use some diffent value/equation for tonemap --- data/shaders/tonemap.frag | 22 +++++++++++++--------- data/shaders/utils/getCIEXYZ.frag | 9 ++------- src/graphics/post_processing.cpp | 10 +++++----- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/data/shaders/tonemap.frag b/data/shaders/tonemap.frag index 9718adcb5..923e51d59 100644 --- a/data/shaders/tonemap.frag +++ b/data/shaders/tonemap.frag @@ -1,4 +1,4 @@ -#define AUTO_EXPOSURE +// From http://www.ceng.metu.edu.tr/~akyuz/files/hdrgpu.pdf uniform sampler2D tex; uniform sampler2D logluminancetex; @@ -9,19 +9,23 @@ out vec4 FragColor; vec3 getCIEYxy(vec3 rgbColor); vec3 getRGBFromCIEXxy(vec3 YxyColor); -float exposure = .2; -float whitePoint = 1.; +float exposure = .18; +float Lwhite = 1.; float delta = .0001; +float saturation = 1.; void main() { vec4 col = texture(tex, uv); - float avgLuminance = textureLod(logluminancetex, uv, 10.).x; - avgLuminance = max(exp(avgLuminance) - delta, delta); + float avgLw = textureLod(logluminancetex, uv, 10.).x; + avgLw = max(exp(avgLw) - delta, delta); - vec3 Yxy = getCIEYxy(col.xyz); - float Lp = Yxy.r * exposure / avgLuminance; - Yxy.r = (Lp * (1. * Lp / (whitePoint * whitePoint))) / (1. + Lp); - FragColor = vec4(getRGBFromCIEXxy(Yxy), 1.); + vec3 Cw = getCIEYxy(col.xyz); + float Lw = Cw.y; + 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.); } diff --git a/data/shaders/utils/getCIEXYZ.frag b/data/shaders/utils/getCIEXYZ.frag index 607f4e396..8776b7fdf 100644 --- a/data/shaders/utils/getCIEXYZ.frag +++ b/data/shaders/utils/getCIEXYZ.frag @@ -3,15 +3,10 @@ vec3 getCIEYxy(vec3 rgbColor) { - // convert rgb to srgb - vec3 sRGBColor = rgbColor;//vec3(pow(rgbColor.x, 1. / 2.2), pow(rgbColor.y, 1. / 2.2), pow(rgbColor.z, 1. / 2.2)); - mat3 sRGB2XYZ = transpose(mat3( vec3(.4125, .2126, .0193), vec3(.3576, .7152, .1192), vec3(.1805, .0722, .9505))); - vec3 XYZ = sRGB2XYZ * sRGBColor; - float sum = dot(vec3(1.), XYZ); - return vec3(XYZ.y, XYZ.xy / sum); -} \ No newline at end of file + return sRGB2XYZ * rgbColor; +} diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index a7a5b6c7f..065296a8c 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -637,11 +637,6 @@ void PostProcessing::render() glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); - computeLogLuminance(in_rtt); - toneMap(out_fbo, in_rtt); - std::swap(in_rtt, out_rtt); - std::swap(in_fbo, out_fbo); - PROFILER_PUSH_CPU_MARKER("- Bloom", 0xFF, 0x00, 0x00); if (UserConfigParams::m_bloom) { @@ -699,6 +694,11 @@ void PostProcessing::render() PROFILER_POP_CPU_MARKER(); + computeLogLuminance(in_rtt); + toneMap(out_fbo, in_rtt); + std::swap(in_rtt, out_rtt); + std::swap(in_fbo, out_fbo); + PROFILER_PUSH_CPU_MARKER("- Godrays", 0xFF, 0x00, 0x00); if (UserConfigParams::m_light_shaft && m_sunpixels > 30)//World::getWorld()->getTrack()->hasGodRays() && ) // god rays {