From 19905ed86a8662f9f54e6a8c590706e73e99745c Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 15 Jul 2026 13:57:18 +0800 Subject: [PATCH] fix(shader): port MAX_OCTAVES-with-break into fbm3 This branch is the first to call fbm3 with runtime-variable octave counts (previously only compile-time constants 3u/4u). The spec's WebGPU safety mitigation (fixed upper bound + early break) was applied to ridged_fbm but missed on fbm3. Ports the same pattern so older WebGPU drivers don't miscompile the dynamic loop bound. --- assets/shaders/black_hole.wgsl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assets/shaders/black_hole.wgsl b/assets/shaders/black_hole.wgsl index b2d75ba..8609204 100644 --- a/assets/shaders/black_hole.wgsl +++ b/assets/shaders/black_hole.wgsl @@ -215,10 +215,15 @@ fn value_noise3(p: vec3) -> f32 { } fn fbm3(p: vec3, octaves: u32) -> f32 { + // MAX_OCTAVES-with-break: the conservative WebGPU form for a runtime- + // chosen octave count. Older drivers can miscompile non-constant loop + // bounds; this branch is the first to pass dynamic octaves here. + const MAX_OCTAVES = 6u; var sum = 0.0; var amp = 0.5; var freq = 1.0; - for (var i: u32 = 0u; i < octaves; i = i + 1u) { + for (var i: u32 = 0u; i < MAX_OCTAVES; i = i + 1u) { + if (i >= octaves) { break; } sum = sum + amp * value_noise3(p * freq); freq = freq * 2.0; amp = amp * 0.5;