Skip to content

Nauvis terrain matches the game on every pixel: expression_in_range's real form (#521) - #523

Merged
wormeyman merged 4 commits into
mainfrom
nauvis-f32-tiles
Nov 25, 2026
Merged

wormeyman merged 4 commits into
mainfrom
nauvis-f32-tiles

Conversation

@wormeyman

@wormeyman wormeyman commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #522. Its base is nauvis-f32-fields, so this diff shows only the four commits below. Merge #522 first.

The Nauvis terrain preview now matches the game's own preview on every pixel: 0 of 1,048,576 differ, down from 1.

What was wrong

After #522, the last differing pixel was (229, -19): we drew grass-3 and the game drew grass-1. A new probe read the game's own values at that tile. Its aux, moisture, elevation and the four grass noise layers all matched ours bit for bit, so the inputs were not the problem. The scores built from them were.

The cause was expression_in_range, the builtin that turns aux and moisture into a tile's score. We computed each dimension as min(value - from, to - value). Ghidra on the 2.1.23 binary (NoiseExpressions::expressionInRange) shows the game builds it differently:

half   = (to - from) * 0.5        folded into a constant
center = (from + to) * 0.5        folded into a constant
d      = half - |value - center|  then * peak_multiplier, capped at peak_maximum
result = min over dimensions, starting from +inf

The two are equal in exact math. In f32 they are not, because value - center subtracts a far-away number and rounds differently. The existing 404-point fixture could not see this: its ranges are centred on 0 or have exact f32 bounds, where both forms agree.

The evidence

From scripts/probes/expression-in-range-form, which rebuilds each grass score from the game's own inputs at the pixel and its 8 neighbours:

form exact of 36
the game's (center) 36
ours until now (edge) 11

Because every input is the game's, only the form can separate the two, so this check could have gone either way.

Commits

  1. expression_in_range in the center form. Nauvis terrain 1 -> 0. A unit test pins the game's grass-1 score at (229, -19) and checks the old form misses it. 114 Nauvis tier-2 rows (the 19 land tiles) re-recorded. The 404-point fixture stays exact.
  2. Each land tile's box + noise_layer rounded to f32. With this, both grass scores equal the game's bit for bit on the point kernel, and the test asserts that directly.
  3. water_base and Fulgora's ocean test in f32. Nauvis water rows move. Nothing on Fulgora moves: its terrain count stays 20 and no Fulgora row changes. So the ocean arithmetic is not Fulgora terrain: factorio.extm.dev misses 4 pixels to our 22, and the sets do not overlap #453's cause. Kept because it is how the game evaluates these tiles.
  4. The probe, kept so the pinned numbers can be re-checked.

Only Nauvis tiles call expression_in_range in the game's Lua, so no other planet's tiles change.

Checks

  • cargo test (fmw-noise): 537 passed.
  • 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 6m26s on hammond. cargo deny skipped there (not installed); CI runs it.
  • The probe ran against 2.1.23 build 87750 and printed the table above.

#400's table is updated for the new Nauvis count. #521 tracks the remaining f64 arithmetic.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC

Summary by CodeRabbit

  • Bug Fixes

    • Improved Nauvis terrain scoring precision so grass-tile selection more closely matches Factorio, including the previously mismatched pixel.
    • Corrected ocean and water probability calculations to better reflect the game’s floating-point results.
    • Updated expected terrain outputs; Nauvis rendering parity checks now report no differing pixels.
  • Documentation

    • Added notes describing the game’s range-scoring behavior and updated the terrain discrepancy analysis.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PR changes expression_in_range to use the game’s center/half-width form with f32 arithmetic. It also rounds tile calculations at specified f32 steps and updates probes, documentation, and regression fixtures to record the resulting scores and Nauvis render parity.

Changes: Tile scoring parity

Layer / File(s) Summary
Game-compatible range scoring
crates/fmw-noise/src/tiles/expression_in_range.rs, scripts/probes/expression-in-range-form/*, docs/noise/expression-in-range-NOTES.md
expression_in_range now computes per-dimension scores using f32 half-width, center, multiplier, and cap operations. The probe compares the center and edge forms with game scores. The notes document both forms.
F32 rounding in tile calculations
crates/fmw-noise/src/tiles/helpers.rs, crates/fmw-noise/src/tiles/fulgora_ocean.rs, crates/fmw-noise/src/tiles/nauvis_catalog.rs
water_base, Fulgora ocean calculations, and the 19 Nauvis land scores now round specified calculation steps to f32.
Updated parity checks and recorded results
crates/fmw-noise/src/fixtures.rs, test/fixtures/tier2-checksums.json, test/wasmNauvisRenderParity.spec.ts, docs/noise/tile-correction-NOTES.md
Nauvis score expectations and checksums are updated. The render parity expectation changes to zero differing pixels. A probe logs component values at selected positions.

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

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

  • Issue 521 tracks remaining f64 arithmetic in noise calculations. This PR updates the Nauvis tile scores and Fulgora ocean arithmetic identified in that issue.
  • Issue 452 documents f32 step rounding for Nauvis fields. This PR applies the same rounding approach to tile calculations and updates Nauvis checksums.
  • Issue 400 tracks exact pixel counts per planet. This PR records the Nauvis terrain count as zero in the correction notes.

Possibly related PRs

Merge Risk: Minimal · up to 7b168 · 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 terrain now matches the game on every pixel, via the game's real form of expression_in_range (#521). The raw summary and PR objectives confirm this: expression_…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: Nauvis terrain now matches the game on every pixel, via the game's real form of expression_in_range (#521). The raw summary and PR objectives confirm this: expression_in_range now uses the game's f32 center/half-width form, and the Nauvis preview reports 0 of 1,048,576 pixels differing. The title does not mention the f32 rounding changes to land tiles, water_base, and Fulgora, but those are supporting changes.

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: ed2182f3-d178-4bbd-b55a-673397e73dd7
Commits

Reviewing files that changed from the base of the PR and between 5a4fda6 and 7b1684b.

Files ignored due to path filters: 1

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

  • crates/fmw-noise/src/fixtures.rs
  • crates/fmw-noise/src/tiles/expression_in_range.rs
  • crates/fmw-noise/src/tiles/fulgora_ocean.rs
  • crates/fmw-noise/src/tiles/helpers.rs
  • crates/fmw-noise/src/tiles/nauvis_catalog.rs
  • docs/noise/expression-in-range-NOTES.md
  • docs/noise/tile-correction-NOTES.md
  • scripts/probes/expression-in-range-form/README.md
  • scripts/probes/expression-in-range-form/capture.ts
  • test/fixtures/tier2-checksums.json
  • test/wasmNauvisRenderParity.spec.ts

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.

🤖 Generated with Claude Code

@wormeyman
wormeyman added this pull request to stack #524 November 25, 2026 00:24
Base automatically changed from nauvis-f32-fields to main November 25, 2026 00:31
wormeyman and others added 4 commits November 24, 2026 16:31
The game's builder (NoiseExpressions::expressionInRange, read from the
2.1.23 binary with Ghidra) folds center = (from + to) / 2 and
half = (to - from) / 2 into constants and evaluates
half - |value - center| per dim, then the multiplier, the cap, and a min
across dims starting from +inf. That equals min(value - from, to - value)
in exact math, which we computed, but rounds differently in f32.

A probe at the last differing Nauvis pixel, (229, -19), read the game's
aux, moisture, elevation and the four grass noise layers: all matched
ours. The center form then reproduces the game's grass scores at all 36
values in the 3x3 around it; the edge form matched 11.

- Nauvis terrain against the game's preview: 1 -> 0 differing pixels.
- The last-pixel diagnostics: grass-1 now wins by 28 ULPs on the grid
  kernel, and both scores are within half an ULP of the game's on the
  point kernel (grass-1 bit-exact).
- A unit test pins the game's grass-1 score at (229, -19) and checks the
  edge form misses it. The zero-dimension case now returns the builder's
  starting +inf (unreachable: the game needs at least one dim).
- Tier 2: 114 Nauvis rows re-recorded (the 19 land tiles). The 404-sample
  expression_in_range fixture is still exact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
Every land tile is box + noise_layer_noise(N), one f32 add in the game.
The catalog added in f64 and never rounded. With the center-form box
from the commit before, both grass scores at the last Nauvis pixel,
(229, -19), now equal the game's bit for bit on the point kernel, and
the test asserts that directly. The grid-kernel gap for grass-1 over
grass-3 is 27 ULPs (was 28).

Tier 2: the 19 land-tile rows re-recorded. Tier 3 and the Nauvis
terrain count (0) do not move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
water_base(max_elevation, influence) is shared by the Nauvis water tiles
and Fulgora's four oil-ocean tiles. Both now round each step in the
Lua's order: the headroom, the product with the influence, and on
Fulgora the 50 * mask * water_base * max(...) chain and deep-2's scale.

Measured: Nauvis deepwater and water rows move in tier 2. Nothing on
Fulgora moves: its terrain count stays 20 pixels and no Fulgora tier-2
row changes, so the ocean arithmetic is not the cause of #453. Kept
because it is how the game evaluates these tiles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
scripts/probes/expression-in-range-form reads the game's aux, moisture,
elevation, grass noise layers and grass scores at (229, -19) and its
3x3, then rebuilds each score from the game's own inputs in both forms.
2.1.23 build 87750: center form 36 of 36 exact, edge form 11. It writes
nothing to the repo; it is what makes the unit test's pinned numbers
repeatable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
@wormeyman
wormeyman merged commit 329c611 into main Nov 25, 2026
17 checks passed
@wormeyman
wormeyman deleted the nauvis-f32-tiles branch November 25, 2026 01:07
wormeyman added a commit that referenced this pull request Nov 25, 2026
All 19 tile ranges from tiles-vulcanus.lua, plus mountain_lava_spots,
now evaluate one f32 operation at a time in the Lua's order, with each
non-exact literal (0.05, 0.3, 0.15, 0.85, 0.35, 0.2, 0.8, 0.25, 0.6,
0.66, 0.01, 0.1, 1.95, 0.95, 0.4, 1.8) narrowed first. Each range's
final sum is rounded too. A private range_select_base_f32 holds the
f32 form of clamp(min(input - from, to - input) / slope, lo, hi); the
shared f64 helper is left alone. Vulcanus tile ranges use no
expression_in_range builtin, so the center/half-width form (#523) does
not apply.

Tier 1: tile argmax 374/381, saves-surface-seed 368/381 and lava
classification 49/49 with 0 mismatches do not move. The last-pixel
argmax gap moves 19,301 -> 19,300 ULPs. On the point kernel warm stays
exact to the game and cracks moves -60,387 -> -60,388 ULPs (grid shift
627 -> 628). The 60k cracks gap is not step rounding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant