ParticipatingMedium.component
This package holds more than this page lists. See all of its files in its world.
README.md
ParticipatingMedium
A bank of fog or mist, a cloud of smoke, dust or steam in one place, as a component. It marks its entity as a volume of fog, smoke, dust or steam, something light has to travel through. The camera sees it: what is behind the volume comes out dimmer than what is beside it, and the volume shows by the sunlight and the sky light it scatters. The ground under it is in its shadow: the volume dims the scene's sun there and leaves the sky and the other lights. Overlapping volumes stack.
local id = entity.spawn("fog_bank").id
entity(id).component.add("ParticipatingMedium", {
sizeX = 30, sizeY = 8, sizeZ = 30,
density = 0.15,
})
Fields
| Field | Meaning |
|---|---|
shape | "box" (default) or "sphere" |
density | Extinction per world unit. 0 releases the medium. |
sizeX / sizeY / sizeZ | Half-extents, for a box |
radius | Radius, for a sphere |
skyLight | How much of its surroundings' light the medium takes: the sky, the ambient term and the probes. 1 (the default) lights it as the surroundings light a surface standing in it; 0 leaves the sun alone. |
lightResponse | The .shaderModule the medium's light is drawn with, for a drawn style (toon bands, a palette, a hard edge); empty draws the engine's own light. The media in a scene are drawn with one response, with one set of lightResponseParams: those of the first registered medium that names one. @builtin::systems.volumetrics.shaders.medium_light's README states what a response defines. |
lightResponseParams | Up to sixteen numbers the response reads as params, in order. |
density is the physical knob: a ray crossing d world units of a medium of
density k leaves with exp(-k * d) of the light it entered with. A 20-unit
bank at 0.15 therefore passes about 5% of the light straight through it.
The entity's position places the volume; move the entity and the volume and its shadow move with it.
Drawn in a style
lightResponse names a .shaderModule of the world that draws the fog bank 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.
Notes
- The medium is lit by the light the surfaces around it are lit by, in the same frame: the scene's own sun, and where the sun does not reach, the ambient term, the sky and the reflection probes the environment captured and the baked light-probe volumes, so the side of a fog bank turned from the sun reads like fog rather than a dark box. The ambient term and the sky reach a point of the medium as far as it sees the sky past every surface standing over it, a tree's crown or a roof, movable and instanced ones included, so a bank under a canopy takes the sky the canopy leaves open; the reflection probes and light-probe volumes light it as they light a surface there. Its shadow falls the way the scene's shadows do and follows the sun, and with the sun, the ambient and the sky dark the medium is black.
- The medium dims the sun's light on the surfaces under it, so a thick bank's shadow reads like an opaque blocker's: lit by the sky and the ambient.
See mediaTransmittance for the scene-wide settings and the direct API,
quality among them: how finely the view rays sample the media, following the
device's quality tier unless the scene names a level
(mediaTransmittance.set({ quality = "high" })).