2021-07-31 14:52:10 +00:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:15:57 +00:00
|
|
|
// Exposure curve from 'Perceptual Effects in Real-time Tone Mapping'.
|
2021-07-31 14:52:10 +00:00
|
|
|
// http://resources.mpi-inf.mpg.de/hdr/peffects/krawczyk05sccg.pdf
|
|
|
|
float keyValue(float L)
|
|
|
|
{
|
2021-08-25 13:15:57 +00:00
|
|
|
return 1.03 - 2.0 / (log10(L + 1.0) + 2.0);
|
2021-07-31 14:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|