From 4db69f6b538506345d0f0b8fd2a1f50e77301414 Mon Sep 17 00:00:00 2001
From: pkuzic
Date: Fri, 25 Sep 2026 23:27:18 +0100
Subject: [PATCH] MONKEY (reviewfix-a): SSAO normal cannot go NaN on isolated
pixels against the sky
Co-Authored-By: Claude Opus 5.5
---
crates/benilla-app/src/shaders/ssao.wgsl | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/crates/benilla-app/src/shaders/ssao.wgsl b/crates/benilla-app/src/shaders/ssao.wgsl
index 6b5b9bb9..afbbad39 100644
--- a/crates/benilla-app/src/shaders/ssao.wgsl
+++ b/crates/benilla-app/src/shaders/ssao.wgsl
@@ -98,7 +98,12 @@ fn ao_main(@builtin(position) frag: vec4) -> @location(0) vec4 {
let pu = neighbour(f - vec2(0, 1), p);
let dx = select(p - pl, pr - p, abs(pr.z - p.z) < abs(p.z - pl.z));
let dy = select(p - pu, pd - p, abs(pd.z - p.z) < abs(p.z - pu.z));
- var n = normalize(cross(dx, dy));
+ // MONKEY (reviewfix-a): sky on both sides of an axis makes the two steps parallel (a 1-px pole
+ // or rope against the sky); normalize(0) would be NaN and bloom would spread it. No AO there.
+ let c = cross(dx, dy);
+ let l2 = dot(c, c);
+ if (l2 < 1e-12) { return vec4(0.0, dist, protect, 1.0); }
+ var n = c * inverseSqrt(l2);
if (dot(n, p) > 0.0) { n = -n; }
// MONKEY (followups): cutout leaves scatter depth spikes through a canopy, and there the taps
// are noise. The spike is the smaller of the two one-sided steps two pixels out, capped by the