Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Particle System with many new FX #4506

Merged
merged 253 commits into from
Feb 17, 2025
Merged

Conversation

DedeHai
Copy link
Collaborator

@DedeHai DedeHai commented Jan 19, 2025

this replaces the previous PR (#3823) since I made too many changes and a rebase was needed.
Some info on the particle system:

  • effects look best at 40-80FPS
  • all FX can be overlaid: overlay is auto-detected, blurring may not work properly in multi-overlay
  • PS and its buffers reside in segment data and is dynamically managed to keep a small RAM memory footprint (local render buffers are shared between segments)
  • since most FX are random number based, segments do not run in sync
  • 1M and 2M ESP8266 have the particle effects disabled for memory reasons

there are three compile time defines

  • WLED_DISABLE_PARTICLESYSTEM2D -> disables 2D system and FX, automatically set if WLED_DISABLE_2D is set
  • WLED_DISABLE_PARTICLESYSTEM1D -> disables 1D system and FX
  • WLED_PS_DONT_REPLACE_FX -> re-enables the replaced FX (uses 12k more flash)

Replaced FX
to save on flash, effects that have a particle system based replacement are disabled. This saves 12k of flash. Users who want the originals back can custom compile using compile flag.

  • Ghost Rider -> PS Ghost Rider (with new options and faster rendering)
  • Blobs -> PS Blobs (with new options, optional AR functionality and nicer rendering)
  • Fire 2012 -> PS Fire (1D and 2D versions)
  • Fireworks 1D -> PS Fireworks (1D and 2D versions)
  • Dancing Shadows -> PS Dancing Shadows
  • Fireworks Starburst -> PS Starburst
  • Glitter & Solid Glitter -> PS Sparkler (with overlay and settings tweked to users liking)
  • Sparkle -> PS Sparkler
  • Rolling Balls -> PS Pinball with checkmark "rolling"
  • Multi Comet -> PS Pinball with gravity set to 0

Known issues:

  • ESP8266 truncates the FX info JSON, the last added FX have missing sliders
  • changing segment arrangements or changing FX during transitions can somettimes lead to crashes due memory race conditions/pointer issues
  • replaced FX are not 100% identical

Summary by CodeRabbit

  • New Features
    • Expanded LED animations with a suite of new particle effects for more diverse and dynamic visual displays.
    • Introduced configurable options to enable or disable specific particle effects on select setups, giving users greater control over performance and appearance.
    • Enhanced transition handling for smoother visual updates during effect changes.

update from another commit that got lost
this somehow also got lost from an earlier commit
particle box now is more random in random mode (still a work in progress)
firework is now more configurable by sliders
particle attractor animation does not work, somthing wrong with pointer allocation, it worked with static variables
still unknown, why more than 256 particles are needed in memory allocation to not make it crash, but it works for now
at the expense of more ram usage, animations now have more options for color control (already used in fireworks now)
improved efficiency for stackup (pushback), added code to correctly determine direction if particles meed (probably overkill but now its there)
untested, need to verify it works
…ables to 32bit for faster calculation

32bit variables are faster on ESP32, so use them whenever a variable is used a lot, it saves one instruction per access.
it made very little difference in performance, but for ESP8266 it may matter so it is set permanently there. graphically the difference is also very small (sometimes a particle gets brighter or less saturated)
particle pile-up did not work correctly, now fixed
touch is implemented differently on S2 and S3, these changes make touch buttons work on S2 and S3
now better fits the default threshold value of 32
@DedeHai
Copy link
Collaborator Author

DedeHai commented Jan 26, 2025

Updated to play nice with blending styles. @blazoncek regarding

I specifically do not approve changing blending mode during effect run.

that (intermediate) disabling is necessary to not have one FX fade out and the other fade in as that is not how PS transitions work anymore when "fade" style is set. It is also only disabled during the buffer transfer. I don't see a better way except if another blending style specifically for the PS is added, but that is just confusing. If you have any other good ideas, I am open to suggestions.

@blazoncek
Copy link
Collaborator

If you have any other good ideas

I do not know if it is a "good idea" but am just thinking out loud:
Forget about blending inside PS system. There should be no notion of two separate runs of PS effects to know of each other (although you think it looks really good but it does so in edge cases only). Leave blending (mixing) to strip logic (as mentioned above) or segment logic (inside setPixelColor()).
It may sound counterproductive or counterintuitive but consider this scenario: 32x32 matrix with 5 segments set up, 0,0-16,16; 16,0-32,16; 0,16-16,32; 16,16-32,32 and 0,0-32,32 (or even a more complex one). Each of them running separate effect, the last segment overlays all others. It will be a lot of work for PS system to correctly blend that.

If done outside of PS it is as simple* as color_blend() for each pixel.
* not really that simple but simpler still

@DedeHai
Copy link
Collaborator Author

DedeHai commented Jan 26, 2025

thanks for the input. I agree it would be better to do blending in one place BUT: blending between FX inside the PS is only done for one segment, not multiple. The reason it does that is to share the buffer AND the particles for one segment: if you had your proposed scenario, each segment would require two render buffers and twice the particles, which would exceed RAM already at 32x32 and multiple segments + transitions. Disabling the "particle blending" is as easy as changing two or three if's as it already disables it when not using 'fade' style. The "two PS FX can interact" part is more of an addition than a necessity, it could be a user selectable option as well.
edit:
I would like to get some user's feedback on the PS as well as the 'blending' and adjust if requested.

@DedeHai
Copy link
Collaborator Author

DedeHai commented Jan 27, 2025

@netmindz feel free to squash-merge this

…, minor tweaks

- collisions are now also velocity based in 1D, there was a bug that prevented that from working well (wrong collision distance calculation)
- improvement and bugfix in 2D collision distance calculation
- added distance based pushing in 2D (instead of only using the dotproduct)
the combination of improved distance calculation and proper pushing make collisions a lot better in all tested FX
@netmindz
Copy link
Member

netmindz commented Feb 1, 2025

@netmindz feel free to squash-merge this

Sorry I wasn't sure what you meant by this and got distracted before I replied. Was this just a note to use squash when I merge, but not yet or a request for merge with squash now?

@DedeHai
Copy link
Collaborator Author

DedeHai commented Feb 1, 2025

Just a suggestion to squash merge so commits are compacted. Merge when you took a look at it, any remaining issues are minor and can be worked out with more feedback from users

@DedeHai
Copy link
Collaborator Author

DedeHai commented Feb 3, 2025

@netmindz regarding the max number of FX: I think increasing mode (and _modeT) to int16_t and making the "reserved" to be -1 instead of the current 255 should be possible without too much fuss. I can take a stab at it in a new PR.

@blazoncek
Copy link
Collaborator

blazoncek commented Feb 3, 2025

@DedeHai there are numerous old effects that can be removed (and replaced with other existing effects with added sliders and options) some of which you already modified or consolidated. I would recommend to do that.

These are: 11, 14, 19, 52, 53, 60, 77, 93, 94, 99, 102, 103, 117

@blazoncek
Copy link
Collaborator

I think increasing mode (and _modeT) to int16_t ... should be possible without too much fuss.

Are you aware of all consequences? I guess not otherwise you wouldn't make such a bold claim.

@DedeHai
Copy link
Collaborator Author

DedeHai commented Feb 3, 2025

Are you aware of all consequences? I guess not otherwise you wouldn't make such a bold claim.

I am not. please do enlighten me: which is the tricky part?

@blazoncek
Copy link
Collaborator

Sync etc.

if a PS FX is partially overlapping, it will render in overlay mode
@DedeHai
Copy link
Collaborator Author

DedeHai commented Feb 10, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Feb 10, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Feb 10, 2025

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (2)
  • wled00/FX.cpp
  • wled00/FXparticleSystem.cpp

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes update the build configuration and particle effects support. The platformio.ini file now includes new build flags to disable particle systems in various environments. The FX module has been enhanced by replacing the previous MODE_COUNT definition with a new particle mode and adding multiple new particle effect macros. A new method (loadOldPalette) was added to the Segment class, and a new header file introduces ParticleSystem2D and ParticleSystem1D classes with associated update, emission, and allocation methods. Additionally, a minor formatting adjustment was made in the configuration file.

Changes

File(s) Change Summary
platformio.ini Added build flags -D WLED_DISABLE_PARTICLESYSTEM2D and -D WLED_DISABLE_PARTICLESYSTEM1D for multiple environments (NodeMCU, ESP8266, ESP01 variants).
wled00/FX.h, wled00/FX_fcn.cpp, wled00/FXparticleSystem.h Expanded particle system support: replaced MODE_COUNT with FX_MODE_PARTICLEVOLCANO and introduced new FX_MODE_* macros; added loadOldPalette() method in Segment; introduced ParticleSystem2D/1D classes with update, emitter, and allocation methods.
wled00/cfg.cpp Added a newline at the end of the file in the serializeConfigSec function for formatting consistency.

Sequence Diagram(s)

sequenceDiagram
    participant Core as WLED Core
    participant Seg as Segment
    participant PS as Particle System
    Core->>Seg: Trigger animation update
    Seg->>Seg: Check transition state
    alt Transition Active
        Seg->>Seg: Call loadOldPalette() → loadPalette()
    end
    Seg->>PS: Update particle effects
    PS->>PS: Process update (emit particles, apply forces, update state)
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (9)
wled00/FXparticleSystem.h (4)

1-9: Consider renaming the file header.
The file name and initial comment mention "FXparticleSystem.cpp," but the actual file appears to be a header (".h"). Ensuring consistency between file name, top-level comment, and included references will help avoid confusion.


33-44: Evaluate bitfield usage for booleans.
In the 'partMem' struct, multiple booleans are used (e.g., finalTransfer, transferParticles), but only some entries are grouped into bitfields (watchdog is an 8-bit integer). Converting more booleans into bitfields or combining them could reduce memory footprints, which is crucial on ESP8266.


158-163: Consider a destructor or explicit memory freeing.
The ParticleSystem2D constructor sets up external memory pointers (particles, sources, etc.). Although this is typically managed externally, ensure there's no scenario where the system is allocated but never freed.


210-220: Reduce the size of collision logic for performance.
Methods like handleCollisions() could be large, especially if the device must handle many particles. Consider partitioning collisions into spatial buckets or using more efficient data structures if performance degrades with high particle counts.

wled00/FX.h (3)

325-353: Document newly introduced particle effect modes.
These macros (FX_MODE_PARTICLEVOLCANO to FX_MODE_PS1DSONICSTREAM) add numerous effect modes. In future maintenance, ensure they are well-documented in user-facing material (UI labels, docs) so that users understand their distinctive behaviors.


510-510: Clarify the padding purpose.
This inline comment merely notes a padding byte in the Transition struct. Consider expanding the comment to indicate why it is necessary (alignment vs. future usage) so future maintainers do not remove it inadvertently.


606-607: Rename getmodeBlend() for consistency.
The static function getmodeBlend() returns a boolean. For clarity, consider renaming it to isModeBlend(), better reflecting its true/false return.

-inline static bool     getmodeBlend(void)              { return _modeBlend; }
+inline static bool     isModeBlend(void)               { return _modeBlend; }
wled00/FX_fcn.cpp (2)

14-14: Consider moving memory service definition to FX.h as suggested by TODO comment.

The TODO comment indicates that memory service functionality should be defined in FX.h. This would improve code organization by keeping related functionality together.


474-478: Add null pointer check in loadOldPalette.

While the implementation is clean and focused, consider adding a null pointer check before accessing _t to prevent potential crashes.

void Segment::loadOldPalette(void) {
-  if(isInTransition())
+  if(isInTransition() && _t != nullptr)
    loadPalette(_currentPalette, _t->_palTid);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b64cd36 and bb0de15.

📒 Files selected for processing (5)
  • platformio.ini (6 hunks)
  • wled00/FX.h (5 hunks)
  • wled00/FX_fcn.cpp (4 hunks)
  • wled00/FXparticleSystem.h (1 hunks)
  • wled00/cfg.cpp (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • wled00/cfg.cpp
🔇 Additional comments (8)
wled00/FXparticleSystem.h (5)

56-58: Validate speed limiting range.
The limitSpeed() function clamps speed between ±PS_P_MAXSPEED (120). Verify that 120 is an acceptable limit for all hardware targets and does not break any intended behaviors for advanced or large displays.


94-102: Review struct alignment and potential padding in PSparticle.
This struct is 10 bytes. Depending on compiler alignment rules, it might insert padding if used in arrays or forced alignment. Carefully confirm how the memory manager and transitions handle partial alignment to avoid subtle bugs.


135-140: Review advanced particle size logic.
The PSsizeControl struct introduces multiple bitfields and flags (e.g., grow, shrink, pulsate). Verify all size manipulations are tested thoroughly, especially edge cases with maxsize or 0.


200-205: Confirm that advanced pointers gather correct offsets.
PSadvancedParticle and PSsizeControl pointers are marked nullable. Validate that code paths where they are null do not lead to accidental dereferencing.


249-253: Validate memory constraints for large 2D arrays.
allocateParticleSystemMemory2D can allocate up to thousands of particles for large segments. For lower-memory devices (1M/2M ESP8266), this might cause out-of-memory errors. Confirm compile-time guards or runtime checks are sufficient.

wled00/FX.h (1)

655-655: Ensure backward compatibility in loadOldPalette().
This new method loads an “old FX palette” into the current palette. Verify it correctly handles older configurations or user data to prevent color mismatches, especially during transitions.

wled00/FX_fcn.cpp (1)

1556-1558: LGTM! Good use of conditional compilation.

The particle system memory handling is properly guarded by conditional compilation, allowing it to be disabled when not needed.

platformio.ini (1)

370-370: LGTM! Appropriate handling of memory constraints.

The build flags to disable particle systems are correctly applied to memory-constrained environments, particularly ESP8266 boards. This aligns well with the PR objectives to manage memory usage.

Also applies to: 380-380, 388-388, 397-398, 407-408, 415-416, 426-427, 436-437, 445-446

@netmindz
Copy link
Member

Are we good for you to merge now? If there are any outstanding issues I think we should open an issue to track them rather than blocking this PR any further

@DedeHai
Copy link
Collaborator Author

DedeHai commented Feb 17, 2025

yes, its good to merge. I will be pushing updates from time to time as I am still improving things as I see them in testing (or from feedback).
I did not yet figure out why it sometimes crashes, whether its due to async timing of commands, memory handling conflicts with other FX or just a simple index-overflow.

- slight improvement to 2D collision code efficiency
- added faster "division" to C3/ESP8266 by using a right shift trick (biasing towards 0 also for negative numbers by applying proper rounding)
@DedeHai DedeHai merged commit 46a3e3d into wled:main Feb 17, 2025
20 checks passed
@netmindz
Copy link
Member

I'm layed up in bed ill at the moment but can't wait to have a play when I'm doing a bit better

blazoncek pushed a commit to blazoncek/WLED that referenced this pull request Mar 6, 2025
* added collision handling back in
update from another commit that got lost
* added latest version of functions
this somehow also got lost from an earlier commit
* Update platformio.ini
* updated particle box and firework effects

particle box now is more random in random mode (still a work in progress)
firework is now more configurable by sliders

* added preliminary functions and FX

* added particle attractor, added two new FX but still buggy

particle attractor animation does not work, somthing wrong with pointer allocation, it worked with static variables

* bugfixes, attracot now works

still unknown, why more than 256 particles are needed in memory allocation to not make it crash, but it works for now

* added angle emitter, added fireworks effect using it

* Added saturation to be set for each particle individually

at the expense of more ram usage, animations now have more options for color control (already used in fireworks now)

* bugfixes in impact animation

* added option to use fast color add, may improve performance a little

also fixed a bug in fire animation

* collision detection is now a function plus some improvements & fixes

* improved collision efficiency

improved efficiency for stackup (pushback), added code to correctly determine direction if particles meed (probably overkill but now its there)

* added fix for piling oscillations

untested, need to verify it works

* Improved collision handling (faster, less oscillations), changed variables to 32bit for faster calculation

32bit variables are faster on ESP32, so use them whenever a variable is used a lot, it saves one instruction per access.

* removed option for fastcolor add

it made very little difference in performance, but for ESP8266 it may matter so it is set permanently there. graphically the difference is also very small (sometimes a particle gets brighter or less saturated)

* Fixed some bugs in particle system, runs much smoother now

also tweaked some of the FX

* Bugfix in particle push, now piling is working again

particle pile-up did not work correctly, now fixed

* changed particle pile demo into waterfall plus some tweaks

* lots of bugfixes

* updated particle attractor animation parameters and added more user options to perlin noise

* removed TODOs

* added particle WrapUpdate function, added spray FX, some bugfixes

* fixed touch buttons for ESP32 S2 and S3

touch is implemented differently on S2 and S3, these changes make touch buttons work on S2 and S3

* some tuning for touch buttons on S2/S3

now better fits the default threshold value of 32

* updated rotating particle spray with more user options

* chaned rotating spray default parameters

* add todo

* Revert "some tuning for touch buttons on S2/S3"

This reverts commit d21ad8e.

* Revert "fixed touch buttons for ESP32 S2 and S3"

This reverts commit 0904155.

* removed comments, added comments

* cleanup

-removed wrap_update function, now integrated into move_update
-added more 'out of bounds' checking in fire functions, may speed it up a little

* cleanup session

-removed particle box 'rocking boat' (buggy) and replaced with random sloshing.
-removed comments
-changed some variables into 32bit for speed boost on ESP32
-added link to KB at the top of FX.cpp

* cleanup

removed / added comments

* added particle GEQ effect (untested)

* Particle GEQ fixes, it now actually works

* GEQ  FX parameter tuning

* added rotating GEQ, work in progress

-animation works but sliders are too sensitive. need to adjust the ranges

* FX update

- changed firework exhaust to low saturation
- updated rotating particle spray animation

* Cleanup & Bugfixes plus major improvements for ESP8266

-added particle reductions for ESP8266 for all FX
-Removed collisions from Particle Perlin Noise FX, slows things down and does not contribute to a better effect experience
-lots of optimizations for ESP8266, all FX now work (at least on 160MHz but still slow)
-Some bugfixes
-removed unused variables to make compiler happy

* Particle FX Rename, default parameter tuning, bugfix

-Now shorter names, 'PS' in front to filter the list
-Tuned default parameters to make them look better by default
-Bugfix in particle system (removed duplicate application of velocity)
-reduced PS fire RAM usage (less particles, less base flames, no noticeable difference)
-some variable renaming

* slight speed improvements in fire, like 1-2FPS

* Big update: lots of little fixes and big speed boost on fire animation

-fixed fire burning more on the left side
-fixed crash in particle attractor
-added many improvements for ESP8266
-improved particle rendering efficiency
-efficiency improvements in general
-changed the way fire is rendered, now more than 2x faster
-re-tuned fire to new rendering, also seperately tuned it for ESP8266
-changed all random8() to random16() as it runs faster on ESPs
-some reformating
-some renaming of effect stuff
-fine tuning on falling particle effect
-improvements to collision handling (faster and better)
-added a (temporary) function for speed tests, will be removed again

* bugfix

* updated PS Fireworks with many changes and fine-tuning of parameters

-removed spiral explosions
-added more versatility to circular explosions
-removed user selectable amount of rockets
-tuned explosion size of circular explosions to match random explosions (more or less, may need improvement)
-changed order of sliders in volcano animation

* put particle system in a class. work in progress.

another huge update to the particle system.
went through the whole code, rewrote many of the functions. many improvements over the previous code. fixed many bugs (and even an ancient one in rendering function). spent many hours optimizing the code for speed and usability.
still a work in progress, debugging is ongoing. more updates to come.

* many (many!) bugfixes, added fire FX back in (and improved it a lot) added local renderbuffer for huge speed boost

-lots of bugfixes in Particle system
-added local rendering buffer (renders to buffer in heap)
-added fast and accurate color-add function
-bugfixes in render function
-added improved 'sticky' particles in collision (unfinished business)
-added ballpit animation back
-lots of tweaks to fire FX and fire rendering functions, looks even better now (still unfinished)
-added palette render option to fire

still many debug print outputs around, needs cleanup at one point

* More Bugfixes, more converted FX

* more bugfixes, some animation tuning, added volcano back in

- fixed animation transitions with proper pointer setting in each FX call
- added color by age setting to particle system
- maybe fixed collision having a tendency to go to the left
- fixed bugs in fireworks FX
- added fire spread width as a slider
- changed max number of particles and sprays based on some ram calculations
- some other random fixes

* updated fire, added some functions to PS, ported attractor FX

- added turbulance to fire (after hours of fine-tuning) it now looks even more awesome
- added attractor animation back in and improved it with more functionality
- fixed the attractor function in the PS
- renamed FX: 'candy' is now called 'vortex'
- added new force function to apply a force immediately (and handle the timing in the FX)
- added update function to PS for size update to handle dynamic segment size change
- made waterfall width dynamic on segment width
- removed some debug stuff
- added #defines for maximum number of particles/sprays
- updated fire parameter to make it look better on ESP8266
- some little bugfixes

* another huge update, many improvements, fine-tune collision, fire and some other FX

-removed classic fire render as palette now looks much better
-tweaked fire parameters to more awesome
-added (optional) turbulence to fire using perlin-noise
-ported spray FX to use PS-class
-now definitely fixed asymmetrical collision issue: do not use bitshifts on negative numbers!
-changed piling behaviour of particles, full rework. looks way more natural now and works much better
-changed bouncing behavour: they now bounce at full diameter, making them stay fully in frame when laying on the floor
-replaced all relevant bitshifts with divisions for higher accuracy throughout the PS
-added new modes to particle box FX
-changed a lot of FX parameters (finetuning)
-changed all config strings to proper settings (matrix only)
-fixed newly introduced bugs
-added speedup/slowdown to vortex FX (aka candy, aka rotating sprays)
-some renaming
-fixed bugs… lots of bugs
-merged rendering functions, removed obsolete stuff

* Fixed Speed limit

limiting speed was incorrect, leading to overflows. fixed this.
also fixed bugs in GEQ, removed some debug stuff, added FPS limit to fire (just en experiment)

* work in progress, added motion blur and line attracto (non working)

* work in progress, added test function to increase particle size, also added wobbling test

* added more tests, non compiling at the moment

* in the middle of fixing FX to use new PS functions

* debugging going on

* bugfix in wrap function and firwork FX

* added local render blurring, boosting FPS, work in progress

- changed fast-add function to use pointers
- added fast-scaling function
- added simple (but fast) 2D blurring function
test shows that local blurring of full frame is almost double the speed (40FPS now is 80FPS).
lots of comments still there

* Bugfixes, improvements and added wall roughness setting

- fixed bug in PS fuzzy noise which made it asymmetric for some reason, seems to work better now
- added particle size option to attractor but had to remove speed setting (now fixed emit speed)
- some parameter tuning of FX
- improvements to code size in render function
- added smear option to blurring (not tested much, may be buggy without smear)
- speed improvement to caldForce_dv, added zero checking.

* removed zero inits

- removed zero initialisations in FX, segment.data is set to zero by alloc function

* added individual size particle rendering plus some fixes

- advanced particles can now be rendered to individual sizes. It is computationally intensive but it works well for up to 15 very large particles and more smaller ones
- added collision handling for individual sizes (walls and collisions)
- fixed bugs in particlebox
- fixed fire not transitioning properly (flickering) when frame skip is active
- removed 'wraparound' function as it can easily be done by casting to an unsigned and then modulo
- fixed ballpit particles wandering left and right very fast if wrapX is set

* Fixed some nasty memory bugs, fixed some FX parameters

- fixed memory alignment bug in PS pointer assignment by making sure only multiples of 4 are allowed for particles and sources
- added saturation back to particle struct, as it was aligned to 10 bytes anyway.
- fixed a bug where a null pointer could be accessed
- fixed rendering out of frame particles if buffer allocation failed
- improvements on ESP8266

* Replaced Ghost Rider FX with PS version

- new FX is kept close to original animation but added more user settings

* added walls to ghostride, fixed some bugs

* added 'perpetual' flag to particles

* Fixed another memory / pointer bug, but there is still one left...

-also some minor fixes

* Found and fixed crashes, it was wrongly assigned pointers

* Added advanced particle size control and new Blob FX

- advanced size control allows for growing, shrinking, wobbling
- render function updated to support asymmetric rendering
- various code improvements and bugfixes
- some FX parameter tuning
- bugfix: removed sli() sei() calls in render function that caused random flickering on S3/C3 (may add that back in but only for ESP8266 to reduce fragmentation)
- removed some debug / test stuff

* code cleanup, removed some unused stuff

* bugfix, sprayEmit() would not return and get stuck

- forgot default return value...

* remove esp_random() as it is not supported on ESP8266

* small bugfix for ESP32, cleanup / reformatting

* added WLED_DISABLE_PARTICLESYSTEM option, fixed volcano movement

use '-D WLED_DISABLE_PARTICLESYSTEM' to disable compiling

* a line got lost in the last commit

* - added WLED_DISABLE_PARTICLESYSTEM option & cleanup & bugfixes

- cleanup / reformatting
- fixed volcano movement
- small bugfix for ESP32 (random() does not work, using random16() )

* Added PS source option to emit more than one particle, addes AR to Blobs and Spray

* added center GEQ back in, changed AR behaviour of spray a little

center GEQ is a mix between the PS equalizer and vortex, tuned for AR. some more tuning may be needed, it can probably be extended and improved a little.

* Bugfix and minor improvements

- fixed bug in center GEQ
- added '2D washing machine' mode for particle box
- improved color-change rate in ghostrider
- added AR to attractor (experimental, may remove again)

* hacked in a 1D port of the 2D PS, untested code

* fixed first bugs in 1D system, added test FX

* fixed bug in wrapping (also was wrong for 2D system)

* fixed collisions, added bouncing ball replacement (work in progress)

* replaced more FX, some tweaks to 1D PS

- changed virtual particle size from 64 to 32, making them able to move faster
- added 'rolling balls' option to bouncing balls (i.e. no gravity plus some tweaks)
- added dancing shadows with PS (work in progress)
- temporarily removed native FX: bouncing balls, rolling balls, popcorn, dancing shadows
-and of course some bugfixes

* updated dancing shadows to more closely mimic original

* added drip FX, added #ifdefs, removed some common functions

* fixed compile issue, removed replaced FX (again)

* added Fireworks1D replacement (unfinished)

also fixed a bug in `applyForce()` using uninitialized variable.

* added sparkler and hourglass (both work in progress) tried fixing 1D collisions

* many improvements in 1D collisions (fine tuned), hour glass FX is almost done

spent A LOT of time in fine-tuning collisions for best stacking without collipsing, ringing, oscillations or particle flips. still not perfect but probably as good as it can be with the limited time-resolution

* many bugfixes in PS and FX

* minor FX adjustments

* Improved 1D collisions, added 2 new 1D FX (work in progress)

* bugfixes

* added 'color by position' as a PS setting

 -made settings struct for 1D and 2D version to be different
 -added setting 'color by position' as that is used by multiple FX now

* added large size rendering to 1D PS, work in progress

* bugfix (forgot to free memory)

also: made random size a permanent option in 1D fireworks as it looks kind of cool

* Added PS based Chase, fixed some bugs

* minor update

* two new FX: Starburst and 1D GEQ

* Added more advanced (and proper) size handling in collisions, work in progress

 - copied and adapted some stuff from 2D system (out of bounds size rendering, dynamic collision detection distance, dynamic wall bounce distance)

* fixed some parameters in 1D FX

* added #ifndef to disable FX replaced by PS

- define DISABLE_1D_PS_REPLACEMENTS or DISABLE_2D_PS_REPLACEMENTS

* bugfixes

* default parameter change

* explicit cast to fix compile error

* Bugfixes

* added color-waves to PS chase, some parameter tuning plus bugfixes

* FX update and bugfixes

- fixed wall collisions on larger particle sizes
- update to bouncing balls:
 - added size setting
 - added proper updating on parameter change
 - bugfixes
added support for 'colorwaves' and 'pride' to PS Chase to save on code size. currently broken...

* minor update to rolling balls, fixed stuff in Chase, pride option still not working

* update on 'pride' now working again but needs finetuning

* SEGMENT -> SEGENV on data, aux0, aux1, step

also removed debug outputs

* added pride and colorwaves to 1D replacement list

* removed unused variables

* added variable to set number of particles if not all are required (saves ram) also fixed a nasty render bug

* added preliminary 1D fire function, unfinished

* added fractal FX test, fixed bugs in emit function

* tweaked 1D fire a little, still work in progress

* minor tuning on 1D fire to avoid 'oscillation' at start

* improved 1D particle fire, much more natural now.

* updated 2D fire, fixed init bug

- source init was wrong making fire init weirdly
- changed parameters on 2D fire making it look better and improving flame height for larger setups

* fixed 'nervours' fire

* slight improvements and some cleanup

* removed douplicate code for fire emit (tradeoff for some speed), removed unfinished fractal FX

- with the duplicate code removed, the fire particle emits are a bit slower but it saves on code. it is not really noticeable, its slower by about 1FPS

* Re-license from MIT to EUPL

* Started cleanup, speed improvement to rendering, renamed class

- removed 'smar' parameter in blur functions as smear is always used
- improved particle rendering (passing by reference, passing wrap parameters for faster access)
- renamed class to ParticleSystem2D
- removed some whitespaces
- some reformating, removed some comments
- minor tweaks
- removed non-working line-attractor function

* Optimization and bugfixes

- added out of bounds checking function
- fixed rendering at boundaries
- various small changes and cleanup
- bugfixes with comparing ints of different signeness
- fixed bounce radius

* Cleanup, bugfixes, speed improvements, refactoring

- lots of code refactoring / reformating
- fixed bug in fire particle update and improved speed a bit
- refactoring of pixel rendering
- removed 2D buffers, replaced with 1D buffer for faster access
- bugfix in blur2D
- many small improvements to 2D system

* Refactoring and cleanup of 1D PS, removed debug printouts

- code reformating for consistency and readability
- replaced "'?" operator with min / max (produces the same code, more readable)
- minor changes for speed (random16 used, can later be replaced with hardware random function)
- renamed PS Equalizer to PS 2D GEQ

* Cleanup and some refactoring of particle FX

- moved 2D / length check to PS initi
- code reformating
- removed some comments

* missed a spot

* minor tweaks to fast_color_add()

* Work in progress: update to fireworks, needs more testing & finetuning

also bugs fixed and some minor cleanup

* Work in Progress: added particle memory manager for transitions

- uses only one, persistant buffer to render all present particle systems
- Buffer for particles is shared for one segment (may allow interacitng systems in the future)
- updated some of the FX to handle the new transfer, 1D FX still not done
- updated parameters for particle impact FX

* work in progress: lots of changes & fixes, transitions now work correctly in 2D

- still fragile code with lots of cleanup to do

* added transitions for big-size rendering

- transitions now work with FX that use global large size rendering. this is done by handling the buffer correctly. to avoid creating a second buffer, it is transferred back and forth to the segment. this is a bit slow but a compromise solution.
- multiple segment handling is still untested

* speed improvement to  fast_color_add, added preliminary buffer transfer function

* merge fixes

* bugfix in setCurrentPalette, corrected order of 2D memory allocation, increased max particles/sources

- fixed timing for vortex

* fixed particle buffer handover, added 2D blur option, increased particle limits, various fixes

- fixed bug in memory watchdog, now works and also works when freezing segments
- fixed PS Box to work again with particle handover
- added smear blurring to waterfall
- added smear blurring to vortex, fixed color distribution, removed random color distribution option
- replaced all random() calls with hw_random()
- transitions now work but only if FX transitions are enabled and not when chaning segment size

* implemented correct 1D<->2D buffer handover+bugfixes

work in progress

* added smear to fuzzy noise, some cleanup

* added blurring option to PS 2D fireworks, work in progress in finding that nasty bug that crashes all

* BUGFIX: finally found and squased the memory bug, no more random crashes

also: removed debug outputs and minor cleanup

* minor cleanup and fixed a bug

1D system had a lot of crashes, some out of bounds memory issue. fixed it but I have no idea which change did that, maybe the order in 1D initialization

* BUGFIX: out of bounds checking was wrong, leading to crashes

* better handling of used particles in transitions

for FX that do not use all particles, transitions were constantly shifting the pointer, resulting in newly generated particles and weird particle flickering, this is not fixed by keeping the pointer constant once the number of used particles is reached.

* improved particle transition for low-count FX, updated 1D FX

now most 1D FX work again, still needs some fine-tuning

* Rework on Fireworks 1D, some minor fixes

- fireworks 1D now matches as closely as possible to the old FX
still not identical but as good as it gets.

* bugfix in PS Chase, increased brightness of 1D fireworks

* replaced sin16/cos16 with new versions

* bugfixes

* fixed hourglass init, rearranged PS FX init

* speed optimization

- moved out of bounds calculation to proper spot
- removed repeated allocation attempts if initial buffer alloc fails

* Added Sonic Stream FX, some cleanup, bugfix in emitter

* changed TTL to brightness calculation, added collision binning

- brightness is now doubled as some FX were really dim due to low TTL
- added binning in x-direction giving a huge speed advantage on larger matrix sizes

* collision binning bugfix, made particles less sticky, update to waterfall

- updated waterfall intensity and blurring

* WIP: fixed 1D system for over 1000 pixels, added collision binning for 1D

- making x coordinate 32bit allows for larger strips but uses a lot of ram due to struct memory alignment (12bytes instead of 8 bytes), this needs some more work to properly fix.
- adding collision binning significantly speeds things up, about a factor of 2 on most FX using collision
- there are still some bugs in FX or 1D memory handling (or both) on large setups

* moved particle flags to seperate array to save on RAM, refactoring

- moving the flags optimizes ram alignment, saving memory for each particle
- changed lots of parameters to `const`
- moved fire intensity to a variable instead of passing it to every render() call
- changed passing pointers to passing reference where possible
- saves a total of 340 bytes of flash

* removed todos after some checks, minor improvements

* inverted y axis in 2D render, 1D collision improvements, cleanup and fixes

- inverting the y-axis in the buffer instead of in buffer transfer fixes the FX flipping when transitiononing 1D<->2D
- improved particle binning for collisions
- added hard-pushing also when not using gravity so piles close to an edge dont collapse
- some improvments to "balance" FX
- renaming and cleanup

* FX fixes and minor tweaks

* increased min rockets

* fixed #ifdefs

* another fix

* revert unnecessary changes to base code

* merge fix

* minor tweak

* tweaked sparkler FX, some cleanup

* Fix in volcano FX, changed blurring of volcano and waterfall

* added ifdefs

* minor tweaks, increased 1D minsurfacehardness

* improved sparkler FX, made overlay possible (1D not yet), cleanup

* cleanup, now using new hsv2rgb/rgb2hsv, add overlay rendering to 1D

- new hsv2rgb is a tiny bit faster
- removed redundant code (using transferBuffer instead)
- tweked parameters in vortex, removed unneeded slider defaults

* fix for non or partially overlapping segments

- can not use overlay rendering if no segment clears the buffer, it will all add up to white eventually
- now additive transfer i.e. overlay mode is only activated if the segment is fully overlapping an underlying segment

* change got lost...

* increased sparkler intensity, some cleanup

* replaced #ifdefs, removed 1D replacements that have 2D version, removed notes

* cleanup, improvements to PS bouncing ball, replaced multicomet

- bouncing balls is now named pinball and has settings/parameters updated to be a replacement for multicomet

* cleanup, improvements, bugfixes

- large size rendering now works without framebuffer
- background adding is now done on buffer (if avilable) instead of segment
- fixed overflow bug in 2D large particle rendering (it worked only for powers of 2 size)

* potential bugfix, compiler warning fix

* removed colorwaves and pride option from chase (not worthy replacements)

* updated #defines, removed PS from 1M and 2M builds

* Adding Particle System and PS FX

Adding all 187 commits from particle system dev branch

* reverted some accidental changes

* reverted some accidental changes

* merge fixes

* changed replacement: multicomet instead of comet (lighthouse)

* changed replacement: multicomet instead of comet (lighthouse)

* disable 2D PS for ESP8266, some cleanup, improved pinball FX parameters, bugfixes

* Improved collision binning for large particles, improved pinball FX

* improved speed handling in pinball FX - rolling

* disable 2D PS for ESP8266, some cleanup, improved pinball FX parameters, bugfixes

* improved hourglass: millis instead of frame timing, better stacking. and cleanup.

* revert whitespaces

* simplified 1D collisions, improved binning for larger particles

- ran a lot of experiments with collisions in 1D, the new much simpler approach seems to be a good compromise with regards to stacking and normal collisions.

* Improved collision binning for large particles, improved pinball FX

* improved speed handling in pinball FX - rolling

* improved hourglass: millis instead of frame timing, better stacking. and cleanup.

* revert whitespaces

* prohibit use of 1D and 2D system simultaneously on ESP8266

* prohibit use of 1D and 2D system simultaneously on ESP8266

* update to handle blending styles

* fixed bugs, improved new transition handling

* updated 1D system to work with new transitions, replaced NULL with nullptr

* merge fixes

* added single pixel particle rendering for 2D system, adjusted FX to work with it

* improved collisions in 1D and 2D, some bugfixes in radius calculation, minor tweaks

- collisions are now also velocity based in 1D, there was a bug that prevented that from working well (wrong collision distance calculation)
- improvement and bugfix in 2D collision distance calculation
- added distance based pushing in 2D (instead of only using the dotproduct)
the combination of improved distance calculation and proper pushing make collisions a lot better in all tested FX

* minor fix

* fixed overlay detection, checking for partial overlay

if a PS FX is partially overlapping, it will render in overlay mode

* better blur range in PS Firworks

* minor code consolidation

* updated 1D collisions (yet again), improved 2D collision speed

- slight improvement to 2D collision code efficiency
- added faster "division" to C3/ESP8266 by using a right shift trick (biasing towards 0 also for negative numbers by applying proper rounding)

* minor tweak in PS balance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants