Skip to content

Commit 039772a

Browse files
authored
[FIX] Fix particle emission rate when looping (playcanvas#8263)
1 parent 3fe7463 commit 039772a

File tree

9 files changed

+10
-10
lines changed

9 files changed

+10
-10
lines changed

src/scene/particle-system/cpu-updater.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class ParticleCPUUpdater {
141141
const a2 = 1.0;
142142
particleTex[i * particleTexChannels + 3 + emitter.numParticlesPot * particleTexChannels * 2] = a2;
143143

144-
const maxNegLife = Math.max(emitter.lifetime, (emitter.numParticles - 1.0) * (Math.max(emitter.rate, emitter.rate2)));
144+
const maxNegLife = Math.max(emitter.lifetime, emitter.numParticles * (Math.max(emitter.rate, emitter.rate2)));
145145
const maxPosLife = emitter.lifetime + 1.0;
146146
startSpawnTime = (startSpawnTime + maxNegLife) / (maxNegLife + maxPosLife);
147147
const rgba3 = encodeFloatRGBA(startSpawnTime);
@@ -396,7 +396,7 @@ class ParticleCPUUpdater {
396396
// respawn particle by moving it's life back to zero.
397397
// OR below zero, if there are still unspawned particles to be emitted before this one.
398398
// such thing happens when you have an enormous amount of particles with short lifetime.
399-
life -= Math.max(particleLifetime, (emitter.numParticles - 1) * particleRate);
399+
life -= Math.max(particleLifetime, emitter.numParticles * particleRate);
400400

401401
// dead particles in a single-shot system continue their paths, but marked as invisible.
402402
// it is necessary for keeping correct separation between particles, based on emission rate.

src/scene/shader-lib/glsl/chunks/particle/frag/particleInputRgba8.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void readInput(float uv) {
3535
inShow = tex2.a > 0.5;
3636
3737
inLife = decodeFloatRGBA(tex3);
38-
float maxNegLife = max(lifetime, (numParticles - 1.0) * (rate+rateDiv));
38+
float maxNegLife = max(lifetime, numParticles * (rate+rateDiv));
3939
float maxPosLife = lifetime+1.0;
4040
inLife = inLife * (maxNegLife + maxPosLife) - maxNegLife;
4141
}

src/scene/shader-lib/glsl/chunks/particle/frag/particleOutputRgba8.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void writeOutput() {
2222
2323
outVel = (outVel / maxVel) + vec3(0.5); // TODO: mul
2424
25-
float maxNegLife = max(lifetime, (numParticles - 1.0) * (rate+rateDiv));
25+
float maxNegLife = max(lifetime, numParticles * (rate+rateDiv));
2626
float maxPosLife = lifetime+1.0;
2727
outLife = (outLife + maxNegLife) / (maxNegLife + maxPosLife);
2828
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default /* glsl */`
22
if (outLife >= lifetime) {
3-
outLife -= max(lifetime, (numParticles - 1.0) * particleRate);
3+
outLife -= max(lifetime, numParticles * particleRate);
44
visMode = -1.0;
55
}
66
`;

src/scene/shader-lib/glsl/chunks/particle/frag/particleUpdaterRespawn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default /* glsl */`
22
if (outLife >= lifetime) {
3-
outLife -= max(lifetime, (numParticles - 1.0) * particleRate);
3+
outLife -= max(lifetime, numParticles * particleRate);
44
visMode = 1.0;
55
}
66
visMode = outLife < 0.0? 1.0: visMode;

src/scene/shader-lib/wgsl/chunks/particle/frag/particleInputRgba8.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn readInput(uv: f32) {
4040
inShow = tex2.a > 0.5;
4141
4242
let life_decoded = decodeFloatRGBA(tex3);
43-
let maxNegLife = max(uniform.lifetime, (uniform.numParticles - 1.0) * (uniform.rate + uniform.rateDiv));
43+
let maxNegLife = max(uniform.lifetime, uniform.numParticles * (uniform.rate + uniform.rateDiv));
4444
let maxPosLife = uniform.lifetime + 1.0;
4545
inLife = life_decoded * (maxNegLife + maxPosLife) - maxNegLife;
4646
}`;

src/scene/shader-lib/wgsl/chunks/particle/frag/particleOutputRgba8.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn getOutput() -> vec4f {
2323
2424
outVel = (outVel / uniform.maxVel) + vec3f(0.5); // TODO: mul
2525
26-
let maxNegLife = max(uniform.lifetime, (uniform.numParticles - 1.0) * (uniform.rate + uniform.rateDiv));
26+
let maxNegLife = max(uniform.lifetime, uniform.numParticles * (uniform.rate + uniform.rateDiv));
2727
let maxPosLife = uniform.lifetime + 1.0;
2828
outLife = (outLife + maxNegLife) / (maxNegLife + maxPosLife);
2929
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default /* wgsl */`
22
if (outLife >= uniform.lifetime) {
3-
outLife = outLife - max(uniform.lifetime, (uniform.numParticles - 1.0) * particleRate);
3+
outLife = outLife - max(uniform.lifetime, uniform.numParticles * particleRate);
44
visMode = -1.0;
55
}
66
`;

src/scene/shader-lib/wgsl/chunks/particle/frag/particleUpdaterRespawn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default /* wgsl */`
22
if (outLife >= uniform.lifetime) {
3-
let subtractAmount = max(uniform.lifetime, (uniform.numParticles - 1.0) * particleRate);
3+
let subtractAmount = max(uniform.lifetime, uniform.numParticles * particleRate);
44
outLife = outLife - subtractAmount;
55
visMode = 1.0;
66
}

0 commit comments

Comments
 (0)