Use some diffent value/equation for tonemap

This commit is contained in:
Vincent Lejeune 2014-04-22 02:29:22 +02:00
parent 2aa6676050
commit b0e56ca2b0
3 changed files with 20 additions and 21 deletions

View File

@ -1,4 +1,4 @@
#define AUTO_EXPOSURE // From http://www.ceng.metu.edu.tr/~akyuz/files/hdrgpu.pdf
uniform sampler2D tex; uniform sampler2D tex;
uniform sampler2D logluminancetex; uniform sampler2D logluminancetex;
@ -9,19 +9,23 @@ out vec4 FragColor;
vec3 getCIEYxy(vec3 rgbColor); vec3 getCIEYxy(vec3 rgbColor);
vec3 getRGBFromCIEXxy(vec3 YxyColor); vec3 getRGBFromCIEXxy(vec3 YxyColor);
float exposure = .2; float exposure = .18;
float whitePoint = 1.; float Lwhite = 1.;
float delta = .0001; float delta = .0001;
float saturation = 1.;
void main() void main()
{ {
vec4 col = texture(tex, uv); vec4 col = texture(tex, uv);
float avgLuminance = textureLod(logluminancetex, uv, 10.).x; float avgLw = textureLod(logluminancetex, uv, 10.).x;
avgLuminance = max(exp(avgLuminance) - delta, delta); avgLw = max(exp(avgLw) - delta, delta);
vec3 Yxy = getCIEYxy(col.xyz); vec3 Cw = getCIEYxy(col.xyz);
float Lp = Yxy.r * exposure / avgLuminance; float Lw = Cw.y;
Yxy.r = (Lp * (1. * Lp / (whitePoint * whitePoint))) / (1. + Lp); float L = Lw * exposure / avgLw;
FragColor = vec4(getRGBFromCIEXxy(Yxy), 1.); float Ld = L * (1. + L / (Lwhite * Lwhite));
Ld /= (1. + L);
FragColor = vec4(Ld * pow(col.xyz / Lw, vec3(saturation)), 1.);
} }

View File

@ -3,15 +3,10 @@
vec3 getCIEYxy(vec3 rgbColor) 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( mat3 sRGB2XYZ = transpose(mat3(
vec3(.4125, .2126, .0193), vec3(.4125, .2126, .0193),
vec3(.3576, .7152, .1192), vec3(.3576, .7152, .1192),
vec3(.1805, .0722, .9505))); vec3(.1805, .0722, .9505)));
vec3 XYZ = sRGB2XYZ * sRGBColor; return sRGB2XYZ * rgbColor;
float sum = dot(vec3(1.), XYZ); }
return vec3(XYZ.y, XYZ.xy / sum);
}

View File

@ -637,11 +637,6 @@ void PostProcessing::render()
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND); 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); PROFILER_PUSH_CPU_MARKER("- Bloom", 0xFF, 0x00, 0x00);
if (UserConfigParams::m_bloom) if (UserConfigParams::m_bloom)
{ {
@ -699,6 +694,11 @@ void PostProcessing::render()
PROFILER_POP_CPU_MARKER(); 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); PROFILER_PUSH_CPU_MARKER("- Godrays", 0xFF, 0x00, 0x00);
if (UserConfigParams::m_light_shaft && m_sunpixels > 30)//World::getWorld()->getTrack()->hasGodRays() && ) // god rays if (UserConfigParams::m_light_shaft && m_sunpixels > 30)//World::getWorld()->getTrack()->hasGodRays() && ) // god rays
{ {