Skip to content

Commit

Permalink
improved sparkler FX, made overlay possible (1D not yet), cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DedeHai committed Jan 16, 2025
1 parent 4294834 commit fc8960a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
39 changes: 20 additions & 19 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9502,36 +9502,32 @@ uint16_t mode_particleSparkler(void) {
// Particle System settings
PartSys->updateSystem(); // update system properties (dimensions and data pointers)

sparklersettings.wrap = SEGMENT.check2;
sparklersettings.bounce = !SEGMENT.check2;
sparklersettings.wrap = !SEGMENT.check2;
sparklersettings.bounce = SEGMENT.check2; // note: bounce always takes priority over wrap

numSparklers = PartSys->numSources;
PartSys->setMotionBlur(SEGMENT.custom2); // anable motion blur
//PartSys->setParticleSize(SEGMENT.check3); // 1 or 2 pixel rendering
PartSys->setMotionBlur(SEGMENT.custom2); // anable motion blur/overlay
//PartSys->setSmearBlur(SEGMENT.custom2); // anable smearing blur

for (uint32_t i = 0; i < numSparklers; i++) {
PartSys->sources[i].source.hue = hw_random16();
PartSys->sources[i].var = SEGMENT.intensity >> 4 ;
PartSys->sources[i].minLife = 150 + (SEGMENT.intensity >> 1);
PartSys->sources[i].maxLife = 200 + SEGMENT.intensity;
PartSys->sources[i].var = 0; // sparks stationary
PartSys->sources[i].minLife = 150 + SEGMENT.intensity;
PartSys->sources[i].maxLife = 250 + (SEGMENT.intensity << 2);
uint32_t speed = SEGMENT.speed >> 1;
if(SEGMENT.check1) // invert spray speed
speed = -speed;
if(SEGMENT.check1) // sparks move (slide option)
PartSys->sources[i].var = SEGMENT.intensity >> 3;
PartSys->sources[i].source.vx = speed; // update speed, do not change direction
PartSys->sources[i].source.ttl = 400; // replenish its life (setting it perpetual uses more code)
PartSys->sources[i].sat = SEGMENT.custom1; // color saturation
PartSys->sources[i].size = SEGMENT.check3 ? 120 : 0;
for(uint32_t j = 0; j < 2; j++) { // move twice for higher speeds
PartSys->particleMoveUpdate(PartSys->sources[i].source, PartSys->sources[i].sourceFlags, &sparklersettings); //move sparkler 1243972-
}
}

for (uint32_t i = 0; i < PartSys->usedParticles; i++) {
if (PartSys->particles[i].ttl > 10) PartSys->particles[i].ttl -= 10; //ttl is linked to brightness, this allows to use higher brightness but still a short spark lifespan
else PartSys->particles[i].ttl = 0;
if(SEGMENT.speed == 255) // random position at highest speed setting
PartSys->sources[i].source.x = hw_random16(PartSys->maxX);
else
PartSys->particleMoveUpdate(PartSys->sources[i].source, PartSys->sources[i].sourceFlags, &sparklersettings); //move sparkler
}

numSparklers = min(1 + (SEGMENT.custom3 >> 2), (int)numSparklers); // set used sparklers, 1 to 8
numSparklers = min(1 + (SEGMENT.custom3 >> 1), (int)numSparklers); // set used sparklers, 1 to 16

if (SEGENV.aux0 != SEGMENT.custom3) { //number of used sparklers changed, redistribute
for (uint32_t i = 1; i < numSparklers; i++) {
Expand All @@ -9547,9 +9543,14 @@ uint16_t mode_particleSparkler(void) {

PartSys->update(); // update and render

for(uint32_t i = 0; i < PartSys->usedParticles; i++) {
if(PartSys->particles[i].ttl > (64 - (SEGMENT.intensity >> 2))) PartSys->particles[i].ttl -= (64 - (SEGMENT.intensity >> 2)); //ttl is linked to brightness, this allows to use higher brightness but still a short spark lifespan
else PartSys->particles[i].ttl = 0;
}

return FRAMETIME;
}
static const char _data_FX_MODE_PS_SPARKLER[] PROGMEM = "PS Sparkler@Speed,!,Saturation,Blur,Sparklers,Direction,Wrap/Bounce,Large;,!;!;1;pal=0,sx=50,ix=200,c1=0,c2=0,c3=0,o1=1,o2=1";
static const char _data_FX_MODE_PS_SPARKLER[] PROGMEM = "PS Sparkler@Speed,!,Saturation,Blur,Sparklers,Slide,Bounce,Large;,!;!;1;pal=0,sx=255,ix=200,c1=0,c2=0,c3=6";

/*
Particle based Hourglass, particles falling at defined intervals
Expand Down
15 changes: 7 additions & 8 deletions wled00/FXparticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,9 @@ void ParticleSystem2D::ParticleSys_render() {

// handle blurring and framebuffer update
if (framebuffer) {
if(!pmem->inTransition) useAdditiveTransfer = false; // additive rendering is only used in PS FX transitions
//if(!pmem->inTransition) useAdditiveTransfer = false; // additive rendering is only used in PS FX transitions
if(strip.getCurrSegmentId() > 0) useAdditiveTransfer = true; //!!! test for overlay rendering
else useAdditiveTransfer = false;
// handle buffer blurring or clearing
bool bufferNeedsUpdate = (!pmem->inTransition || pmem->inTransition == effectID); // not a transition; or new FX: update buffer (blur, or clear)

Expand All @@ -592,8 +594,7 @@ void ParticleSystem2D::ParticleSys_render() {
int index = y * (maxXpixel + 1);
for (int32_t x = 0; x <= maxXpixel; x++) {
if (!renderSolo) { // sharing the framebuffer with another segment: read buffer back from segment
uint32_t yflipped = maxYpixel - y;
framebuffer[index] = SEGMENT.getPixelColorXY(x, yflipped); // read from segment
framebuffer[index] = SEGMENT.getPixelColorXY(x, y); // read from segment
}
fast_color_scale(framebuffer[index], globalBlur); // note: could skip if only globalsmear is active but usually they are both active and scaling is fast enough
index++;
Expand Down Expand Up @@ -639,8 +640,6 @@ void ParticleSystem2D::ParticleSys_render() {
SEGMENT.fill(BLACK); //clear the buffer before rendering next frame
}

bool wrapX = particlesettings.wrapX; // use local variables for faster access
bool wrapY = particlesettings.wrapY;
// go over particles and render them to the buffer
for (uint32_t i = 0; i < usedParticles; i++) {
if (particles[i].ttl == 0 || particleFlags[i].outofbounds)
Expand All @@ -660,7 +659,7 @@ void ParticleSystem2D::ParticleSys_render() {
baseRGB = (CRGB)baseHSV; // convert back to RGB
}
}
renderParticle(i, brightness, baseRGB, wrapX, wrapY);
renderParticle(i, brightness, baseRGB, particlesettings.wrapX, particlesettings.wrapY);
}

if (particlesize > 0) {
Expand Down Expand Up @@ -1530,7 +1529,7 @@ void ParticleSystem1D::ParticleSys_render() {
else
SEGMENT.fill(BLACK); // clear the buffer before rendering to it
}
bool wrap = particlesettings.wrap; // local copy for speed

// go over particles and render them to the buffer
for (uint32_t i = 0; i < usedParticles; i++) {
if ( particles[i].ttl == 0 || particleFlags[i].outofbounds)
Expand All @@ -1547,7 +1546,7 @@ void ParticleSystem1D::ParticleSys_render() {
baseRGB = (CRGB)baseHSV; // convert back to RGB
}
}
renderParticle(i, brightness, baseRGB, wrap);
renderParticle(i, brightness, baseRGB, particlesettings.wrap);
}
// apply smear-blur to rendered frame
if(globalSmear > 0) {
Expand Down

0 comments on commit fc8960a

Please sign in to comment.