Light Probe
Updated
Lights what is inside its box with probes, and shadows, baked by the Light Probe Solver.
- Type
ent-light-probe- Script class
LightProbeEntity- Family
- Lights
Overview
Section titled “Overview”A Light Probe is an invisible box that holds baked light for the area inside it, usually one room. Real light bounces: a red wall tints the floor beside it, corners are darker than the middle of a room. Computing that every frame is too expensive for a browser, a phone or a headset, so it is computed once, in the editor, and saved in the volume. In play, the room is then lit by its own bounced light, with soft baked shadows and darkened corners, at almost no cost.
The volume is its required Light Probe component (comp-light-probe). It holds a regular grid of probes, points that each record the light arriving from every direction. The box is a 1 m cube sized and placed by the entity’s transform; a new Light Probe entity is 4 × 3 × 4 m, and it turns about the vertical axis only. The Light Probe Solver on the scene root bakes every volume at once; baking works only in the editor.
Inside a volume, the probes’ light replaces the Environment’s diffuse light; reflections stay the Environment’s. Use Light Probes for indoor scenes, together with a few real-time Point, Spot and Rect Area lights. They add to real-time lights; they do not replace them.
The props:
lightingQualityis how fine the probe grid is, from0(probes 4 m apart) to1(0.25 m apart).0.5puts them 1 m apart.receiveBakedmakes the volume also store and show baked shadows and ambient occlusion, the darkening near blockers such as under furniture.shadowQualityis how fine the baked shadows are, from0to1.
A script can also read isBaked (true once its data matches its current box and quality), drawsShadows and issue (a sentence explaining why it lights less than its props say, or undefined).
Set it up
Section titled “Set it up”- On the scene root, add a Light Probe Solver (see Scenes and hierarchy).
- Add a Light Probe entity around each room and scale it a little larger than the walls, so its light does not fade inside the room.
- Light the rooms with real-time lights. For baked shadows, keep the Light Shadow of the lights that should cast them, and give casting objects a Shadow component.
- Bake in the editor and save the scene. Bake again whenever you move walls, lights or volumes.
Examples
Section titled “Examples”Warn when a volume needs a bake
Section titled “Warn when a volume needs a bake”Goal: at play start, report whether a volume is baked and why it may light less than expected.
#pragma lifecycle(startup)
function startup() { const probe = findEntity('Living Room Probe').getComponent(LightProbeComponent); if (probe.issue) console.warn(probe.issue); log('baked:', probe.isBaked, 'draws shadows:', probe.drawsShadows);}isBakedisfalsewhen the volume was never baked, or was moved, resized or changed quality since its bake.issueexplains in words what is wrong;console.warnwrites it to the script log as a warning.- Reading these members costs nothing.
List every volume that needs baking
Section titled “List every volume that needs baking”Goal: walk the scene once and report how many Light Probe volumes are out of date.
#pragma lifecycle(startup)
function startup() { let total = 0; let unbaked = 0;
for (const entity of scene.entities.values()) { if (!(entity instanceof LightProbeEntity)) continue; total++; if (!entity.getComponent(LightProbeComponent).isBaked) { unbaked++; console.warn(`${entity.name} needs a bake`); } } log(`${total} light probe volumes, ${unbaked} need a bake`);}scene.entitiesis aMapof every entity in the scene; walking it once at startup is fine.instanceof LightProbeEntitykeeps only Light Probe entities.- Run it while testing, then remove it: it does nothing a player needs.
A bake button in the editor
Section titled “A bake button in the editor”Goal: add a button to the Behavior’s properties that raises one room’s quality and bakes the scene, with progress in the log.
This is an editor-only script. The scene root, here named Main, carries the Light Probe Solver.
#editor_only#pragma slot(ref=bakeLobby, type=Button, label="Bake lobby in high quality", on_event=onBakeLobby)
async function onBakeLobby() { const probe = findEntity('Lobby Probe').getComponent(LightProbeComponent); probe.setProps({ lightingQuality: 0.75, shadowQuality: 0.75 });
const solver = findEntity('Main').getComponent(LightProbeSolverComponent); let shown = -1; const baked = await solver.bake((progress) => { const percent = Math.round(progress * 100); if (percent >= shown + 10) { shown = percent; log(`Baking… ${percent}%`); } }); log(baked ? 'Lobby baked' : 'Bake did not run');}#editor_onlymakes the whole script editor code: the player never downloads or runs it.#pragma slot(... type=Button, on_event=onBakeLobby)adds a button that callsonBakeLobbywhen pressed.- Changing
lightingQualitymakes the old data stop lighting until the next bake, so the script bakes right away. A quality of0.75puts probes 0.5 m apart. bake(onProgress)bakes every volume of the scene and resolvestrueorfalse; it isfalsewhen the bake was cancelled or could not run, for example in play.
- Make each volume a little larger than its room. At its faces, probe light fades into the Environment’s over half a probe spacing, which shows as a seam on what stands near a face inside the room.
- Moving or scaling a volume in play does not move its light, and data baked for another box lights nothing until you bake again.
- Memory and bake time grow with the cube of the detail: raise the quality only where it shows.
- A Directional Light casts no shadows, so it bakes none. Baked shadows come from Spot and Point lights with an enabled Light Shadow.
Components
Section titled “Components”What a new Light Probe is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.
| Component | Type | Role | Per entity | What it does |
|---|---|---|---|---|
| Layer | comp-layer |
Required | One | Puts the entity on a render/raycast layer so cameras and rays can include or skip it. |
| Lock | comp-lock |
Required | One | Editor-only flag that stops the entity from being selected or moved. |
| Enable | comp-enable |
Required | One | Turns the entity and its children on or off: hides them and stops their behavior. |
| Transform | comp- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| Light Probe | comp- |
Required | One | Lights what is inside its box with probes, and shadows, baked by the Light Probe Solver. |
You can also add 4 optional components, such as Animation Graph, Animation Timeline, Motion Path Controller, Signal Emitter.
The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).
| Prop | Default | Range |
|---|---|---|
lighting |
0.5 |
0 ≤ x ≤ 1 |
receiveBaked |
true |
|
shadowQuality |
0.5 |
0 ≤ x ≤ 1 |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
It reports the events every entity has: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
A kitchen whose light probe volume was never baked gets its hemisphere fill light raised so it is not left dark: a Light Probe checked by a Behavior script at startup.
The volume is not baked, so the fill light is raised to 0.7. Drag to orbit the camera, scroll to zoom.
From a script
Section titled “From a script”Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Light Probe.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Light Probe'); if (!(entity instanceof LightProbeEntity)) return;
// Its Light Probe component holds the settings listed under Props. const component = entity.getComponent(LightProbeComponent); log('lightingQuality is', component.props.lightingQuality); component.setProps({ lightingQuality: 0.75 });}