Volume.component
This package holds more than this page lists. See all of its files in its world.
README.md
Volume
A smoke plume, a single cloud, a fire, a nebula or an imported VDB grid
standing in the scene, as a component: it renders a 3D voxel texture into the
scene as a volumetric body. A producer (the volume module's builders, a
custom compute fill, or compute.writeTexture3D) builds the texture and owns
its lifetime, and the component names it in volumeName. The entity's world
transform defines the AABB the raymarcher samples.
The volume stands in the scene: the frame marches it for every view it draws
(the viewport, a capture, a render-to-texture camera), against that view's
camera and its depth, so opaque geometry in front of the volume hides it and
geometry inside it cuts it where it stands. The march covers the drawn view's
resolution at the high level and half its width and height at medium and
low, brought up to the view as it is laid over the frame. A disabled Volume draws nothing.
volumeName is resolved through Volume.get, so a volume the volume
module built is rendered as it stands — at its own dimensions, from its own
density channel, through its occupancy grid, and out of its brick pool if it
is paged. A name no volume answers to is taken as a bare 3D texture some
other system owns, and occupancyName / isRgba describe it.
Smoke lit by the scene is scattering = 1, emission = 0: the sun lights the
side facing it, the volume shadows its far side, and with every light off it is
black. Rising smoke and fire that need no texture of their own are the Smoke
and Fire components, which fill and stand a lit volume for you.
Usage
local Volume = require("@builtin::systems.volumetrics.volume")
local cloud = Volume.noise({ name = "cloud", size = 64, scale = 4 })
cloud:buildOccupancy({ brickSize = 8 })
local e = entity.spawn("cloud_entity")
e.localScale.set(8, 4, 8)
e.component.add("Volume", {
volumeName = "cloud",
occupancyName = cloud.occupancyName,
density = 6.0,
})
A paged volume costs what it holds and is named the same way:
local cloud = Volume.noise({ name = "cloud", size = 128, threshold = 0.6 })
cloud:buildSparse({ brickSize = 8, threshold = 0.01 })
cloud:releaseDense() -- the brick pool is now the only copy
local e = entity.spawn("cloud_entity")
entity(e.id).localScale = { 8, 4, 8 }
e.component.add("Volume", { volumeName = "cloud", density = 6.0 })
Public fields
| Field | Type | Sync | Default | Meaning |
|---|---|---|---|---|
volumeName | string | Sync | "" | Required. Name of the volume, or of a bare 3D texture, to render. |
occupancyName | string | Sync | "" | R8 occupancy texture for a bare texture's empty-space skipping. Empty = no occupancy. A volume the module built carries its own, and a name set against one is reported as left aside. |
density | number | Sync | 1.0 | Density gain multiplier. |
absorption | number | Sync | 1.0 | Beer-Lambert absorption coefficient. |
emission | number | Sync | 1.0 | Emission gain. |
color | color | Sync | {1,1,1,0} | RGB tint + density floor in alpha. |
stepSize | number | NoSync | 0 | World units per ray step. 0 = auto-derive from volume extent. |
maxSteps | number | NoSync | 256 | Ray-march step cap. |
useOccupancy | boolean | NoSync | true | Toggle empty-space skipping. |
quality | string | NoSync | "auto" | The level the march takes stepSize and maxSteps at: high as stated over the whole view, medium steps 1.5 times as long under 67 % of the cap, low twice as long under half of it, both over half the view's width and height. auto follows the device's quality tier. |
isRgba | boolean | Sync | true | false reads density from the red channel. Left true, a volume the module built is read from the channel it was built with, and a bare texture as RGBA. |
scattering | number | Sync | 0 | The share of the scene's light the medium scatters, its albedo. 0 shows the volume by its emission alone; above 0 the sun, the ambient term and the point, spot and rect lights reaching it light it, each dimmed by the volume between it and the light. |
anisotropy | number | Sync | 0.3 | How far the scattering leans forward, -0.95..0.95: smoke between the camera and the sun glows at its rim. |
flame | number | Sync | 0 | Gain of the light a density volume's temperature (its green channel) emits along a blackbody ramp. |
flameTemperature | number | Sync | 1.0 | The temperature that burns white-hot; cooler glows yellow, orange, then dull red. |
shadowSteps | number | NoSync | 6 | Samples of each march toward a light, the shadow the volume casts on itself (half as many toward a local light); 0 casts none. Scaled by quality (medium two thirds, low half). |
lights | number | NoSync | 4 | How many of the scene's local lights a sample takes. Scaled by quality (medium half, low a quarter). |
lightResponse | string | Sync | "" | The .shaderModule the volume's 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. |
All public fields use the Field.<kind>(default, Sync|NoSync) schema.
Visual params (look, tint, density) propagate Sync; quality knobs
(stepSize, maxSteps, useOccupancy, quality) are NoSync, so each client picks
its own perf/quality point.
Under auto a desktop's or a browser's high tier draws high, a handheld's
high tier and every medium tier medium, and the low tier low
(renderer.qualityTier(), @builtin::modules.qualityLevels), and
renderer.setQualityTier moves it on the next frame. The graphics-quality
guide lists what each level costs.
Volume.draws() names each draw's quality, the level its march is packed
at, the stepSize and maxSteps it marches there and the share of the view
its march covers (resolution); a draw following the
tier is packed again at the level in force on the frame after the tier moves.
Lifecycle
awake— no-op. The volume texture is owned by the producer and looked up lazily on the firstupdate.update(dt)— resolvesvolumeNamethroughVolume.get, falling back to a wrapper over a bare texture of that name, and stands it in the scene with this frame's box and settings (Volume:draw). The resolution runs every frame, so a volume built, paged or destroyed after this component attached is picked up on the next one.editorUpdate(dt): the same draw in edit mode, so the volume shows while the scene is being edited.onDisable/onDestroy: take the draw down (Volume.withdraw), so the frame draws nothing of the volume. The next update after the component is enabled again stands it back up. The last draw to go takes thevolumerender feature down.onPropertyChanged(key, value, old)— drops the resolved volume whenvolumeName,occupancyName, orisRgbachanges, forcing a re-resolve on the next frame.
Related
volumemodule — texture builders and name lookup (Volume.noise,Volume.get,Volume.wrap,:buildSparse,:draw,Volume.draws).vdb_to_zvol.importer— VDB → dense voxel pipeline that produces textures consumable by this component.volumeDemos/volumetricSkypackages — worked examples.