Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit5597fb7c06

README.md

Smoke

Smoke rising from a chimney, a stove pipe, a vent, a kettle or a cooling tower, the wisps over embers or ruins, the thick black column over a city block, an oil well or a wreck seen from far away, or the puffs of a smoke signal: a smoke volume lit by the scene, as a component. Put it on an entity where the smoke leaves (the top of the chimney) and the smoke rises from there, with the sun on one side and the smoke's own shadow on the other, greyed by the ambient light and lit by the lamps near it, a lamp inside it from within. It churns as it climbs, widens, thins toward the top and drifts with the wind.

local e = entity.spawn("chimney_smoke")
e.localPosition = { 4, 9, -2 }   -- the chimney's top
e.component.add("Smoke", { style = "chimney", windX = 2 })

Smoke with a blaze under it is the Fire component. Plumes whose boxes overlap draw as one group, the widest first and the ones it holds over it.

Styles

styleWhat it isHeight
chimneyA thin grey column from a chimney or a stove pipe7 m
steamWhite steam from a vent, a kettle or a hot spring, thinning out fast3.5 m
smoulderLow, wide grey wisps over embers or ruins2.5 m
columnA tall, thick black column over a city block, an oil well or a wreck30 m
signalSeparate puffs rising one after another9 m

Public fields

FieldTypeSyncDefaultMeaning
styleenumSync"chimney"The kind of smoke (above).
heightnumberSync0Metres it rises; 0 takes the style's. Its width scales with it.
radiusnumberSync0Metres from the centre to the edge of the opening the smoke leaves (a chimney's flue, a vent, the fire under a column); the smoke widens from it as it climbs, by the style's spread (a column from 2.5 m to 9 m over its 30 m). 0 takes the style's at this height.
densitynumberSync1How thick the smoke is, as a multiple of the style's.
colorcolorSyncwhiteTints the style's smoke colour.
speednumberSync1How fast it climbs and churns.
windX, windZnumberSync0Metres the top drifts along world x and z, on top of what the scene's wind carries it.
sceneWindnumberSync1How 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.
seednumberSync0Which turbulence it takes, so two plumes side by side differ.
qualityenumNoSync"auto"auto follows the device's quality tier; high, medium, low.
lightResponsestringSync""The .shaderModule its light is drawn with, for a drawn style: toon bands, a palette, an ink line, a hard silhouette. Empty draws the engine's own light. @builtin::systems.volumetrics.shaders.medium_light's README states what a response defines.
lightResponseParamstableSync{}Up to sixteen numbers the response reads as params (colours, thresholds), in order.

Drawn in a style

lightResponse names a .shaderModule of the world that draws 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. 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 smoke is a 3D texture written every frame the scene draws and marched like any Volume, only over the pixels its box covers. What each level holds:

LevelVoxels acrossMarch stepsShadow samplesLocal lightsMarch resolution
high489664the view's
medium406442half the view's width and height
low324831half the view's width and height

auto draws high on a desktop's or browser's high tier, medium on a handheld's high tier and every medium tier, and low on the low tier.

Measured on a desktop discrete GPU with the view at 1920 x 1080, the march of a campfire's plume filling the whole view costs 7 to 14 ms at high, 0.38 ms at medium and 0.35 ms at low; seen from 9 m away, 0.69, 0.13 and 0.08 ms. The fill costs 0.01 to 0.02 ms. A scene holding several plumes close to the camera draws them at medium to keep the frame. The march skips the parts of the box the column cannot reach.

Related

  • Fire: a blaze with its smoke, and the light it casts.
  • plume module: the same smoke from a script (plume.create), every style in plume.STYLES.
  • Volume: any 3D texture as a volume; scattering lights it by the scene.
  • ParticipatingMedium: a bank of fog, haze or mist filling a box.