Bevy renders internally in HDR (the Hdr camera component), but at the end of
every frame it squeezes the image into 8-bit sRGB and assumes a standard SDR monitor on the other side. This
work teaches Bevy what a display actually is, and how to drive a real HDR one: how bright it gets, which
colors it can show, which signal it expects. It senses those capabilities from the OS where it can, merges
them with the calibration the project asks for, and feeds the result to the tone mapper and display encoder.
Along the way I add a wide working color space (Rec.2020) and port the full Gran Turismo 7 tone-mapping
system (operator, lens glare, physiological auto-exposure, auto white balance) from Polyphony's
SIGGRAPH 2025 talk.
I wanted one thing to stay true no matter what: an existing SDR project renders the same image it always has, byte-for-byte. HDR shouldn't cost anything to a project that never asks for it. So every HDR feature is opt-in, gated behind conditional shader defs: a default project compiles exactly the shaders it does today. There are two deliberate exceptions, both spelled out in “One tone-mapping path” below.
| nit | A unit of brightness (candela/m²). A typical SDR monitor peaks around 100–300 nits; HDR displays reach 1,000–10,000. |
| paper white | The brightness of “plain white”, a white UI panel or a sheet of paper in the scene. On HDR displays it sits well below peak so highlights have headroom. SDR default: 100 nits. |
| gamut | The range of colors a display can show, defined by its red/green/blue primaries. Rec.709 is the SDR standard; Rec.2020 is the much wider HDR standard. |
| transfer function | How linear light values are encoded into the numbers sent to the display. sRGB (SDR), scRGB (linear float, 1.0 = 80 nits), extended-sRGB (the same range but sRGB-gamma-encoded, the web's HDR path), and PQ (HDR10, absolute brightness up to 10,000 nits). |
| scene-linear | Light values proportional to physical light, unbounded (the sun is allowed to be 100,000× brighter than a wall). All rendering happens here; tone mapping compresses it for the display at the very end. |
I split the end of the frame into clean, separate stages. Tone mapping decides how bright things look; the new display encoder decides how to express that for a particular display. Nothing upstream of the encoder knows or cares what kind of display is attached.
The core is complete. Where things stand, at a glance:
| Area | Status |
|---|---|
| wgpu HDR surface support: the surface color-space API (wgpu#9658) and the read-only display query (wgpu#9739), the platform prerequisite for HDR surface output and display sensing. Both ship in wgpu v30, which Bevy depends on from crates.io. | upstream |
Display description (DisplayTarget), the separated tone-map → gamut → transfer pipeline, scRGB / extended-sRGB / PQ surface output (Rec.709 and wide-gamut Display-P3) | implemented |
| Rec.2020 working space, color & asset foundations, gamut compression, AA/bloom HDR correctness, calibration example | implemented |
| GT7 system: operator, glare, auto exposure, auto white balance | implemented |
Display-capability query & auto-calibration: the OS→EffectiveDisplayTarget sensing path, with per-field auto-resolve and event-driven re-query | implemented |
| UI & gizmos on HDR: writer-side compositing-space encode and Rec.709 → working-gamut conversion | implemented |
The central new concept is DisplayTarget (in bevy_window): a small plain-data
description of the display a render target is headed for. It is a required component on every
Window, defaulting to DisplayTarget::SDR_SRGB, which is why nothing changes
until you ask for more.
| Field | Meaning | SDR default |
|---|---|---|
paper_white_nits | How bright “plain white” should be | 100 |
peak_luminance_nits | The brightest the display can go | 100 |
min_luminance_nits | Black floor (calibration metadata) | 0 |
gamut | Rec709 · DisplayP3 · Rec2020 | Rec709 |
transfer | Srgb · ScRgbLinear · ExtendedSrgb · Pq | Srgb |
Image or TextureView) get theirs from the
ManualDisplayTargets resource; anything unlisted is treated as SDR sRGB.WindowSurfaceTransfers::resolved so an app can tell when an HDR request resolved to SDR.EffectiveDisplayTarget,
below). DisplayTarget itself stays exactly as authored. When a
window moves between monitors its OnMonitor relationship is retargeted, so the app can
watch Changed<OnMonitor> and decide whether to re-calibrate.DisplayTarget::SDR_SRGB.with_paper_white(200.0).with_peak(1000.0).with_transfer(DisplayTransfer::ScRgbLinear).How it reaches the GPU. Bevy packs the resolved paper white into a small per-view uniform once per frame — the gamut and transfer never travel as data; they select compile-time shader defs in the encoder pipeline — and only the display encoder binds it (to scale the encode for the display), so it shows up only on the HDR-transfer targets the encoder actually runs on. The tone-mapping pass needs no display calibration at all: it outputs “1.0 = paper white” and leaves encoding to the encoder, and Bevy computes GT7's HDR parameters on the CPU into the operator's own per-camera uniform. So an SDR camera's tone-mapping pipeline carries nothing display-specific (the same bindings it had before HDR), and the only conditional binding left in that pass is GT7's params.
DisplayTarget is what the project wants. But four different things have an opinion about
how to drive a display, and they update on completely different clocks. So I keep them as four
separate components; Bevy merges them once per frame, in the main
world, into a single derived EffectiveDisplayTarget that the render pipeline consumes in place
of the raw DisplayTarget.
| Component | Lives on | Changes | Carries |
|---|---|---|---|
Capability · MonitorDisplayCapability | the Monitor entity | static per display | peak / full-frame / min nits and a coarse gamut hint. Every field is Option; its absence means “can't tell,” never “SDR.” |
Live state · WindowDisplayState | the Window entity | drifts per surface | the live tone_map_headroom (one cross-platform multiplier of SDR white) and the SDR-white anchor. The renderer commits a reading only once it moves past a relative epsilon, and mirrors it back insert-on-change, so Changed<WindowDisplayState> marks a real transition rather than read jitter. |
Intent · DisplayTarget + DisplayCalibrationPolicy | the Window entity | user-authored | the calibration you want, plus per-field auto_* booleans saying which fields the engine may fill from sensing. |
Effective · EffectiveDisplayTarget | the Window entity (required, engine-written) | recomputed each frame | the merged DisplayTarget the pipeline actually uses, plus per-field DisplayProvenance recording why each value won. |
Opt-in, per field. DisplayCalibrationPolicy defaults to all-manual, and a manual
field is copied from DisplayTarget verbatim, so a project that never
touches the policy gets an EffectiveDisplayTarget equal to its DisplayTarget
field-for-field, and renders byte-identically. Only the fields a project explicitly flips on
(auto_paper_white, auto_peak_luminance, auto_min_luminance,
auto_gamut) ever take a sensed value. Transfer is deliberately not a policy field
(see below).
The precedence ladder. For each auto field the resolver walks a fixed ranking, highest wins:
| Rank | Source | Provenance tag |
|---|---|---|
| 1 | explicit user value (the field is manual) | User |
| 2 | OS-sensed (capability + live state) | Os |
| 3 | the SDR_SRGB fallback | Default |
Three rungs, because three is what a platform can reach. Two more belong in the ranking between
the user value and OS-sensed — an HDR-game-interface (HGIG) live override, then an engine policy — and I
kept both out of the code: neither wgpu nor winit exposes a channel that could fill them (the HGIG push is
console-SDK territory), and a rung nothing can stand on is a public enum variant Bevy would have to explain
forever. The order is recorded as prose on resolve, so the day a console fork gains an HGIG
push it slots in there. Note that the HGIG procedure already lands at rank 1 on this branch: the
calibration wizard's manual mode keeps every field manual, so the numbers a player tunes are the authored
ones. The engine never writes
DisplayTarget; the GT7 operator's parameter clamps still sit
below the whole ladder, so a resolved request flows into the same clamps an authored
one does. DisplayProvenance records the winning rank per resolvable field (the transfer has
no entry — it is never auto-resolved), so a calibration UI can show
whether a number came from the user, the OS, or the default.
Two render-world systems and a main-world merge, all under WindowRenderPlugin.
poll_display_state reads each surface's live state through wgpu, which folds the platforms'
incompatible reports (Windows absolute nits, Apple's unitless EDR headroom, the web's coarse HDR flag) into
the single cross-platform tone_map_headroom the table above lists; it re-reads only when the backing
display can have moved: a surface (re)configure, a window move / focus / monitor event, or, for Apple's
event-less EDR drift, every frame while an HDR surface is auto-calibrating. write_back_display_state
mirrors each committed change to the main world, where resolve_calibration merges it
into the authored target under the project's policy before extraction, so the resolved EffectiveDisplayTarget
reaches the render pipeline with zero frame lag. Off-screen ManualDisplayTargets skip that merge
entirely and are extracted as authored: with no window entity there is no policy and nothing sensed to
merge against, so resolution for them would be the identity. The screenshot decode path reads the
authored map directly.
need_surface_configuration → a swapchain rebuild, below). A sensed gamut that disagrees
with the transfer is coerced to fit at encode time with a warn_once, but sensing never rewrites
the transfer, so advisory drift can't trigger a swapchain churn. The transfer stays whatever the project
asked for, and carries no provenance entry — there is nothing to track.
Bevy used to tone-map SDR cameras inside each material shader (six separate call sites), while HDR cameras went through a post-process node: two divergent paths that made a separated encoder impossible. So I moved everyone onto one path: every camera with tone mapping enabled now runs the same post-process node, and I keep the in-shader path only as an opt-out-free SDR fast path for cameras that can't tell the difference (see Retaining the SDR fast path below). What that means for every camera on the node-side path:
Rgba16Float so highlight data above
1.0 survives until the tone-map runs. A camera on an HDR-transfer target (PQ/HDR10) gets the fp16
intermediate too, even with Tonemapping::None, the encoder still needs unclamped
display-linear input, so the main pass never renders straight into the 10-bit Rgb10a2Unorm
swapchain (which would clamp at 1.0 before the encode). This is deliberate change #1: default SDR scenes show
slightly less banding (quantization now happens once, at the end), at the cost of doubled
main-texture memory.Tonemapping::None is now a true passthrough (no grading, no dither), and a new
Tonemapping::Linear covers the old in-between: color grading and exposure with no
tone curve.
Retaining the SDR fast path. The doubled memory and extra sampling pass are real costs on tiled mobile
GPUs, so I keep the old in-shader fold as a fast path that a camera uses automatically when it
qualifies, dropping back to the node path the moment it doesn't. A camera qualifies only when
all of these hold: the target is a plain SDR_SRGB window; tone mapping is
enabled; it is the sole camera on that target; it uses linear compositing (the default; an explicit
Srgb or Oklab space needs the node path); and nothing reads the pre-tone-map HDR
buffer (no bloom, auto exposure, depth of field, motion blur, TAA, DLSS, or custom
GranTurismo7Params). Such a camera keeps its 8-bit Rgba8UnormSrgb main texture and
the tone-map node skips it, reproducing the pre-HDR SDR pipeline exactly. The disqualifiers reach camera
extraction as required-component markers, so a veto is sticky: after a plain remove of bloom,
or of a camera's GranTurismo7Params, the marker stays and so does the node path.
Camera stacks. Several cameras can share one render target; when each later one composites over the
previous output full-screen instead of clearing it (ClearColorConfig::None), they form a
stack backed by a single main-texture buffer. The fullscreen end-of-frame passes (tone mapping,
this encoder, the final blit) therefore run once on the last camera in the stack, not once per
camera, so already-composited pixels are never processed twice. (The full resolution rules live in
the composition contract below.)
A new node (bevy_core_pipeline::display_encoding) sits after tone mapping and runs once per
camera stack, so stacked cameras and UI all composite in one shared space (display-linear,
1.0 = paper white) before a single encode. Its three stages mirror the diagram above. The transfer
functions (scRGB linear, the odd-symmetric extended-range sRGB OETF, PQ)
are the first real shader-side OETFs in Bevy, each with a CPU mirror and unit tests against the published
standards. The gamut transform reaches Rec.709, Rec.2020, and Display-P3 (the wide-gamut HDR path),
with full-precision 709/2020→P3 matrices alongside the existing 709↔2020 pair. Its
source inputs, which primaries the buffer is in and which compositing space it was
composed in, come from the per-stack composition contract (below),
so a stack tone-mapped by one camera and encoded by another is keyed to the buffer's actual contents.
The unit conventions at the seam are the load-bearing contract:
| Stage | Convention |
|---|---|
| Tone-map output | 1.0 = paper white (operators renormalize by 100 / paper_white_nits) |
| scRGB encode | multiply by paper_white_nits / 80 (scRGB defines 1.0 = 80 nits) |
| extended-sRGB encode | the same paper_white_nits / 80 scaling, then the odd-symmetric (sign-preserving) sRGB OETF; the final max(0) clip is skipped so it can carry the extended range |
| PQ encode | multiply by paper_white_nits to get absolute nits, encode against the 10,000-nit PQ curve |
A camera's CompositingSpace is a request, and so is the display transfer on its
DisplayTarget. What those requests mean for a given camera depends on its neighbors on a
shared render target, and several consumers (tone mapping, the display encoder, the final blit)
all have to agree on the answer. Bevy resolves it once per frame, in two phases, into state every
consumer reads.
ResolvedCompositingSpace, a per-view component in bevy_render). Cameras that
share one main-texture ping-pong are grouped, and each group resolves to one compositing space.
A solo camera or a non-stack shape (cameras that clear, or render to a viewport) keeps its own request
verbatim; a compositing stack (every camera after the first composites over the previous output
full-screen) collapses to a single space: the one space its members request, or linear if they
disagree (with a warning) or if any member is not a 2D camera (the 3D path does not encode into a
compositing space). UI and 2D gizmos drawn over a 2D camera do writer-encode into the resolved
Srgb/Oklab space, and, like sprites, convert their
Rec.709-authored colors to the buffer's working primaries on a Rec.2020 (GT7) HDR view so saturated
colors don't oversaturate (3D gizmos get the gamut conversion only). This is the “requested vs
resolved” split applied to compositing, exactly as DisplayTarget already splits it for
the display.ViewStackContract, in bevy_core_pipeline). One analysis of
each render target's camera stack produces a per-view contract: each view's role for the tone-map pass
and (separately) the display-encode pass (Solo, Deferred to a finalizer,
or Finalizer), plus its blit disposition, its resolved compositing space, the color
primaries the encoder should treat the buffer as holding, and the resolved encode parameters. Tone
mapping, the display encoder, and the upscaling blit all read this one component.
The two pass roles stay distinct on purpose: a Tonemapping::None overlay can legitimately
make one camera finalize tone mapping and a different camera finalize encoding. They are tied together by a
single coherence rule: encoding can never be deferred past a camera that tone mapping wants to
defer over (that would encode a buffer before it is tone-mapped). When the stack shape would force exactly
that, tone-map deferral is cancelled for the whole stack (each camera tone-maps its own region) and Bevy
warns.
Who owns the final image. When a stack defers its passes to a finalizer, only that finalizer's blit
should reach the screen, since the earlier members' buffers are not yet tone-mapped or encoded. So every
member ordered below the finalizer skips its upscaling blit, and the finalizer (now the only blit) presents
with replace and owns the output texture, including its clear color. That clear is encoded the same way
rendered pixels are: an HDR display target gets a transfer-encoded, gamut-converted, paper-white-scaled clear
instead of a raw linear value that would read as full-peak nits in any region no camera covers. Because the
finalizer tone-maps the whole composed buffer once, its operator and grading own every member: a stacked
camera that authors a different Tonemapping operator, or different ColorGrading /
GranTurismo7Params / DebandDither, has those values discarded in favor of the
finalizer's, and Bevy warns.
Telling a surface which color space to use is a wgpu v30 API
(wgpu#9658). It adds
SurfaceColorSpace (Auto / Srgb / ExtendedSrgbLinear / DisplayP3 / Bt2100Pq / Bt2100Hlg /
ExtendedSrgb / ExtendedDisplayP3) plus per-format capability listing, and everything here is built
against its API. Bevy's negotiation
maps the requested transfer (and, for the encoded extended-range path, the requested gamut) to what the
backend advertises:
Rgba16Float + ExtendedSrgbLinear. It is the
linear extended-range encoding and is native-only (macOS/iOS Metal EDR, Windows
Vulkan/DX12, Wayland Vulkan), because the browser cannot present a linear-transfer canvas.ExtendedSrgb, Display-P3 →
ExtendedDisplayP3 (wide-gamut HDR, Metal & WebGPU), the first time a P3 surface is
negotiated.Rgb10a2Unorm + Bt2100Pq on Vulkan, DX12 and Metal when the OS
has HDR enabled.
Apps choose from the advertised set rather than guess: a surface's negotiable transfers are mirrored to the
main world as WindowSurfaceTransfers::supported, so a setup plugin (the reusable
hdr_helper example's HdrPlugin) can request the best transfer the surface actually presents. Negotiation is the safety
net behind that choice, where a requested transfer the backend can't configure is downgraded, one warning per
step: PQ to scRGB-linear and then to SDR sRGB, scRGB-linear and extended-sRGB straight to SDR. The two
extended-range encodings never swap silently (the web HDR path is reached by requesting ExtendedSrgb
explicitly), and there is no cross-gamut fallback, so a Display-P3 request never lands on a Rec.709
surface. A full drop to SDR resets the whole target to DisplayTarget::SDR_SRGB (the view is then
byte-identical to a natively-SDR one), whereas a cross-HDR step (PQ→scRGB-linear) keeps the authored
calibration and swaps only the transfer, since scRGB encoding still scales by paper_white_nits.
If the user toggles HDR off in OS settings mid-run, the surface renegotiates and the frame degrades to SDR
rather than breaking. Whatever transfer it settled on is mirrored back as WindowSurfaceTransfers::resolved
(read-only, one frame behind negotiation), so an app can tell when an HDR request resolved to SDR, and
match its UI or calibration prompts, without inspecting backend internals. Because everything Bevy-side
is written against the request/resolve model, nothing here changes as backends gain support.
The every-frame merge never provokes a renegotiation. Negotiation keys on the transfer (and, for the
encoded extended-range path, the gamut), the one thing display sensing never fills
(above). So nothing the OS→target merge does forces a surface renegotiation; the
only triggers are an explicit transfer change, a gamut change under ExtendedSrgb, and the OS
dropping HDR support out from under an HDR surface.
BloomPrefilter::threshold_nits.ExtendedDisplayP3 both converted back to
Rec.709), to one shared display-linear scale, and float captures save losslessly to
.exr.Srgb or Oklab compositing space,
UI now writer-encodes its output into that space (each UI fragment shader encodes its final color the
same way the sprite shader does), so UI lands in the same encoded buffer the rest of the camera writes
instead of dumping linear values into it. The separate UI-on-wide-display-gamut axis (Rec.709-authored
UI colors on a Rec.2020 buffer) stays the RFC follow-on (below).HdrCalibrationPlugin<S>, that an app drops into one of its own states; the
hdr_calibration example mounts it as a thin demo. The wizard (a peak-luminance test
pattern you bisect from both directions, a paper-white card next to a 203-nit BT.2408 reference strip,
and near-black steps for the black floor) writes the player's choices into DisplayTarget /
DisplayCalibrationPolicy live and emits CalibrationComplete on confirm. It
complements the automatic OS→EffectiveDisplayTarget path (above):
a project can sense what the OS knows and let the user hand-tune the rest, with
DisplayProvenance showing which numbers came from where.tests/gpu_hdr_fixture.rs)
exercises the HDR encode path end to end.
The working color space is the gamut that scene-linear math happens in, what the numbers in
lighting buffers mean. I made it project-global (RenderPlugin { working_color_space }),
not per-camera, because meshes, lights and textures are shared between cameras; per-camera spaces would
force per-draw conversions. Two values: Rec709 (the default, today's behavior, untouched)
and Rec2020 (opt-in). Saturated emissive colors, wide-gamut displays, and GT7's native gamut
all need the working space to be wider than the display.
Bevy's entire ecosystem authors colors in Rec.709/sRGB: color pickers, palettes, textures. So under
Rec2020 I keep the rule deliberately simple and global: assume everything is Rec.709-authored,
and convert it exactly once.
WORKING_COLOR_SPACE_REC2020) that is
only pushed when the setting is Rec2020; default projects compile literally the same
shaders as before.Rec2020 they convert to Rec.709
and max(0)-clip at their input, dropping any out-of-Rec.709 color, which therefore
reaches the display only on the GT7 path. The one exception: GT7 in HDR mode stays native
Rec.2020, see below.This is deliberately the simplest correct rule: a per-texture flag at general sampling sites can't know whether a value was already converted earlier in composition, and double-conversion is the classic wide-gamut bug. The cost is that textures genuinely authored in wide gamuts don't gain extra gamut yet; their source metadata is recorded (below), and consuming it per-texture at single-texture pipelines (skybox, environment maps) is a planned follow-on PR (below).
bevy_color: a first-class LinearRec2020 color space; chromaticity-accurate
primary definitions (RgbPrimaries: BT.709, BT.2020, Display P3, ACEScg) with derived
conversion matrices; and HDR-safe relaxation of [0,1] clamps in
operations like lighter()/with_luminance(): bit-identical for SDR inputs
(the SDR branch keeps the exact old clamp), well-defined above 1.0. New constructors:
Color::rec2020(), Color::display_p3(), Color::xy_y().Image::source_primaries),
read from KTX2 metadata, EXR chromaticities, and Radiance
PRIMARIES headers (glTF textures are always stamped Rec.709, as its spec mandates), with a
per-asset loader override. This is the bookkeeping that prevents the classic wide-gamut failure mode:
every existing texture silently shifting saturation when the working space changes.
When the image lives in a wider gamut than the display (GT7's Rec.2020 output onto a Rec.709-coordinate
scRGB / extended-sRGB signal, or onto a Display-P3 ExtendedDisplayP3 signal, since P3 is
narrower than Rec.2020), out-of-range colors have to be pulled inside. Hard clipping distorts hue and flattens
gradients, so the encoder uses perceptual compression in the style of the ACES 1.3 Reference Gamut
Compression: colors near the display gamut pass through bit-exactly, and only the out-of-range tail is
smoothly compressed into the edge zone, per channel. The ACES thresholds and curve are kept verbatim; the
limits were re-derived for the Rec.2020→Rec.709 case (ACES' camera-fitted limits don't cover it) by
sweeping the full Rec.2020 hull, and they comfortably over-cover the smaller Rec.2020→Display-P3
contraction. Measured hue drift is ~1–4.5° for typical out-of-gamut colors, up to
~16° at the extreme Rec.2020 blue corner; a truly hue-preserving upgrade is named follow-on
work (below). A DisplayGamutCompression resource selects
Auto (on only when the gamut stage actually contracts) / Always / Clip
(debug).
I chose GT7's tone mapper (Polyphony Digital, SIGGRAPH 2025) as Bevy's first HDR-native operator because it's the current state of the art: the one published system designed end-to-end for HDR displays rather than retrofitted from SDR. One curve family adapts its shoulder to the actual display peak, and the supporting “camera/eye” systems make HDR footage feel natural. Each piece is independently usable, except auto white balance, which rides auto exposure's metering pass and requires it.
Tonemapping::GranTurismo7, with an optional GranTurismo7Params component for
tuning. The curve has three regions (a toe that keeps shadows from washing out, a linear middle that
preserves the lighting artist's intent, and a shoulder that rolls highlights off smoothly) and one key
property: the shoulder is parameterized by the display's real peak brightness. That peak is the
resolved peak_luminance_nits from the camera's EffectiveDisplayTarget
(above), so when a project opts peak_luminance in to auto-calibration the
shoulder targets the panel's OS-sensed peak (reconstructed on macOS as the resolved paper white times the
display's live tone-map headroom) rather than a hand-entered number. Bright highlights
also desaturate toward white the way overexposed film does, computed in the ICtCp color space so hue
holds while chroma fades.
Tonemapping::None (a true passthrough — the
pass does not run) or Tonemapping::Linear (an encode with no tone curve), so a stack with
no active operator on an HDR target transfer-encodes
its scene-linear values without tone mapping and warns once. Opting a window into an HDR transfer
therefore means pairing it with GranTurismo7 (or Linear).
GT7 replaces artistic bloom weights with the actual diffraction pattern of a camera aperture (the Airy
pattern, via Fraunhofer diffraction). Bevy's port derives, for each bloom mip level, how much energy a
given f-number's diffraction pattern deposits at that radius, integrating real Bessel functions over
the visible spectrum, no magic constants. The finished per-f-stop table is baked into the source as
literals; the derivation lives in the module's tests, which re-derive it and compare bit for bit, so no
app pays the quadrature at startup. It rides the existing bloom pyramid:
Bloom::scatter = BloomScatterModel::Gt7Glare { f_number } (or the Bloom::GT7_GLARE
preset at f/5.6), composited energy-conservingly with no threshold: faint glare around every
bright source, exactly as a lens does. Zero shader changes; the physics lives entirely in the per-pass
blend weights.
GT7's insight: a camera's auto-exposure reacts in milliseconds, but human eyes take minutes, and HDR
is bright enough for that to matter. Bevy's existing AutoExposure gains an optional second
stage (physiological: Some(PhysiologicalAdaptation { .. })): the existing fast response is
clamped to a band around a slow-moving adaptation envelope that brightens at ~0.05 EV/s
(fully light-adapting in about 4 minutes) and darkens at ~0.01 EV/s (about 20 minutes: walk into
a cave and it stays dark, then your eyes slowly adjust). Also new: metering_bias, a flat EV
offset added to the metered luminance before the compensation curve is sampled. Fusing other metering
references (e.g. known sun illuminance) into that value is future work
(below).
No shipping real-time engine does this; GT7 is the prior art. The new AutoWhiteBalance
component requires AutoExposure and estimates the scene's illuminant from that shared metering dispatch (mean
chromaticity via fixed-point atomics), smooths it over time, converts it to a correlated color temperature
(McCamy's formula, clamped to 2,500–7,000 K) plus a green–magenta tint, and corrects via a
von Kries cone-response matrix composed under the user's own color grading. A
virtual_light_anchor blends a faint ideal-D65 reference in by inverse scene luminance, so
near-black scenes drift to neutral instead of chasing noise. Walk from tungsten interior to daylight and
the image re-balances over a few seconds, like your visual system does.
The design leaves clear seams for the next round of work, each independently shippable. What I'd prioritize:
Per-texture wide-gamut flags planned
Textures stamped Bt2020/DisplayP3 (via Image::source_primaries) are recorded but not yet
consumed: under the Rec.2020 working space they currently render the same as Rec.709 content,
gaining no extra gamut. The follow-on PR adds a per-pipeline shader def for single-texture sites (skybox
and environment maps first, since wide-gamut HDRIs are the dominant case) and extends to
other pipelines from there.
Lower-priority or more speculative items. Each is what it would do, what it would buy, and what would bring it forward or hold it back.
CompositorLayer for a render graph to declare its compositing intent directly, the
writer-encode mechanism extending to 3D materials, viewport and picture-in-picture cameras processing
only their own region (today they reprocess the area a later camera does not cover, the documented
split-screen/PiP limit), and a view that both tone-maps and encodes doing both in one fused pass. Mainly
for elaborate multi-camera setups.EffectiveDisplayTarget path, above). The remaining direction
is the write: tagging the swapchain with ST 2086 mastering-display metadata (the content's own
peak/primaries) so the display can tone-map what exceeds its panel. That waits on wgpu surface-metadata
support, which does not exist yet; the read direction needs no such API.ClearColorConfig::None) re-process already-tone-mapped pixels and drift; today that is
flagged with a warning. Keeping the buffer scene-referred across frames would make them stable, at the
cost of a separate presentation step, worth it when someone wants feedback effects on an HDR
target.DisplayTransfer exposes no HLG variant and HLG surfaces are never negotiated, even on
the Vulkan and Metal surfaces that expose them. HLG is scene-referred (the display applies the OOTF),
whereas the display pipeline emits display-referred, already-tone-mapped values; encoding those through
the HLG OETF would double-tone-map. A correct HLG path needs a scene-referred encoder input (a
pre-tone-map signal fed to an HLG OETF), which the pipeline does not currently produce; until then,
request PQ/HDR10 for HDR output instead. The GPU keys gamut and transfer by named shader defs
rather than numeric indices, so a DisplayTransfer::Hlg variant and its OETF can be
reintroduced without renumbering concerns once that scene-referred path exists.The branch splits into sixteen PRs, grouped into five waves. A wave's PRs are independent of each other; each wave depends only on the waves before it. Line and file counts are estimates from the current diff.
The plan is to work wave by wave: split out and submit a wave's PRs, merge review feedback back into the full branch as it lands, then cut the next wave from the updated branch and repeat. Each wave is split from a branch that already reflects upstream review, so feedback never has to be re-applied across pending PRs.
| # | PR | ~Lines added | ~Files | Depends on |
|---|---|---|---|---|
| Wave 1 · mechanical, no HDR concepts | ||||
| 1 | Incidental render infra fixes (pipelined-rendering teardown, buffer labels) | 100 | 10 | — |
| 2 | bevy_color: LinearRec2020, primaries module, HDR-safe clamps | 1,300 | 15 | — |
| 3 | Image source-primaries metadata (KTX2 / HDR / EXR / glTF) | 800 | 20 | — |
| Wave 2 · render-path backbone | ||||
| 4 | Tonemapping render path: node-based tone mapping, TonemapInShader, Tonemapping::Linear | 1,500 | 45 | — |
| 5 | Composition contract: camera stacks, ViewStackContract, writer-encode defs | 2,700 | 25 | 4 |
| Wave 3 · display target & encoding | ||||
| 6 | DisplayTarget data model in bevy_window, required on Window | 600 | 5 | — |
| 7 | Surface negotiation + downgrade, ViewDisplayTarget, DisplayTargetUniform | 2,300 | 5 | 5, 6 |
| 8 | Display-encoding pass, transfer functions (Rust + WGSL), gamut compression | 2,200 | 5 | 7 |
| 9 | HDR screenshot readback and float save | 500 | 2 | 8 |
| 10 | OS headroom sensing: WindowDisplayState, calibration policy, EffectiveDisplayTarget | 900 | 5 | 7 |
| Wave 4 · net-new features | ||||
| 11 | GT7 tone-mapping operator (gt7.rs / gt7.wgsl, GranTurismo7Params) | 1,700 | 5 | 8 |
| 12 | GT7 glare as a bloom scatter model | 800 | 5 | — |
| 13 | Physiological auto exposure + automatic white balance | 1,800 | 10 | 4 |
| 14 | Rec.2020 working color space (RenderPlugin::working_color_space) | 700 | 15 | 5 |
| 15 | AA + bloom HDR correctness (CAS, FXAA, SMAA, fp16 pyramid, threshold_nits) | 900 | 15 | 8, 12 |
| Wave 5 · examples & tests | ||||
| 16 | hdr_calibration example, HDR helper plugin, GPU test fixture, CI | 2,000 | 5 | 10, 11 |