[PR #7462] [CLOSED] Greedy merging of identically-shaded coplanar section quads #7615

Closed
opened 2026-11-03 07:20:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7462
Author: @socksprox
Created: 11/2/2026
Status: ❌ Closed

Base: main ← Head: greedy-meshing


📝 Commits (1)

  • 13fbb2e Greedy merging of identically-shaded coplanar section quads

📊 Changes

14 files changed (+914 additions, -62 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx/native_material.rs (+3 -3)
📝 crates/horizon-client-render/src/mesher.rs (+29 -7)
➕ crates/horizon-client-render/src/mesher/merge.rs (+686 -0)
📝 crates/horizon-client-render/src/mesher/reuse_tests.rs (+1 -0)
📝 crates/horizon-client-render/src/oit_world.wgsl (+1 -1)
📝 crates/horizon-client-render/src/streaming.rs (+7 -0)
📝 crates/horizon-client-render/src/terrain.wgsl (+24 -12)
📝 crates/horizon-client/examples/chunk_load_bench.rs (+2 -0)
📝 crates/horizon-client/examples/probe/section_mesh_fixture.rs (+45 -35)
📝 crates/horizon-client/src/game.rs (+13 -2)
📝 crates/horizon-client/src/game/world_loading.rs (+1 -0)
📝 crates/horizon-client/tests/streaming_meshes.rs (+1 -0)
📝 crates/horizon-client/tests/tall_column.rs (+1 -0)
📝 tools/test_section_mesh_parity.py (+100 -2)

📄 Description

🤖 Opened by socksprox's AI agent (Devin, SWE-2 High), not by socksprox personally.

Closes #7294.

Summary

Merges coplanar solid quads in the section mesher only where the merged quad renders identically — the new mesher/merge.rs runs over the solid buffer after emission:

  • same sprite layer, plane and facing
  • UVs continuing one affine map over the merge (sprite layers tile at the sampler's repeat; a new MERGED_UV layer bit marks the TILED_UV_STEPS packing so the terrain shader decodes and wraps the UV before the clamped filtering modes)
  • constant smooth light + emission alpha (the vertex shader multiplies colour by the lightmap sample per vertex — a product no merge can reproduce where light varies)
  • vertex colours on one affine surface, so the merged quad's interpolation reproduces every removed vertex exactly

Anything failing a check stays as emitted: partial/sloped faces, rotated UVs, overlays, coincident coplanar quads (draw order verified per overlapping member), translucent/fluid geometry (untouched). Merging disables itself while extras.dynamic_lights is on, since it shades per vertex position.

Verification

  • tools/test_section_mesh_parity.py: unmerged output stays byte-identical (99.89% of client quads identical — the 330 cauldron_inner missing/extra are pre-existing); the harness now also verifies each merged quad covers whole original quads whose vertices its interpolation reproduces (colour, light, UVs mod one) — 457 merged quads checked, 0 illegal on the 38-scene quick corpus.
  • mesher::merge unit tests: 13 new (merge cases + all the non-merge conditions: light/colour/UV-phase/sprite/plane mismatches, winding, overlay ordering).

Numbers

chunk_load_bench (seed 1234, village terrain, radius 8, best of 3):

vertices mesh CPU
unmerged 2,709,572 201.9 ms (45.5 µs/section)
greedy 2,642,312 (−2.4%) 333.3 ms (75.1 µs/section)

The win scales with how much flat identically-lit surface a scene has: uniform 256-quad sections collapse to a handful of quads, while this hilly area saves ~2.4% of vertices overall. The meshing cost is on the worker threads; whether it pays off depends on terrain flatness. Honest trade-off shown for review — happy to tune or restrict it if you'd rather have a narrower merge domain.

🤖 Generated with Devin (SWE-2 High)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/7462 **Author:** [@socksprox](https://github.com/socksprox) **Created:** 11/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `greedy-meshing` --- ### 📝 Commits (1) - [`13fbb2e`](https://github.com/horizon-rust/horizon/commit/13fbb2eb4d1f7025ec88b978aa66a5e04f4040df) Greedy merging of identically-shaded coplanar section quads ### 📊 Changes **14 files changed** (+914 additions, -62 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx/native_material.rs` (+3 -3) 📝 `crates/horizon-client-render/src/mesher.rs` (+29 -7) ➕ `crates/horizon-client-render/src/mesher/merge.rs` (+686 -0) 📝 `crates/horizon-client-render/src/mesher/reuse_tests.rs` (+1 -0) 📝 `crates/horizon-client-render/src/oit_world.wgsl` (+1 -1) 📝 `crates/horizon-client-render/src/streaming.rs` (+7 -0) 📝 `crates/horizon-client-render/src/terrain.wgsl` (+24 -12) 📝 `crates/horizon-client/examples/chunk_load_bench.rs` (+2 -0) 📝 `crates/horizon-client/examples/probe/section_mesh_fixture.rs` (+45 -35) 📝 `crates/horizon-client/src/game.rs` (+13 -2) 📝 `crates/horizon-client/src/game/world_loading.rs` (+1 -0) 📝 `crates/horizon-client/tests/streaming_meshes.rs` (+1 -0) 📝 `crates/horizon-client/tests/tall_column.rs` (+1 -0) 📝 `tools/test_section_mesh_parity.py` (+100 -2) </details> ### 📄 Description > 🤖 Opened by socksprox's AI agent (Devin, SWE-2 High), not by socksprox personally. Closes #7294. ## Summary Merges coplanar solid quads in the section mesher **only where the merged quad renders identically** — the new `mesher/merge.rs` runs over the solid buffer after emission: - same sprite layer, plane and facing - UVs continuing one affine map over the merge (sprite layers tile at the sampler's repeat; a new `MERGED_UV` layer bit marks the `TILED_UV_STEPS` packing so the terrain shader decodes and wraps the UV before the clamped filtering modes) - constant smooth light + emission alpha (the vertex shader multiplies colour by the lightmap sample per vertex — a product no merge can reproduce where light varies) - vertex colours on one affine surface, so the merged quad's interpolation reproduces every removed vertex exactly Anything failing a check stays as emitted: partial/sloped faces, rotated UVs, overlays, coincident coplanar quads (draw order verified per overlapping member), translucent/fluid geometry (untouched). Merging disables itself while `extras.dynamic_lights` is on, since it shades per vertex position. ## Verification - `tools/test_section_mesh_parity.py`: unmerged output stays byte-identical (99.89% of client quads identical — the 330 `cauldron_inner` missing/extra are pre-existing); the harness now also verifies each merged quad covers whole original quads whose vertices its interpolation reproduces (colour, light, UVs mod one) — **457 merged quads checked, 0 illegal** on the 38-scene quick corpus. - `mesher::merge` unit tests: 13 new (merge cases + all the non-merge conditions: light/colour/UV-phase/sprite/plane mismatches, winding, overlay ordering). ## Numbers `chunk_load_bench` (seed 1234, village terrain, radius 8, best of 3): | | vertices | mesh CPU | |---|---|---| | unmerged | 2,709,572 | 201.9 ms (45.5 µs/section) | | greedy | 2,642,312 (−2.4%) | 333.3 ms (75.1 µs/section) | The win scales with how much flat identically-lit surface a scene has: uniform 256-quad sections collapse to a handful of quads, while this hilly area saves ~2.4% of vertices overall. The meshing cost is on the worker threads; whether it pays off depends on terrain flatness. Honest trade-off shown for review — happy to tune or restrict it if you'd rather have a narrower merge domain. 🤖 Generated with [Devin](https://devin.ai) (SWE-2 High) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 07:20:49 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#7615
No description provided.