26 lines
761 B
GLSL
26 lines
761 B
GLSL
#type compute
|
|
#version 460 core
|
|
layout(local_size_x = 16, local_size_y = 16) in;
|
|
|
|
layout(binding = 0) uniform sampler2D u_SceneColor;
|
|
layout(binding = 1, std430) buffer Histogram {
|
|
uint bins[64];
|
|
};
|
|
|
|
uniform float u_LogMin;
|
|
uniform float u_LogMax;
|
|
|
|
void main() {
|
|
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
|
|
ivec2 size = textureSize(u_SceneColor, 0);
|
|
if (texel.x >= size.x || texel.y >= size.y) return;
|
|
|
|
vec3 color = texelFetch(u_SceneColor, texel, 0).rgb;
|
|
float lum = max(dot(color, vec3(0.2126, 0.7152, 0.0722)), 0.0001);
|
|
float logLum = log2(lum);
|
|
|
|
float invLogRange = 1.0 / (u_LogMax - u_LogMin);
|
|
float t = (logLum - u_LogMin) * invLogRange;
|
|
int bin = int(clamp(t * 64.0, 0.0, 63.0));
|
|
atomicAdd(bins[bin], 1u);
|
|
} |