WIP: [pr-feature][rendering][lighting] EXPOSURE: a brightness offset in EV for the finished picture (DARNER_EXPOSURE, off by default, live from F1) #305

Draft
Jesper-A wants to merge 0 commits from Jesper-A/Darner:up-exposure into main
Collaborator

Contributor role (optional)

  • Fluxer ID:

What it changes

Some scenes look too dark or too bright on a given screen. README offers GRAY SHADOW LIFT for "too dark" (and LIGHT ESTIMATE for shade and indoors). This adds one more lever: a plain brightness step for the whole picture, up or down, before the HUD is drawn. It is off by default, so nothing changes unless you turn it on.

This is a work in progress. The shader has not run on a GPU yet, and nothing has been measured or looked at in the game. The unit tests and the gates below are all there is so far. Next: a diag build and a short look in SDR and in HDR, then the results go here and WIP: comes off.

  • New switch DARNER_EXPOSURE: -2 to +2 stops (EV). The picture's light is scaled by 2 to the power of that number: +1 is twice the light, -1 is half. Unset, 0 and any text that is not a number mean off.
  • New F1 row LIGHTING > EXPOSURE: -1, -0.5, 0 (OFF), +0.5, +1 EV. It is a live row and is saved as DARNER_EXPOSURE. (The switch accepts any value from -2 to +2; the menu offers five.)
  • Where: in the plane composer's pixel shader (crates/darner-gpu/src/compose.rs), one new root constant (20 becomes 21) that carries the scale.
    • SDR: gamma 2.2 decode, scale, clamp and encode, ahead of GRAY SHADOW LIFT and the HUD blend. When the scale is 1 this step is skipped, so the shader does what it did before.
    • HDR10: the PQ-decoded scene light is scaled before the HUD is blended at paper white (host/hdr.rs has the matching round-trip test).
  • A README row in the LIGHTING table, a README switch row, a docs/findings.md entry, and the F1 texts in locales/en.json and locales/zh-CN.json.

What it does not do. It is an output-side offset only. It works on the picture the game has already exposed. It does not change the game's own auto exposure or how fast the game adapts to light (a dark room stays as slow to brighten as before). Changing that would need a hook into the game's code, which this does not attempt. Highlights the game has already clipped stay clipped, and on an 8-bit scene plane a large positive step also lifts banding. The help text in F1 and the README say that the game's own exposure stays.

Related, not fixed by this: #254 reports a phone screen that is very dark indoors and normal outside (an AMD card). EXPOSURE might make such a screen brighter, but that has not been tried, and the cause there may be elsewhere, so this PR does not claim to fix it. #100 (closed, the release discussion) has a report of a scene washed out by white haze. That looks like a different fault (the haze is not a taste setting), and this PR is not meant for it.

How it was tested

  • Tested revision: 9cc0f3d5d (one commit on main f3840d73d).
  • Commands and results (no game run, no GPU run):
    • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
    • cargo test --workspace --exclude darner-shader --locked --no-fail-fast: everything passes except one test, darner-gpu watch::tests::ask_once_by_res_splits_reservations_without_refusals. It is in a file this change does not touch. It passed when run alone, twice, and it also failed once in another of our branches' runs today, so it looks flaky. I have not looked for its cause. darner-shader was left out because it has 4 known DXIL-validation failures on this PC that this change does not touch. So the third gate as upstream states it (cargo test --workspace --locked) was not run as written.
    • cargo xtask policy: ok.
    • New tests: compose::exposure_tests (3 tests: the switch text is parsed and clamped; +1 EV is a factor of 2 in linear light; the shader source text has the new constant, the scaling before the HUD and the skip at scale 1) and host::hdr::tests::pq_exposure_round_trip (the PQ step in f64: no offset gives the signal back, and an offset scales the nits by 2^EV). One of the three exposure_tests checks the shader's source text, not what a GPU draws. None of them runs the shader.
    • There is no CI upstream; none of this is a CI result.
  • Changes a default: no. Off unless DARNER_EXPOSURE is set to a non-zero number.
  • A/B result: none. Nothing is measured, and no speed claim is made. The pass already ran; this adds one multiply per pixel (not measured).
  • Gameplay: not run yet. Planned: RTX 2070 SUPER 8 GB, Series S profile, DLSS Performance, SDR and HDR, EXPOSURE at -1 and +1 against OFF, looking for clipping, banding and whether the HUD stays unchanged.
  • Shader wave sizes tested: not relevant (a pixel shader of the composer; no title shader is changed).
  • Hardware dependence: see "Spec dependence" below.
  • Coverage gaps: the shader has not been compiled and run on a GPU by us; the SDR and HDR10 branches have not been looked at; banding at +1 on an 8-bit plane is expected but not seen; a monitor in HDR is needed for the HDR check; the full cargo test --workspace --locked gate; the F1 row (layout, saving, the OFF label) has only been checked by reading.

Spec dependence. Likely general: the change is in the output composer and has nothing GPU-specific in it. May depend on our specs: how it looks (banding at +1, clipping) depends on the scene plane's format and the title's own tone mapping, and we only have a Series S profile with DLSS Performance on an RTX 2070 SUPER (Turing, 8 GB, ReBAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320). Untested elsewhere: AMD and Intel cards, Series X, other DLSS modes, other monitors.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Not yet; that is why this is WIP:.
  • This PR contains one change based on main. (One commit on f3840d73d.)
  • The diff follows docs/asset-policy.md. (Text only; cargo xtask policy ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found about exposure, brightness or gamma (searched the open and closed pull requests and issues for "exposure", "brightness", "gamma", "DARNER_EXPOSURE", "SHADOW_LIFT", "overexposed" and "too dark"). Open PRs that change the same files with different changes: #143 (ASPECT RATIO) and #75 (ULTRAWIDE) both touch compose.rs, host/menu.rs and locales/en.json (#75 also README.md); #302, #297, #289, #255, #217, #205, #196, #175, #154, #146, #145, #80, #48, #47, #16, #12 and #9 touch host/menu.rs, and a few also locales/en.json. Expect small merge conflicts in the F1 menu table and the locale file. This is a draft, so the branch stays on its base for now.
  • Replaces or overlaps: none found.

This change was made with AI assistance (Claude Code).

## Contributor role (optional) - Fluxer ID: ## What it changes Some scenes look too dark or too bright on a given screen. README offers GRAY SHADOW LIFT for "too dark" (and LIGHT ESTIMATE for shade and indoors). This adds one more lever: a plain brightness step for the whole picture, up or down, before the HUD is drawn. It is off by default, so nothing changes unless you turn it on. **This is a work in progress.** The shader has not run on a GPU yet, and nothing has been measured or looked at in the game. The unit tests and the gates below are all there is so far. Next: a diag build and a short look in SDR and in HDR, then the results go here and `WIP:` comes off. - New switch `DARNER_EXPOSURE`: -2 to +2 stops (EV). The picture's light is scaled by 2 to the power of that number: +1 is twice the light, -1 is half. Unset, 0 and any text that is not a number mean off. - New F1 row LIGHTING > EXPOSURE: -1, -0.5, 0 (OFF), +0.5, +1 EV. It is a live row and is saved as `DARNER_EXPOSURE`. (The switch accepts any value from -2 to +2; the menu offers five.) - Where: in the plane composer's pixel shader (`crates/darner-gpu/src/compose.rs`), one new root constant (20 becomes 21) that carries the scale. - SDR: gamma 2.2 decode, scale, clamp and encode, ahead of GRAY SHADOW LIFT and the HUD blend. When the scale is 1 this step is skipped, so the shader does what it did before. - HDR10: the PQ-decoded scene light is scaled before the HUD is blended at paper white (`host/hdr.rs` has the matching round-trip test). - A README row in the LIGHTING table, a README switch row, a `docs/findings.md` entry, and the F1 texts in `locales/en.json` and `locales/zh-CN.json`. **What it does not do.** It is an output-side offset only. It works on the picture the game has already exposed. It does not change the game's own auto exposure or how fast the game adapts to light (a dark room stays as slow to brighten as before). Changing that would need a hook into the game's code, which this does not attempt. Highlights the game has already clipped stay clipped, and on an 8-bit scene plane a large positive step also lifts banding. The help text in F1 and the README say that the game's own exposure stays. Related, not fixed by this: #254 reports a phone screen that is very dark indoors and normal outside (an AMD card). EXPOSURE might make such a screen brighter, but that has not been tried, and the cause there may be elsewhere, so this PR does not claim to fix it. #100 (closed, the release discussion) has a report of a scene washed out by white haze. That looks like a different fault (the haze is not a taste setting), and this PR is not meant for it. ## How it was tested - Tested revision: `9cc0f3d5d` (one commit on main `f3840d73d`). - Commands and results (no game run, no GPU run): - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. - `cargo test --workspace --exclude darner-shader --locked --no-fail-fast`: everything passes except one test, `darner-gpu` `watch::tests::ask_once_by_res_splits_reservations_without_refusals`. It is in a file this change does not touch. It passed when run alone, twice, and it also failed once in another of our branches' runs today, so it looks flaky. I have not looked for its cause. `darner-shader` was left out because it has 4 known DXIL-validation failures on this PC that this change does not touch. So the third gate as upstream states it (`cargo test --workspace --locked`) was **not** run as written. - `cargo xtask policy`: ok. - New tests: `compose::exposure_tests` (3 tests: the switch text is parsed and clamped; +1 EV is a factor of 2 in linear light; the shader source text has the new constant, the scaling before the HUD and the skip at scale 1) and `host::hdr::tests::pq_exposure_round_trip` (the PQ step in f64: no offset gives the signal back, and an offset scales the nits by 2^EV). One of the three `exposure_tests` checks the shader's source text, not what a GPU draws. None of them runs the shader. - There is no CI upstream; none of this is a CI result. - Changes a default: no. Off unless `DARNER_EXPOSURE` is set to a non-zero number. - A/B result: none. Nothing is measured, and no speed claim is made. The pass already ran; this adds one multiply per pixel (not measured). - Gameplay: **not run yet.** Planned: RTX 2070 SUPER 8 GB, Series S profile, DLSS Performance, SDR and HDR, EXPOSURE at -1 and +1 against OFF, looking for clipping, banding and whether the HUD stays unchanged. - Shader wave sizes tested: not relevant (a pixel shader of the composer; no title shader is changed). - Hardware dependence: see "Spec dependence" below. - Coverage gaps: the shader has not been compiled and run on a GPU by us; the SDR and HDR10 branches have not been looked at; banding at +1 on an 8-bit plane is expected but not seen; a monitor in HDR is needed for the HDR check; the full `cargo test --workspace --locked` gate; the F1 row (layout, saving, the OFF label) has only been checked by reading. **Spec dependence.** Likely general: the change is in the output composer and has nothing GPU-specific in it. May depend on our specs: how it looks (banding at +1, clipping) depends on the scene plane's format and the title's own tone mapping, and we only have a Series S profile with DLSS Performance on an RTX 2070 SUPER (Turing, 8 GB, ReBAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320). Untested elsewhere: AMD and Intel cards, Series X, other DLSS modes, other monitors. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). **Not yet; that is why this is `WIP:`.** - [x] This PR contains one change based on `main`. (One commit on `f3840d73d`.) - [x] The diff follows `docs/asset-policy.md`. (Text only; `cargo xtask policy` ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found about exposure, brightness or gamma (searched the open and closed pull requests and issues for "exposure", "brightness", "gamma", "DARNER_EXPOSURE", "SHADOW_LIFT", "overexposed" and "too dark"). Open PRs that change the same files with different changes: #143 (ASPECT RATIO) and #75 (ULTRAWIDE) both touch `compose.rs`, `host/menu.rs` and `locales/en.json` (#75 also README.md); #302, #297, #289, #255, #217, #205, #196, #175, #154, #146, #145, #80, #48, #47, #16, #12 and #9 touch `host/menu.rs`, and a few also `locales/en.json`. Expect small merge conflicts in the F1 menu table and the locale file. This is a draft, so the branch stays on its base for now. - Replaces or overlaps: none found. This change was made with AI assistance (Claude Code).
The plane composer multiplies the scene's linear light by 2^EV before the
interface is blended: gamma 2.2 decode, scale, encode, clamp in the SDR branch
(ahead of GRAY SHADOW LIFT), PQ decode, scale, encode, clamp in the HDR10
branch. -2 to +2 accepted; F1 LIGHTING offers -1, -0.5, 0 (OFF), +0.5, +1.
Output side only: the game's own exposure and adaptation speed are unchanged.
Unset or 0: a scale of 1, the SDR branch is skipped.

This change was made with AI assistance (Claude Code).
First-time contributor

One scope detail before the SDR/HDR run. The exposure math is in ps and ps_pq. In Host::present_planes, a full-size plane without an overlay goes through CopyResource when the formats match. Packed formats use ps_single, which also skips exposure. The F1 row will be visible on those paths, but changing it has no effect there.

Could the README and F1 help say that exposure applies when the plane compositor is active? A positive test can check for display output: compositing the planes while changing EV. This would keep the before-HUD promise scoped to frames where we can still separate the scene from the interface.

One scope detail before the SDR/HDR run. The exposure math is in `ps` and `ps_pq`. In `Host::present_planes`, a full-size plane without an overlay goes through `CopyResource` when the formats match. Packed formats use `ps_single`, which also skips exposure. The F1 row will be visible on those paths, but changing it has no effect there. Could the README and F1 help say that exposure applies when the plane compositor is active? A positive test can check for `display output: compositing the planes` while changing EV. This would keep the before-HUD promise scoped to frames where we can still separate the scene from the interface.
The offset was only in the plane composer's ps and ps_pq. ps_single now
applies it too (a plain multiply on linear float planes, PQ maths on an
HDR10 output), and a whole plane that would be copied is drawn instead
while the offset is set: a float plane by the single-plane composer,
any other by the plane composer. With the offset off nothing changes:
the same copy, no extra pass.

This change was made with AI assistance (Claude Code).
Author
Collaborator

Thanks, that is a real gap, and the code path you traced is right.

We took the other route and extended the code instead of narrowing the docs. New commit 170688480 on the PR head (up-exposure):

  • ps_single now applies the exposure offset.
  • While the offset is active and the output is not HDR10-composed, present_placed no longer takes the CopyResource shortcut. A whole plane without an overlay goes through the plane composer. A linear FP16 plane goes through the single-plane composer.
  • With the offset off, the paths are unchanged. One difference: the switch is now read once per present (an env read). We may cache it.
  • In ps_single, the non-PQ branch is a plain multiply with no clamp. The planes that reach it are linear floats, so a 2.2 decode/encode round trip and a clamp would clip HDR values. A PQ output still decodes, scales and encodes.
  • README and docs/findings.md now say the offset applies on every present path.

Checked so far, on 170688480: cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features are clean. cargo test -p darner-gpu --locked gave 1761 passed and 1 failed, a known flaky watch test that passed on rerun. cargo xtask policy is ok. I did not run the full cargo test --workspace --locked.

Not tested: nothing has run on a GPU yet. The SDR, HDR10, FP16 and packed-float look, and the cost of the extra draw, come with the in-game run.

On the positive check: display output: compositing the planes is logged once per run and already fires for any overlay or placed plane, so it will likely be in the log from normal HUD play before EV changes, and a whole FP16 plane (single-plane composer) never logs it. So it is not proof that exposure is applied. We will judge the change from the picture, on a scene without the HUD as well as with it.

This comment was written with AI assistance (Claude Code).

Thanks, that is a real gap, and the code path you traced is right. We took the other route and extended the code instead of narrowing the docs. New commit `170688480` on the PR head (`up-exposure`): - `ps_single` now applies the exposure offset. - While the offset is active and the output is not HDR10-composed, `present_placed` no longer takes the `CopyResource` shortcut. A whole plane without an overlay goes through the plane composer. A linear FP16 plane goes through the single-plane composer. - With the offset off, the paths are unchanged. One difference: the switch is now read once per present (an env read). We may cache it. - In `ps_single`, the non-PQ branch is a plain multiply with no clamp. The planes that reach it are linear floats, so a 2.2 decode/encode round trip and a clamp would clip HDR values. A PQ output still decodes, scales and encodes. - README and `docs/findings.md` now say the offset applies on every present path. Checked so far, on `170688480`: `cargo clippy --workspace --all-targets --locked -- -D warnings` and the same with `--all-features` are clean. `cargo test -p darner-gpu --locked` gave 1761 passed and 1 failed, a known flaky watch test that passed on rerun. `cargo xtask policy` is ok. I did not run the full `cargo test --workspace --locked`. Not tested: nothing has run on a GPU yet. The SDR, HDR10, FP16 and packed-float look, and the cost of the extra draw, come with the in-game run. On the positive check: `display output: compositing the planes` is logged once per run and already fires for any overlay or placed plane, so it will likely be in the log from normal HUD play before EV changes, and a whole FP16 plane (single-plane composer) never logs it. So it is not proof that exposure is applied. We will judge the change from the picture, on a scene without the HUD as well as with it. This comment was written with AI assistance (Claude Code).
First-time contributor

Thanks for covering the whole-plane paths. There is one more fallback issue on 170688480. If the regular composer is still pending or cannot be created, show_base_only calls back through present_planes. With exposure active, a whole SDR plane then selects the same composer again.

4bc7d8c makes that retry a base-only present, so a copyable plane can be shown while the composer is unavailable. In the synthetic routing check, both an SDR plane with an overlay and a whole SDR plane went from repeated composer attempts to one attempt followed by a copy. The no-exposure, explicit output-format and linear FP16 cases retained their behavior. The focused GPU crate type check and asset policy passed. GPU output remains to be checked on the same bench as the exposure change.

If you cherry-pick or rebase the contribution, please keep the Git author. If you fold it into your own commit, please add this trailer.

Co-authored-by: andrewpozdnakov7-jpg <[email protected]>

Thanks for covering the whole-plane paths. There is one more fallback issue on 170688480. If the regular composer is still pending or cannot be created, `show_base_only` calls back through `present_planes`. With exposure active, a whole SDR plane then selects the same composer again. [4bc7d8c](https://git.gtahub.st/andrewpozdnakov7-jpg/Darner/commit/4bc7d8c3392685ea231a6032d5c3119cabd1bcf9) makes that retry a base-only present, so a copyable plane can be shown while the composer is unavailable. In the synthetic routing check, both an SDR plane with an overlay and a whole SDR plane went from repeated composer attempts to one attempt followed by a copy. The no-exposure, explicit output-format and linear FP16 cases retained their behavior. The focused GPU crate type check and asset policy passed. GPU output remains to be checked on the same bench as the exposure change. If you cherry-pick or rebase the contribution, please keep the Git author. If you fold it into your own commit, please add this trailer. `Co-authored-by: andrewpozdnakov7-jpg <296776509+[email protected]>`
Contributor

Code review only (read the diff at 1706884), nothing built or run. The forge's "not mergeable" is the WIP/draft state: the branch sits on the current main tip, so it has no conflict with main itself.

  • Likely crash in the fallback (more than repeated attempts): with the offset on, show_base_only re-enters present_planes with no overlay, and a whole plane now selects the composer again. If Composer::new keeps failing, or composer_aside is still pending with DARNER_COMPOSER_ASIDE=1, it calls show_base_only again with nothing to stop it. That is unbounded recursion, so likely a stack overflow, where main ends in a CopyResource. 4bc7d8c above (a base-only retry) fixes it. Passing "exposure off" into the fallback would too.
  • Frame generation: DLSS-FG and FSR get the pre-composer scene as HUD-less colour, while the back buffer is scaled by 2^EV. Where frame generation finds the HUD by difference (always in HDR10; in SDR with #344 when a Darner overlay is drawn), every pixel then differs. Worth including FG on, EXPOSURE ±1 in the planned in-game run. GRAY SHADOW LIFT already has the same mismatch on main, to a lesser degree.
  • Small: exposure_ev() reads the environment twice per present. An atomic set by the live F1 row would avoid that.
  • Checked and fine: parsing and clamping, the 21-constant root signature, unset shown as OFF, and the scale-1 path leaving routing and shaders as on main.
  • Overlaps: #75 and #143 change the same composer constants and shader, so expect a conflict on CONSTANTS. #344 changes Host::present next to this and interacts as above. The fog and sparkle reports (#20, #206) are not addressed by an output offset, as the description already says.

Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.

Code review only (read the diff at `1706884`), nothing built or run. The forge's "not mergeable" is the WIP/draft state: the branch sits on the current `main` tip, so it has no conflict with `main` itself. - **Likely crash in the fallback (more than repeated attempts):** with the offset on, `show_base_only` re-enters `present_planes` with no overlay, and a whole plane now selects the composer again. If `Composer::new` keeps failing, or `composer_aside` is still pending with `DARNER_COMPOSER_ASIDE=1`, it calls `show_base_only` again with nothing to stop it. That is unbounded recursion, so likely a stack overflow, where `main` ends in a `CopyResource`. `4bc7d8c` above (a base-only retry) fixes it. Passing "exposure off" into the fallback would too. - **Frame generation:** DLSS-FG and FSR get the pre-composer `scene` as HUD-less colour, while the back buffer is scaled by 2^EV. Where frame generation finds the HUD by difference (always in HDR10; in SDR with #344 when a Darner overlay is drawn), every pixel then differs. Worth including FG on, EXPOSURE ±1 in the planned in-game run. GRAY SHADOW LIFT already has the same mismatch on `main`, to a lesser degree. - Small: `exposure_ev()` reads the environment twice per present. An atomic set by the live F1 row would avoid that. - Checked and fine: parsing and clamping, the 21-constant root signature, unset shown as OFF, and the scale-1 path leaving routing and shaders as on `main`. - Overlaps: #75 and #143 change the same composer constants and shader, so expect a conflict on `CONSTANTS`. #344 changes `Host::present` next to this and interacts as above. The fog and sparkle reports (#20, #206) are not addressed by an output offset, as the description already says. Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'up-exposure:Jesper-A-up-exposure'
git switch 'Jesper-A-up-exposure'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'Jesper-A-up-exposure'
git switch 'Jesper-A-up-exposure'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Jesper-A-up-exposure'
git switch 'Jesper-A-up-exposure'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Jesper-A-up-exposure'
git switch 'main'
git merge --squash 'Jesper-A-up-exposure'
git switch 'main'
git merge --ff-only 'Jesper-A-up-exposure'
git switch 'main'
git merge 'Jesper-A-up-exposure'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!305
No description provided.