what’s the fastest way to caculate 1 main or average color from frameBuffer?
I think making a compute shader to sum and average all pixels in a structure kinda like acerola’s (a youtuber) pixel sorting shader(if you want per fragment could work where you have multiple workgroups that each compute sums of two pixels per thread then output that to another workgroup kinda in a pyramid shape and then you do a divide by the amount of samples.
Or just sample a few points and do an average real quick on the cpu if you don’t need realtime performance and just want to control a effect auto-exposure because it’s easy to ramp the exposure if the data is cpu side. This mostly speculation because I didn’t try it out myself but maybe look into some papers that talk about this from nvidia, researchgate or something along those lines.
I think the fastest is going to depend on the exact situation and goal here.
The best general-case suggestion I can give is run a compute shader on the texture backing the framebuffer, average it in regions (write outputs to another texture), then average the averages in another compute shader pass. The last one will probably be a weighted average because it’s not likely all regions will be the same size.
I’ve not actually implemented that, so there might be some nuance to the best way to do it. You could probably eliminate the second pass if you used in-shader synchronization. If it’s any simpler or faster to do it that way is unclear. See:
https://registry.khronos.org/OpenGL-Refpages/gl4/html/barrier.xhtml
https://registry.khronos.org/OpenGL-Refpages/gl4/html/memoryBarrier.xhtml