Skip to content

feat(wave): expose 9-point isotropic Laplacian as UI toggle in 5 example sketches (closes #3109) - #3110

Merged
zackees merged 1 commit into
masterfrom
fix/3109-wave-stencil-ui-toggle
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3109-wave-stencil-ui-toggle

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Implements #3109. Lets humans A/B compare 5-point vs 9-point isotropic Laplacian on their hardware via a UI checkbox in five 2D-wave example sketches.

Source-side API additions

Header-only passthroughs — no behavior change for callers that don't touch them:

  • WaveSimulation2D::setStencil(LaplacianStencil) FL_NOEXCEPT / getStencil() — passthrough to inner _Real. Marks the choice as user-set so subsequent setSuperSample() calls preserve it across the wrapper's re-init instead of re-applying the multiplier-based default.
  • WaveFx::setStencil(LaplacianStencil) FL_NOEXCEPT / getStencil() — passthrough to the wrapper.

A private bool mUserSetStencil in WaveSimulation2D tracks the override.

UI toggle added to 5 sketches

Sketch Note
examples/Wave2d/Wave2d.h single WaveSimulation2D; one checkbox in waveSimControls group
examples/Fx/FxWave2d/wavefx.cpp two-layer WaveFx; one checkbox per layer (Upper / Lower) so layers can A/B independently
examples/Downscale/Downscale.h two-layer WaveEffect (wraps two WaveFxPtr); one checkbox, both layers track
examples/XYPath/complex.h same WaveEffect pattern; one checkbox
examples/FestivalStick/curr.h single WaveFx in drawWave(); one checkbox in waveGroup

UI label: "Isotropic stencil (rounder ripples)". Default unchecked (5-point), preserving existing behavior. Toggle is applied after setSuperSample() so the user choice wins.

Validation

  • bash test fl_math_wave_wave_simulation_real --cpp — 8/8 pass.
  • bash lint --cpp — clean.
  • bash compile wasm --examples — Wave2d, Downscale, XYPath, FestivalStick all build cleanly. (FxWave2d's nested examples/Fx/FxWave2d/ path can't be driven through the build tool from the CLI but uses the same WaveFx::setStencil API exercised by the other three WaveFx-using sketches.)

Closes #3109
Refs #3098 (parent audit), #3104 (§5 — the 9-point Laplacian itself)

Summary by CodeRabbit

  • New Features
    • Wave stencil mode selection now available across examples, allowing users to toggle between isotropic (rounder ripples) and standard stencil modes for customizable wave appearance.
    • Selected stencil modes persist correctly when adjusting other wave simulation parameters.

…ample sketches

Background: PR #3104 added the opt-in 9-point isotropic Laplacian to
WaveSimulation2D_Real and auto-selected it in the supersampled wrapper
only at mMultiplier >= 2. That auto-select gate is too conservative —
the 5-point anisotropy artifact (square-ish bright ring) is a property
of the stencil, not the grid resolution, and shows up at 1x on any
16x16+ grid with gradient coloring (which is exactly what Wave2d ships
with by default).

This PR lets humans A/B compare on their hardware via a UI checkbox in
five 2D-wave example sketches.

## Source-side API additions (header-only passthroughs)

- WaveSimulation2D::setStencil(LaplacianStencil) — passthrough to inner
  _Real. Marks the choice as "user set" so subsequent setSuperSample()
  calls preserve it across the wrapper's re-init instead of re-applying
  the multiplier-based default.
- WaveSimulation2D::getStencil() — getter.
- WaveFx::setStencil(LaplacianStencil) — passthrough to the wrapper.
- WaveFx::getStencil() — getter.
- Private bool mUserSetStencil in WaveSimulation2D tracks user override.

No new tests required; existing wave_simulation_real.cpp suite covers
setStencil/getStencil on the inner class and continues to pass (8/8).

## Example sketches — UI toggle added

- examples/Wave2d/Wave2d.h — single WaveSimulation2D; one checkbox in
  the existing waveSimControls group.
- examples/Fx/FxWave2d/wavefx.cpp — two-layer WaveFx demo; one checkbox
  per layer (Upper / Lower) so layers can A/B independently.
- examples/Downscale/Downscale.h — two-layer WaveEffect (wraps two
  WaveFxPtr); one checkbox, both layers track.
- examples/XYPath/complex.h — same WaveEffect pattern; one checkbox.
- examples/FestivalStick/curr.h — single WaveFx in drawWave(); one
  checkbox in the waveGroup.

UI label across all sketches: "Isotropic stencil (rounder ripples)".
Default is unchecked (5-point), preserving existing behavior. Toggle is
applied after setSuperSample() so the user choice wins over the
wrapper's auto-select.

## Validation

- bash test fl_math_wave_wave_simulation_real --cpp — 8/8 pass.
- bash lint --cpp — clean.
- bash compile wasm --examples Wave2d / Downscale / XYPath /
  FestivalStick — all build cleanly. (FxWave2d's nested examples/Fx/
  path can't be driven through the build tool from the command line but
  uses the same WaveFx::setStencil API exercised by the other four
  WaveFx-using sketches.)

Closes #3109
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d990cb29-c6ae-4182-9cd6-648928a0bd8c

📥 Commits

Reviewing files that changed from the base of the PR and between 16c8ab7 and 06b32df.

📒 Files selected for processing (7)
  • examples/Downscale/Downscale.h
  • examples/FestivalStick/curr.h
  • examples/Fx/FxWave2d/wavefx.cpp
  • examples/Wave2d/Wave2d.h
  • examples/XYPath/complex.h
  • src/fl/fx/2d/wave.h
  • src/fl/math/wave/wave_simulation.h

📝 Walkthrough

Walkthrough

Adds setStencil(LaplacianStencil) and getStencil() to WaveSimulation2D and WaveFx, with a mUserSetStencil flag so the chosen stencil survives setSuperSample() re-initializations. Five wave example sketches each gain a UICheckbox wired to these new APIs, allowing runtime toggle between nine-point isotropic and five-point Laplacian stencils.

Changes

Isotropic Laplacian stencil toggle

Layer / File(s) Summary
WaveSimulation2D and WaveFx stencil API
src/fl/math/wave/wave_simulation.h, src/fl/fx/2d/wave.h
WaveSimulation2D gains public setStencil()/getStencil() and a private mUserSetStencil flag; setSuperSample() now captures and restores the stencil when user-set. WaveFx adds thin-passthrough setStencil()/getStencil() delegating to mWaveSim.
UICheckbox wiring across five example sketches
examples/Wave2d/Wave2d.h, examples/Fx/FxWave2d/wavefx.cpp, examples/Downscale/Downscale.h, examples/XYPath/complex.h, examples/FestivalStick/curr.h
Each sketch adds an isotropicStencil checkbox to the UI group and calls setStencil(NinePointIsotropic or FivePoint) in the per-frame loop after any setSuperSample() call. FxWave2d adds separate checkboxes for its upper and lower wave layers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • #3109 — This PR directly implements the full proposal from that issue: setStencil()/getStencil() on WaveSimulation2D and WaveFx, sticky behavior across setSuperSample(), and UICheckbox toggles in all five named example sketches.
  • #3095 — The PR implements the user-selectable stencil control described there, including the setStencil()/getStencil() API additions and the preservation across setSuperSample() calls.
  • #3073 — The PR implements the §5 suggestion from that audit by exposing the nine-point isotropic Laplacian as an opt-in via the public WaveFx/WaveSimulation2D API.

Poem

🐇 Five points or nine — the ripple must choose,
A checkbox appears so no rounder ring loses.
Through setSuperSample the stencil holds tight,
The waves roll out round in the soft LED light.
From Wave2d to FestivalStick, the toggle is set —
The roundest of ripples the bunny's got yet! 🌊

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/3109-wave-stencil-ui-toggle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 15, 2026
@zackees
zackees merged commit 9bb097d into master Jun 15, 2026
7 of 8 checks passed
@zackees
zackees deleted the fix/3109-wave-stencil-ui-toggle branch June 15, 2026 22:26
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 15, 2026
zackees added a commit that referenced this pull request Jun 15, 2026
…3112)

Delivers the research-bot deliverable specified by #3111: a definitive
recommendation document covering the 10 approach families catalogued in
the issue body (compact higher-order stencils, output anti-aliasing
filters, implicit time integration, spectral/FFT, lattice Boltzmann,
procedural/non-PDE, adaptive mesh refinement, low-precision Q7/Q8
storage, industry SOTA, anti-aliasing post-process).

Each candidate is scored against the FastLED embeddability matrix
(AVR / Cortex-M0 / Cortex-M4+ / ESP32-S3 / Host) with cycles-per-cell
estimates and explicit RAM overhead. Non-recommendations are
catalogued with reasons so future research doesn't re-walk dead ends.

Headline findings, after surveying ~25 papers + open-source impls:

1. Compact O(h^4) 9-point Laplacian (Walstijn-Kowalczyk style; Thampi-
   Ansumali Patra-Karttunen family) — same memory access pattern as
   the existing isotropic 9-point added in #3104, but O(h^4) accuracy
   instead of O(h^2). Drop-in win at the existing stencil-selection
   switch. *Top recommendation.*

2. Output Gaussian blur (separable 3x3) as an explicit alternative to
   super-sample. Super-sample's primary user benefit is AA on the
   rendered LED grid, not better physics — a screen-space blur
   delivers comparable visual quality at 1.05-1.2x scalar cost vs
   8-512x for SuperSample 2X/4X/8X. *Second recommendation.*

3. WaveProceduralFx — a sum-of-Gerstner-wavelets ripple synthesizer
   that bypasses the PDE entirely. For AVR / Low-memory targets where
   neither the scalar PDE nor compact-4 fits well, this is dramatically
   cheaper (zero grid memory, O(N_wavelets) per cell) and visually
   strong. References Finch (NVIDIA GPU Gems Ch.1), Quilez Simple
   Water, and Tessendorf-without-FFT. *Third recommendation.*

Conditional finds (worth implementing only on specific platforms):
- ADI implicit time integration (ESP32-S3 with PSRAM only)
- Tessendorf FFT propagation (ESP32-S3+ only — uses CMSIS-DSP)

Explicit dead ends:
- TAA: no motion vectors in static-camera wave field
- LBM D2Q5: memory cost rules out AVR/M0
- Crank-Nicolson: strictly dominated by ADI for our topology
- SMAA/FXAA: wrong scale (designed for 1080p+, not 16x16)
- 13-point/17-point stencils: diminishing returns past O(h^4)

Also recommends three new sub-issues spawned from items 1/2/3, and
explicitly puts the pending SIMD work (#3106/#3107/#3108) on hold —
items 1, 2, 4 above each beat SIMD's typical 4-8x speedup, and the
algorithmic wins compose with later SIMD tuning.

Document is ~4500 words, 25 inline citations, structured per the
output schema specified in the issue body. Lives at
agents/docs/research/wave_pde_alternatives.md.

Closes #3111
Refs #3098 (parent audit meta), #3104 (9-point Laplacian), #3110
(UI toggle)
zackees added a commit that referenced this pull request Jun 16, 2026
…efs #3122 A4) (#3145)

A4 of meta #3122. Implements #3112 research doc §A1 recommendation —
addresses super-sample's actual user motivation (LED-grid anti-aliasing
on smooth fields) at ~1.2x scalar cost vs 8-512x for true super-sample.

## API

Two new fields on WaveFxArgs:
  fl::u8 output_blur_amount = 0;  // 0 disables. 32-128 ≈ SUPER_SAMPLE_2X
  fl::u8 output_blur_passes = 1;

Runtime setter on WaveFx (FL_NOEXCEPT):
  void setOutputBlur(fl::u8 amount, fl::u8 passes = 1);
  fl::u8 getOutputBlurAmount() const;
  fl::u8 getOutputBlurPasses() const;

The blur runs in WaveFx::draw() after mCrgbMap->mapWaveToLEDs() via the
existing fl::blur2d (which already takes an XYMap and handles the LED
grid topology including cylindrical / serpentine).

## What's NOT in this PR

Deliberate slicing:
- Defaulting SuperSample to NONE wholesale — that's a wider behavioral
  change that should land separately after users have evaluated the
  blur quality. Today's PR is opt-in (amount=0 is the default).
- New UI checkbox in the example sketches — separate slice; current
  WaveFx users can wire setOutputBlur() into their existing UI loop
  similarly to how #3110 added the stencil toggle.
- Bench numbers from --wave2d-perf — separate slice, requires hardware
  on desk.

## Validation

- bash lint --cpp — clean.
- bash compile wasm --examples Wave2d — build clean.

Cost-vs-quality breakdown vs SuperSample on a 16x16+ grid with gradient
palette (from the #3112 research doc):
  SUPER_SAMPLE_NONE + output_blur=64: ~1.1x baseline cost
  SUPER_SAMPLE_2X (current default):  ~8x baseline cost
  SUPER_SAMPLE_4X:                    ~64x baseline cost

The blur path is roughly comparable visually to SUPER_SAMPLE_2X on
smooth wave fields; super-sample wins on hard edges (e.g. half-duplex
zero floor) but WaveFx is rarely used at hard edges.

Refs #3122 A4, #3112 research doc §A1, #3113 parent meta.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

1 participant