Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

Implement adaptive exposure

Open VReaperV opened this issue 1 year ago • 12 comments

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).

VReaperV avatar Feb 21 '25 21:02 VReaperV

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.

VReaperV avatar Feb 21 '25 21:02 VReaperV

I've put some of these changes into #1563 to make this pr lighter.

VReaperV avatar Feb 24 '25 17:02 VReaperV

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:

unvanquished_2025-03-03_020134_000

unvanquished_2025-03-03_020132_000

slipher avatar Mar 03 '25 08:03 slipher

Hmm, I might've broken something with the more recent push, the changes were pretty mild when I was testing it.

VReaperV avatar Mar 03 '25 10:03 VReaperV

Rebased + fixed some issues. That should hopefully fix the drastic exposure changes as seen on the above screenshot too.

VReaperV avatar Mar 10 '25 18:03 VReaperV

LGTM

sweet235 avatar Mar 14 '25 20:03 sweet235

I found another buggy place with huge exposure changes between spots that look about the same in mxl-school.

unvanquished_2025-03-15_013605_000 unvanquished_2025-03-15_013607_000

slipher avatar Mar 15 '25 06:03 slipher

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.

VReaperV avatar Mar 15 '25 08:03 VReaperV

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.

slipher avatar Mar 15 '25 08:03 slipher

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.

VReaperV avatar Mar 15 '25 08:03 VReaperV

I found another buggy place with huge exposure changes between spots that look about the same in mxl-school.

unvanquished_2025-03-15_013605_000 unvanquished_2025-03-15_013607_000

This should be fixed now.

VReaperV avatar Mar 16 '25 19:03 VReaperV

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.

illwieckz avatar Mar 17 '25 14:03 illwieckz

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 avatar Oct 16 '25 19:10 VReaperV

@VReaperV you'll notice I kept the release published this way. So I'm not taking my own opinion as something absolute.

illwieckz avatar Oct 16 '25 19:10 illwieckz