Repository navigation
Description
Problem framing
fl::WaveSimulation2D (and the WaveFx effect on top of it) currently produces visual quality by brute force: simulate at a k× higher-resolution internal grid, run k time-steps per displayed frame, then downsample. With the current implementation in src/fl/math/wave/wave_simulation.cpp.hpp:
mMultiplier = static_cast<u32>(factor);
u32 w = width * mMultiplier;
u32 h = height * mMultiplier;
mSim = fl::make_unique<WaveSimulation2D_Real>(w, h, speed, dampening);
mExtraFrames = u8(factor) - 1; // run mExtraFrames + 1 updates per displayed frame| SuperSample | Cells | Updates/frame | Total work multiplier |
|---|---|---|---|
| NONE (1×) | 1× | 1 | 1× (baseline) |
| 2X | 4× | 2 | 8× |
| 4X | 16× | 4 | 64× |
| 8X | 64× | 8 | 512× |
Most users running WaveFx at SUPER_SAMPLE_2X or _4X are paying 8–64× the scalar baseline cost almost entirely to get an anti-aliasing-like averaging effect on the output, plus a side benefit of reduced 5-point-stencil anisotropy (already partially addressed by #3104's opt-in 9-point isotropic Laplacian). That's a very expensive way to anti-alias.
Research question: What does the math / CS / embedded-graphics state of the art look like for keeping a real-time 2D wave PDE running at the native LED grid resolution (1× cells, 1 update per displayed frame) while matching the perceived visual quality of a 2–4× super-sampled scalar simulation? Specifically:
- Anti-aliasing without super-sampling. Screen-space filtering, temporal anti-aliasing, MIP-style downsample of intermediate state — what is the actual visual cost of decoupling AA from the time integration?
- Higher-order spatial discretizations. Compact O(h⁴) / O(h⁶) stencils, mass-lumping, modified-equation corrections — can these match super-sample quality at the same grid resolution?
- Better time integration. ADI (alternating-direction implicit), operator splitting, larger stable CFL via implicit/semi-implicit schemes — can each step do more work?
- Spectral / pseudospectral methods. FFT-based propagation eliminates numerical dispersion but introduces O(N log N) cost — viable on ESP32 / Teensy 4 grid sizes (≤ 64×64)?
- Lattice Boltzmann methods (LBM) for wave equations — different formulation, potentially more cache-friendly, comparable cost per cell.
- Procedural / non-PDE alternatives. Gerstner waves, FFT ocean waves (Tessendorf), sum-of-sines, additive sinusoid fields — give up physical-PDE correctness, gain O(1)-per-cell-per-frame independent of grid size. May be the right answer for LED art specifically.
- Adaptive mesh refinement / sparse grids. Most of the grid is near-zero amplitude most of the time — focus compute on active wave fronts only.
- Fixed-point precision tradeoffs. Current code is Q15. Would Q7 or Q8 be enough for visual purposes on small grids? Less memory pressure, faster on AVR.
The deliverable from this research is a definitive recommendation document — not code — comparing approaches with embedded-feasibility scores, citation lists, and a short-list of "land this next" candidates that can then be filed as focused implementation issues (the way the original audit #3073 / #3098 produced #3092–#3097).
Research bot persona
Role: "Embedded LED real-time wave PDE research analyst"
Mission: Survey academic literature, graphics-industry technical articles, and open-source implementations for techniques that improve visual quality or reduce cost of 2D wave-equation simulation in the constraints that FastLED operates under.
Constraints to score every candidate against:
| Constraint | Why it matters |
|---|---|
| Native platforms: AVR (Uno), ESP8266, ESP32 / S3 / C6, Teensy 3.x / 4.x, RP2040, LPC8xx | Target hardware for FastLED users |
| Grid sizes: typically 8×8 to 100×100, occasionally up to 256×256 on ESP32+ | Real-world LED matrix sizes |
| Frame rate target: 30–60 fps | Smooth animation |
| RAM budget: from 2 KB (AVR) to 512 KB (ESP32-S3 PSRAM) for the grid | Hard limit on grid size + buffers |
| No FPU on most targets — integer / fixed-point preferred | Floating-point is software on AVR/M0 |
| No external libs allowed — no FFTW, no Eigen, no OpenCV | Library footprint matters |
| Visual quality is a perceptual judgment, not RMSE | This is art, not science |
Skills the bot should bring:
- Numerical analysis of finite-difference / finite-element / spectral / LBM methods.
- Real-time graphics literature (game-industry, demoscene, shader-toy).
- Embedded systems pragmatism — knows when "the math is beautiful but the constant factor kills it".
- Ability to read a method paper and estimate cycles-per-cell on a Cortex-M4 by inspection.
Output format (per candidate):
### <Method name>
- **Family:** [higher-order stencil / implicit / spectral / LBM / procedural / AA filter / AMR / other]
- **Visual quality vs SUPER_SAMPLE_4X baseline:** [worse / comparable / better]
- **Cost vs 1× scalar baseline (cycles per cell per displayed frame):** [exact figure or band]
- **RAM overhead:** [bytes per cell, plus per-grid overhead]
- **Embeddability score (1–5):**
- AVR: ?
- Cortex-M0 (RP2040 / Teensy-LC): ?
- Cortex-M4/M7 (Teensy 3.x/4.x): ?
- ESP32 / S3 / C6: ?
- **Key citations:** [paper / article / SIGGRAPH talk]
- **Reference implementations:** [open-source repos]
- **Risk / open question:** [the one thing that might kill this in our context]
End the document with a prioritized short-list of 3–5 candidates worth implementing next, with one-line rationales.
Search-term catalog (organized by approach family)
The bot should use these as starting points, follow citations, and check the last 10 years of literature plus seminal older works.
A. Anti-aliasing decoupled from time integration
temporal anti-aliasing wave equationTAA real-time wave simulationscreen space anti-aliasing PDE visualizationMIP-map output finite difference simulationlow-pass filter wave field renderingdithering Q15 wave amplitude visualizationsubpixel anti-aliasing scalar field rendering
B. Higher-order spatial stencils (the family §5 / #3104 only scratched)
compact high-order finite difference Laplacianisotropic Laplacian stencil 9-point 17-pointPatra-Karttunen stencil wave equationKreiss compact scheme wave equationmimetic finite difference Laplaciandiscrete exterior calculus Laplacianmodified equation analysis 2D wavedispersion-corrected FDTD 2D scalar waveH-shifted stencil O(h^4) wave equation
C. Implicit / semi-implicit time integration
ADI alternating direction implicit wave equationCrank-Nicolson 2D wave equationNewmark-beta time integration acousticunconditionally stable explicit wave equationlarge-CFL wave equation real-timeLIM locally implicit method wave PDEoperator splitting 2D wave simulation
D. Spectral / pseudospectral
pseudospectral wave equation real-timeFourier collocation 2D waveFFT wave equation embedded ARMcosine transform Dirichlet wave equationChebyshev pseudospectral wave 2D
E. Lattice Boltzmann (LBM)
lattice Boltzmann wave equationLBM scalar wave propagationD2Q5 D2Q9 wave equation lattice Boltzmannlattice gas wave propagation cellular automaton
F. Procedural / non-PDE approximations
Gerstner waves real-time GPUTessendorf FFT ocean wavessum of sines water surfacePerlin noise wave field synthesisradial basis function ripple simulationwave packet superposition LED art
G. Adaptive / sparse representations
adaptive mesh refinement wave equationsparse grid wave PDEoctree wave simulation real-timequadtree wave propagationbounding-box culling wave PDE
H. Fixed-point + low-precision
8-bit fixed point wave equation visualizationQ7 acoustic simulation embeddedposit numbers wave equationblock floating point wave PDEINT8 wave field GPU shader
I. Embedded-graphics state of the art (industry-side)
Tiny Code Christmas demo wave effectShadertoy water ripple optimizationOLC wave equation tutorialInigo Quilez SDF ripplesrealtime water simulation embedded ARMmicrocontroller fluid simulation
J. Anti-aliasing-specific filters
morphological anti-aliasing MLAA SMAAFXAA temporal stabilizationbilateral filter scalar fieldGaussian pyramid downsampling wave
What to deliver back to this issue
- A research report (post as a comment on this issue or as a separate
.mdinagents/docs/research/wave_pde_alternatives.md) covering at minimum the top 5 candidates from sections A–J, scored against the embeddability matrix. - A short-list of 3–5 PR-able implementation candidates — each with enough detail that someone can file it as a focused sub-issue and start work without re-doing the research.
- Counter-examples / explicit non-recommendations — methods the bot investigated and ruled out, with the reason. This is high-value: saves future researchers from re-walking the same dead ends.
- A 1-page comparison table of all candidates investigated, with embeddability scores, cost-per-cell, and visual quality vs the SUPER_SAMPLE_4X baseline.
The bot is allowed to recommend "the current super-sample approach is actually near-optimal for these constraints, here's why" — that's a valid conclusion too.
Why this matters
The closed audit issue #3073 / meta #3098 produced six focused PRs (#3083, #3099, #3101, #3103, #3104, #3105, #3110) of scalar-kernel improvements. They incrementally improved the 5-point/9-point explicit leapfrog scheme by maybe 30–50% on the inner loop. SIMD (#3106/#3107/#3108) might add another 2–8×.
But the super-sample factor is 8×–512×. If the right answer turns out to be "drop super-sample entirely and use screen-space anti-aliasing + a compact higher-order stencil", that's a 10×+ visual-quality-per-cycle improvement — orders of magnitude beyond what SIMD or further scalar tuning can deliver.
This is the research that should happen before anyone writes SIMD code for SuperSample 4X.
History / cross-references
- audit(wave/diff-eq): overflow risk + perf wins in WaveSimulation Q15 stencil (behind WaveFx) #3073 — original audit (CLOSED)
- [meta] WaveSimulation Q15 stencil — perf + algorithmic follow-ups from #3073 #3098 — meta tracker for §1–§7 (CLOSED)
- feat(wave): opt-in 9-point isotropic Laplacian for WaveSimulation2D (closes #3095) #3104 — §5: opt-in 9-point isotropic Laplacian
- feat(wave): expose 9-point isotropic Laplacian as UI toggle in 5 example sketches (closes #3109) #3110 — UI toggle for the 9-point stencil in example sketches
- 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 — pending SIMD work; should NOT be started until this research lands
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
research(wave): state-of-the-art survey for 2D wave PDE alternatives (#…