David Catuhe 7 éve
szülő
commit
ce3a839ba4

+ 2 - 3
src/Particles/babylon.gpuParticleSystem.ts

@@ -329,7 +329,7 @@
             this._updateEffectOptions = {
                 attributes: ["position", "age", "life", "seed", "size", "color", "direction"],
                 uniformsNames: ["currentCount", "timeDelta", "generalRandoms", "emitterWM", "lifeTime", "color1", "color2", "sizeRange", "gravity", "emitPower",
-                                "direction1", "direction2", "minEmitBox", "maxEmitBox", "radius", "directionRandomizer", "height", "angle"],
+                                "direction1", "direction2", "minEmitBox", "maxEmitBox", "radius", "directionRandomizer", "height", "angle", "stopFactor"],
                 uniformBuffersNames: [],
                 samplers:["randomSampler"],
                 defines: "",
@@ -490,8 +490,6 @@
 
                 if (this.targetStopDuration && this._actualFrame >= this.targetStopDuration)
                     this.stop();
-            } else {
-                this._timeDelta = 0;
             }             
         }        
 
@@ -529,6 +527,7 @@
             
             this._updateEffect.setFloat("currentCount", this._currentActiveCount);
             this._updateEffect.setFloat("timeDelta", this._timeDelta);
+            this._updateEffect.setFloat("stopFactor", this._stopped ? 0 : 1);
             this._updateEffect.setFloat3("generalRandoms", Math.random(), Math.random(), Math.random());
             this._updateEffect.setTexture("randomSampler", this._randomTexture);
             this._updateEffect.setFloat2("lifeTime", this.minLifeTime, this.maxLifeTime);

+ 13 - 2
src/Shaders/gpuUpdateParticles.vertex.fx

@@ -4,6 +4,7 @@
 
 uniform float currentCount;
 uniform float timeDelta;
+uniform float stopFactor;
 uniform vec3 generalRandoms;
 uniform mat4 emitterWM;
 uniform vec2 lifeTime;
@@ -67,6 +68,16 @@ vec4 getRandomVec4(float offset) {
 
 void main() {
   if (age >= life) {
+    if (stopFactor == 0.) {
+      outPosition = position;
+      outAge = life;
+      outLife = life;
+      outSeed = seed;
+      outColor = vec4(0.,0.,0.,0.);
+      outSize = size;
+      outDirection = direction;
+      return;
+    }
     vec3 position;
     vec3 direction;
 
@@ -151,12 +162,12 @@ void main() {
     outDirection = (emitterWM * vec4(direction * power, 0.)).xyz;
 
   } else {   
-    outPosition = position + (direction + gravity) * timeDelta;
+    outPosition = position + direction * timeDelta;
     outAge = age + timeDelta;
     outLife = life;
     outSeed = seed;
     outColor = color;
     outSize = size;
-    outDirection = direction;
+    outDirection = direction + gravity * timeDelta;
   }
 }