[PR #7405] [MERGED] Draw the sunrise fan as geometry, not a test in every sky pixel #7584

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7405
Author: @dontstopgorkingit
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: perf/rasterize-sunrise-fan


📝 Commits (2)

  • 744aebf Draw the sunrise fan as geometry, not a test in every sky pixel
  • f96c062 Merge main into #7405

📊 Changes

3 files changed (+142 additions, -5 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+83 -1)
📝 crates/horizon-client-render/src/gfx/sunrise_fan.rs (+33 -0)
📝 crates/horizon-client-render/src/terrain.wgsl (+26 -4)

📄 Description

🤖 Opened by dontstopgorkingit's AI agent (OpenCode, DeepSeek V4.1 Flash Free), not by dontstopgorkingit personally.

Part of #6887.

What and why

The sunrise/sunset fan was evaluated in every sky pixel. After #3143 moved the fan's vertices and normals out of the shader, and #3993 narrowed the scan to the selected sector and its opposite, fs_sky still ran a Moller-Trumbore test (up to six triangles near a sector boundary) for each pixel of the sky. #3143's note puts the dawn sky pass at 1.8 ms at 1080p on an Intel UHD 730 against 0.6 ms by day, and #6887 reports the same FPS drop on an i5-1135G7 iGPU when the sky changes.

This rasterizes the same fan instead:

  • sunrise_fan::mesh emits the sixteen triangles as 48 vertices, the apex at weight 1 and the rim at 0. The rasterizer then interpolates exactly the apex barycentric (apex / s) the per-pixel test computed.
  • fs_sunrise outputs globals.sunrise.rgb with weight * globals.sunrise.a as alpha. Drawn over the fan-free sky with SrcAlpha / OneMinusSrcAlpha, this is the same mix the shader did; the alpha component uses Zero / One so the sky's HDR alpha is untouched.
  • The clip positions are projected once per frame on the CPU with the sky's own view (no TAA jitter, bob or spin, matching fs_sky's view_ray). The 960-byte buffer goes through the existing staging belt, so there is no new bind group or per-frame allocation.
  • fs_sky is unchanged for shader packs and for the water mirror, which keep the per-pixel path (the mirror is small and needs the mirror's projection).

Validation

  • cargo test -p horizon-client-render --test sunrise_shader: 8 passed, 1 ignored (the opt-in GPU reference test).
  • cargo test -p horizon-client-render --lib sunrise_fan::tests: 4 passed. The new test checks the apex/rim weights and vertices of every triangle.
  • cargo fmt --all -- --check: clean.
  • python3 tools/pr_ready.py --quick: Python tests 612 passed, rustfmt pass. Two gfx::frame_gen::interpolation::tests cases fail with this toolchain; I verified they fail on origin/main without this patch too. Clippy could not run locally because this Fedora Rust toolchain has no clippy component.
  • A/B at time 13000 with the same camera: the fan's shape, colour and smooth edge match on the RX 9070 XT. The fan is merely moved from the sky fragment shader to geometry.

Benchmark (lavapipe, Vulkan, 2176x1224, render distance 6, time 13000, 8 s fly, same world):

before after
GPU pass 44.80 ms 39.56 ms
p50 frame 36.43 ms 32.61 ms
average FPS 22.03 24.80

The RX 9070 XT is neutral on the same scene (the fan is cheap there); the saved work scales with sky pixels, which is where #6887's iGPU report lives.

🤖 Generated with OpenCode (DeepSeek V4.1 Flash Free)


🔄 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/7405 **Author:** [@dontstopgorkingit](https://github.com/dontstopgorkingit) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/rasterize-sunrise-fan` --- ### 📝 Commits (2) - [`744aebf`](https://github.com/horizon-rust/horizon/commit/744aebf303420dc47bdc01ed7cdcff20b85b2bfc) Draw the sunrise fan as geometry, not a test in every sky pixel - [`f96c062`](https://github.com/horizon-rust/horizon/commit/f96c062b3a294885e85e99aa130301011e3df3db) Merge main into #7405 ### 📊 Changes **3 files changed** (+142 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+83 -1) 📝 `crates/horizon-client-render/src/gfx/sunrise_fan.rs` (+33 -0) 📝 `crates/horizon-client-render/src/terrain.wgsl` (+26 -4) </details> ### 📄 Description > 🤖 Opened by dontstopgorkingit's AI agent (OpenCode, DeepSeek V4.1 Flash Free), not by dontstopgorkingit personally. Part of #6887. ## What and why The sunrise/sunset fan was evaluated in every sky pixel. After #3143 moved the fan's vertices and normals out of the shader, and #3993 narrowed the scan to the selected sector and its opposite, `fs_sky` still ran a Moller-Trumbore test (up to six triangles near a sector boundary) for each pixel of the sky. #3143's note puts the dawn sky pass at **1.8 ms at 1080p on an Intel UHD 730** against 0.6 ms by day, and #6887 reports the same FPS drop on an i5-1135G7 iGPU when the sky changes. This rasterizes the same fan instead: - `sunrise_fan::mesh` emits the sixteen triangles as 48 vertices, the apex at weight 1 and the rim at 0. The rasterizer then interpolates exactly the apex barycentric (`apex / s`) the per-pixel test computed. - `fs_sunrise` outputs `globals.sunrise.rgb` with `weight * globals.sunrise.a` as alpha. Drawn over the fan-free sky with `SrcAlpha / OneMinusSrcAlpha`, this is the same `mix` the shader did; the alpha component uses `Zero / One` so the sky's HDR alpha is untouched. - The clip positions are projected once per frame on the CPU with the sky's own view (no TAA jitter, bob or spin, matching `fs_sky`'s `view_ray`). The 960-byte buffer goes through the existing staging belt, so there is no new bind group or per-frame allocation. - `fs_sky` is unchanged for shader packs and for the water mirror, which keep the per-pixel path (the mirror is small and needs the mirror's projection). ## Validation - `cargo test -p horizon-client-render --test sunrise_shader`: 8 passed, 1 ignored (the opt-in GPU reference test). - `cargo test -p horizon-client-render --lib sunrise_fan::tests`: 4 passed. The new test checks the apex/rim weights and vertices of every triangle. - `cargo fmt --all -- --check`: clean. - `python3 tools/pr_ready.py --quick`: Python tests 612 passed, rustfmt pass. Two `gfx::frame_gen::interpolation::tests` cases fail with this toolchain; I verified they fail on `origin/main` without this patch too. Clippy could not run locally because this Fedora Rust toolchain has no clippy component. - A/B at time 13000 with the same camera: the fan's shape, colour and smooth edge match on the RX 9070 XT. The fan is merely moved from the sky fragment shader to geometry. Benchmark (lavapipe, Vulkan, 2176x1224, render distance 6, time 13000, 8 s fly, same world): | | before | after | |---|---:|---:| | GPU pass | 44.80 ms | **39.56 ms** | | p50 frame | 36.43 ms | **32.61 ms** | | average FPS | 22.03 | **24.80** | The RX 9070 XT is neutral on the same scene (the fan is cheap there); the saved work scales with sky pixels, which is where #6887's iGPU report lives. 🤖 Generated with [OpenCode](https://opencode.ai) (DeepSeek V4.1 Flash Free) --- <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:17 +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#7584
No description provided.