Browse Source

Curve update normalized by particle life time.

clementlandrin 10 months ago
parent
commit
e06bb5bff2

+ 3 - 1
hrt/prefab/fx/gpuemitter/BaseSpawn.hx

@@ -5,7 +5,7 @@ class BaseSpawn extends ComputeUtils {
 		@param var batchBuffer : RWPartialBuffer<{
 			modelView : Mat4, 
 		}>;
-		@param var particleBuffer : RWPartialBuffer<{ speed : Vec3, lifeTime : Float }>;
+		@param var particleBuffer : RWPartialBuffer<{ speed : Vec3, lifeTime : Float, lifeRatio : Float }>;
 
 		@const var SPEED_NORMAL : Bool;
 		@param var minLifeTime : Float;
@@ -34,6 +34,8 @@ class BaseSpawn extends ComputeUtils {
 					s = emitNormal;
 				particleBuffer[idx].speed = s * maxStartSpeed;
 				particleBuffer[idx].lifeTime = lifeTime;
+				// Keep in memory duration of particle to normalize curve update.
+				particleBuffer[idx].lifeRatio = 1.0 / lifeTime;
 			}
 		}
 	}

+ 2 - 4
hrt/prefab/fx/gpuemitter/GPUEmitter.hx

@@ -101,10 +101,6 @@ class GPUEmitterObject extends h3d.scene.MeshBatch {
 		simulationPass = new h3d.mat.Pass("simulation");
 		simulationPass.addShader(new BaseSimulation());
 
-		init();
-	}
-
-	public function init() {
 		begin();
 		for ( _ in 0...data.maxCount )
 			emitInstance();
@@ -121,6 +117,8 @@ class GPUEmitterObject extends h3d.scene.MeshBatch {
 		var particleBufferFormat = hxd.BufferFormat.make([
 			{ name : "speed", type : DVec3 },
 			{ name : "lifeTime", type : DFloat },
+			{ name : "lifeRatio", type : DFloat },
+			{ name : "padding", type : DVec3 },
 		]);
 		while ( p != null ) {
 			if ( particleBuffer.buffer == null )

+ 2 - 2
hrt/prefab/fx/gpuemitter/UpdateParamShader.hx

@@ -5,7 +5,7 @@ class UpdateParamShader extends hxsl.Shader {
 
 		@param var batchBuffer : RWBuffer<Float>;
 
-		@param var particleBuffer : RWPartialBuffer<{ speed : Vec3, lifeTime : Float }>;
+		@param var particleBuffer : RWPartialBuffer<{ speed : Vec3, lifeTime : Float, lifeRatio : Float }>;
 
 		@param var paramTexture : Sampler2D;
 		@param var stride : Int;
@@ -15,7 +15,7 @@ class UpdateParamShader extends hxsl.Shader {
 
 		function main() {
 			var idx = computeVar.globalInvocation.x;
-			batchBuffer[idx * stride + pos] = paramTexture.get(vec2(particleBuffer[idx].lifeTime, row)).x;
+			batchBuffer[idx * stride + pos] = paramTexture.get(vec2(particleBuffer[idx].lifeTime * particleBuffer[idx].lifeRatio, row)).x;
 		}
 	}
 }