Browse Source

Adding onRemove method to ComputeUtils.hx

clementlandrin 2 months ago
parent
commit
2385c2cc54

+ 2 - 0
hrt/prefab/fx/gpuemitter/ComputeUtils.hx

@@ -4,6 +4,8 @@ class ComputeUtils extends hxsl.Shader {
 
 	public function onUpdate(emitter : GPUEmitterObject, buffer : h3d.Buffer, index : Int) {}
 
+	public function onRemove(emitter : GPUEmitterObject) {}
+
 	static var SRC = {
 
 		@global var global : {

+ 13 - 0
hrt/prefab/fx/gpuemitter/GPUEmitterObject.hx

@@ -26,6 +26,7 @@ class ParticleShader extends hxsl.Shader {
 		var transformedPosition : Vec3;
 		function __init__vertex() {
 			{
+				// TODO : particleLife is decreasing, need to be flipped to guarantee compatibility with regular emitter shaders.
 				particleLife = particleBuffer[instanceID].life;
 				particleLifeTime = particleBuffer[instanceID].lifeTime;
 				particleRandom = particleBuffer[instanceID].random;
@@ -356,5 +357,17 @@ class GPUEmitterObject extends h3d.scene.MeshBatch {
 
 		if ( paramTexture != null )
 			paramTexture.dispose();
+
+		for ( s in spawnPass.getShaders() ) {
+			var computeUtils = Std.downcast(s, ComputeUtils);
+			if ( computeUtils != null )
+				computeUtils.onRemove(this);
+		}
+
+		for ( s in simulationPass.getShaders() ) {
+			var computeUtils = Std.downcast(s, ComputeUtils);
+			if ( computeUtils != null )
+				computeUtils.onRemove(this);
+		}
 	}
 }