David Catuhe 7 年之前
父节点
当前提交
91c1da37cb
共有 2 个文件被更改,包括 11 次插入4 次删除
  1. 8 2
      src/Particles/babylon.gpuParticleSystem.ts
  2. 3 2
      src/Shaders/gpuUpdateParticles.vertex.fx

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

@@ -112,7 +112,12 @@
         /**
          * The maximum number of particles to emit per frame until we reach the activeParticleCount value
          */
-        public emitRate = 100;        
+        public emitRate = 100; 
+        
+        /**
+         * You can use gravity if you want to give an orientation to your particles.
+         */
+        public gravity = Vector3.Zero();        
 
         /**
          * Gets the maximum number of particles supported by this system
@@ -174,7 +179,7 @@
 
             let updateEffectOptions: EffectCreationOptions = {
                 attributes: ["position", "age", "life", "seed", "size", "color", "direction"],
-                uniformsNames: ["currentCount", "timeDelta", "generalRandom", "emitterWM", "lifeTime", "color1", "color2", "sizeRange"],
+                uniformsNames: ["currentCount", "timeDelta", "generalRandom", "emitterWM", "lifeTime", "color1", "color2", "sizeRange", "gravity"],
                 uniformBuffersNames: [],
                 samplers:["randomSampler"],
                 defines: "",
@@ -333,6 +338,7 @@
             this._updateEffect.setDirectColor4("color1", this.color1);
             this._updateEffect.setDirectColor4("color2", this.color2);
             this._updateEffect.setFloat2("sizeRange", this.minSize, this.maxSize);
+            this._updateEffect.setVector3("gravity", this.gravity);
 
             let emitterWM: Matrix;
             if ((<AbstractMesh>this.emitter).position) {

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

@@ -8,6 +8,7 @@ uniform vec2 lifeTime;
 uniform vec2 sizeRange;
 uniform vec4 color1;
 uniform vec4 color2;
+uniform vec3 gravity;
 uniform sampler2D randomSampler;
 
 // Particles state
@@ -55,8 +56,8 @@ void main() {
 
     // Direction
     outDirection = 2.0 * (getRandomVec3(seed) - vec3(0.5, 0.5, 0.5));
-  } else {
-    outPosition = position + direction * timeDelta;
+  } else {   
+    outPosition = position + (direction + gravity) * timeDelta;
     outAge = age + timeDelta;
     outLife = life;
     outSeed = seed;