1
0
Fork 0
fgdata/Shaders/HDR/exposure-include.frag
Fernando García Liñán aaf6bb9309 HDR: Improve ACES tone mapping curve
The previous one tended to over-expose the final image.
2021-08-25 15:15:57 +02:00

26 lines
706 B
GLSL

#version 330 core
uniform float exposure_compensation;
const float one_over_log10 = 1.0 / log(10.0);
float log10(float x)
{
return one_over_log10 * log(x);
}
// Exposure curve from 'Perceptual Effects in Real-time Tone Mapping'.
// http://resources.mpi-inf.mpg.de/hdr/peffects/krawczyk05sccg.pdf
float keyValue(float L)
{
return 1.03 - 2.0 / (log10(L + 1.0) + 2.0);
}
vec3 applyExposure(vec3 color, float avgLuminance, float threshold)
{
avgLuminance = max(avgLuminance, 0.001);
float linearExposure = keyValue(avgLuminance) / avgLuminance;
float exposure = log2(max(linearExposure, 0.0001));
exposure += exposure_compensation - threshold;
return color * exp2(exposure);
}