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.
This commit is contained in:
xfy 2026-07-15 13:57:18 +08:00
parent 7621ff12bb
commit 19905ed86a

View File

@ -215,10 +215,15 @@ fn value_noise3(p: vec3<f32>) -> f32 {
}
fn fbm3(p: vec3<f32>, 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;