Repository navigation
Smooth fade for HMTL Sparkle effect - #1
Conversation
Points to 9ddfccc7 which adds smooth per-pixel fade to the HMTL Sparkle effect via SEGENV.data target array + blendPixelColor. Submodule PR: aphelps/WLED#1 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
aphelps-claude-bot
left a comment
There was a problem hiding this comment.
Fade semantics inverted — c2=0 now gives instant snap (blend step=255), higher values slow the fade (fade_step = 255 - c2, floored at 1 at c2=255). Default updated from 32 to 200 for a visible fade out of the box.
Re the ampworks CI failure: pre-existing issue — the build references the MPR121 library at an absolute local path (/Users/amp/Dropbox/Arduino/ArduinoLibs/MPR121) that CI runners can't resolve. Unrelated to this change.
aphelps
left a comment
There was a problem hiding this comment.
In addition to the comment, the range of the slider isn't very useful. The middle of the values seem almost instant. It would be good to expand the upper range to provide a better sliding value for slow fades, while compressing the lower range which seem mostly instant to human eye. I think this could be solved with some sort of logarythmic function.
aphelps-claude-bot
left a comment
There was a problem hiding this comment.
Re 'values of 254 or 255 result in pixels fading to red or black': with the quadratic curve now in place, c2=254-255 gives fade_step=1 (maximum slowness, ~4 seconds to fully blend). The behaviour seen was likely pixels slowly converging toward their assigned targets — red from the palette, black/background from Color 2. Could you confirm whether this is still a concern with the new curve, or if it was the intended very-slow-fade working correctly?
aphelps
left a comment
There was a problem hiding this comment.
After the changes fade values starting at 233 fade to black, at least when he background color includes no red. When I set the background color to pure white it fades to red, as it does for background colors with some red in them
aphelps
left a comment
There was a problem hiding this comment.
After the changes fade values starting at 233 fade to black, at least when he background color includes no red. When I set the background color to pure white it fades to red, as it does for background colors with some red in them
8c6cee7 to
c0c579c
Compare
|
Fixed in c0c579c. Root cause: Fix: replaced |
| */ | ||
| struct SparklePixel { | ||
| uint32_t target; | ||
| uint32_t current; |
There was a problem hiding this comment.
What is the reason for storing "current" here rather than using SEGMENT.setPixelColor()? If its not much of a performance hit its often better to use less allocated memory since the number of pixels could be quite large.
There was a problem hiding this comment.
Good point on memory. Dropped the SparklePixel::current field — getPixelColor returns exactly the raw value last written by setPixelColor with no brightness scaling or transformation applied, so reading it back loses no precision. Back to 4 bytes/pixel.
| // Quadratic curve: c2=0 → instant snap (255), c2=255 → very slow (1). | ||
| // (255-c2)²/255 compresses the fast end and expands the slow end so the | ||
| // full slider range is perceptually useful. Integer-only, no powf. | ||
| uint8_t inv = 255 - SEGMENT.custom2; | ||
| uint8_t fade_step = (uint8_t)max(1u, (uint32_t)inv * inv / 255u); |
There was a problem hiding this comment.
Even with this the slow end is still overly compressed, can you further stretch out that end of the value? I'd never need to use the fastest 1/3 of the values as they're close enough to instant to not matter.
There was a problem hiding this comment.
Switched to cubic curve (inv³/255²). Comparison at key points:
| c2 | quadratic fade_step | cubic fade_step |
|---|---|---|
| 85 | 113 (~2 frames) | 75 (~3 frames) |
| 128 | 63 (~4 frames) | 31 (~8 frames) |
| 170 | 28 (~9 frames) | 9 (~28 frames) |
| 200 | 11 (~23 frames) | 2 (~128 frames) |
| 212 | 5 (~51 frames) | 1 (~8.5 s) |
| 233 | 1 (~8.5 s) | 1 |
Slow-end resolution improves meaningfully: fade_step=1 now starts at c2≈212 rather than c2≈233, giving ~43 more slider positions in the interesting slow range. Let me know if you want it stretched further.
Add per-pixel target tracking to the HMTL Sparkle effect. Each pixel independently rolls each cycle to become a palette sparkle or reset to the background color (Color 2). Pixels then fade toward their target using per-channel delta stepping. Fade Speed (c2) uses a cubic curve (inv³/255²) so the full slider range is perceptually useful: 0=instant snap, 255=very slow dissolve (~8.5s full range at 30fps, fade_step=1 from c2≈212). The cubic gives more resolution in the slow end than the earlier quadratic. Channel-delta stepping guarantees monotonic convergence at all fade speeds. Current color is read back via getPixelColor (returns the raw set value) eliminating the need for a separate per-pixel current-state buffer and keeping data at 4 bytes/pixel.
c0c579c to
21e95d8
Compare
Summary
Pixels now blend toward their target color each frame instead of snapping
instantly. A new Fade Speed slider (c2, default 32) controls blend step per
frame: low = slow dissolve, high = snap.
Internally allocates a
uint32_t targets[]array inSEGENV.data; dice rollsset targets each cycle tick,
blendPixelColor()advances each pixel everyFRAMETIME. Existing Speed / Intensity / BG Reset / Color 2 / Paletteparameters unchanged.
Parent repo PR
Part of aphelps/WLED_dev#3
🤖 Generated with Claude Code