[PR #1180] [CLOSED] Ray tracing spike: experimental ray-traced sun shadows (off by default) + report #3394

Closed
opened 2026-11-03 04:09:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1180
Author: @ludovic111
Created: 10/22/2026
Status: ❌ Closed

Base: main ← Head: feat/raytracing-spike


📝 Commits (4)

  • b517ac3 Experimental ray-traced sun shadows behind HORIZON_RT_SHADOWS (research spike)
  • c604cf2 Ray-traced shadows spike: BLAS compaction, timed BLAS builds, TLAS distance cap
  • 11d256e rt_shadow_bench: Linux driver libraries as perf_bench gives them
  • 42c752d Ray tracing spike report: docs/raytracing.md, screenshots

📊 Changes

22 files changed (+1298 additions, -8 deletions)

View changed files

📝 Cargo.lock (+8 -0)
📝 Cargo.toml (+1 -1)
📝 crates/horizon-client/Cargo.toml (+2 -0)
📝 crates/horizon-client/src/game/control.rs (+16 -0)
📝 crates/horizon-client/src/game/render_control.rs (+1 -0)
📝 crates/horizon-client/src/gfx.rs (+145 -6)
📝 crates/horizon-client/src/gfx/arena.rs (+5 -0)
➕ crates/horizon-client/src/gfx/raytrace.rs (+609 -0)
📝 crates/horizon-client/src/gfx/resident.rs (+13 -1)
📝 crates/horizon-client/src/gfx/timing.rs (+4 -0)
➕ crates/horizon-client/src/terrain_rt.wgsl (+70 -0)
➕ crates/horizon-gpu-experimental/Cargo.toml (+13 -0)
➕ crates/horizon-gpu-experimental/src/lib.rs (+11 -0)
📝 docs/README.md (+1 -0)
➕ docs/raytracing.md (+164 -0)
➕ shots/raytracing-1/metal-morning-forest-rd12-rt-off.jpg (+0 -0)
➕ shots/raytracing-1/metal-morning-forest-rd12-rt-on.jpg (+0 -0)
➕ shots/raytracing-1/metal-morning-village-rd12-rt-off.jpg (+0 -0)
➕ shots/raytracing-1/metal-morning-village-rd12-rt-on.jpg (+0 -0)
➕ shots/raytracing-1/rtx4080-morning-village-rd12-rt-off.jpg (+0 -0)

...and 2 more files

📄 Description

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

Research spike (raytracing-1, FEATURES.md item 15): draft, not for merge as is. Experimental ray-traced sun shadows, off by default: nothing runs unless the game starts with HORIZON_RT_SHADOWS=1 on a GPU with hardware ray queries. The report with every number is docs/raytracing.md.

What

  • gfx/raytrace.rs: one BLAS per chunk section, built straight from the section arena (no copy), compacted; one TLAS rebuilt every frame (HORIZON_RT_SHADOW_CHUNKS=N caps it to N chunks); at most 512 BLAS builds a frame; a remeshed section gets a new BLAS.
  • terrain_rt.wgsl: the solid terrain pipeline with one ray query per pixel towards the sun; a shadowed pixel reads the lightmap with less sky light, so torches and caves keep the vanilla look.
  • crates/horizon-gpu-experimental: wgpu's ExperimentalFeatures::enabled() is unsafe, and horizon-client forbids unsafe code.
  • Control socket rt-shadows [on|off|rebuild|bench-builds]; tools/rt_shadow_bench.py measures it against vanilla.
  • With the variable unset, the device, pipelines and draws are the same as on main (experimental_features stays disabled, no extra buffer usages, the vanilla solid pipeline).

Findings (short)

  • wgpu 30.0.1 ray queries work on Vulkan (RTX 4080) and Metal (M4 Pro), no wgpu errors. DX12 needs DXC (Horizon uses FXC unless dxcompiler.dll is on the PATH); Windows defaults to Vulkan anyway. M1/M2 report ray tracing without RT hardware: gate to M3+.
  • RTX 4080 GPU time: shadow rays + per-frame TLAS cost about 1 ms (RD 32: 2.40 → 3.06 ms village, 1.36 → 2.41 ms mountain). The CPU is the problem: the per-frame TLAS over 26 000-31 000 sections costs 2-7 ms of wgpu bookkeeping per frame at RD 32 (frame 3.8 → 15.6 ms village). Capping the TLAS to 8 chunks: RD 32 village 2.8 ms a frame with shadows on.
  • M4 Pro: rays about 3 ms a frame at 1280x720; RD 32 frame 3.9 → 15.7 ms (village), 10.8 ms with the 8-chunk cap.
  • BLAS build: 35-41 µs GPU + 21-26 µs CPU per section on the 4080, 16-22 µs + 11-27 µs on the M4 Pro. Block updates: ~40 µs per changed section: cheap.
  • Memory: ~22 bytes per triangle compacted on the 4080 (+0.6-0.8 GB at RD 32), +2-3 GB at RD 32 on the M4 Pro.
  • Limits: plants and leaves cast square shadows (cutout quads are opaque in the BLAS); only solid terrain receives shadows.

Recommendation: go as an opt-in experimental setting after two fixes (cap/stop rebuilding the TLAS every frame, alpha-test cutout geometry); no-go for reflections/GI until then. Details and next steps in the report.

Screenshots (morning, M4 Pro, shadows on / off):

on
off

How tested

cargo fmt --all -- --check                                   ok
cargo clippy --workspace --all-targets -- -D warnings        ok
cargo test -p horizon-client -p horizon-gpu-experimental     ok (985 + 91 + smaller suites, 0 failed;
                                                                incl. gfx::tests::ray_traced_shadow_shader, HLSL 6.5)
tools/parity.py block_entity_render cloud_render environment_render section_mesh
                terrain weather_render world_border_render   7 passed, 0 failed
(--changed origin/main lists all 327 harnesses because Cargo.lock changed; the render ones were run.)

Measurements: tools/rt_shadow_bench.py on the RTX 4080 (desktop, Vulkan, offscreen on a vscreen, run only while its monitors were off and no game ran) and the Mac mini's M4 Pro (Metal, offscreen). Both machines were busy with other agents' jobs: CPU frame times are noisy, the 4080's GPU timestamps are not.

Needs Ludovic

  • Decide go / no-go / next step from docs/raytracing.md. This PR stays a draft; a real version would be split into small PRs (TLAS cap + world-anchored TLAS, cutout alpha test, a video setting).
  • Not tried: DX12 on Windows, AMD and Intel GPUs, Apple M1-M3.

🤖 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/1180 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/raytracing-spike` --- ### 📝 Commits (4) - [`b517ac3`](https://github.com/horizon-rust/horizon/commit/b517ac32550d4e40d74c9f836a9331e434222451) Experimental ray-traced sun shadows behind HORIZON_RT_SHADOWS (research spike) - [`c604cf2`](https://github.com/horizon-rust/horizon/commit/c604cf29c81bb612a1753e74c7de31796bee70bb) Ray-traced shadows spike: BLAS compaction, timed BLAS builds, TLAS distance cap - [`11d256e`](https://github.com/horizon-rust/horizon/commit/11d256ec2d5e43c7815107cb30d4ce0c4bf82244) rt_shadow_bench: Linux driver libraries as perf_bench gives them - [`42c752d`](https://github.com/horizon-rust/horizon/commit/42c752d6b7c45b890d223bfce63eea9040dc6735) Ray tracing spike report: docs/raytracing.md, screenshots ### 📊 Changes **22 files changed** (+1298 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+8 -0) 📝 `Cargo.toml` (+1 -1) 📝 `crates/horizon-client/Cargo.toml` (+2 -0) 📝 `crates/horizon-client/src/game/control.rs` (+16 -0) 📝 `crates/horizon-client/src/game/render_control.rs` (+1 -0) 📝 `crates/horizon-client/src/gfx.rs` (+145 -6) 📝 `crates/horizon-client/src/gfx/arena.rs` (+5 -0) ➕ `crates/horizon-client/src/gfx/raytrace.rs` (+609 -0) 📝 `crates/horizon-client/src/gfx/resident.rs` (+13 -1) 📝 `crates/horizon-client/src/gfx/timing.rs` (+4 -0) ➕ `crates/horizon-client/src/terrain_rt.wgsl` (+70 -0) ➕ `crates/horizon-gpu-experimental/Cargo.toml` (+13 -0) ➕ `crates/horizon-gpu-experimental/src/lib.rs` (+11 -0) 📝 `docs/README.md` (+1 -0) ➕ `docs/raytracing.md` (+164 -0) ➕ `shots/raytracing-1/metal-morning-forest-rd12-rt-off.jpg` (+0 -0) ➕ `shots/raytracing-1/metal-morning-forest-rd12-rt-on.jpg` (+0 -0) ➕ `shots/raytracing-1/metal-morning-village-rd12-rt-off.jpg` (+0 -0) ➕ `shots/raytracing-1/metal-morning-village-rd12-rt-on.jpg` (+0 -0) ➕ `shots/raytracing-1/rtx4080-morning-village-rd12-rt-off.jpg` (+0 -0) _...and 2 more files_ </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Research spike (raytracing-1, FEATURES.md item 15): draft, not for merge as is.** Experimental ray-traced sun shadows, **off by default**: nothing runs unless the game starts with `HORIZON_RT_SHADOWS=1` on a GPU with hardware ray queries. The report with every number is [docs/raytracing.md](https://github.com/ludovic111/horizon/blob/feat/raytracing-spike/docs/raytracing.md). ## What - `gfx/raytrace.rs`: one BLAS per chunk section, built straight from the section arena (no copy), compacted; one TLAS rebuilt every frame (`HORIZON_RT_SHADOW_CHUNKS=N` caps it to N chunks); at most 512 BLAS builds a frame; a remeshed section gets a new BLAS. - `terrain_rt.wgsl`: the solid terrain pipeline with one ray query per pixel towards the sun; a shadowed pixel reads the lightmap with less sky light, so torches and caves keep the vanilla look. - `crates/horizon-gpu-experimental`: wgpu's `ExperimentalFeatures::enabled()` is `unsafe`, and horizon-client forbids unsafe code. - Control socket `rt-shadows [on|off|rebuild|bench-builds]`; `tools/rt_shadow_bench.py` measures it against vanilla. - With the variable unset, the device, pipelines and draws are the same as on main (`experimental_features` stays disabled, no extra buffer usages, the vanilla solid pipeline). ## Findings (short) - wgpu 30.0.1 ray queries **work on Vulkan (RTX 4080) and Metal (M4 Pro)**, no wgpu errors. DX12 needs DXC (Horizon uses FXC unless dxcompiler.dll is on the PATH); Windows defaults to Vulkan anyway. M1/M2 report ray tracing without RT hardware: gate to M3+. - RTX 4080 GPU time: shadow rays + per-frame TLAS cost about **1 ms** (RD 32: 2.40 → 3.06 ms village, 1.36 → 2.41 ms mountain). The **CPU** is the problem: the per-frame TLAS over 26 000-31 000 sections costs 2-7 ms of wgpu bookkeeping per frame at RD 32 (frame 3.8 → 15.6 ms village). Capping the TLAS to 8 chunks: RD 32 village 2.8 ms a frame with shadows on. - M4 Pro: rays about 3 ms a frame at 1280x720; RD 32 frame 3.9 → 15.7 ms (village), 10.8 ms with the 8-chunk cap. - BLAS build: 35-41 µs GPU + 21-26 µs CPU per section on the 4080, 16-22 µs + 11-27 µs on the M4 Pro. Block updates: ~40 µs per changed section: cheap. - Memory: ~22 bytes per triangle compacted on the 4080 (+0.6-0.8 GB at RD 32), +2-3 GB at RD 32 on the M4 Pro. - Limits: plants and leaves cast square shadows (cutout quads are opaque in the BLAS); only solid terrain receives shadows. **Recommendation: go as an opt-in experimental setting after two fixes** (cap/stop rebuilding the TLAS every frame, alpha-test cutout geometry); no-go for reflections/GI until then. Details and next steps in the report. Screenshots (morning, M4 Pro, shadows on / off): ![on](https://github.com/ludovic111/horizon/blob/feat/raytracing-spike/shots/raytracing-1/metal-morning-village-rd12-rt-on.jpg?raw=true) ![off](https://github.com/ludovic111/horizon/blob/feat/raytracing-spike/shots/raytracing-1/metal-morning-village-rd12-rt-off.jpg?raw=true) ## How tested ``` cargo fmt --all -- --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client -p horizon-gpu-experimental ok (985 + 91 + smaller suites, 0 failed; incl. gfx::tests::ray_traced_shadow_shader, HLSL 6.5) tools/parity.py block_entity_render cloud_render environment_render section_mesh terrain weather_render world_border_render 7 passed, 0 failed (--changed origin/main lists all 327 harnesses because Cargo.lock changed; the render ones were run.) ``` Measurements: `tools/rt_shadow_bench.py` on the RTX 4080 (desktop, Vulkan, offscreen on a vscreen, run only while its monitors were off and no game ran) and the Mac mini's M4 Pro (Metal, offscreen). Both machines were busy with other agents' jobs: CPU frame times are noisy, the 4080's GPU timestamps are not. ## Needs Ludovic - Decide go / no-go / next step from docs/raytracing.md. This PR stays a draft; a real version would be split into small PRs (TLAS cap + world-anchored TLAS, cutout alpha test, a video setting). - Not tried: DX12 on Windows, AMD and Intel GPUs, Apple M1-M3. 🤖 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-03 04:09:13 +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#3394
No description provided.