1
0
Fork 0
fgdata/Shaders/HDR/exposure.glsl
Fernando García Liñán f53a170539 HDR: Better bloom effect
We also now pre-expose our lighting before writing to the HDR buffers.
This solves some precision issues and prevents the Sun from producing
infinite values.
2023-04-13 00:30:02 +02:00

39 lines
838 B
GLSL

#version 330 core
uniform sampler2D lum_tex;
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 key_value(float L)
{
return 1.0 - 2.0 / (log10(L + 1.0) + 2.0);
}
float get_exposure()
{
float avg_lum = max(texelFetch(lum_tex, ivec2(0), 0).r, 0.001);
float linear_exposure = key_value(avg_lum) / avg_lum;
float exposure = log2(max(linear_exposure, 0.0001));
exposure += exposure_compensation;
return exposure;
}
vec3 apply_exposure(vec3 color)
{
return color * exp2(get_exposure());
}
vec3 undo_exposure(vec3 color)
{
return color / exp2(get_exposure());
}