[PR #6005] [MERGED] Draw opaque terrain through a shader that never discards #6602

Closed
opened 2026-11-03 06:23:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6005
Author: @kacpherek
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: perf/opaque-terrain-pass


📝 Commits (5)

  • aa46228 Draw opaque terrain through a shader that never discards
  • 701e3ca Draw far tile faces over opaque texels in the opaque pass
  • 15cc1e4 Merge remote-tracking branch 'origin/main' into pk1/6005
  • 28aa931 Format the opaque pass
  • 887f6e9 Opaque pass: two solid passes on Metal only

📊 Changes

4 files changed (+184 additions, -30 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+81 -27)
📝 crates/horizon-client-render/src/gfx/flat.rs (+34 -2)
📝 crates/horizon-client-render/src/lod/mesh.rs (+8 -1)
📝 crates/horizon-client-render/src/terrain.wgsl (+61 -0)

📄 Description

Why

The solid terrain shader could discard every pixel: the fade dither and the alpha cutout. One possible discard in a pipeline turns off the hidden surface removal of tiled GPUs (Apple's) for everything that pipeline draws, so all opaque terrain was shaded even where nearer terrain hid it.

What it does

  • The world pass draws each solid list twice. First the quads over opaque texels that are not fading, through fs_opaque, which has no discard. Then the rest (cutout quads, fading sections) through fs_solid.
  • Each vertex shader decides its pass before doing any other work, and a quad of the other pass lies outside the clip volume.
  • Both draw paths get the split: the instanced one and the flat one. Shader packs and native materials keep the single pipeline.
  • Far tiles marked only leaves as opaque, so every stone, sand or ice face of the far terrain went through the cutout pass. They are now marked the way the mesher marks section quads.

Measurements

M1 Pro, 1280x720, render distance 24, far distance 256, same commit before and after, same world copy:

Scene GPU before after FPS before after
Standing 10.85 ms 10.54 ms 88.9 92.5
Flight over new ground 10.39 ms 9.59 ms 90.7 97.2
Rain and particles 12.85 ms 10.95 ms 75.3 86.5
300 mobs in view 9.45 ms 8.08 ms 97.8 115.7

Screenshots before and after are the same.

What is left: the cutout quads themselves (fancy leaves) cost about 2.6 ms in a spruce forest, as in vanilla. Running the vertex shader a second time for the cutout pass costs about 1.3 ms; keeping opaque and cutout quads in separate index ranges would remove that, as a follow-up.

Testing

  • cargo clippy -p horizon-client-render -p horizon-client --all-targets --no-deps -- -D warnings: clean.
  • cargo test -p horizon-client-render --lib: 839 passed.
  • Played on a world with forests, ice spikes and far terrain.

🔄 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/6005 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/opaque-terrain-pass` --- ### 📝 Commits (5) - [`aa46228`](https://github.com/horizon-rust/horizon/commit/aa4622805d81541961c6019005312247bd2d2a26) Draw opaque terrain through a shader that never discards - [`701e3ca`](https://github.com/horizon-rust/horizon/commit/701e3ca79085b9ce33ef3859ed6b82b06dfd792d) Draw far tile faces over opaque texels in the opaque pass - [`15cc1e4`](https://github.com/horizon-rust/horizon/commit/15cc1e4d8e78acade6a185cb9346afd62c1ed9bf) Merge remote-tracking branch 'origin/main' into pk1/6005 - [`28aa931`](https://github.com/horizon-rust/horizon/commit/28aa93145d811b50a0d9cb2e22f84aad0f1241f9) Format the opaque pass - [`887f6e9`](https://github.com/horizon-rust/horizon/commit/887f6e97507f685fcb05c39c774b6d1e84cee4d6) Opaque pass: two solid passes on Metal only ### 📊 Changes **4 files changed** (+184 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+81 -27) 📝 `crates/horizon-client-render/src/gfx/flat.rs` (+34 -2) 📝 `crates/horizon-client-render/src/lod/mesh.rs` (+8 -1) 📝 `crates/horizon-client-render/src/terrain.wgsl` (+61 -0) </details> ### 📄 Description ## Why The solid terrain shader could discard every pixel: the fade dither and the alpha cutout. One possible discard in a pipeline turns off the hidden surface removal of tiled GPUs (Apple's) for everything that pipeline draws, so all opaque terrain was shaded even where nearer terrain hid it. ## What it does - The world pass draws each solid list twice. First the quads over opaque texels that are not fading, through `fs_opaque`, which has no discard. Then the rest (cutout quads, fading sections) through `fs_solid`. - Each vertex shader decides its pass before doing any other work, and a quad of the other pass lies outside the clip volume. - Both draw paths get the split: the instanced one and the flat one. Shader packs and native materials keep the single pipeline. - Far tiles marked only leaves as opaque, so every stone, sand or ice face of the far terrain went through the cutout pass. They are now marked the way the mesher marks section quads. ## Measurements M1 Pro, 1280x720, render distance 24, far distance 256, same commit before and after, same world copy: | Scene | GPU before | after | FPS before | after | |---|---|---|---|---| | Standing | 10.85 ms | 10.54 ms | 88.9 | 92.5 | | Flight over new ground | 10.39 ms | 9.59 ms | 90.7 | 97.2 | | Rain and particles | 12.85 ms | 10.95 ms | 75.3 | 86.5 | | 300 mobs in view | 9.45 ms | 8.08 ms | 97.8 | 115.7 | Screenshots before and after are the same. What is left: the cutout quads themselves (fancy leaves) cost about 2.6 ms in a spruce forest, as in vanilla. Running the vertex shader a second time for the cutout pass costs about 1.3 ms; keeping opaque and cutout quads in separate index ranges would remove that, as a follow-up. ## Testing - `cargo clippy -p horizon-client-render -p horizon-client --all-targets --no-deps -- -D warnings`: clean. - `cargo test -p horizon-client-render --lib`: 839 passed. - Played on a world with forests, ice spikes and far terrain. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:23:41 +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#6602
No description provided.