Skip to content

feat(wave): expose 9-point isotropic Laplacian as a UI toggle in Wave2d/FxWave2d/Downscale/XYPath/FestivalStick sketches #3109

Closed

Description

@zackees

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)

  1. WaveSimulation2D::setStencil(LaplacianStencil) — passthrough to the inner _Real. Sticky across setSuperSample() re-inits, which currently overwrite the stencil back to auto-selected default. (Today the user has to reach through waveSim.real().setStencil(...) AND re-set it after every setSuperSample() call — neither ergonomic nor reliable.)
  2. WaveFx::setStencil(LaplacianStencil) — same, on the highest-level user-facing class.
  3. 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 — declare setStencil/getStencil on WaveSimulation2D.
  • 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 — declare setStencil/getStencil on WaveFx.
  • (No .cpp.hpp change needed for WaveFx since it's a thin pass-through.)

Example sketches:

  • examples/Wave2d/Wave2d.h — direct WaveSimulation2D user with rich UI; add one checkbox to the existing waveSimControls group.
  • examples/Fx/FxWave2d/wavefx.cpp — two-layer WaveFx demo; 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-layer WaveFx; one checkbox.
  • examples/XYPath/complex.h (and src/wave.h) — uses two WaveFxPtr (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

History / refs

Activity

  1. added a commit that references this issue on Jun 15, 2026
    9bb097d
  2. moved this from Triage to Done in FastLED Trackeron Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions