Set the default target exposure to the minimum value, not 0 (#13562)

# Objective

- In particularly dark scenes, auto-exposure would lead to an unexpected
darkening of the view.
- Fixes #13446.

## Solution

The average luminance should default to something else than 0.0 instead,
when there are no samples. We set it to `settings.min_log_lum`.

## Testing

I was able to reproduce the problem on the `auto_exposure` example by
setting the point light intensity to 2000 and looking into the
right-hand corner. There was a sudden darkening.

Now, the discontinuity is gone.

---------

Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
Co-authored-by: Bram Buurlage <brambuurlage@gmail.com>
This commit is contained in:
Alice Cecile 2024-05-29 18:37:42 -04:00 committed by GitHub
parent 4e72bf4751
commit 9d74e16821
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 14 deletions

View file

@ -155,26 +155,26 @@ fn compute_average(@builtin(local_invocation_index) local_index: u32) {
count += bin_count;
}
var target_exposure = 0.0;
var avg_lum = settings.min_log_lum;
if count > 0u {
// The average luminance of the included histogram samples.
let avg_lum = sum / (f32(count) * 63.0)
avg_lum = sum / (f32(count) * 63.0)
* settings.log_lum_range
+ settings.min_log_lum;
// The position in the compensation curve texture to sample for avg_lum.
let u = (avg_lum - compensation_curve.min_log_lum) * compensation_curve.inv_log_lum_range;
// The target exposure is the negative of the average log luminance.
// The compensation value is added to the target exposure to adjust the exposure for
// artistic purposes.
target_exposure = textureLoad(tex_compensation, i32(saturate(u) * 255.0), 0).r
* compensation_curve.compensation_range
+ compensation_curve.min_compensation
- avg_lum;
}
// The position in the compensation curve texture to sample for avg_lum.
let u = (avg_lum - compensation_curve.min_log_lum) * compensation_curve.inv_log_lum_range;
// The target exposure is the negative of the average log luminance.
// The compensation value is added to the target exposure to adjust the exposure for
// artistic purposes.
let target_exposure = textureLoad(tex_compensation, i32(saturate(u) * 255.0), 0).r
* compensation_curve.compensation_range
+ compensation_curve.min_compensation
- avg_lum;
// Smoothly adjust the `exposure` towards the `target_exposure`
let delta = target_exposure - exposure;
if target_exposure > exposure {

View file

@ -111,7 +111,7 @@ fn setup(
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 5000.0,
intensity: 2000.0,
..default()
},
transform: Transform::from_xyz(0.0, 0.0, 0.0),