Repository navigation
Description
Background
PR #3104 (§5 of the closed audit meta #3098) added the opt-in NinePointIsotropic Laplacian to WaveSimulation2D_Real. The wrapper WaveSimulation2D::init() auto-selects it only when mMultiplier >= 2:
if (mMultiplier >= 2) {
mSim->setStencil(LaplacianStencil::NinePointIsotropic);
}That gate was lifted from the audit body's framing — "the artifact becomes obvious at SUPER_SAMPLE_2X/4X/8X." On reflection that framing is too conservative. The 5-point stencil's anisotropy (a square-ish "+" or "×" pattern in the bright ring of a circular ripple) is a property of the stencil itself, not the grid resolution. At 1× it's still visible whenever:
- Native grid is ≥ 16×16 — ripples are big enough on the LED matrix for the eye to perceive the 4-pointed-star shape.
- Coloring is gradient/palette — the bright-ring isolevel exaggerates spatial structure that grayscale would smooth over.
- Wave decay is slow — the eye has time to lock onto ripple shape across many frames.
The Wave2d sketch (100×100, gradient coloring, slow dampening = 9.0) hits all three. The auto-selected 5-point at 1× there is visibly worse than 9-point would be.
Cost of 9-point at 1×: ~2× reads + ALU per inner-loop cell. On a 100×100 grid that's an extra ~10k cells/step worth of arithmetic — fine on every platform the wave sketches actually run on.
Proposal
Let humans A/B compare on their specific hardware via a UI toggle. Concretely:
Public API additions (small, header-only passthroughs)
WaveSimulation2D::setStencil(LaplacianStencil)— passthrough to the inner_Real. Sticky acrosssetSuperSample()re-inits, which currently overwrite the stencil back to auto-selected default. (Today the user has to reach throughwaveSim.real().setStencil(...)AND re-set it after everysetSuperSample()call — neither ergonomic nor reliable.)WaveFx::setStencil(LaplacianStencil)— same, on the highest-level user-facing class.- Matching
getStencil()getters on both for round-trip readability in UI code.
UI toggle in example sketches
Add a UICheckbox (default false = 5-point, backward compatible) to each of the five 2D-wave sketches and wire it through to setStencil() in the loop. Suggested label: "Isotropic stencil (rounder ripples)".
Files touched
Source (API additions):
src/fl/math/wave/wave_simulation.h— declaresetStencil/getStencilonWaveSimulation2D.src/fl/math/wave/wave_simulation.cpp.hpp— implement; existing auto-select stays as the default but the user toggle overrides it.src/fl/fx/2d/wave.h— declaresetStencil/getStencilonWaveFx.- (No
.cpp.hppchange needed forWaveFxsince it's a thin pass-through.)
Example sketches:
examples/Wave2d/Wave2d.h— directWaveSimulation2Duser with rich UI; add one checkbox to the existingwaveSimControlsgroup.examples/Fx/FxWave2d/wavefx.cpp— two-layerWaveFxdemo; add one checkbox PER LAYER (Upper / Lower) so the human can see them side-by-side under different speeds/dampening.examples/Downscale/Downscale.h— single-layerWaveFx; one checkbox.examples/XYPath/complex.h(andsrc/wave.h) — uses twoWaveFxPtr(wave_fx_low+wave_fx_high); one checkbox is fine — both layers should track the same setting since the visual comparison the user wants is "stencil on vs off" not "stencil mixed".examples/FestivalStick/curr.h— uses the wave kernel; add a single checkbox if the active path actually exercises the 2D PDE (verify before wiring).
Not touched (not 2D wave):
examples/Wave/Wave.h— 1D wave; 9-point Laplacian is a 2D concept.
Reference snippet for the .ino side
// At file scope, alongside the existing UI checkboxes:
fl::UICheckbox isotropicStencil("Isotropic stencil (rounder ripples)", false);
// In loop(), AFTER any setSuperSample() call (so the user toggle wins over
// the wrapper's auto-select at SuperSample>=2X):
waveSim.setStencil(isotropicStencil
? fl::LaplacianStencil::NinePointIsotropic
: fl::LaplacianStencil::FivePoint);For the two-layer sketches (FxWave2d, XYPath/complex.h) use one toggle per layer where it makes sense.
Acceptance
Human visual evaluation in the FastLED web compiler, against the canonical Wave2d sketch at its default settings (100×100, gradient coloring, dampening 9.0):
- Toggle OFF (5-point, the existing default): ripples are visibly "square-ish" — a 4-pointed-star bright ring is obvious.
- Toggle ON (9-point isotropic): ripples are round.
- Frame rate impact on the WASM build is < ~20% (a one-line
millis()delta in the existing example loop is enough to capture this — no formal microbench needed).
No new tests required for the source side; the API additions are header-level passthroughs to the already-tested setStencil/getStencil on WaveSimulation2D_Real (#3104).
Out of scope
- Changing the wrapper's auto-select gate. Leave the existing
mMultiplier >= 2auto-on behavior in place; the new toggle is an explicit user override, not a replacement. - Per-stencil microbench or platform sweep. The audit issue's §7 SIMD work (split into feat(wave): host SIMD backend for 2D wave PDE update kernel — SSE2/AVX2/NEON (split from #3097) #3106 / feat(wave): ESP32-S3 PIE SIMD backend for 2D wave PDE update kernel (split from #3097) #3107 / feat(wave): Teensy 4 DSP-intrinsic SIMD backend for 2D wave PDE update kernel (split from #3097) #3108) is the right place for that.
- 1D Laplacian variants — irrelevant;
WaveSimulation1D_Realdoesn't have a 9-point analog in this audit.
History / refs
- Closed audit: audit(wave/diff-eq): overflow risk + perf wins in WaveSimulation Q15 stencil (behind WaveFx) #3073 (PR fix(wave): prevent i32 overflow in Q15 Courant*Laplacian multiply (refs #3073) #3083)
- Closed meta: [meta] WaveSimulation Q15 stencil — perf + algorithmic follow-ups from #3073 #3098
- §5 implementation: feat(wave): opt-in 9-point isotropic Laplacian for WaveSimulation2D (closes #3095) #3104 (this is the user-facing follow-on)
- Related auto-select rationale: feat(wave): opt-in 9-point isotropic Laplacian for WaveSimulation2D (closes #3095) #3104 PR body and the meta-close comment on [meta] WaveSimulation Q15 stencil — perf + algorithmic follow-ups from #3073 #3098
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(wave): expose 9-point isotropic Laplacian as a UI toggle in 5 ex…