Skip to content

Meter the lowest histogram bin in auto exposure - #25798

Merged
alice-i-cecile merged 3 commits into
bevyengine:mainfrom
stuartparmenter:fix/auto-exposure-bin-zero
Sep 20, 2026
Merged

alice-i-cecile merged 3 commits into
bevyengine:mainfrom
stuartparmenter:fix/auto-exposure-bin-zero

Conversation

@stuartparmenter

@stuartparmenter stuartparmenter commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Objective

Auto exposure can make a sudden adjustment when most of the view becomes dark.

To work out how much to brighten or darken the image, auto exposure groups pixels by luminance in a histogram, filters out a percentage of the darkest and brightest samples, and averages the rest.

The problem is that pixels below AutoExposure::range count toward the filtering percentages but get skipped when calculating the average. As the view gets darker, the average still depends on the brighter samples. Once those are all filtered out, it falls back to the minimum luminance, making the target exposure jump.

Solution

Include the darkest pixels in the average too. They go into histogram bin 0 and are treated as having the minimum luminance. That lets the average decrease as more of the view gets dark, without the jump when only dark samples remain.

The filter and metering_mask settings can still be used to leave dark pixels out.

Testing

In addition to testing as part of my Zorah work, I built tests that add more dark pixels in steps and check the exposure against expected values. They reproduce the jump before the fix and show gradual changes afterward. Also checked different luminance ranges, filter settings, and metering masks.


This was AI assisted w/ Fable 5.1 & Astra as part of my work to get the Zorah scene working, which has a lot of very bright and very dark areas, and I was noticing weird behavior after I added auto exposure in, so had the LLM help track it down, put together a fix, and then visually confirm it was fixed. Then built explicit tests to validate exact measurable behavior. Reviewed everything carefully & cleaned it up a bit before posting.

@stuartparmenter stuartparmenter added the A-Rendering Drawing game state to the screen label Sep 15, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Sep 15, 2026
@stuartparmenter stuartparmenter added C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 15, 2026
@alice-i-cecile alice-i-cecile added the C-Refinement Improves output quality, without fixing a clear bug or adding new functionality. label Sep 15, 2026

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave a quick migration guide note? This is the sort of thing that people are going to be baffled by and struggle to track down, even though I think that this is a reasonable refinement.

Otherwise I like this PR and think it's correct: I have some exposure to this stuff via photography and think that this is a better approach than our previous one.

@alice-i-cecile alice-i-cecile added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Sep 15, 2026
@Zeophlite Zeophlite added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 19, 2026
@alice-i-cecile
alice-i-cecile added this pull request to the merge queue Sep 20, 2026
Merged via the queue into bevyengine:main with commit 3133d99 Sep 20, 2026
40 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Rendering Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Refinement Improves output quality, without fixing a clear bug or adding new functionality. D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants