Fire.component
This package holds more than this page lists. See all of its files in its world.
README.md
Fire
Fire with its smoke, as a component: a campfire or a hearth, a torch, a brazier or a candle-sized flame, a bonfire or a pyre, a building, a vehicle or a forest on fire, or an explosion's fireball. Put it on an entity where the fire burns and it burns there: flames that glow white-hot at the core through yellow and orange to dull red at the tips, grey or black smoke rising over them lit by the scene with a shadow of its own, and a point light that lights the ground, the walls and the people around it and the smoke from within.
local e = entity.spawn("campfire")
e.localPosition = { 0, 0, 0 }
e.component.add("Fire", { style = "campfire" })
An explosion is a burst: the explosion style ignites when the component
starts, and gameplay sets it off again by changing ignite:
local boom = entity.spawn("barrel_explosion")
boom.localPosition = { 6, 0, 3 }
boom.component.add("Fire", { style = "explosion" })
-- later, to set it off again:
local fire = boom.component.get("Fire")
fire.ignite = fire.ignite + 1
For smoke alone use the Smoke component.
Fires and smoke whose boxes overlap draw as one group, the widest first and the ones it holds over it: small fires breaking out along a burning barn show in front of the barn's big smoke plume.
Styles
style | What it is | Height | Flames | Light |
|---|---|---|---|---|
campfire | Flames a metre high under a thin grey smoke | 5 m | 1.2 m | 6, radius 9 m |
torch | A small flame with a thin wisp of smoke | 1.6 m | 0.6 m | 3, radius 6 m |
bonfire | Roaring flames a few metres high under heavy smoke | 12 m | 3.6 m | 14, radius 20 m |
burning | Wide flames under thick black smoke: a building or vehicle on fire | 22 m | 6.6 m | 24, radius 30 m |
explosion | A fireball that swells, rises and cools into dark smoke over 2.6 s | 9 m | the ball | 40 while it burns |
Public fields
| Field | Type | Sync | Default | Meaning |
|---|---|---|---|---|
style | enum | Sync | "campfire" | The kind of fire (above). |
height | number | Sync | 0 | Metres the fire and its smoke rise; 0 takes the style's. Its width scales with it. |
radius | number | Sync | 0 | Metres from the centre to the edge of the flames at their base; the smoke widens from it as it climbs, by the style's spread. 0 takes the style's at this height. |
flame | number | Sync | 1 | How bright the flames burn, as a multiple of the style's. |
flameHeight | number | Sync | 0 | Metres the flames reach above the base; 0 takes the style's (the Flames column, scaled with height). Tall flames for a house fire: flameHeight = 10. |
smoke | number | Sync | 1 | How thick the smoke is; 0 burns clean. |
color | color | Sync | white | Tints the style's smoke colour. |
light | number | Sync | -1 | The intensity of the point light it casts; -1 takes the style's, 0 casts none. |
flicker | number | Sync | 1 | How far the light rises and falls with the flames (0 to 1); 0 holds it steady. |
speed | number | Sync | 1 | How fast the flames lick and the smoke climbs. |
windX, windZ | number | Sync | 0 | Metres the top of the smoke drifts along world x and z, on top of what the scene's wind carries it. |
sceneWind | number | Sync | 1 | How far the scene's wind carries the smoke: 1 drifts with every Wind blowing at the source (Physics.wind), the top carried by the wind for as long as the smoke takes to climb there (up to half the plume's height; a thin wisp drifts far, a big fire's column stands up to the wind); 0 leans it by windX / windZ alone. |
seed | number | Sync | 0 | Which turbulence it takes. |
loop | boolean | Sync | false | For explosion: start over once its smoke has cleared. |
ignite | number | Sync | 0 | For explosion: each change sets it off again. |
quality | enum | NoSync | "auto" | auto follows the device's quality tier; high, medium, low. |
lightResponse | string | Sync | "" | The .shaderModule its light is drawn with, for a drawn style: toon bands, a palette, an ink line, a hard silhouette, flames in flat bands. Empty draws the engine's own light. @builtin::systems.volumetrics.shaders.medium_light's README states what a response defines. |
lightResponseParams | table | Sync | {} | Up to sixteen numbers the response reads as params (colours, thresholds), in order. |
The light is a point light halfway up the flames, where it lights the ground,
the logs and the walls around the fire and the smoke from within. It stands on
a child entity the fire puts up for the session and keeps out of every save
(fire:lightEntity() answers it), and flickers with the flames (flicker),
each peer drawing its own.
A fire is seen the way anything is: a wall, a roof or any opaque surface in front of it hides it. A building on fire shows its flames where it is open, so stand the fire where the roof has burnt through, in a doorway or at a broken wall, or above the roofline.
Drawn in a style
lightResponse names a .shaderModule of the world that draws the flames and the smoke in a
style instead of the engine's own light: flat lit and shade tones with a hard
edge, a painted palette, an ink line, a crisp silhouette, flames in a few flat bands. The
module includes @builtin::systems.volumetrics.shaders.medium_light and
defines medium_shape, medium_light and medium_flame; that module's
README states what each is handed and shows a two-tone response. One module
can draw the clouds (VolumetricSky), smoke, fire, volumes and fog banks
(ParticipatingMedium) alike, and the volumetrics guide
(systems/volumetrics/documentation/README) walks through it.
Cost
The same as the Smoke component's: a 3D texture written every frame the scene
draws and marched over the pixels its box covers, at 48, 40 or 32 voxels across
with 96, 64 or 48 march steps for high, medium and low, over the whole
view at high and half its width and height at medium and low. A campfire
filling a 1920 x 1080 view costs 7 to 14 ms at high and 0.38 ms at medium on
a desktop GPU; from 9 m away 0.69 and 0.13 ms.
Related
Smoke: smoke without flames.plumemodule: the same fire from a script (plume.create).