Skip to content

Particles

DownDraft includes a GPU compute particle system with configurable emitters.

import { ParticleSystem, createFireEmitter } from "@downdraft/engine";
const particles = new ParticleSystem({
maxParticlesPerEmitter: 5000,
useGPUCompute: true,
surfaceFormat: "rgba16float",
});
particles.prepare(device);
const emitterId = particles.registerEmitter(
createFireEmitter({ position: [0, 1, 0] })
);
// In update loop:
particles.update(dt);
// In render pass:
particles.render(ctx, viewProj, cameraPos);
import { ParticleSystem, createSmokeEmitter } from "@downdraft/engine";
const particles = new ParticleSystem({
maxParticlesPerEmitter: 10000,
useGPUCompute: true,
surfaceFormat: "rgba16float",
});
particles.prepare(device);
const smokeId = particles.registerEmitter(
createSmokeEmitter({ position: [0, 2, 0] })
);
// Update each frame
particles.update(dt);
particles.render(renderCtx, camera.viewProj, camera.position);

When useGPUCompute is true, particle simulation (position integration, lifetime, spawning) runs on the GPU via compute shaders. This enables tens of thousands of particles with minimal CPU overhead.

EmitterDescription
createFireEmitterFire effect with upward velocity, color fade, and size shrink
createSmokeEmitterSmoke effect with slow upward drift and expansion

Custom emitters can be created by implementing the emitter interface.