initial commit
This commit is contained in:
@ -15,19 +15,6 @@ layout(std430, binding = 1) buffer HistogramBuffer {
|
||||
// Workgroup size (adjust based on GPU architecture for performance, 16x16 is often reasonable)
|
||||
layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
// Helper to convert linear float (potentially HDR 0.0+) to 0-255 bin index
|
||||
// Applies an approximate gamma curve for perceptual binning.
|
||||
uint linearToVisualBin(float linearVal) {
|
||||
// Clamp linear value to 0.0-1.0 range before gamma/binning
|
||||
// This histograms the displayable range after processing.
|
||||
float clampedVal = clamp(linearVal, 0.0, 1.0);
|
||||
// Apply approximate sRGB gamma for perceptual brightness mapping
|
||||
float displayApprox = pow(clampedVal, 1.0/2.2);
|
||||
// Convert 0.0-1.0 display value to 0-255 bin index
|
||||
return uint(displayApprox * 255.999); // Use 255.999 to ensure 1.0 maps to 255
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Get the global invocation ID (like pixel coordinates)
|
||||
ivec2 pixelCoord = ivec2(gl_GlobalInvocationID.xy);
|
||||
@ -43,9 +30,10 @@ void main() {
|
||||
|
||||
// Calculate bin indices (0-255)
|
||||
// We clamp just in case, although imageLoad from rgba8 should be in range.
|
||||
uint rBin = linearToVisualBin(pixelColor.r);
|
||||
uint gBin = linearToVisualBin(pixelColor.g);
|
||||
uint bBin = linearToVisualBin(pixelColor.b);
|
||||
uint rBin = uint(clamp(pixelColor.r, 0.0, 1.0) * 255.0);
|
||||
uint gBin = uint(clamp(pixelColor.g, 0.0, 1.0) * 255.0);
|
||||
uint bBin = uint(clamp(pixelColor.b, 0.0, 1.0) * 255.0);
|
||||
|
||||
// Atomically increment the counters in the SSBO
|
||||
// Offset Green bins by 256, Blue bins by 512
|
||||
atomicAdd(histogram.bins[rBin], 1u);
|
||||
|
Reference in New Issue
Block a user