1
0
Fork 0
fgdata/Shaders/HDR/histogram-include.frag
Fernando García Liñán c4d19877cf HDR: Significant update
- New atmosphering rendering technique based on my own work.
- Attempt to fix some remaining transparency issues.
- Use a luminance histogram for auto exposure.
- Add support for clustered shading.
- Add WS 2.0 shaders.
- Add 3D cloud shaders.
- Add orthoscenery support.
2023-04-06 00:18:29 +02:00

24 lines
695 B
GLSL

#version 330 core
const float NUM_BINS = 254.0;
const float INV_NUM_BINS = 1.0 / NUM_BINS;
const float MIN_LOG_LUM = -10.0;
const float LOG_LUM_RANGE = 16.0;
const float INV_LOG_LUM_RANGE = 1.0 / LOG_LUM_RANGE;
uint luminance_to_bin_index(float luminance)
{
// Avoid taking the log of zero
if (luminance < 0.005)
return 0u;
float log_lum = (log2(luminance) - MIN_LOG_LUM) * INV_LOG_LUM_RANGE;
log_lum = clamp(log_lum, 0.0, 1.0);
// From [0, 1] to [1, 255]. The 0th bin is handled by the near-zero check
return uint(log_lum * NUM_BINS + 1.0);
}
float bin_index_to_luminance(float bin)
{
return exp2(((bin * INV_NUM_BINS) * LOG_LUM_RANGE) + MIN_LOG_LUM);
}