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

FX improvements and cleanup #4145

Open
wants to merge 16 commits into
base: 0_15
Choose a base branch
from

Conversation

DedeHai
Copy link
Collaborator

@DedeHai DedeHai commented Sep 15, 2024

This has been on my todo list for a long time, finally done.
It adds some new functionality to 2D FX (blurring / smearing / palette support) and saves on code size (merged 1D FX)
Note: Polar Lights is now slightly different as no palette matches the original effect palette

  • Waving Cell: Improved with higher temporal resolution (smoother at lower speeds) and added additional mode setting and optional blurring

  • Merged puddles and puddlepeak

  • Merged Gravcenter, Gravcentric, Gravfreq and Gravimeter (saves 1.2k of flash)

  • Merged meteor and meteor smooth

  • Renamed police_base into mode_two_dots as that was just an alias

  • Changed default of Palette effect: Animate rotation is now unchecked by default (it looks weird and confusing in 1D as a default)

  • Added or enhanced blurring of

    • DNA
    • DNA Spiral
    • Drift
    • Drift Rose
    • Crazy Bees
    • Ripple
    • Colored Bursts
    • Frizzles
    • Lissajous
    • Sindots
    • Spaceships
  • Added palette support to

    • Crazy Bees
    • Polar Lights
    • Drift Rose
  • Some code cleanup (removed unused / commented stuff)

  • Moved dev info for AR to the top so ist easier to find as a reference, also added link to KB there

- Waving Cell: Improved with higher temporal resolution (smoother at lower speeds) and added additional mode setting and optional blurring
- Merged puddles and puddlepeak
- Merged Gravcenter, Gravcentric, Gravfreq and Gravimeter (saves 1.2k of flash)
- Merged meteor and meteor smooth
- Renamed police_base into mode_two_dots as that was just an alias
- Changed default of Palette effect: Animate rotation is now unchecked by default (it looks weird and confusing in 1D as a default)

- Added or enhanced blurring of
    - DNA
    - DNA Spiral
    - Drift
    - Drift Rose
    - Crazy Bees
    - Ripple
    - Colored Bursts
    - Frizzles
    - Lissajous
    - Sindots
    - Spaceships

- Added palette support to
    - Crazy Bees
    - Polar Lights
    - Drift Rose

- Some code cleanup (removed unused / commented stuff)
    - Renamed police_base into mode_two_dots (was just an alias not used by anything else)
    - Moved dev info for AR to the top so ist easier to find as a reference, also added link to KB there
@blazoncek
Copy link
Collaborator

@ewoudwijma @netmindz would you care to take a look as some effects were created by you.

  • Changed default of Palette effect: Animate rotation is now unchecked by default (it looks weird and confusing in 1D as a default)

This will need to be checked with @TripleWhy

Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

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

I do welcome the changes and see great value in optimisations, but...

Please avoid breaking existing default behaviour of effects unless strictly necessary. It is not all about speed when you have 10.000+ users.
There are also some trailing spaces and formatting glitches to be fixed.

wled00/FX.cpp Show resolved Hide resolved
wled00/FX.cpp Outdated Show resolved Hide resolved
wled00/FX.cpp Outdated
@@ -5021,10 +5024,11 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma
SEGMENT.setPixelColorXY(x1, i, WHITE);
}
}
SEGMENT.blur(SEGMENT.custom1 >> (!SEGMENT.check1), SEGMENT.check1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will cause different looking effect on existing presets. Please consider backwards compatibility.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in FX where I added blur, the default slider position is set to 0, checks are set to 0.
that will change behaviour on users that have 'default fx parameters' unused. if that is a restriction, none of the FX can be extended (ever).

wled00/FX.cpp Outdated
@@ -5048,13 +5052,13 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli
int mySin = sin_t(angle) * i;
int myCos = cos_t(angle) * i;
SEGMENT.setPixelColorXY(colsCenter + mySin, rowsCenter + myCos, ColorFromPalette(SEGPALETTE, (i * 20) + t_20, 255, LINEARBLEND));
if (SEGMENT.check1) SEGMENT.setPixelColorXY(colsCenter + myCos, rowsCenter + mySin, ColorFromPalette(SEGPALETTE, (i * 20) + t_20, 255, LINEARBLEND));
if (SEGMENT.check2) SEGMENT.setPixelColorXY(colsCenter + myCos, rowsCenter + mySin, ColorFromPalette(SEGPALETTE, (i * 20) + t_20, 255, LINEARBLEND));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will cause different looking effect on existing presets. Please consider backwards compatibility.

wled00/FX.cpp Outdated
@@ -5100,17 +5104,17 @@ uint16_t mode_2DFrizzles(void) { // By: Stepko https://editor.so
const int cols = SEGMENT.virtualWidth();
const int rows = SEGMENT.virtualHeight();

SEGMENT.fadeToBlackBy(16);
SEGMENT.fadeToBlackBy(18);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will cause different looking effectand may case playlists to no longer function as intended. Please consider backwards compatibility.

wled00/FX.cpp Outdated Show resolved Hide resolved
wled00/FX.cpp Outdated
SEGMENT.addPixelColorXY(bee[i].aimX, bee[i].aimY + 1, CHSV(bee[i].hue, 255, 255));
SEGMENT.addPixelColorXY(bee[i].aimX - 1, bee[i].aimY, CHSV(bee[i].hue, 255, 255));
SEGMENT.addPixelColorXY(bee[i].aimX, bee[i].aimY - 1, CHSV(bee[i].hue, 255, 255));
CRGB flowerCcolor = ColorFromPalette(SEGPALETTE,bee[i].hue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use SEGMENT.color_from_palette() to keep using WLED native pixels and behaviour?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Regarding ColorFromPalette() and SEGMENT.color_from_palette().

The former was used in FastLED effects ported to WLED with minimal effort (or to keep changes simple). Unfortunately this does not adhere to WLED's "default" behaviour for palettes and color, unless specifically crafted within effect. So I would prefer to use SEGMENT.color_from_palette() wherever possible if there are changes to an effect function.

Copy link
Collaborator Author

@DedeHai DedeHai Sep 16, 2024

Choose a reason for hiding this comment

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

generally agreed.
color_from_palette does some additional checks and calculations, plus converts to 32bits, then FX may convert it back to CRGB, then setPixelColor converts it again to 32bit. That makes FX slow that call this for every pixel so I don't see it as a good solution. I have some basic ideas on how to fix this with CRGBW (basically overload some functions to accept RGB and RGBW and calculate the fastest way possible).
Once there is a good solution, this will be a simple search and replace but that will have to wait for round2 cleanup.

Copy link
Collaborator

Choose a reason for hiding this comment

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

then FX may convert it back to CRGB,

This (and other manipulations like that) will need to be removed or converted. color_from_palette() is there for a reason, to ensure consistent behaviour of "Default" options.

wled00/FX.cpp Outdated Show resolved Hide resolved
@DedeHai
Copy link
Collaborator Author

DedeHai commented Sep 16, 2024

I did not consider backward compatibility to be so important but you are right, will revert default behaviour back to what it was before.
edit:
should meteor_smooth be kept as an alias or is removing it ok?

@blazoncek
Copy link
Collaborator

should meteor_smooth be kept as an alias or is removing it ok

As we removed some effects in 0.13 and then again in 0.14 I think we can do that again in favour of the possibility to finally merge in PS effects. I would really like to see those (at least 2D) in.

wled00/FX.cpp Outdated Show resolved Hide resolved
wled00/FX.cpp Show resolved Hide resolved
wled00/FX.cpp Outdated Show resolved Hide resolved
wled00/FX.cpp Outdated Show resolved Hide resolved
wled00/FX.cpp Outdated
unsigned width = ((SEGLEN*(SEGMENT.intensity+1))>>9); //max width is half the strip
if (!width) width = 1;
if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(2));
uint32_t color1 = SEGCOLOR(0);
uint32_t color2 = (SEGCOLOR(1) == SEGCOLOR(2)) ? color1 : SEGCOLOR(1);

Choose a reason for hiding this comment

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

Does anyone else find this logic strange? ^^

Not a change introduced this PR, but I never noticed that before. I would prefer a more straightforward approach, even if that may break a few existing configurations

Copy link
Collaborator

Choose a reason for hiding this comment

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

Legacy.
If colors 2 & 3 match, use color 1 for both "dots". Color 3 is background. Color 3 (AKA background) can be omitted if "Overlay" is selected.
Unfortunately a poor choice of variable names if that is what you are referring to. 😁

wled00/FX.cpp Show resolved Hide resolved
wled00/FX.cpp Outdated
// Gravcenter effects By Andrew Tuline.
// Gravcenter base function for Gravcenter (0), Gravcentric (1), Gravimeter (2), Gravfreq (3) (merged by @dedehai)

uint16_t mode_gravcenter_base(unsigned mode) {

Choose a reason for hiding this comment

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

After having read through this function now:

While I do appreciate an effort to generalize things, is that really the best approach for these effects? How much of the code is actually shared in this new version. Not that much if we are honest. So I don't think this particular approach makes too much sense in this case.

An alternative approach could be to move the portions of the code that are actually shared/generalizable into gravcenter helper functions, then call those from the specific functions. Less interleaving, no runtime checks, clear readable code path from top to bottom.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, merging them like this saves 1.2k of flash so actually it is quite some shared code.
while I agree this could be made prettier I don't think seperating it in a different way would improve the readability.
the runtime checks are negligible, that is only done once per frame.

wled00/FX.cpp Outdated Show resolved Hide resolved
wled00/FX.cpp Show resolved Hide resolved
wled00/FX.cpp Outdated Show resolved Hide resolved
- reverted blurring to old values (where applicable)
- added 'Traffic Light' palette (originally defined in Polar Lights FX)
- Bugfix in Meteor: starting point was not the same before merge
- made blurring in ripple_base a passing argument instead of a bool
- Code cleanup
@netmindz
Copy link
Collaborator

@ewoudwijma @netmindz would you care to take a look as some effects were created by you.

  • Changed default of Palette effect: Animate rotation is now unchecked by default (it looks weird and confusing in 1D as a default)

This will need to be checked with @TripleWhy

I don't think any of those were added by me, but I can try and take a look at this PR in the next few days

wled00/FX.cpp Show resolved Hide resolved
wled00/FX.cpp Outdated

return FRAMETIME;
} // mode_2DSindots()
static const char _data_FX_MODE_2DSINDOTS[] PROGMEM = "Sindots@!,Dot distance,Fade rate,Blur;;!;2;c2=64";
static const char _data_FX_MODE_2DSINDOTS[] PROGMEM = "Sindots@!,Dot distance,Fade rate,Blur,,Extra Blur;;!;2;";

Choose a reason for hiding this comment

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

call it smear maybe? that would be the same as in other effects where you added it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not happy with that name either... but smear is a different behaviour (it blurs without fading underlaying colors, causing a motion blurring or 'smear'). Well screw it, I will just update it to use smear (did not succeed in that before but I have an Idea)

uses fire palette by default, looks is 95% identical.
also the /cols should be /rows or it will look different depending on matrix dimensions (brightness changes, also there are weird lines if width != height)
no penalty in size of `Segment` struct (if it is kept just at the place I added it, compiler does not optimize struct alignment order and just adds padding if not aligned, there it falls into a padding)
checking 'gradient' applies the selected palette as a gradient, default palette still does color gradient.
@DedeHai
Copy link
Collaborator Author

DedeHai commented Sep 19, 2024

last two commits (pal0 override and palette gradient for scrolling text) are just suggestions for review/comment.

@@ -213,24 +213,12 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0;
if (pal > 245 && (strip.customPalettes.size() == 0 || 255U-pal > strip.customPalettes.size()-1)) pal = 0; // TODO remove strip dependency by moving customPalettes out of strip
//default palette. Differs depending on effect
if (pal == 0) switch (mode) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The unfortunate consequence of this removal is that when used from existing preset, there will be no "default" palette to choose from. So, unless user chooses the effect in UI (with defined "default" palette from metadata) it will not have "default" palette defined. Once user selects it from UI the palette will be defined.

This is then inconsistent behaviour.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the default palette gets set when FX is loaded.
I don't fully understand in what scenario the behaviour would differ (with the latest bugfix). Can you check latest commit changes and give me a description of a test case I can try?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Take, for example, effect "Fire 2012". Its default platte is "Fire" (35) even if user selects palette "Default" (0).

If I have an existing preset with Fire 2012 it will most likely have ”pal”:0 as its selected palette. But after removal of this code this will mean "Party" palette until user manually selects Fire 2012 from UI which will populate its default palette to 35.

Steps to reproduce:

  • use 0.14 to create preset of Fire 2012 with default values (i.e. palette chosen is Default)
  • update to this PR
  • restart ESP
  • select preset with Fire 2012 effect
  • it will display with Party colors instead of Fire
  • select another preset or effect
  • now select Fire 2012 in Effects tab, palette will change to Fire
  • select another preset or effect
  • select preset with Fire 2012
  • it will display with Fire palette.

Copy link
Collaborator Author

@DedeHai DedeHai Sep 21, 2024

Choose a reason for hiding this comment

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

Got it thx, I will try to fix this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, fixed it. can confirm your test scenario now works.

- _default_palette now always gets properly set to party colors (in that case the FX does not have a 'pal' argument and sOpt is -1)
- added initialization to zero for _default_palette (reason to crash)
- 'pal' FX option is always extracted when chaning an FX, _default_palette variable is thus always set in setMode()
Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

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

This is now a little better but still does not cover HTTP API.
FYI palette with ID 255 is first custom palette.

wled00/FX_fcn.cpp Show resolved Hide resolved
wled00/FX_fcn.cpp Outdated Show resolved Hide resolved
@DedeHai
Copy link
Collaborator Author

DedeHai commented Sep 22, 2024

This is now a little better but still does not cover HTTP API.

a little hint which function handles this?

@blazoncek
Copy link
Collaborator

a little hint which function handles this?

set.cpp ; handleSet()

@DedeHai
Copy link
Collaborator Author

DedeHai commented Sep 22, 2024

handleSet() calls seg.setMode() which takes care of setting the default palette. what am I missing?

@blazoncek
Copy link
Collaborator

what am I missing?

Then you are all set. I do not know every line of code from the top of my head, but I do now a few relations that may be hidden.

@softhack007 softhack007 added Awaiting testing in progress This pull request is currently being reviewed and, if necessary, modified labels Sep 28, 2024
@softhack007 softhack007 added this to the 0.15.1 candidate milestone Sep 28, 2024
@blazoncek
Copy link
Collaborator

blazoncek commented Oct 2, 2024

Ah, disregard. 🤦

Apparently the C3 can not convert negative floats to uint8_t directly, casting it into an int first fixes it.
@DedeHai
Copy link
Collaborator Author

DedeHai commented Oct 15, 2024

maybe cherry-pick the latest commit before 0.15 release?(6a26944 )

@blazoncek
Copy link
Collaborator

maybe cherry-pick the latest commit before 0.15 release?(6a26944 )

As this is a bugfix you can edit and push 0_15 branch directly. Just don't do it like you did for #3877 😄 use AC repo.

…ents

- smearing was introduced as a byproduct of my particle-system, it relies on smearing to be the way it was originally: this is in preparation of merging the particle system
- adjusted the FX to accomodate the change
- fixed bug in ripple FX not correctly blurring
- added smearing option to Lissajous
- improved blurring / smearing in crazy bees
- added fade option to Squared Swirl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting testing effect in progress This pull request is currently being reviewed and, if necessary, modified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants