Repository navigation
feat!: anchored exposure, an atmosphere type, and snow that knows what shape it is - #88
Merged
Merged
Conversation
Turbidity lived on AnalyticSky, which is the Preetham parameter block. Hosek-Wilkie replaces that block, so anything parked on it dies with the model, and which air the sky is rendered through is not a property of whichever model happens to be reading it. Atmosphere carries that state instead, and AnalyticSky reads turbidity through it. The type is #[non_exhaustive] from the first commit, which is the whole reason to have it. Ground albedo is the next axis and Hosek-Wilkie fits it where Preetham has nowhere to put it; aerosol species is the one after, and nothing in the Perez family carries it at all. Each would otherwise break every caller writing a struct literal. ComposeOpts gets the same marker for the same reason, following Config, with new() taking the one option that has no universal default since which way is worth facing depends on the hemisphere. It also puts a disagreement where it can be seen. turbidity_from_visibility ramps across 2 to 24 km while build_haze switches off entirely above 12, so at 13 km reported visibility the analytic sky is told the air is fairly hazy and the haze layer is told there is none. Both curves are unchanged here and both now read one value, so the next person deciding what to do about that is looking at one type rather than two functions that never met. Nothing renders differently: every golden holds, and the analytic properties hold with no assertion relaxed.
adapted_exposure divided a frame's own log-average luminance into a fixed target, which is full auto-exposure. Measured across the domain the model actually renders, turbidity 2 to 9 with the sun above the horizon, 4.9 stops of real sky luminance arrived on screen inside 0.012 of Oklab lightness. Every sky was the same brightness. The one absolute quantity Preetham computes was surveyed and then divided straight back out, so a dim sky was not something this renderer could draw, and every property in tests/analytic.rs had to be phrased as contrast within one sky because comparing two of them measured the tone curve instead of the atmosphere. The exposure is a partial adaptation now, g * (Lref / Lbar)^p at p = 0.7, the shape photographic tone reproduction calls incomplete adaptation. 1 - p is the fraction of a stop of real difference that reaches the terminal, and it is the only quantity the constant controls: p = 1 is the old behaviour exactly and p = 0 is the fixed gain that came before it. The same domain now spans 0.126, roughly ten times more, with nothing crushed to black or blown to white. The curve itself is untouched, against what TODO.md asked for. BRU17 renders all nine models it surveys with exactly the 1 - exp(-kL) that note wanted replaced, and its perceptual study puts the realism gain in white balance rather than in the curve's shape. The shape was never it. Anchoring turned up a second thing. 0.045 * 2.35 was one constant, and under full adaptation only the product is observable, so neither factor had to describe anything real: a clear noon measures Lbar = 12.858, not 2.35, because the projection went rectilinear in v0.5.0 and the frame stopped reaching the zenith. Both are measured from that sky now and a unit test re-measures it, so the next projection change says so instead of leaving a stale number nothing can see. Three tests this makes possible and one it does not. Two skies of different real brightness must not render alike, no sky in the domain may be crushed or blown, and the palette-to-analytic handover must not step, which measures 0.041 of lightness against the 0.107 dawn itself moves in a quarter hour. Frame-mean lightness is deliberately not asserted to rise with the sun: Lbar peaks near 45 degrees and falls after, because past about 69 the sun leaves the top of the frame and takes the aureole with it, so that is the geometry rather than the curve. The colour tests are unrelated repair. Nothing here asserted on chromaticity, and every mutant that survived a run over this module lived in cx_coeffs or cy_coeffs: the arithmetic deciding what colour the sky is could be corrupted with the whole suite still green.
The three colour tests were written after a mutation run showed every survivor in this module sitting in cx_coeffs or cy_coeffs, and the doc comment read as though they closed that. They do not. Four of those survivors were reapplied by hand with all three tests in place and every one still passed. Those are Perez distribution coefficients, and prepare() normalises by perez(1, theta_sun), so a mutated coefficient moves the numerator and the denominator together and sampling one direction cannot see it. The measurements, and the two survivors that do change the sky substantially, are written up as item 10 in QUALITY-GATES.md. The tests stay, because what the sky's colour is was worth pinning on its own and nothing pinned it before. The claim about why they exist is what was wrong.
…rminal The module doc described the radiance model and stopped there, but the model's output is in kcd/m^2 across orders of magnitude and the exposure is what decides which of that range a terminal actually shows. That is the load-bearing half for anyone reading this on docs.rs, and the reasoning for it was only visible on a private constant.
Snow was rain with the colour swapped. That is wrong in the way that matters most: a raindrop draws as a line because it falls fast enough to smear across an exposure, and a flake does not. What a flake looks like instead is set by the air it grew in, and the Nakaya morphology diagram (Libbrecht 2006) is that relationship: temperature picks the habit, supersaturation picks how branched it is. FlakeForm::select is the diagram as a lookup, so a -15 C sky snows dendrites and a -5 C sky snows needles. Getting there needs a conversion that is easy to skip. Open-Meteo reports relative humidity over water and the diagram is drawn against excess vapour density over ice, and near freezing the two curves nearly meet: at -1 C, ice saturation alone needs 99.05 percent relative humidity. Reading the forecast value straight onto the diagram's axis reports a blizzard as dry air and every flake comes out faceted. The Magnus pair and the conversion are in snow.rs with the arithmetic stated, and the test table walks both columns of every temperature band. Density comes from the forecast's snowfall in cm, not from precipitation in mm, which reports the same fall as liquid water and understates it about tenfold, and not from buffer area, which is what the old drop count used. Count is an absolute over the frame's fixed field of view and the drawn flake grows with the buffer, per rules/reference-size.md. The seed carries the hour, so scrubbing a forecast day shows different snow; precipitation seeds on the UTC day alone and shows one frozen layout for twenty-four hours. This is the first effect drawn in both stills and motion, and the reason is the opposite of lightning's. A still that catches a flash mid-strike is wrong, so lightning stays outside render(); a snowfall scene with no flakes in its PNG is not a scene, so snow is inside it, at t = 0. The TUI calls the same function on its own clock. The risk that creates is snow baked into the cached base *and* animated on top, at double density with half of it standing still, which is why App lifts snowfall off display at both points display is built and a test asserts it. BREAKING CHANGE: PrecipKind::Snow is removed; snow is celsius::snow. Also breaking: SkyState gains snowfall, and HourlyArrays gains relative_humidity_2m and snowfall.
Contributor
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Track E's two cross-cutting prerequisites, plus the B4 snow work that was waiting on them. Five commits, one release, because every part of it is breaking and splitting them would cut three.
Track E, and the two premises that did not survive reading the papers
E1 asked for the wrong thing. TODO.md wanted "a principled curve rather than
1 - exp(-c*E)". BRU17, the reference it cites, renders all nine models it surveys with exactly that curve, and its perceptual study attributes the realism gain to white balance rather than to the curve's shape. The curve is untouched here.The defect was the line above it.
ADAPT_KEYdivided each frame's own log-average luminance into a fixed target, which is full auto-exposure. Measured across the domain the model actually renders, 4.9 stops of real sky luminance arrived on screen inside 0.012 of Oklab lightness. Every sky was the same brightness, so a dim sky was not something this renderer could draw. Exposure is a partial adaptation now,g * (Lref / Lbar)^0.7, and the same domain spans 0.126.Anchoring it found a stale constant.
0.045 * 2.35was one product, and under full adaptation only the product is observable, so neither factor had to describe anything real: a clear noon measuresLbar = 12.858, not 2.35, because the projection went rectilinear in v0.5.0 and the frame stopped reaching the zenith. Both are measured now and a unit test re-measures them, so the next projection change says so.E2 had a dependency that was not written down. HW12's headline albedo result is that a snow-covered surround nearly doubles sky-dome brightness, and a uniform doubling is exactly what a log-average auto-exposure cancels. E2 depended on E1, not only on A1. What ships is the plumbing:
src/atmosphere.rswith a#[non_exhaustive]Atmospherethat lifts turbidity off the Preetham struct, so A1 becomes a model swap rather than a plumbing rewrite. Noalbedofield, because no model can read one yet; the marker is the deliverable.The palette retune was measured rather than assumed and deliberately not spent. The analytic-to-palette handover dips 0.041 of lightness, and it dipped 0.031 before any of this, against the 0.107 dawn itself moves in a quarter hour. Closing it means calibrating seven hand-authored palettes against Preetham at 0 to 8 degrees of elevation, which is the exact band Hosek-Wilkie exists to fix, so it is A1's to close. A test pins a ceiling meanwhile.
Snow
Snow was rain with the colour swapped. A raindrop draws as a line because it falls fast enough to smear across an exposure and a flake does not; what a flake looks like instead is set by the air it grew in.
FlakeForm::selectis the Nakaya morphology diagram (Libbrecht 2006) as a lookup, so a -15 C sky snows dendrites and a -5 C sky snows needles.The conversion that makes it work is easy to skip. Open-Meteo reports relative humidity over water and the diagram is drawn against excess vapour density over ice, and near freezing the two curves nearly meet: at -1 C, ice saturation alone needs 99.05 percent relative humidity. Reading the forecast value straight onto the diagram's axis reports a blizzard as dry air and every flake comes out faceted.
Density comes from
snowfallin cm, notprecipitationin mm, which reports the same fall as liquid water and understates it about tenfold, and not from buffer area, which is what the old drop count used. Count is an absolute over a fixed field of view and the drawn flake grows with the buffer, perrules/reference-size.md. The seed carries the hour, so scrubbing a forecast day shows different snow.This is the first effect drawn in both stills and motion, and the reason is the opposite of lightning's: a still that catches a flash mid-strike is wrong, but a snowfall scene with no flakes in its PNG is not a scene.
render()calls the overlay att = 0and the TUI calls the same function on its own clock. The risk that creates is snow baked into the cached base and animated on top at double density, soApplifts it offdisplayat both pointsdisplayis built, and a test asserts it.The scene
scenes/snowfall.tomlis promoted as a public WIP scene: inwip_scenes, excluded from the tarball individually, noBUILTINSentry and no manifest entry. Two defects fixed on the way in. The old draft setintensity = 2.8against a documented range of 0 to 1 and rendered anyway, which parse-time validation now rejects. And its haze pulled toward a colour darker than the gradient's own horizon stop, so raising its strength from 0.45 to 0.85 moved no pixel by more than 5 of 255 and made the horizon dimmer: the low visibility was written in the chrome and encoded nowhere.The contact sheet caught the follow-on. Fixing the haze first made the scene the brightest sky in the library, above
cloudy_dayandhigh_noon_clearboth, which is wrong for a sky the scene's own header calls a dull medium grey. Flakes cover about a quarter of the frame and every one is near white, so they carry more of the tone than they look like they should. It measures 149.1 mean luma now, betweenstormy_afternoon_advancingandcloudy_day.Fog is deliberately not in this PR.
Release
0.7.0on the 0.x shift. The breaks, all intended:PrecipKind::Snowremoved,turbiditymoved offAnalyticSkyontoAtmosphere,weather::turbidity_from_visibilitymoved toatmosphere,ComposeOptsmarked#[non_exhaustive], and additive fields onSkyStateandHourlyArrays.Verification
just cigreen. 200 tests, up from 176.just lockre-renders all seven goldens byte-identically, which is the load-bearing check sincerender()now calls the snow overlay unconditionally.cargo package --listconfirms the seven locked scenes ship andsnowfalldoes not.Not done: a
cargo mutantspass oversrc/snow.rs. Themutants.ymljob covers the diff on this PR. Related and recorded rather than fixed, as item 10 in the quality gates: every mutant surviving a run overanalytic_sky.rssits in the chromaticity coefficients, and the three colour tests added here were measured against four of them and killed none.