mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
fix particle texture animation bug (#5339)
* fix particle texture animation bug * change particle effect uniform
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -267,7 +267,9 @@ export class UI {
|
||||
for (let i = idx; i < this._screens.length; i++) {
|
||||
camera = this._screens[i].camera;
|
||||
if (camera) {
|
||||
camera.view.visibility = -1;
|
||||
const matRecord = this._canvasMaterials.get(camera.view.visibility)!;
|
||||
camera.view.visibility -= 1;
|
||||
this._canvasMaterials.set(camera.view.visibility, matRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +202,10 @@ export default class TextureAnimationModule {
|
||||
this.ps = ps;
|
||||
}
|
||||
|
||||
public init (p: Particle) {
|
||||
p.startRow = Math.floor(Math.random() * this.numTilesY);
|
||||
}
|
||||
|
||||
public animate (p: Particle) {
|
||||
const normalizedTime = 1 - p.remainingLifetime / p.startLifetime;
|
||||
const startFrame = this.startFrame.evaluate(normalizedTime, pseudoRandom(p.randomSeed + TEXTURE_ANIMATION_RAND_OFFSET))! / (this.numTilesX * this.numTilesY);
|
||||
@@ -212,8 +216,7 @@ export default class TextureAnimationModule {
|
||||
const rowLength = 1 / this.numTilesY;
|
||||
if (this.randomRow) {
|
||||
const f = repeat(this.cycleCount * (this.frameOverTime.evaluate(normalizedTime, pseudoRandom(p.randomSeed + TEXTURE_ANIMATION_RAND_OFFSET))! + startFrame), 1);
|
||||
const startRow = Math.floor(Math.random() * this.numTilesY);
|
||||
const from = startRow * rowLength;
|
||||
const from = p.startRow * rowLength;
|
||||
const to = from + rowLength;
|
||||
p.frameIndex = lerp(from, to, f);
|
||||
}
|
||||
|
||||
@@ -583,6 +583,10 @@ export class ParticleSystemComponent extends RenderableComponent {
|
||||
Vec3.copy(particle.velocity, particleEmitZAxis);
|
||||
}
|
||||
|
||||
if (this.textureAnimationModule.enable) {
|
||||
this.textureAnimationModule.init(particle);
|
||||
}
|
||||
|
||||
Vec3.multiplyScalar(particle.velocity, particle.velocity, this.startSpeed.evaluate(this._time / this.duration, rand)!);
|
||||
|
||||
switch (this._simulationSpace) {
|
||||
|
||||
@@ -24,6 +24,7 @@ export default class Particle {
|
||||
public emitAccumulator0: number;
|
||||
public emitAccumulator1: number;
|
||||
public frameIndex: number;
|
||||
public startRow: number;
|
||||
|
||||
constructor (particleSystem: any) {
|
||||
this.particleSystem = particleSystem;
|
||||
@@ -44,5 +45,6 @@ export default class Particle {
|
||||
this.emitAccumulator0 = 0.0;
|
||||
this.emitAccumulator1 = 0.0;
|
||||
this.frameIndex = 0.0;
|
||||
this.startRow = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user