[PR #7697] Shader packs: sqrt never takes a negative in functions #7770

Open
opened 2026-11-03 07:23:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7697
Author: @senjinthedragon
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: shader-sqrt


📝 Commits (1)

  • 2452415 Shader packs: sqrt never takes a negative in functions

📊 Changes

2 files changed (+31 additions, -0 deletions)

View changed files

📝 crates/horizon-shaders/src/translate/mod.rs (+22 -0)
📝 crates/horizon-shaders/src/translate/rewrite.rs (+9 -0)

📄 Description

🤖 Opened by senjinthedragon's AI agent (Claude Code, Claude Opus 5.5), not by senjinthedragon personally.

What and why

GLSL leaves sqrt of a negative undefined. Packs written against GL drivers compute things like sqrt(1.0 - y * y) where y is exactly 1 in exact arithmetic. The GL compiler's rounding keeps that at zero; on our SPIR-V path the fused arithmetic can leave it a hair below, and the NaN spreads. In SEUS PTGI HRR 3 the GGX sample for perfectly smooth water became NaN for a pattern of pixels: dark speckles on water at shallow angles, absent in the same pack under OptiFine. sqrt in function bodies now clamps its argument at zero; global initializers keep the built-in so constants stay constant.

Tested

Together with #7694 (SEUS PTGI HRR 3 needs it to render at all), the same view in the same world: grain on open water 7.4 before, 0.8 after (picture: before left, after right). Translator test sqrt_in_functions_never_takes_a_negative. pr_ready --quick passes.

pr_ready (tools/pr_ready.py --quick on e7dd1881bbcd, against origin/main at 97dc1b553, 1 min 35 s)

Check Result
Scope ✅ 2 files, +31 −0
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (44 s)
rustfmt ✅ (10 s)
clippy ✅ (27 s)
tests: horizon-shaders ✅ 156 passed (13 s)
doc tests ✅ 0 passed
content root tests ➖ content root untouched
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/7697 **Author:** [@senjinthedragon](https://github.com/senjinthedragon) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `shader-sqrt` --- ### 📝 Commits (1) - [`2452415`](https://github.com/horizon-rust/horizon/commit/24524150500376b83d0d1f2be6bbdf87856f92ea) Shader packs: sqrt never takes a negative in functions ### 📊 Changes **2 files changed** (+31 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-shaders/src/translate/mod.rs` (+22 -0) 📝 `crates/horizon-shaders/src/translate/rewrite.rs` (+9 -0) </details> ### 📄 Description > 🤖 Opened by senjinthedragon's AI agent (Claude Code, Claude Opus 5.5), not by senjinthedragon personally. ## What and why GLSL leaves `sqrt` of a negative undefined. Packs written against GL drivers compute things like `sqrt(1.0 - y * y)` where y is exactly 1 in exact arithmetic. The GL compiler's rounding keeps that at zero; on our SPIR-V path the fused arithmetic can leave it a hair below, and the NaN spreads. In SEUS PTGI HRR 3 the GGX sample for perfectly smooth water became NaN for a pattern of pixels: dark speckles on water at shallow angles, absent in the same pack under OptiFine. `sqrt` in function bodies now clamps its argument at zero; global initializers keep the built-in so constants stay constant. ## Tested Together with #7694 (SEUS PTGI HRR 3 needs it to render at all), the same view in the same world: grain on open water 7.4 before, 0.8 after (picture: before left, after right). Translator test `sqrt_in_functions_never_takes_a_negative`. `pr_ready --quick` passes. **pr_ready** (`tools/pr_ready.py --quick` on e7dd1881bbcd, against origin/main at 97dc1b553, 1 min 35 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +31 −0 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (44 s) | | rustfmt | ✅ (10 s) | | clippy | ✅ (27 s) | | tests: horizon-shaders | ✅ 156 passed (13 s) | | doc tests | ✅ 0 passed | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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>
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#7770
No description provided.