Skip to content

Commit

Permalink
Gpuemitter same life/lifeTime naming as in emitter.
Browse files Browse the repository at this point in the history
  • Loading branch information
clementlandrin committed Nov 24, 2024
1 parent 2010078 commit 40add08
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
9 changes: 4 additions & 5 deletions hrt/prefab/fx/gpuemitter/BaseSimulation.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class BaseSimulation extends ComputeUtils {
}>;
@param var particleBuffer : RWPartialBuffer<{
speed : Vec3,
lifeTime : Float,
lifeRatio : Float,
life : Float,
random : Float,
}>;

Expand All @@ -24,7 +23,7 @@ class BaseSimulation extends ComputeUtils {

var dt : Float;
var speed : Vec3;
var lifeTime : Float;
var life : Float;
var particleRandom : Float;
var modelView : Mat4;
var instanceID : Int;
Expand All @@ -34,7 +33,7 @@ class BaseSimulation extends ComputeUtils {
function __init__() {
dt = dtParam;
speed = particleBuffer[computeVar.globalInvocation.x].speed;
lifeTime = particleBuffer[computeVar.globalInvocation.x].lifeTime;
life = particleBuffer[computeVar.globalInvocation.x].life;
prevModelView = batchBuffer[computeVar.globalInvocation.x].modelView;
particleRandom = particleBuffer[computeVar.globalInvocation.x].random;
relativeTransform = scaleMatrix(vec3(particleRandom * (maxSize - minSize) + minSize));
Expand All @@ -53,7 +52,7 @@ class BaseSimulation extends ComputeUtils {
newPos = ((newPos - boundsPos) % boundsSize) + boundsPos;
modelView = relativeTransform * align * translationMatrix(newPos);
var idx = computeVar.globalInvocation.x;
particleBuffer[idx].lifeTime = lifeTime - dt;
particleBuffer[idx].life = life - dt;
particleBuffer[idx].speed = speed;
batchBuffer[idx].modelView = modelView;
}
Expand Down
12 changes: 6 additions & 6 deletions hrt/prefab/fx/gpuemitter/BaseSpawn.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class BaseSpawn extends ComputeUtils {
}>;
@param var particleBuffer : RWPartialBuffer<{
speed : Vec3,
life : Float,
lifeTime : Float,
lifeRatio : Float,
random : Float,
}>;
@param var atomic : RWBuffer<Int>;
Expand All @@ -23,32 +23,32 @@ class BaseSpawn extends ComputeUtils {
@param var rate : Int;
@param var absPos : Mat4;

var lifeTime : Float;
var life : Float;
var particleRandom : Float;
var modelView : Mat4;
var relativeTransform : Mat4;
var emitNormal : Vec3;
function __init__() {
emitNormal = vec3(0.0, 0.0, 1.0);
particleRandom = particleBuffer[computeVar.globalInvocation.x].random;
lifeTime = mix(minLifeTime, maxLifeTime, (global.time + particleRandom) % 1.0);
life = mix(minLifeTime, maxLifeTime, (global.time + particleRandom) % 1.0);
relativeTransform = translationMatrix(vec3(0.0));
modelView = relativeTransform * absPos;
}

function main() {
var idx = computeVar.globalInvocation.x;
if ( FORCED || (!INFINITE && particleBuffer[idx].lifeTime < 0.0) ) {
if ( FORCED || (!INFINITE && particleBuffer[idx].life < 0.0) ) {
var c = atomicAdd(atomic, 0, 1);
if ( FORCED || (!INFINITE && c < rate) ) {
batchBuffer[idx].modelView = modelView;
var s = vec3(0.0, 0.0, 1.0);
if ( SPEED_NORMAL )
s = emitNormal;
particleBuffer[idx].speed = s * maxStartSpeed;
particleBuffer[idx].lifeTime = lifeTime;
particleBuffer[idx].life = life;
// Keep in memory duration of particle to normalize curve update.
particleBuffer[idx].lifeRatio = 1.0 / lifeTime;
particleBuffer[idx].lifeTime = life;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions hrt/prefab/fx/gpuemitter/GPUEmitter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class GPUEmitterObject extends h3d.scene.MeshBatch {
var p = dataPasses;
var particleBufferFormat = hxd.BufferFormat.make([
{ name : "speed", type : DVec3 },
{ name : "life", type : DFloat },
{ name : "lifeTime", type : DFloat },
{ name : "lifeRatio", type : DFloat },
{ name : "random", type : DFloat },
{ name : "padding", type : DVec2 },
]);
Expand All @@ -130,9 +130,9 @@ class GPUEmitterObject extends h3d.scene.MeshBatch {
// floats[i * stride] = 0.0;
// floats[i * stride + 1] = 0.0;
// floats[i * stride + 2] = 0.0;
floats[i * stride + 3] = -1000.0; // lifeTime warmup
floats[i * stride + 3] = -1000.0; // life warmup
var l = hxd.Math.random() * (data.maxLifeTime - data.minLifeTime) + data.minLifeTime;
floats[i * stride + 4] = 1.0 / l; // lifeRatio
floats[i * stride + 4] = l; // lifeTime
floats[i * stride + 5] = hxd.Math.random(); // random
// padding
// floats[i * stride + 6] = 0.0;
Expand Down
8 changes: 4 additions & 4 deletions hrt/prefab/fx/gpuemitter/LocalRotation.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class LocalRotationShader extends ComputeUtils {

var relativeTransform : Mat4;
var dt : Float;
var lifeTime : Float;
var life : Float;
var particleRandom : Float;
function main() {
var r = 2.0 * random3d(vec2(particleRandom)) - 1.0;
relativeTransform = rotateMatrixX(speedRotation * lifeTime * r.x) *
rotateMatrixY(speedRotation * lifeTime * r.y) *
rotateMatrixZ(speedRotation * lifeTime * r.z) *
relativeTransform = rotateMatrixX(speedRotation * life * r.x) *
rotateMatrixY(speedRotation * life * r.y) *
rotateMatrixZ(speedRotation * life * r.z) *
relativeTransform;
}
}
Expand Down
4 changes: 2 additions & 2 deletions hrt/prefab/fx/gpuemitter/UpdateParamShader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class UpdateParamShader extends hxsl.Shader {

@param var batchBuffer : RWBuffer<Float>;

@param var particleBuffer : RWPartialBuffer<{ lifeTime : Float, lifeRatio : Float }>;
@param var particleBuffer : RWPartialBuffer<{ life : Float, lifeTime : Float }>;

@param var paramTexture : Sampler2D;
@param var stride : Int;
Expand All @@ -15,7 +15,7 @@ class UpdateParamShader extends hxsl.Shader {

function main() {
var idx = computeVar.globalInvocation.x;
batchBuffer[idx * stride + pos] = paramTexture.get(vec2(1.0 - particleBuffer[idx].lifeTime * particleBuffer[idx].lifeRatio, row)).x;
batchBuffer[idx * stride + pos] = paramTexture.get(vec2(1.0 - particleBuffer[idx].life / particleBuffer[idx].lifeTime, row)).x;
}
}
}

0 comments on commit 40add08

Please sign in to comment.