pioneerspacesim/pioneer — Issue #933: HDR average luminance calculation incorrectly incorporates black space
Author: Ae-2222
Created: 2012-01-31 23:28:13+00:00
State: open

The HDR works by calculating an average by rendering the scene to texture and calculating the nth level mipmap which is one pixel. This is effectively an average. It then uses the average to affect the brightness using a second shader.

The problem
For example if the screen depicted a slightly dark object taking up full view the average luminance would be slightly dark. HDR would make the scene slightly brighter. If that object took 20% of the screen with black space taking 80%. The resulting value would be slightly dark *0.2. This is too low and results in overcompensation. This average needs to be divided by 0.2 to get the average of actual objects.

To solve this the object-fraction needs to be computed. This is ideally done by running a shader which gives 1.0 if the luminance is above a threshold 0 otherwise, then averaging it by RTT/mipmaps, using a threshold which is a fraction of the average. Not taking a fraction of the average results in nans for dark scenes etc.

This is a demo branch which shows the effect of compensating but uses a threshold which is fixed.
It prints out the average luminance and lit fraction so the effect can be seen by commenting out the line which adjusts the average.
https://github.com/Ae-2222/pioneer/tree/fixhdr

.