Sunstone dev log 26: luminance histogram
Today I tried to improve automatic exposure to get less grey scenes. Nothing has worked so far.
I wrote a compute shader that produces a histogram of log-luminance. Deriving the binning formula was fun:

Here’s the histogram produced for the helmet scene:

No wonder automatic exposure is having such a hard time. Bucket 170, which corresponds to luminances of roughly , has 3.5 million entries due to the pure white skybox. That easily wins the battle for the mean.
I’m still not sure of a good way to handle this automatically. If I were making a game engine, I’d be tempted to add ways to work around it. Exposure compensation could be applied to different parts of the map. Certain meshes could be marked as exposure targets, which would form a mask that only allows the subject’s luminance to be counted for automatic exposure. Seems like a bit of a rabbit hole.
What I learned
std140is gives a bad layout for arraysGLSL’s
std140layout gave my array of floats a stride of 16Sum the histogram counts as a sanity check
After I finished writing the histogram, I noticed that it contained an abnormally high count. I had forgotten to clear the histogram at the start of the frame. I realised that it has an invariant: the sum of counts should equal the number of pixels in my render target.
Next steps
- Review use of physical units
- Add imgui
- Implement manual exposure compensation