diff --git a/crates/shaders/src/cpu/flatten.rs b/crates/shaders/src/cpu/flatten.rs index cce140dc9..bd501d396 100644 --- a/crates/shaders/src/cpu/flatten.rs +++ b/crates/shaders/src/cpu/flatten.rs @@ -333,7 +333,7 @@ fn flatten_euler( let n_frac = scaled_int; (n_frac, EspcRobust::Normal) }; - let n = (n_frac * scale_multiplier).ceil().max(1.0); + let n = (n_frac * scale_multiplier).ceil().clamp(1.0, 100.0); // Flatten line segments log!("@@@ loop: lines: {n}"); diff --git a/shader/flatten.wgsl b/shader/flatten.wgsl index 80da1880c..9371061d1 100644 --- a/shader/flatten.wgsl +++ b/shader/flatten.wgsl @@ -434,7 +434,10 @@ fn flatten_euler( let integrand_peak = sqrt(abs(k_peak * (k_peak * dist_scaled + 1.0))); n_frac = integral * integrand_peak / a; } - let n = max(ceil(n_frac * scale_multiplier), 1.0); + // Bound number of subdivisions to a reasonable number when the scale is huge. + // This may give slightly incorrect rendering but avoids hangs. + // TODO: aggressively cull to viewport + let n = clamp(ceil(n_frac * scale_multiplier), 1.0, 100.0); for (var i = 0u; i < u32(n); i++) { var lp1: vec2f; if i + 1u == u32(n) && t1 == 1.0 {