Click anywhere to blast · Press Esc to exit

3D PARTICLE
BLAST EFFECT

Build a click-to-fire explosion of glowing particles in the browser with Three.js — each one flies out with its own velocity, casts a flash of light, then fades away.

Particle explosion Click interaction Three.js
See it live

LIVE DEMO

Blasts fire on their own every few seconds behind this page. Open the Live Demo to click anywhere and fire your own, and drag to orbit the camera around the grid.

Hides the page so you get the scene full screen — click anywhere to blast, press Esc to exit. A free one-click Google sign-in unlocks it.

NEW FREE THREE.JS TUTORIAL

Want a bigger explosion? Build a 3D rockfire explosion in Three.js — flying debris, fire, smoke, a shockwave, and a scorch crater that grows with the blast. The whole effect in one copy-paste file, with a live demo you can orbit.

3D Rockfire Explosion effect built in Three.js See the Rockfire Explosion Tutorial

Introduction

A blast effect is the quickest way to make a 3D scene feel alive and game-like. The idea is simple: when the user clicks, spawn a burst of small glowing spheres at that point, give each a random outward velocity, and let them fly apart. Add a quick point-light flash for the "boom," then remove each particle after a short lifespan so the scene stays fast.

This free tutorial builds exactly that — an interactive, click-to-fire particle explosion with Three.js. It's the same technique you'd use for muzzle flashes, impacts, pickups, or spell effects in a browser game.

Frequently Asked Questions

How do you make an explosion effect in Three.js?

Spawn a burst of small meshes at the blast origin, each with a random outward velocity. Move them along their velocity every frame, add a point light for a glow flash, and remove each particle after a short lifespan. Firing the burst on a mouse click gives you an interactive explosion.

How do you fire particles from where the user clicks?

Convert the 2D mouse coordinates to a 3D point by building a normalized device vector and calling vector.unproject(camera). Cast from the camera through that point onto a plane to get the world-space origin, then spawn the particle burst there.

How do you clean up blast particles so they don't slow the scene?

Give each particle a lifespan. Use a timer to remove the mesh and its light from the scene after a couple of seconds, and splice it out of your tracking array. Also remove particles once they travel past a distance limit. This keeps the particle count bounded and the frame rate smooth.

Is this Three.js blast effect tutorial free?

Yes. This is a completely free tutorial. There is a live click-to-blast demo running in the background, and the full source code is on the page to copy. A free one-click Google sign-in unlocks the code block, and the same sign-in unlocks every free tutorial on the site — no payment or membership required.

Code Breakdown

Here is the whole blast effect, one piece at a time. Beginners: read the bold summaries. Developers: the notes after each block explain the why. It uses OrbitControls from the Three.js addons, so it runs as an ES module with an import map.

1. The HTML shell + import map

<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
  { "imports": { "three": "./build/three.module.js", "three/addons/": "./jsm/" } }
</script>

<script type="module">
  import * as THREE from 'three';
  import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
</script>

In plain English: the import map lets you write import ... from 'three' with no build step. Developer note: es-module-shims adds import-map support for browsers that need it, and three/addons/ maps to the Three.js examples/jsm folder where OrbitControls lives.

2. Scene, camera, renderer & a grid

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, innerWidth / innerHeight, 0.1, 1000);
camera.position.set(6, 4, 6);

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(innerWidth, innerHeight);
renderer.setClearColor(0x000000, 1);
document.body.appendChild(renderer.domElement);

scene.add(new THREE.GridHelper(100, 150));

In plain English: the three things every Three.js scene needs — a scene to hold objects, a camera to view it, and a renderer to draw it — plus a floor grid so you can see depth and where the blast lands. Developer note: the camera sits back at (6, 4, 6) so more of the grid and each burst is in frame.

3. OrbitControls to look around

const controls = new OrbitControls(camera, renderer.domElement);
controls.enableZoom = false; // let the mouse wheel scroll the page
controls.enablePan = false;

In plain English: drag to orbit the camera around the blast. Developer note: zoom and pan are turned OFF so the mouse wheel keeps scrolling the page instead of zooming the scene — important when the demo is a background on a scrollable tutorial.

4. Turn a click into a 3D world point

const raycaster = new THREE.Raycaster();
const groundPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const ndc = new THREE.Vector2();

function getClickedPoint(clientX, clientY) {
  ndc.x = (clientX / window.innerWidth) * 2 - 1;
  ndc.y = -(clientY / window.innerHeight) * 2 + 1;
  raycaster.setFromCamera(ndc, camera);
  const hit = new THREE.Vector3();
  if (raycaster.ray.intersectPlane(groundPlane, hit)) return hit;
  // Fallback: a point in front of the camera if the ray misses the ground.
  return raycaster.ray.origin.clone().add(raycaster.ray.direction.clone().multiplyScalar(30));
}

In plain English: a mouse click is a 2D screen point, but the blast needs a 3D world point. We shoot a ray from the camera through the click and find where it crosses the ground. Developer note: the click is first converted to normalized device coordinates (-1..1), then intersectPlane finds the hit on the y = 0 plane. If the ray misses (clicking the sky), we fall back to a point 30 units down the ray so a blast always appears.

5. fireBlast() — flash + a burst of embers

// Soft round glow texture drawn on a canvas (no image file needed)
function makeGlowTexture() {
  const c = document.createElement('canvas');
  c.width = c.height = 64;
  const g = c.getContext('2d');
  const grd = g.createRadialGradient(32, 32, 0, 32, 32, 32);
  grd.addColorStop(0, 'rgba(255,255,255,1)');
  grd.addColorStop(0.25, 'rgba(255,255,255,0.8)');
  grd.addColorStop(0.6, 'rgba(255,255,255,0.15)');
  grd.addColorStop(1, 'rgba(255,255,255,0)');
  g.fillStyle = grd;
  g.fillRect(0, 0, 64, 64);
  return new THREE.CanvasTexture(c);
}
const glowTex = makeGlowTexture();

// Heat ramp: white -> yellow -> orange -> red as a particle ages (t = 0..1)
const STOPS = [
  new THREE.Color(1, 1, 1), new THREE.Color(1, 0.9, 0.35),
  new THREE.Color(1, 0.45, 0.08), new THREE.Color(0.55, 0.05, 0.02)
];
const tmpColor = new THREE.Color();
function heatColor(t, out) {
  const f = Math.min(Math.max(t, 0), 0.999) * (STOPS.length - 1);
  const i = Math.floor(f);
  return out.copy(STOPS[i]).lerp(STOPS[i + 1], f - i);
}

function randomDir(v) {
  return v.set(Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1).normalize();
}

// Pools are built ONCE and reused for every blast: no per-click allocations,
// no geometries to dispose, and the frame rate stays smooth.
function makePool(size, blending) {
  const pool = [];
  for (let i = 0; i < size; i++) {
    const s = new THREE.Sprite(new THREE.SpriteMaterial({
      map: glowTex, blending: blending, transparent: true, depthWrite: false
    }));
    s.visible = false;
    s.userData = { vel: new THREE.Vector3(), age: 0, life: 1, size: 1, kind: '' };
    scene.add(s);
    pool.push(s);
  }
  return pool;
}
const glowPool = makePool(400, THREE.AdditiveBlending); // embers + core flash
const smokePool = makePool(60, THREE.NormalBlending);   // light smoke

// Sparks: one LineSegments object, each spark is a short head-to-tail streak
const SPARKS = 200;
const sparkPos = new Float32Array(SPARKS * 6);
const sparkCol = new Float32Array(SPARKS * 6);
const sparkGeo = new THREE.BufferGeometry();
sparkGeo.setAttribute('position', new THREE.BufferAttribute(sparkPos, 3));
sparkGeo.setAttribute('color', new THREE.BufferAttribute(sparkCol, 3));
const sparkLines = new THREE.LineSegments(sparkGeo, new THREE.LineBasicMaterial({
  vertexColors: true, blending: THREE.AdditiveBlending, transparent: true, depthWrite: false
}));
sparkLines.frustumCulled = false;
scene.add(sparkLines);
const sparks = [];
for (let i = 0; i < SPARKS; i++) {
  sparks.push({ pos: new THREE.Vector3(), vel: new THREE.Vector3(), age: 0, life: 0 });
}

// Shockwave rings share one geometry
const ringGeo = new THREE.RingGeometry(0.92, 1, 64);
const rings = [];
for (let i = 0; i < 6; i++) {
  const r = new THREE.Mesh(ringGeo, new THREE.MeshBasicMaterial({
    color: 0xffc070, blending: THREE.AdditiveBlending, transparent: true,
    depthWrite: false, side: THREE.DoubleSide
  }));
  r.rotation.x = -Math.PI / 2;
  r.visible = false;
  r.userData.age = 0;
  scene.add(r);
  rings.push(r);
}

// Flash lights stay in the scene (intensity 0) so adding a blast never recompiles shaders
const lights = [];
for (let i = 0; i < 3; i++) {
  const l = new THREE.PointLight(0xffaa33, 0, 40);
  scene.add(l);
  lights.push(l);
}
let nextLight = 0;
let nextRing = 0;

function spawn(pool, kind, origin, speed, life, size) {
  let s = null;
  for (const p of pool) { if (!p.visible) { s = p; break; } }
  if (!s) return; // pool exhausted: skip this particle
  const d = s.userData;
  s.position.copy(origin);
  randomDir(d.vel).multiplyScalar(speed);
  if (kind === 'smoke') d.vel.y = Math.abs(d.vel.y) + 0.8;
  d.kind = kind;
  d.age = 0;
  d.life = life;
  d.size = size;
  s.visible = true;
}

// Fire a layered blast: light flash, core flash, embers, sparks, shockwave, smoke
function fireBlast(origin) {
  const light = lights[nextLight++ % lights.length];
  light.position.copy(origin);
  light.position.y += 0.5;
  light.intensity = 60;

  spawn(glowPool, 'flash', origin, 0, 0.18, 6);

  for (let i = 0; i < 110; i++) {
    spawn(glowPool, 'ember', origin, THREE.MathUtils.randFloat(3, 12),
      THREE.MathUtils.randFloat(0.6, 1.3), THREE.MathUtils.randFloat(0.4, 1.0));
  }

  let n = 0;
  for (const s of sparks) {
    if (s.life > 0) continue;
    s.pos.copy(origin);
    randomDir(s.vel).multiplyScalar(THREE.MathUtils.randFloat(12, 26));
    s.vel.y = Math.abs(s.vel.y) * 0.8 + 2;
    s.age = 0;
    s.life = THREE.MathUtils.randFloat(0.35, 0.7);
    if (++n >= 60) break;
  }

  const ring = rings[nextRing++ % rings.length];
  ring.position.set(origin.x, origin.y + 0.05, origin.z);
  ring.userData.age = 0;
  ring.visible = true;

  for (let i = 0; i < 14; i++) {
    spawn(smokePool, 'smoke', origin, THREE.MathUtils.randFloat(0.5, 2),
      THREE.MathUtils.randFloat(1.4, 2.4), THREE.MathUtils.randFloat(1.2, 2.2));
  }
}

In plain English: the explosion itself, built in layers — a point-light flash and a bright white core for the "boom," 110 soft glowing embers, 60 fast sparks with streak trails, an expanding shockwave ring on the ground, and a few puffs of light smoke. Developer note: the glow is a radial-gradient CanvasTexture on sprites with AdditiveBlending, so overlapping embers brighten like real fire. Every sprite, spark, ring, and light is created once in a pool and reused, so a click never allocates new geometry and the frame rate stays smooth.

6. Fire on click, keep it responsive on resize

// Capture-phase pointerdown so the blast fires even though OrbitControls
// also listens; window-level so a click anywhere counts.
window.addEventListener('pointerdown', (e) => {
  fireBlast(getClickedPoint(e.clientX, e.clientY));
}, true);

addEventListener('resize', () => {
  camera.aspect = innerWidth / innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(innerWidth, innerHeight);
});

In plain English: any click fires a blast where you clicked, and the scene always matches the window size. Developer note: the listener uses the capture phase (the true third argument) so it runs before OrbitControls, which otherwise swallows the pointerdown.

7. The animation loop — move, fade, render

const clock = new THREE.Clock();

function updateVFX(dt) {
  for (const l of lights) l.intensity *= Math.exp(-dt * 12);

  for (const pool of [glowPool, smokePool]) {
    for (const s of pool) {
      if (!s.visible) continue;
      const d = s.userData;
      d.age += dt;
      const t = d.age / d.life;
      if (t >= 1) { s.visible = false; continue; }
      s.position.addScaledVector(d.vel, dt);
      if (d.kind === 'ember') {
        d.vel.y -= 9.8 * dt;                       // gravity
        d.vel.multiplyScalar(Math.exp(-dt * 2.5)); // drag
        heatColor(t, s.material.color);            // white -> yellow -> orange -> red
        s.material.opacity = 1 - t * t;
        s.scale.setScalar(d.size * (1 - 0.6 * t));
      } else if (d.kind === 'flash') {
        s.material.color.setRGB(1, 0.95, 0.8);
        s.material.opacity = 1 - t;
        s.scale.setScalar(d.size * (0.6 + t));
      } else { // smoke
        d.vel.multiplyScalar(Math.exp(-dt * 1.5));
        s.material.color.setRGB(0.25, 0.22, 0.2);
        s.material.opacity = 0.35 * Math.sin(Math.PI * t);
        s.scale.setScalar(d.size * (0.5 + 1.5 * t));
      }
    }
  }

  for (let i = 0; i < SPARKS; i++) {
    const s = sparks[i];
    const k = i * 6;
    if (s.life > 0) {
      s.age += dt;
      if (s.age >= s.life) s.life = 0;
    }
    if (s.life <= 0) { sparkCol.fill(0, k, k + 6); continue; }
    s.vel.y -= 9.8 * dt;
    s.vel.multiplyScalar(Math.exp(-dt * 3));
    s.pos.addScaledVector(s.vel, dt);
    const t = s.age / s.life;
    heatColor(t, tmpColor).multiplyScalar(1 - t);
    // Head at the spark, tail trails behind along the velocity and fades to black
    sparkPos[k] = s.pos.x; sparkPos[k + 1] = s.pos.y; sparkPos[k + 2] = s.pos.z;
    sparkPos[k + 3] = s.pos.x - s.vel.x * 0.04;
    sparkPos[k + 4] = s.pos.y - s.vel.y * 0.04;
    sparkPos[k + 5] = s.pos.z - s.vel.z * 0.04;
    sparkCol[k] = tmpColor.r; sparkCol[k + 1] = tmpColor.g; sparkCol[k + 2] = tmpColor.b;
    sparkCol[k + 3] = 0; sparkCol[k + 4] = 0; sparkCol[k + 5] = 0;
  }
  sparkGeo.attributes.position.needsUpdate = true;
  sparkGeo.attributes.color.needsUpdate = true;

  for (const r of rings) {
    if (!r.visible) continue;
    r.userData.age += dt;
    const t = r.userData.age / 0.6;
    if (t >= 1) { r.visible = false; continue; }
    r.scale.setScalar(0.5 + 9 * (1 - Math.pow(1 - t, 3)));
    r.material.opacity = 0.6 * (1 - t);
  }
}

function animate() {
  requestAnimationFrame(animate);
  updateVFX(Math.min(clock.getDelta(), 0.05));
  controls.update();
  renderer.render(scene, camera);
}
animate();

In plain English: every frame, each ember moves along its velocity, gets pulled down by gravity, slows from drag, shifts from white to yellow to orange to red, and shrinks and fades as it dies; sparks stretch into streaks, the shockwave ring expands and fades — then the whole scene is drawn. Developer note: subtracting from vel.y makes the embers arc and fall, and multiplying by Math.exp(-dt * 2.5) is a frame-rate-independent drag so the burst settles instead of flying forever. Dead particles are just hidden and returned to their pool.

What To Try Next

  • Randomize each particle's color for a firework instead of a single hue.
  • Add gravity — subtract a little from velocity.y each frame so particles arc and fall.
  • Fade particles out by lowering material opacity over their lifespan.
  • Swap spheres for a sprite texture (a soft glow PNG) for a smoky look.
  • Trigger the blast from game events (a hit, a pickup) instead of only clicks.