---
name: ferret-vfx
description: Use to make fire, smoke, explosions, muzzle flashes, impacts, splashes, steam, dust and energy effects in Ferret (@ferret/vfx): catalogue effects driven by physics events or placed by hand, a ladder of volume to dots, fire that spreads, smoke that hides people, sound, vfx.* commands.
---

# Special effects

## When to use
Anything that happens in a scene and is not a body: a campfire, a burning house, a shell bursting, a splash, a fountain, steam, dust behind a truck, a lightning stroke, a shield. Not for a level's ambient motes, nor the glow of hot parts (`ferret-physics-fx-tuning`).

## The model
An effect is a JSON definition (parameters with units, emitters, modules, optional volume, impostor, dot, light, decal, sound) compiled once; `VfxSystem` steps it in the fixed 60 Hz step from a seed, so every peer makes the same particles; `VfxBabylonView` draws it on a ladder chosen by size on the screen. A value set by hand always wins over the physical one; an unset one comes from the energy, the fuel or the material, never a table.

## Steps
1. `const sys = new VfxSystem(); sys.registerAll(FULL_CATALOG)` (or `FIRE_CATALOG`, `BLAST_CATALOG`, `WORLD_CATALOG`, `ENERGY_CATALOG`); `sys.host = { wind, groundHeight }` from the flow and terrain of the level.
2. By hand: `sys.spawn('fire.campfire', { at, seed, params: { heat: 2e5 } })`; `vfx.list` (command) shows each effect's parameters, units and limits. By physics: `driveFromPhysics(world.events, sys, { materialOf, dustAt })`.
3. Draw: `new VfxBabylonView(scene, sys, camera, { soft: true, supports: ['particles','impostor','dot'] })`; each fixed step `sys.step(1/60)`, each frame `view.draw({ cameraPosition, fov, heightPx, tier, dt, night })`.
4. Fire: `FireSpread(grid, env)` with `setFuel`, `ignite(cell, t)`, `step(t)`; `FireBridge(sys, fire, { stride })` with `addTarget({ id, at, material, burn })` for what can catch fire; call `bridge.heat(bridge.burning(), dt)` and `bridge.apply(fire.step(t))` in the fixed step.
5. Sight: `new SmokeSight(sys).transmittance(a, b)` is 1 clear to 0 hidden; the AI and visibility rays ask it.
6. Sound: `defineSynthPresets(audio, { names: SOUND_PRESETS })`, a `VfxSoundPlayer` with `spawned` / `stopped` / `update` for each instance as it starts and ends; delay and filtering come from the distance.
7. Network: `new VfxReplica(sys, { peer, send, fire, bridge })` and `installVfxNet(net, replica)`; start effects through `replica` (or `replica.asSim()` for the drive). Particles never cross the wire.
8. Editing: `registerVfxCommands(registry, new VfxSession(sys))`; a level's manifest takes a `vfx` block `{ defs, place }`.

## Check afterwards
`vfx.stats` and `view.stats.rungs` show what runs; the `?vfx` viewer (`vfx.view`, `vfx.screenshot`) gives the same picture from the same seed; `vfx.undo` restores the picture before a placement; a blast 120 m away is heard about 0.35 s after the flash. Run only single test files (`packages/vfx/test`).

## What usually goes wrong
- Nothing is drawn: `sys.step` is not in the fixed step, `view.draw` is not called each frame, or the name is not registered (`sys.has(name)`).
- "Outside its limits" or "no parameter": `vfx.list` has the names, units and limits.
- The frame drops in a big fire: about 1 ms per 1000 particles; give the scene a governor that stops the farthest effects over a budget, use `stride`, lower `maxParticles`.
- Peers differ: an effect was started from a local event instead of through the replica, or the sim was stepped from the frame time.
- Smoke hides no one: `SmokeSight` is on another `VfxSystem` than the stepped one.
- No dust or splash from a physics event: the body was below `minImpactEnergy`, or the effect is not registered.
- Distant fires wink out: the view lacks `supports: ['impostor','dot']`.
- Nothing in a UE build: that side is unfinished (plan F15); the browser build works.

## Files

- `reference/vfx.md` — Fire and smoke, explosions and weapons, water, steam and dust, energy. An effect is a JSON definition with parameters and expressions; physics fills the parameters, a ladder of volume, GPU particles, impostors and dots draws it, sound follows from the same numbers.
- `reference/api-vfx.md` — every export of `@ferret/vfx` with signature and doc comment
- `reference/api-vfx-2.md` — every export of `@ferret/vfx` with signature and doc comment
- `reference/api-vfx-3.md` — every export of `@ferret/vfx` with signature and doc comment
