2023-02-19 15:47:55 +00:00
|
|
|
#version 330 core
|
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
layout(location = 0) out uint fragHits;
|
2023-02-19 15:47:55 +00:00
|
|
|
|
|
|
|
uniform sampler2D hdr_tex;
|
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
// color.glsl
|
|
|
|
float linear_srgb_to_luminance(vec3 color);
|
|
|
|
// histogram.glsl
|
2023-02-19 15:47:55 +00:00
|
|
|
uint luminance_to_bin_index(float luminance);
|
2023-04-12 20:50:03 +00:00
|
|
|
// exposure.glsl
|
|
|
|
vec3 undo_exposure(vec3 color);
|
2023-02-19 15:47:55 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
ivec2 hdr_tex_size = textureSize(hdr_tex, 0);
|
|
|
|
int column = int(gl_FragCoord.x);
|
|
|
|
uint target_bin = uint(gl_FragCoord.y); // [0, 255]
|
|
|
|
|
|
|
|
uint hits = 0u;
|
|
|
|
|
|
|
|
for (int row = 0; row < hdr_tex_size.y; ++row) {
|
|
|
|
vec3 hdr_color = texelFetch(hdr_tex, ivec2(column, row), 0).rgb;
|
2023-04-12 20:50:03 +00:00
|
|
|
hdr_color = undo_exposure(hdr_color);
|
2023-02-19 15:47:55 +00:00
|
|
|
// sRGB to relative luminance
|
2023-04-07 06:17:37 +00:00
|
|
|
float lum = linear_srgb_to_luminance(hdr_color);
|
2023-02-19 15:47:55 +00:00
|
|
|
// Get the bin index corresponding to the given pixel luminance
|
|
|
|
uint pixel_bin = luminance_to_bin_index(lum);
|
|
|
|
// Check if this pixel should go in the bin
|
|
|
|
if (pixel_bin == target_bin) {
|
|
|
|
hits += 1u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fragHits = hits;
|
|
|
|
}
|