Implement adaptive exposure
Requires #1550 and #1558 Implements #29
This builds up on #1550 by adding automatic exposure based on scene brightness.
When r_tonemapAdaptiveExposure is enabled, a compute shader gets the geometric mean of luminance before tonemapping. Then in the tonemapper this value is mapped to a curve with coefficients chosen to try to avoid sudden changes and too high/too low exposure values, and multiplied with the HDR colour.
An example of this in practice: https://users.unvanquished.net/~reaper/adaptiveLighting/adaptiveLightingGlobal.mp4
Also moved the material stuff from common_cp to material_cp. This wasn't an issue prior because only the material system used compute shaders, but now this would result in shaders failing to compile if r_materialSystem is disabled (and using macros would result in unnecessary shader re-compilations).
I'll see if I can add a non-compute path later. The compute one can also easily give histogram information for https://github.com/Unvanquished/Unvanquished/issues/221.
I've put some of these changes into #1563 to make this pr lighter.
That's a good idea. I just tested and it doesn't seem to work as expected: there are large, sudden exposure changes despite very little change in the scene. For example:
Hmm, I might've broken something with the more recent push, the changes were pretty mild when I was testing it.
Rebased + fixed some issues. That should hopefully fix the drastic exposure changes as seen on the above screenshot too.
LGTM
I found another buggy place with huge exposure changes between spots that look about the same in mxl-school.
I found another buggy place with huge exposure changes between spots that look about the same in mxl-school.
I miscalculated the max value for luminosity sum, so it does overflow sometimes. Will add a fix later.
Also the instant exposure adjustments mess up other effects that are supposed to cause rapid changes in brightness. The flickering of the firelight in metro-b1-2 alien base is almost not visible at all, being canceled out by exposure changes. When a human weapon is fired, the whole scene perversely darkens due to the luminance of the muzzle flash.
With my laptop's Nvidia card, taking a screenshot goes from no noticeable delay to a 2-second delay when adaptive exposure is enabled.
Hmm, it might be best to improve the screenshotting in some way. I don't think there's much that can be done with this from the adaptive exposure side.
Any plans to smooth out the exposure changes over time, like how the eye adapts to light maybe? For now the exposure variation seems too large and rapid to be really usable; all world surfaces are flickering when you move.
Yeah, I plan to add some exponential smoothing there.
Doors feel kind of buggy in general. There is often a bright flash when the door is opening. But maybe that's just the same thing as the preceding paragraph.
It might be due to the overflow too.
Also the instant exposure adjustments mess up other effects that are supposed to cause rapid changes in brightness. The flickering of the firelight in metro-b1-2 alien base is almost not visible at all, being canceled out by exposure changes. When a human weapon is fired, the whole scene perversely darkens due to the luminance of the muzzle flash.
Yeah, smoothing it over time should make it better, maybe some value tweaking too.
I found another buggy place with huge exposure changes between spots that look about the same in mxl-school.
![]()
This should be fixed now.
That looks nice but yes the feature should remain disabled by default until some delay / average on some time is implemented, because of the flicking when moving.
I personally consider that our current release is broken because tone mapping is enabled in some graphics preset but our default configuration for tone mapping is destroying the render, for both maps built the linear way and all existing maps built the naive way (i.e. Tremulous maps and Unvanquished stock maps, and existing community maps). I do want the tone mapping feature, this is a good thing to have and it's a required foundation for other things like adaptative exposure.
@illwieckz You want to change the "broken release" with "destroyed render" - then go fucking do it yourself.
@VReaperV you'll notice I kept the release published this way. So I'm not taking my own opinion as something absolute.
