Skip to content

Nauvis fields: round every step to f32, offset first (#452) - #522

Merged
wormeyman merged 5 commits into
mainfrom
nauvis-f32-fields
Nov 25, 2026
Merged

wormeyman merged 5 commits into
mainfrom
nauvis-f32-fields

Conversation

@wormeyman

@wormeyman wormeyman commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #452. Closes #255.

Four Nauvis fields now match the game at every point of their fixtures. The noise ops were already exact. What was wrong was the arithmetic joining them: we did it in f64, and the game does it in f32, one step at a time.

The numbers (tier 1, exact f32 matches)

fixture before after
oracle-aux 14 26 of 26
oracle-moisture 18 26 of 26
oracle-elevation-lakes 21 26 of 26
oracle-elevation-island 19 26 of 26
oracle-elevation-nauvis 8 26 of 26
oracle-elevation-nauvis-no-cliff, seed 123456 / 777771 6 / 4 25 / 26
oracle-cliff-elevation, two seeds (reads cliff_level) 355 / 281 699 / 648 of 1024
oracle-trees, all 17 fields (read moisture) 120 144 of 442

The four elevation counts now have a worst error of exactly 0, so their bounds became equalities.

The two causes

  1. The glue ran in f64. The game rounds every literal and every operation to f32, left to right as the Lua writes it. A new helper, eval::math::f32r, does one such step. plateaus, cliff_level, aux, moisture, elevation_lakes and elevation_nauvis now use it at each step.
  2. Nauvis's offset_x is 10000 / 1.5 = 6666.67, which is not an f32. The game holds it as an f32 constant, so x + offset_x adds the rounded value. We added the f64 value and rounded the sum, which is a different point. Rounding the offset alone takes elevation_nauvis from 8 to 10. The f32 steps alone take it to 19. Only both reach 26.

One commit per field

  1. aux and the shared plateaus / cliff_level
  2. moisture
  3. elevation_lakes and elevation_island
  4. elevation_nauvis, with the offset and nauvis_segmentation_multiplier folded in f32
  5. Docs: a new port rule in CLAUDE.md, and two notes corrected

Each commit moves its own tier-1 counts, rebuilds engine.wasm, and re-records only the tier-2 rows it moved: 239, 209, 12 and 21 of the 504 Nauvis rows. No tier-3 row moves, and neither does the Nauvis terrain count in #400 (1 pixel). Each commit's message says what moved.

Things a reviewer should know

  • One count went down. tree_04 fell from 11 to 10 when moisture became exact, while the tree total rose from 120 to 144. The trees' own arithmetic is still f64, so some of their old matches were luck that a correct input undid.
  • One point is still off. elevation_nauvis_no_cliff misses one point at seed 123456 by one f32 step, where the full tree is exact. I tried rounding the constant-ended lerp once instead of twice, and it got worse (9 misses). The test records it as open. Reading how the game compiles that lerp, in the binary, is the next step.
  • The aux bias test changed. It used to check the bias shift to 1e-9. That can't hold for an f32 field, so it now checks to one f32 step at 1.0. The measured worst is 0.7 of a step.
  • elevation_lakes still uses the 81/152 amplitude-corrected form; the game form scores 152/152 #254 stays open. These 26 points can't tell the shipped amplitude_corrected_multioctave_noise from the game form (AmplitudeCorrectedGame), since both score 26. Moving Nauvis to the game form is still its own change.
  • How I found it: I read frankh/factorio-mapgen's source, which builds its program from the game's Lua with Math.fround at every op. I did not run its code.

Follow-ups this points at

  • The tile scores, the tree species and cliff_elevation_nauvis still do their own arithmetic in f64. The last Nauvis pixel's grass-1/grass-3 gap barely moved once its inputs were exact, so the tile scores are the next suspect.
  • water_level is narrowed where it is used, but the caller computes 10 * log2(size) in f64. That is exact at the default size only.
  • Round every noise-expression step to f32: the rest of the port after #452 #521 tracks the rest of the port's f64 glue, module by module.

Checks

  • cargo test (fmw-noise): 535 passed after each commit.
  • pnpm vp test, full suite, after each commit: green once the Nauvis tier-2 section was re-recorded.
  • pnpm run verify on the head: exit 0 in 6m40s on hammond. cargo deny skipped there (not installed); CI runs it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC

Summary by CodeRabbit

  • Bug Fixes
    • Improved numerical consistency in generated Nauvis elevation, climate, and terrain data, resulting in exact matches across the tested fields.
    • Updated terrain and tile checksum results across several generation scenarios to reflect the revised output.
  • Documentation
    • Updated noise and terrain references with the latest comparison results and findings.

wormeyman and others added 5 commits November 24, 2026 01:16
The game evaluates a noise expression one f32 operation at a time,
literals included. The Nauvis port combined its (already exact) noise
fields in f64, which held aux at 14 of 26 against the game.

- eval::math::f32r: the per-step rounding, documented once.
- nauvis_hills_cliff_level and nauvis_plateaus: each step through f32r.
- aux_nauvis: the same, with 0.5 + bias folded first as the game does.

Tier 1: aux 14 -> 26 of 26. Nauvis cliff elevation, which reads
cliff_level, 355 -> 699 and 281 -> 648 of 1024 (its own arithmetic is
still f64). The last-pixel diagnostic moves grass-3 from 90 to 80 ULPs
high. The aux bias test now bounds the shift at one f32 step (measured
worst 0.7 of a step), since aux is f32.

Tier 2: 239 of 504 Nauvis rows re-recorded (plateaus, cliffLevel, aux
and everything downstream of them). Tier 3 and the Nauvis terrain
count (1 pixel) do not move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
moisture_nauvis, its starting-area blend and the three forest-path
cutouts now go through f32r one step at a time in the Lua's order. The
blend's constants (bias, slider change, frequency / 400) are folded in
f32, as the game folds them.

Tier 1: moisture 18 -> 26 of 26. Every tree species reads moisture, so
the tree layer moves too: 120 -> 144 exact of 442 (unsnapped 85 -> 99).
Eight species rise and tree_04 falls 11 -> 10; the species' own
arithmetic is still f64, so some old matches were coincidences. The
last-pixel diagnostics move: grass-3 leads grass-1 by 63 ULPs (was 53).

Tier 2: 209 of 504 Nauvis rows re-recorded (moisture and what reads
it). Tier 3 and the Nauvis terrain count do not move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
make_0_12like_lakes and finish_elevation now go through f32r one step
at a time in the Lua's order. segmentation_multiplier, water_level and
0.1 * segmentation_multiplier are narrowed the way the game folds them,
and the persistence clamp uses the f32 literals 0.1 and 0.9.

Tier 1: elevation_lakes 21 -> 26 of 26 and elevation_island 19 -> 26,
both with worst error exactly 0, so their bounds become equalities.
The persistence clamp test compares against the f32 bounds (its count,
430, is unchanged).

Tier 2: 12 Nauvis rows re-recorded (elevationLakes, elevationIsland).
The 18 elevation:render rows do not move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
elevation_nauvis_function now goes through f32r one step at a time in
the Lua's order, and two constants are folded in f32 the way the game
holds them:

- offset_x = 10000 / nauvis_segmentation_multiplier is 6666.67 at the
  default, which is not an f32. The game adds the ROUNDED constant to
  x; we added the f64 one and rounded the sum. Alone this takes the
  tree from 8 to 10; the f32 steps alone take it to 19; together, 26.
- nauvis_segmentation_multiplier = 1.5 * control:water:frequency, in
  the shared layer. Exact at the default, so only moved sliders see it.

Tier 1: elevation_nauvis 8 -> 26 of 26 (worst error 0, so the bound is
now an equality). elevation_nauvis_no_cliff 6 -> 25 and 4 -> 26 at its
two seeds. Its one miss is one f32 step at a point where the full tree
is exact; rounding the constant-ended lerp once was tried and is worse
(9 misses), so it is recorded as open, to be read in the binary.

Tier 2: 21 Nauvis rows re-recorded (elevationNauvis, its no-cliff
variant, and the water, deepwater and sand-1 tiles at moved sliders).
Tier 3 and the Nauvis terrain count (1 pixel) do not move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
- CLAUDE.md: a rule beside the other determinism rules: wrap each
  expression step in f32r and narrow non-exact constants before they
  meet a coordinate.
- rust-wasm-port.md: the "depth beats everything" bullet is refuted;
  the Nauvis residual was the f64 glue, not the depth.
- tile-correction-NOTES.md: the last Nauvis pixel barely moved once its
  three inputs were exact, so the tile scores' own f64 arithmetic is
  the next suspect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Files ignored due to path filters: 1

  • src/noise/wasm/engine.wasm is excluded by !**/*.wasm
Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4de7cb1d-ac06-41fd-a697-111b10cda5d1
Commits

Reviewing files that changed from the base of the PR and between 1a1bfb9 and 1a1bfb9.

Files ignored due to path filters: 1

  • src/noise/wasm/engine.wasm is excluded by !**/*.wasm

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Noise evaluation now rounds intermediate expression operations and selected constants to f32 across elevation, climate, and shared Nauvis calculations. Fixture expectations and tier-2 checksums were updated for the resulting outputs. Documentation describes the rounding rule and reports remaining tile-score differences.

Changes: Per-step f32 noise evaluation

Layer / File(s) Summary
Rounding helper and evaluation rule
crates/fmw-noise/src/eval/math.rs, CLAUDE.md, docs/rust-wasm-port.md
A public f32r helper narrows values to f32 and returns them as f64. The porting guidance describes rounding each expression step, including constants.
Shared Nauvis and climate calculations
crates/fmw-noise/src/expressions/nauvis_shared.rs, crates/fmw-noise/src/expressions/nauvis_climate.rs
Shared Nauvis, aux, and moisture calculations now round intermediate operations and selected constants through f32r. Moisture stores a precomputed, f32-rounded region scale.
Elevation expression calculations
crates/fmw-noise/src/expressions/elevation_lakes.rs, crates/fmw-noise/src/expressions/elevation_nauvis.rs
The elevation-lakes and Nauvis elevation calculations now round intermediate arithmetic and selected stored values through f32r. Persistence tests use f32-rounded clamp bounds.
Fixture and checksum updates
crates/fmw-noise/src/fixtures.rs, test/fixtures/tier2-checksums.json, docs/noise/tile-correction-NOTES.md
Fixture match counts and checksum values were updated. The tile-correction note reports updated Nauvis score gaps and identifies tile-score f64 arithmetic as a remaining suspect.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

Merge Risk: Minimal · up to 1a1bf · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: Nauvis composite-field paths now round each arithmetic step to f32, with the elevation_nauvis offset applied first. The changeset matches this. The raw summary shows f…
Linked Issues check Passed Evidence is the PR description, the AI summary, and the fixture-test changes. I did not inspect the repository directly. Objectives from [#452] and [#255] (grouped, since both concern the same four fi…
Out of Scope Changes check Passed Every listed change serves the four target fields or their direct dependents:
- crates/fmw-noise/src/eval/math.rs: adds the f32r helper used by all four field trees.
- nauvis_shared.rs, nauvis_climate…
Full details: Title check

Explanation

The title names the main change: Nauvis composite-field paths now round each arithmetic step to f32, with the elevation_nauvis offset applied first. The changeset matches this. The raw summary shows f32r rounding added across elevation_lakes, elevation_nauvis, nauvis_climate, nauvis_shared, the new f32r helper, fixtures, and CLAUDE.md. The PR objectives report the same per-step f32 approach for aux, moisture, elevation_lakes, elevation_island, and elevation_nauvis. The title uses a reference (#452) that matches the linked issue. It is specific and does not use vague terms.

Full details: Linked Issues check

Explanation

Evidence is the PR description, the AI summary, and the fixture-test changes. I did not inspect the repository directly. Objectives from [#452] and [#255] (grouped, since both concern the same four fields):

  1. [#452] Reach 26/26 exact f32 matches for elevation_nauvis, elevation_lakes, moisture, and aux, graded per field. The PR reports 26 of 26 for each. The fixture tests now assert exact f32 matches with zero residuals. Changes: f32r helper in eval/math.rs; per-step f32 arithmetic in nauvis_shared.rs, nauvis_climate.rs (aux, moisture), elevation_lakes.rs, and elevation_nauvis.rs; the Nauvis offset rounded to f32 before the add. Each field has its own commit, as the issue's plan asks.
  2. [#255] Resolve the moisture and aux 1-4 ulp residual as an expression-tree difference, without raising bounds or re-capturing, and keep exact-match scoring. The PR attributes the residual to f64 arithmetic between noise operations, not to the tree shape. Its fixes are per-step f32 rounding, which keeps exact-match scoring. It does not re-capture fixtures.

Unmet or deferred items, which this PR does not claim to complete: [#254] amplitude_corrected_multioctave_noise (separate investigation in the issue); the 2.0.77 vs 2.1.20 check with factorio-oracle refs grep, which the PR does not report; and one residual point in elevation_nauvis_no_cliff at seed 123456. The PR explicitly records these as open. The issue assigns #254 as a separate change, so its absence does not fail this PR. The no-cliff point is an acknowledged residual in a field that the issue lists as graded separately and is not among the four named targets.

Uncertainty: the aux bias test tolerance changed from 1e-9 to one f32 step (measured worst 0.7 of a step). [#255] says not to raise bounds to accommodate the residual. The PR's stated reason is that the test checks an f32 field, so the old tolerance cannot hold. This should be reviewed against that requirement.

Full details: Out of Scope Changes check

Explanation

Every listed change serves the four target fields or their direct dependents:

  • crates/fmw-noise/src/eval/math.rs: adds the f32r helper used by all four field trees.
  • nauvis_shared.rs, nauvis_climate.rs, elevation_lakes.rs, elevation_nauvis.rs: per-step f32 arithmetic for the target fields. elevation_island shares the elevation_lakes tree.
  • nauvis_shared.rs cliff_level and plateaus: shared inputs to the target fields. The PR also moves cliff-elevation counts because cliff_elevation reads cliff_level.
  • fixtures.rs and tier2-checksums.json: expected counts updated to the new engine output. The PR says tier-3 rows and the Nauvis terrain count do not move. Tier-2 changes follow from moisture and elevation changes.
  • CLAUDE.md, docs/rust-wasm-port.md, docs/noise/tile-correction-NOTES.md: document the f32 port rule and correct two notes about the residual's cause.

The tree_04 decrease (11 to 10) is a consequence of the moisture input change. The PR states that tree arithmetic is still f64. No change is unrelated to #452 or #255. Not verified: whether each tier-2 checksum rewrite is limited to the rows the PR names. I accept the PR's per-commit description of this.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 457c45f0-fd39-414a-bcd0-0aa7e1772587
Commits

Reviewing files that changed from the base of the PR and between 3295529 and 1a1bfb9.

Files ignored due to path filters: 1

  • src/noise/wasm/engine.wasm is excluded by !**/*.wasm
Files selected for processing: 10

  • CLAUDE.md
  • crates/fmw-noise/src/eval/math.rs
  • crates/fmw-noise/src/expressions/elevation_lakes.rs
  • crates/fmw-noise/src/expressions/elevation_nauvis.rs
  • crates/fmw-noise/src/expressions/nauvis_climate.rs
  • crates/fmw-noise/src/expressions/nauvis_shared.rs
  • crates/fmw-noise/src/fixtures.rs
  • docs/noise/tile-correction-NOTES.md
  • docs/rust-wasm-port.md
  • test/fixtures/tier2-checksums.json

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@claude

claude Bot commented Nov 24, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Scope note: this was a single-pass read of the Rust diff (f32 rounding changes in eval/math.rs, elevation_lakes.rs, elevation_nauvis.rs, nauvis_climate.rs). I did not run the build or tests, and I did not review the regenerated engine.wasm or the re-recorded tier-2 checksums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant