[PR #1079] [MERGED] Stars: build the star buffer once, as vanilla does #3026

Closed
opened 2026-11-02 16:00:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1079
Author: @ludovic111
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @ludovic111

Base: main ← Head: fix/night-sky-stars-cost


📝 Commits (1)

  • 50a5e64 Stars: build the star buffer once and draw it with the sky's rotation

📊 Changes

4 files changed (+255 additions, -47 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+17 -46)
📝 crates/horizon-client/src/gfx.rs (+22 -1)
➕ crates/horizon-client/src/gfx/stars.rs (+200 -0)
➕ crates/horizon-client/src/gfx/stars.wgsl (+16 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #1054. Reported by Visivel (517 FPS by day, 168 FPS at night, same place and settings); rdbtCVS found that turning Sky off removes the drop.

What

Horizon rebuilt all 1,500 stars on the CPU every frame at night: the same seeded buildStars loop, rotated by the sky's angle, appended to the celestial vertex list and uploaded again. Vanilla builds the star buffer once (SkyRenderer.buildStars, seed 10842) and only changes the matrix it draws it with (renderSunMoonAndStars: Y -90°, then X by the star angle).

This PR does the same:

  • gfx/stars.rs builds the star triangles once, with the same seed and maths, into a static vertex buffer when the renderer starts.
  • Each frame only a 80-byte uniform changes: the clip-from-sky matrix (view_proj * rotation) and the star brightness.
  • The draw keeps vanilla's state: drawn after the sun and moon, additive blend (src alpha, one), no depth write.
  • celestial_geometry no longer loops over the stars. It hands the rotation and brightness to Frame::stars, which stays None by day, in the End, and when Sky is off.

Numbers

Same scene for both builds: seed 1234, the village at (-960, 110, 150), mobs off and killed, standing still, horizon-ctl bench 5 s, noon and midnight alternated in one game, medians.

Mac mini (M4 Pro), macOS, Metal, offscreen 1280x720, 12 runs per row, main = this PR's parent (4d2e05dd). The two builds ran in the order main, PR, PR, main. The machine had CI runners on it (load 32–64), so the gap between night and day inside one game is the figure to read:

main this PR
CPU frame, noon 0.796 ms 0.789 ms
CPU frame, midnight 0.865 ms 0.794 ms
night minus day +0.069 ms +0.005 ms
prepare phase, noon → midnight 0.224 → 0.293 ms 0.222 → 0.217 ms
FPS, noon / midnight 1156 / 1075 1170 / 1169

ThinkPad, Intel HD 620, Linux, Mesa Vulkan, offscreen 1280x720, nice 19, 12 runs per row:

main this PR
CPU frame, noon 2.199 ms 2.163 ms
CPU frame, midnight 2.386 ms 2.170 ms
night minus day +0.19 ms +0.007 ms
prepare phase, night 0.715 ms 0.573 ms
GPU frame 2.87 ms 2.87 ms

The HD 620 is GPU-bound here (about 310 FPS on both), so the CPU frame shows the change and the FPS doesn't. On a fast GPU it shows in FPS: on the desktop (RTX 4080, Linux), main dropped from about 4,700–5,100 FPS at noon to 2,100–3,600 at midnight. That machine was running other jobs (load about 22), so I'm not giving its A/B as a number.

Screenshots

Midnight, looking up, ticks frozen, ThinkPad. Below are main, this PR, and the difference between them (black means identical). The stars match pixel for pixel. The only differences are cloud edges, which drift between the two launches.

main this PR difference
main this PR difference

Checks

  • cargo fmt --all --check: clean.
  • cargo clippy -p horizon-client --all-targets -- -D warnings with set -o pipefail: exit 0 (scoped to the touched crate; workspace-wide clippy fails on that machine on hidapi/libudev, which this PR doesn't touch).
  • cargo test -p horizon-client: all pass (lib 941, plus the integration tests). New test stars_lie_on_the_sky_sphere_as_whole_quads.
  • tools/parity.py --changed origin/main lists every harness (none has a pass history yet), so I ran the ones this touches, environment_render, weather_render, biome_weather and heightmap, on the desktop. On main at bc890421 all 4 pass. On bc890421 with this PR and #1084 all 4 pass.

🤖 Generated with Claude Code


🔄 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/1079 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/night-sky-stars-cost` --- ### 📝 Commits (1) - [`50a5e64`](https://github.com/horizon-rust/horizon/commit/50a5e640125f01481284bdc1f2a7930903bff2b7) Stars: build the star buffer once and draw it with the sky's rotation ### 📊 Changes **4 files changed** (+255 additions, -47 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+17 -46) 📝 `crates/horizon-client/src/gfx.rs` (+22 -1) ➕ `crates/horizon-client/src/gfx/stars.rs` (+200 -0) ➕ `crates/horizon-client/src/gfx/stars.wgsl` (+16 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #1054. Reported by **Visivel** (517 FPS by day, 168 FPS at night, same place and settings); **rdbtCVS** found that turning Sky off removes the drop. ## What Horizon rebuilt all 1,500 stars on the CPU every frame at night: the same seeded `buildStars` loop, rotated by the sky's angle, appended to the celestial vertex list and uploaded again. Vanilla builds the star buffer once (`SkyRenderer.buildStars`, seed 10842) and only changes the matrix it draws it with (`renderSunMoonAndStars`: Y -90°, then X by the star angle). This PR does the same: - `gfx/stars.rs` builds the star triangles once, with the same seed and maths, into a static vertex buffer when the renderer starts. - Each frame only a 80-byte uniform changes: the clip-from-sky matrix (`view_proj * rotation`) and the star brightness. - The draw keeps vanilla's state: drawn after the sun and moon, additive blend (src alpha, one), no depth write. - `celestial_geometry` no longer loops over the stars. It hands the rotation and brightness to `Frame::stars`, which stays `None` by day, in the End, and when Sky is off. ## Numbers Same scene for both builds: seed 1234, the village at (-960, 110, 150), mobs off and killed, standing still, `horizon-ctl bench` 5 s, noon and midnight alternated in one game, medians. **Mac mini (M4 Pro), macOS, Metal**, offscreen 1280x720, 12 runs per row, main = this PR's parent (4d2e05dd). The two builds ran in the order main, PR, PR, main. The machine had CI runners on it (load 32–64), so the gap between night and day inside one game is the figure to read: | | main | this PR | |---|---:|---:| | CPU frame, noon | 0.796 ms | 0.789 ms | | CPU frame, midnight | 0.865 ms | 0.794 ms | | night minus day | **+0.069 ms** | **+0.005 ms** | | `prepare` phase, noon → midnight | 0.224 → 0.293 ms | 0.222 → 0.217 ms | | FPS, noon / midnight | 1156 / 1075 | 1170 / 1169 | **ThinkPad, Intel HD 620**, Linux, Mesa Vulkan, offscreen 1280x720, nice 19, 12 runs per row: | | main | this PR | |---|---:|---:| | CPU frame, noon | 2.199 ms | 2.163 ms | | CPU frame, midnight | 2.386 ms | 2.170 ms | | night minus day | **+0.19 ms** | **+0.007 ms** | | `prepare` phase, night | 0.715 ms | 0.573 ms | | GPU frame | 2.87 ms | 2.87 ms | The HD 620 is GPU-bound here (about 310 FPS on both), so the CPU frame shows the change and the FPS doesn't. On a fast GPU it shows in FPS: on the **desktop (RTX 4080, Linux)**, main dropped from about 4,700–5,100 FPS at noon to 2,100–3,600 at midnight. That machine was running other jobs (load about 22), so I'm not giving its A/B as a number. ## Screenshots Midnight, looking up, ticks frozen, ThinkPad. Below are main, this PR, and the difference between them (black means identical). The stars match pixel for pixel. The only differences are cloud edges, which drift between the two launches. | main | this PR | difference | |---|---|---| | ![main](https://raw.githubusercontent.com/ludovic111/horizon/ded3c38e272ef5587c1a1c15fab658a26d801df9/stars/base-sky-up.png) | ![this PR](https://raw.githubusercontent.com/ludovic111/horizon/ded3c38e272ef5587c1a1c15fab658a26d801df9/stars/stars-sky-up.png) | ![difference](https://raw.githubusercontent.com/ludovic111/horizon/ded3c38e272ef5587c1a1c15fab658a26d801df9/stars/diff-stars.png) | ## Checks - `cargo fmt --all --check`: clean. - `cargo clippy -p horizon-client --all-targets -- -D warnings` with `set -o pipefail`: exit 0 (scoped to the touched crate; workspace-wide clippy fails on that machine on hidapi/libudev, which this PR doesn't touch). - `cargo test -p horizon-client`: all pass (lib 941, plus the integration tests). New test `stars_lie_on_the_sky_sphere_as_whole_quads`. - `tools/parity.py --changed origin/main` lists every harness (none has a pass history yet), so I ran the ones this touches, `environment_render`, `weather_render`, `biome_weather` and `heightmap`, on the desktop. On main at bc890421 all 4 pass. On bc890421 with this PR and #1084 all 4 pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 16:00:55 +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#3026
No description provided.