Lighting: how a scene is lit, scene setups, lights and global illumination
How a scene is lit: scene setups and what they hold
A scene can be lit by a scene setup: an asset that applies its members to the scene as a whole. A new world's scene places one on its root entity named lighting. What a member puts on the scene is no entity of the scene: the scene records the root, its Asset link to the setup, and the overrides this placement states (its SceneSetup component).
A member is any asset whose type lists applicable under interfaces:; the sceneSetup type's README describes members. Each type below is described in its own README (guides { path = "types/<type>" }):
| Type | What one is |
|---|---|
sceneSetup | A composition of members with the values it states for them; a member may be another setup. |
sky | A composition whose members draw the sky. |
sceneLight | A position-independent light: directional, ambient or distant. |
postEffect | A post-process shader on the screen with its values, its order and its layer in the post chain. |
renderFeature | A GPU feature that holds its own settings. |
A placed setup is read and tuned through its SceneSetup component: members() reports every member at every depth with the state its application is in (inForce, off, held by another, and a notice such as an ambient term bright enough to flatten the sun's shading), get reads a parameter by its path (fog/density, sun/intensity, sky/backdrop/timeOfDay) with where its value comes from, set and reset write and clear this placement's overrides, and <member>/@enabled turns one member off. @lit = false renders the scene unlit. The component's README and the sceneSetup type's README describe the whole surface; its Inspector card shows the same members and parameters.
Two setups placed in one scene both apply; where an effect is one at a time (the sky, the sun, the ambient term), the newest application holds it and the other reports held. Dropping a setup's root takes its members off the scene and hands each effect back to the application that held it before. Across an edit/play flip the placement stays applied on every frame. Editing a setup's file reaches every placement of it at once: a member added is applied, one removed is dropped, and each placement keeps its overrides.
The library holds lighting examples under @builtin::examples.lighting, each a composition to study.
@builtin::systems.sceneLighting.dynamicLighting is a setup to place on a scene of your own for the engine's whole real-time lighting at once: a sky whose hour drives a sun and a moon, the sky light, ray-traced probe global illumination, ambient occlusion, contact shadows, height fog, exposure that adapts from day to night, temporal anti-aliasing and screen-space reflections, every member listed with its values. Its sky/backdrop/timeOfDay moves the scene from day to night. The public Engine Showcase world places it over a cottage and its garden, in its scene showcase.lighting.dynamicLightingShowcase.
The tools below write the scene's sun, ambient term and sky value by value. On a scene lit by a placed setup they land on the setup's own members, each value as that placement's override; on a scene with no setup they write the scene's own light entities.
Lighting
The lighting toolbox sets the scene's light environment value by value — sun, ambient, sky, and point/spot lights — leaving the scene in the requested lighting state. On a scene lit by a placed setup, the sun, ambient and sky values land on the setup's members as that placement's overrides; on a scene with none, each call writes the scene's own light entities, spawning them when the scene has none. A component or runtime script that adjusts lighting each frame uses the modules.api.engine.lighting capability directly, with the same options.
- setSun — aims the sun and sets its colour and intensity.
- setAmbient — the ambient fill.
- setSky — a preset word, a material, or
"none". - addLight / setLight / removeLight — a named point or spot light, by
position and intensity.
addLightmodifies one that already exists under that name rather than stacking a second. - setup — sun, ambient, sky and clear colour in one call.
- get — the full lighting and sky state, in the shape setup takes back.
A component or runtime script that adjusts lighting each frame reaches the same light environment through the modules.api.engine.lighting capability, with no tool call. Setting and reading are separate calls there: a setter takes the toolbox's opts and answers with the entity id the light resolved to, and a reader takes no arguments and answers from the resolved lighting state. Both find the sun and the ambient through the light the renderer resolved, so a per-frame call is priced by the scene's lights rather than by everything else standing in it.
local lighting = require("@builtin::modules.api.engine.lighting")
-- writes — the same opts the tools above take:
lighting.setSun({ direction = { -0.5, -1, -0.3 }, intensity = 3, color = { 1, 0.95, 0.8 } })
lighting.setAmbient({ intensity = 0.2 })
-- sun, ambient, sky and clearColor in one call — only the sections passed change:
lighting.applySetup({ sun = { intensity = 3 }, ambient = { intensity = 0.2 }, clearColor = { 0.02, 0.02, 0.04 } })
-- reads — what the frame is shaded by:
local s = lighting.sun() -- direction, color, intensity, castsShadows, entityId
local a = lighting.ambient() -- color, intensity, entityId
local rows = lighting.lightRows() -- every punctual light the renderer resolved
lighting.sun() reads and lighting.setSun(opts) writes, so an opts table handed to the reader is refused with the name of the call that applies it. The name-based lookup, the sky presets and the sky-material orchestration stay in the toolbox — the capability resolves each light by its component.
Lighting is real: with every source removed the scene goes dark. Lights also exist as a component (entity.component.add("Light", { intensity = 5 })) for ones that move with an entity — the lighting surface is the scene-environment one, the Light component is the per-entity one.
Point and spot lights share one intensity scale. They take a row of the same light buffer and are shaded by the same term — color * intensity * falloff — with the spot's cone as one further factor that is 1 inside its inner angle. So the same number at the same radius puts the same light on a surface either kind faces from the same place, and addLight hands intensity to both components unchanged. What the cone decides is how much of the room the light reaches: a spot lights the solid angle it opens on and leaves the rest of the room to whatever else is lit, so a frame-wide or room-wide average of a spot reads far below the same average of a point light carrying the same number. Balance a mixed rig by the brightness of the surfaces each light is aimed at, and read a spot on the surface its axis lands on. A spot's angle and innerAngle are HALF-angles from that axis, so angle = 30 opens a 60-degree cone; widening the cone or raising range spreads the same light over more of the room, where raising intensity makes the spot's own pool brighter. The sun, a directional light and a distant light read on a scale of their own: a parallel light arrives from the same direction at every point in the world and no distance attenuates it, so the same number lands far more light on a surface than a point or spot carrying it across a room does. Balance those against the sun and against each other. A clear day's noon sun is lighting.DAYLIGHT, intensity pi: at the display's exposure 1 it lights a white surface facing it to radiance 1 and an 18% grey card to middle grey, the frame a camera exposed for a sunny day takes, and a procedural sky that drives a sun stating no intensity of its own lights it at that.
The sun is a single field: one direction, one colour, and the sun's shadow. Setting it aims that light, so a second Light { kind = "directional" } moves the sun rather than joining it. A scene that wants more than one — a binary star, a moon opposite the sun, a cold fill from the far side of a set — adds DirectionalLight components, which are rows of the scene's light buffer beside its point, spot and area lights:
entity(moon).component.add("DirectionalLight", {
direction = { 0.3, -0.5, 0.4 }, -- the direction the light TRAVELS
color = { 0.7, 0.8, 1.0 },
intensity = 0.6,
})
They shade through the same BRDF the sun does, so one at the sun's direction, colour and intensity renders the frame the sun would have. A distant light that casts (castsShadows) is shadowed by the directional shadow map when it travels along the direction the map is made for: the map is made for the sun, and for the casting distant light that brings the most light once the sun brings less, so a moon that follows the sun by day shares the sun's shadows and the map is made for the moon at night. A light along any other direction casts none through it, and lighting.get reports each light's shadowing accordingly. The sky and the image-based lighting follow the sun, so a distant light reaches every surface facing it that its shadow does not take. A GI bake gathers one the way it gathers the sun — its mobility field says how much of it to bake. lighting.lightRows() reports each of them with kind = "distant", and the lighting toolbox's get tool lists them beside the scene's other lights.
The sky a scene draws is one at a time: a sky asset a setup applies, or a ProceduralSky or Skybox component on an entity of the scene (a material sky, or kind = "none" to draw none); the newest holds it. A scene with no sky renders no sky. The lighting toolbox's setSky tool reconfigures the sky drawn now — an applied sky through its application, with the values a preset word names — or creates the scene's sky entity when nothing draws one. A scene with nothing lighting it renders black: when no sun, ambient term, light or sky is in force in the loaded scene, its asset.validate carries the scene-missing-lighting warning. A scene lit only by lamps does not carry it, and neither does one that states it renders unlit (a scene setup's @lit = false).
The sky lights only what can see it
The sky lights every surface twice: diffusely, along the surface's normal, and in its reflection. Both are scaled by how much of the sky the surface can see in that direction, so a sealed room with no light inside renders black, a window lets in the sky it opens on and no more, and a mirror indoors reflects the room rather than the open sky. That share comes from the sky-visibility field @builtin::systems.skyVisibility builds over the scene's static geometry (Model.mobility resolving to static); the scene's sky component keeps it current, rebuilding it once edits to static geometry settle, so there is nothing to author. renderer.reflectionEnvironment().skyVisibility reports the field the renderer holds, and skyVisibility.settings() its grid, its cell size and the state of its upkeep. Only static geometry occludes the sky. The field resolves the scene to its cell size (smaller scenes get finer cells); a bake, below, resolves every surface exactly and carries the bounce light the field does not.
Global illumination — baked lightmaps & light probes
The lights above are direct light. Indirect light (bounce, color bleed, soft ambient) comes from the @builtin::systems.globalIllumination system, which path-traces global illumination offline so scenes get realistic multi-bounce lighting at no per-frame cost. The Model.mobility field ("auto" | "static" | "movable") decides how each entity participates: static geometry receives lightmaps and occludes baked light, movable geometry (and every player) samples probe volumes. "auto" derives the answer from the entity's components (physics bodies, skinned meshes, animation, and movers all make it movable) and from its motion: geometry a script's update moves frame after frame in play (entity.inMotion) is movable too; set the field explicitly to override.
Lights carry their own mobility ("auto" | "static" | "mixed" | "dynamic") answering a different question — how much of the light the bake takes. "mixed" is what "auto" picks: the bounce bakes, the direct light and shadows stay live, so a light still shines on whatever walks under it. "static" bakes the light whole and stops rendering it, which is the per-frame saving and the promise that nothing will move there.
Baking is a toolbox, so it answers on every tool surface. From the shell, zero baking lists the verbs and zero baking <verb> --help gives one verb's options:
zero baking all # lightmaps + auto-placed probe volumes + reflections
zero baking lightmaps # just the static-surface lightmaps
zero baking probes # just the irradiance probe volumes
zero baking detect # report what is baked vs stale vs missing
zero baking clear # remove baked lighting across a scope
The same verbs are the baking toolbox's tools, all among them, each taking an args table for its options (scope, resolution, samples, ...). Reach for them from code when what you are writing needs to bake, such as a panel offering a Bake button to a person.
Movable entities pick up the baked probes automatically: each baked volume publishes into the renderer's irradiance-volume set, and every standard-PBR fragment inside its bounds samples it — no per-entity setup. The full system (bake settings, UV requirements, mobility, staying current, the overlays) has its own guide: guides { path = "systems/globalIllumination/documentation/baked-lighting" }. ReflectionProbe (per-entity specular reflections) is a sibling component.
Baked light in your own shader
A bake writes nothing to the material. Every receiver keeps the material it was authored with; the bake puts its texels in a region of one shared atlas and records where in the receiver's per-instance shader-data lanes. That means a surface() shader, or any shader that #include "@builtin::shaderModules.pbr_shading", already supports baked lightmaps — you write nothing. The engine resolves the lanes and folds the irradiance into indirect light for you, and two instances of the SAME material resolve independently, so baked and unbaked geometry can share a material.
A self-shading fragment() shader that computes its own lighting takes the bake with the rest of the light of its surroundings from one call, zero_pbr_surroundings_light(input, n, albedo) in @builtin::shaderModules.pbr_shading: the baked irradiance where the instance carries a bake, and the flat ambient, the sky, the reflection probes and the probe volumes where it does not, the way a PBR surface takes them (the shader README's "Writing your own shading" has the whole body). A shader that reads the bake by hand reads the two lanes and samples the atlas:
// lane 0 = (scale.u, scale.v, offset.u, offset.v) — this instance's rect in the page
// lane 1 = (layer, enabled, -, -)
let params = input.shader_data[1];
var baked = vec3<f32>(0.0);
if params.y > 0.5 {
let rect = input.shader_data[0];
let uv = input.lightmap_uv * rect.xy + rect.zw;
baked = zero_feature_texture(uv, u32(params.x)).rgb;
}
input.lightmap_uv is the mesh's unique, atlas-packed uv1 — the bake's own UV set, not the texturing uv. The sample is irradiance (incoming diffuse light), so a surface turns it into outgoing light by multiplying by its own diffuse albedo: baked * albedo. Add that where your shader would otherwise apply ambient — a baked value REPLACES flat ambient and probe-volume irradiance rather than adding to them, since all three approximate the same quantity and summing double-counts the bake.
Gate on params.y and never on "is the texture bound": the atlas is always bound and always valid (black until something bakes), and the enable flag is what varies per instance.