Viewer: time of day and weather lighting from the game's timecycle #276

Manually merged
github merged 2 commits from gh-pr/276/head into gh-pr/276/base 2026-11-26 20:23:47 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-25 13:55 UTC · original
holdmysocks:claude/viewer-time-of-day → master · +748 −6 · 7 files · 2 commits · merged 2026-11-25 14:33 UTC

Adds time-of-day and weather lighting to the model viewer, read from the game's own timecycle.

What changes

  • New sixng-core::daylight: builds a variable table for each of the 12 weather types (sunny, clear, clouds, overcast, overcastdark, misty, fog, drizzle, shower, rain, thunderstorm, hurricane) from the timecycle documents the existing timecycle decoder already reads. Each named weather goes through the weather list's indirection to its weather type. That type gives a base cycle (its GLOBAL region, 13 time samples) and eight modifier fields. The modifiers and their submodifiers are applied in order, and a later one wins. A modifier either sets a constant or sets a curve over the day (keyframe_t_value). Any hour is interpolated between its two neighbouring samples, eased with the earlier sample's easing (linear, or quartic in-out). A curve is read at hour / 24. The table is decoded from common.rpf on first use and cached in <work>/cache/daylight.json, which takes about 2 s.
  • sixng daylight [--weather ..] [--hour ..] [--var ..] [--rebuild] prints the resolved values and the light derived from them.
  • Model view, Light section: a weather list sits next to the existing hour slider. viewer default, the default, keeps the old fixed light set-up, so existing screenshots and checks don't change. Picking a weather sets the sun/moon direction, directional colour and strength, sky tint, ambient and exposure from the table, and shows a one-line readout. Without an index the viewer says so and keeps its own light. --weather W with --tod H does the same for command-line screenshots.
  • No shader changes: only the Look inputs (sun direction/colour/intensity, sky colours, ambient, exposure, emissive) are set. The hair and skin formulas are untouched.

From the timecycle

light_dir_col_*, light_dir_mult, and for the sun light_dir_sun_mult, sky_scattering_sun_intensity_multiplier and sky_scattering_sun_col_*; for the moon light_dir_moon_mult and sky_moon_col_*. Ambient comes from ambient_sky_intensity x indirect_light_sky_multiplier, tinted by ambient_sky_color_mult_* x sky_scattering_sky_col_*. Also postfx_exposure and the high-level cloud_cover.

Not decoded (our own simple model, documented in daylight.rs and the README)

The game feeds these multipliers into a physical sky and eye adaptation that we haven't decoded. The viewer therefore uses its own models for:

  • the sun path: 25.8° N at the summer solstice, with the clock one hour ahead of solar time. That puts sunrise near 06:10 and sunset near 19:50, where the cycle's own directional colours change from moonlight to sunlight (05-06 h) and back (20-21 h).
  • a full moon opposite the sun
  • the Rayleigh/aerosol air-mass tint and the fade of the sun near the horizon
  • the sky brightness over the day (night sky 2 % of day before the cycle's own ambient multiplier)
  • moon strength (0.12 x the cycle's multiplier)
  • sun dimming by 85 % of the cloud cover, standing in for the volumetric cloud shadow
  • an exposure that brightens dark scenes

Directional and ambient strength are scaled so that Sunny at 12:00 equals the viewer default. Which sample's easing applies to a segment (the earlier one) is our reading. Region modifiers, interiors and the URBAN region aren't used. Fog isn't set.

Checked

  • Resolution: the resolved table was compared with an independent resolution of the same decoded export, made by our own weather pipeline. All 179,153 values (12 weathers x 13 samples x every variable) agree to 1e-4.
  • Values at noon and midnight (sixng daylight):
weather, hour light_dir_mult light_dir_col rgb ambient_sky_intensity viewer light
Sunny 12:00 1.2979 1, 1, 1 0.2 sun 76° high, colour 1.0/1.0/0.99, strength 1.0, ambient 1.0 (= default look)
Sunny 00:00 2.5 0.7144, 0.7891, 1.0 3.0 moon 39° high, colour 0.52/0.62/1.0, strength 0.23, ambient 0.30
Overcast 12:00 1.0 0.6797, 0.8511, 1.0 0.2996 sun 76°, colour 0.68/0.86/1.0, strength 0.28 (cloud cover 0.75), ambient 1.50
Overcast 00:00 1.5 0.2271, 0.4761, 1.0 1.0 moon 39°, colour 0.23/0.48/1.0, strength 0.05, ambient 0.10
Rain 12:00 1.1973 1, 1, 1 (sun col 1, 0.8853, 0.6768) 0.2996 sun 76°, colour 1.0/0.88/0.67, strength 0.37, ambient 1.50
Rain 00:00 2.0 0.3992, 0.6104, 1.0 1.0 moon 39°, colour 0.40/0.61/1.0, strength 0.08, ambient 0.10
  • Unit tests: modifier stack with submodifiers and curves, cloud cover override, linear and quartic easing including the 22 h to 0 h wrap, sun path, normalisation to Sunny noon.
  • cargo build --release and cargo test --release -p sixng-core -p sixng-gui pass with -j 8: 273 + 30 tests, no warnings.
  • Viewer screenshots (RTX 4080, one vehicle, --weather / --tod):
    • Sunny 12:00 looks the same as the viewer default, with a slightly bluer sky.
    • Overcast 12:00 is flatter, with a weak bluish sun and more ambient.
    • At Sunny 06:30 and 19:30 the low orange sun (3.7° up) lights one side, under twilight ambient.
    • At Sunny and Rain 00:00 the car is moonlit blue under a dark sky (Rain is dimmer).
    • "viewer default" renders exactly as before.
**@⁠holdmysocks** on GitHub · 2026-11-25 13:55 UTC · [original](https://github.com/holdmysocks/SixNG/pull/276) `holdmysocks:claude/viewer-time-of-day` → `master` · +748 −6 · 7 files · 2 commits · merged 2026-11-25 14:33 UTC Adds time-of-day and weather lighting to the model viewer, read from the game's own timecycle. ## What changes - **New `sixng-core::daylight`**: builds a variable table for each of the 12 weather types (sunny, clear, clouds, overcast, overcastdark, misty, fog, drizzle, shower, rain, thunderstorm, hurricane) from the timecycle documents the existing `timecycle` decoder already reads. Each named weather goes through the weather list's indirection to its weather type. That type gives a base cycle (its `GLOBAL` region, 13 time samples) and eight modifier fields. The modifiers and their submodifiers are applied in order, and a later one wins. A modifier either sets a constant or sets a curve over the day (`keyframe_t_value`). Any hour is interpolated between its two neighbouring samples, eased with the earlier sample's easing (linear, or quartic in-out). A curve is read at hour / 24. The table is decoded from `common.rpf` on first use and cached in `<work>/cache/daylight.json`, which takes about 2 s. - **`sixng daylight [--weather ..] [--hour ..] [--var ..] [--rebuild]`** prints the resolved values and the light derived from them. - **Model view, Light section**: a **weather** list sits next to the existing hour slider. *viewer default*, the default, keeps the old fixed light set-up, so existing screenshots and checks don't change. Picking a weather sets the sun/moon direction, directional colour and strength, sky tint, ambient and exposure from the table, and shows a one-line readout. Without an index the viewer says so and keeps its own light. `--weather W` with `--tod H` does the same for command-line screenshots. - No shader changes: only the `Look` inputs (sun direction/colour/intensity, sky colours, ambient, exposure, emissive) are set. The hair and skin formulas are untouched. ## From the timecycle `light_dir_col_*`, `light_dir_mult`, and for the sun `light_dir_sun_mult`, `sky_scattering_sun_intensity_multiplier` and `sky_scattering_sun_col_*`; for the moon `light_dir_moon_mult` and `sky_moon_col_*`. Ambient comes from `ambient_sky_intensity` x `indirect_light_sky_multiplier`, tinted by `ambient_sky_color_mult_*` x `sky_scattering_sky_col_*`. Also `postfx_exposure` and the high-level `cloud_cover`. ## Not decoded (our own simple model, documented in `daylight.rs` and the README) The game feeds these multipliers into a physical sky and eye adaptation that we haven't decoded. The viewer therefore uses its own models for: - the sun path: 25.8° N at the summer solstice, with the clock one hour ahead of solar time. That puts sunrise near 06:10 and sunset near 19:50, where the cycle's own directional colours change from moonlight to sunlight (05-06 h) and back (20-21 h). - a full moon opposite the sun - the Rayleigh/aerosol air-mass tint and the fade of the sun near the horizon - the sky brightness over the day (night sky 2 % of day before the cycle's own ambient multiplier) - moon strength (0.12 x the cycle's multiplier) - sun dimming by 85 % of the cloud cover, standing in for the volumetric cloud shadow - an exposure that brightens dark scenes Directional and ambient strength are scaled so that Sunny at 12:00 equals the viewer default. Which sample's easing applies to a segment (the earlier one) is our reading. Region modifiers, interiors and the `URBAN` region aren't used. Fog isn't set. ## Checked - **Resolution**: the resolved table was compared with an independent resolution of the same decoded export, made by our own weather pipeline. All 179,153 values (12 weathers x 13 samples x every variable) agree to 1e-4. - **Values at noon and midnight** (`sixng daylight`): | weather, hour | light_dir_mult | light_dir_col rgb | ambient_sky_intensity | viewer light | |---|---|---|---|---| | Sunny 12:00 | 1.2979 | 1, 1, 1 | 0.2 | sun 76° high, colour 1.0/1.0/0.99, strength 1.0, ambient 1.0 (= default look) | | Sunny 00:00 | 2.5 | 0.7144, 0.7891, 1.0 | 3.0 | moon 39° high, colour 0.52/0.62/1.0, strength 0.23, ambient 0.30 | | Overcast 12:00 | 1.0 | 0.6797, 0.8511, 1.0 | 0.2996 | sun 76°, colour 0.68/0.86/1.0, strength 0.28 (cloud cover 0.75), ambient 1.50 | | Overcast 00:00 | 1.5 | 0.2271, 0.4761, 1.0 | 1.0 | moon 39°, colour 0.23/0.48/1.0, strength 0.05, ambient 0.10 | | Rain 12:00 | 1.1973 | 1, 1, 1 (sun col 1, 0.8853, 0.6768) | 0.2996 | sun 76°, colour 1.0/0.88/0.67, strength 0.37, ambient 1.50 | | Rain 00:00 | 2.0 | 0.3992, 0.6104, 1.0 | 1.0 | moon 39°, colour 0.40/0.61/1.0, strength 0.08, ambient 0.10 | - Unit tests: modifier stack with submodifiers and curves, cloud cover override, linear and quartic easing including the 22 h to 0 h wrap, sun path, normalisation to Sunny noon. - `cargo build --release` and `cargo test --release -p sixng-core -p sixng-gui` pass with `-j 8`: 273 + 30 tests, no warnings. - **Viewer screenshots** (RTX 4080, one vehicle, `--weather` / `--tod`): - Sunny 12:00 looks the same as the viewer default, with a slightly bluer sky. - Overcast 12:00 is flatter, with a weak bluish sun and more ambient. - At Sunny 06:30 and 19:30 the low orange sun (3.7° up) lights one side, under twilight ambient. - At Sunny and Rain 00:00 the car is moonlit blue under a dark sky (Rain is dimmer). - "viewer default" renders exactly as before.
sixng-core daylight: resolves the 12 weather types (weather type -> base
cycle GLOBAL region + modifier stack with submodifiers), interpolates the
13 time samples with their easing, and derives sun/moon direction, colour
and strength, ambient tint and strength and exposure. sixng daylight
prints them. The model view's Light section gets a weather list; viewer
default keeps the old light set-up.
Sunrise ~06:10 and sunset ~19:50 match where the cycle's directional
colours change from moonlight to sunlight; the sky stays lit down to -10
degrees.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:23:46 +00:00
github manually merged commit 2e4e176414 into gh-pr/276/base 2026-11-26 20:23:47 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.