Skip to content

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

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:

  • lightingQuality is how fine the probe grid is, from 0 (probes 4 m apart) to 1 (0.25 m apart). 0.5 puts them 1 m apart.
  • receiveBaked makes the volume also store and show baked shadows and ambient occlusion, the darkening near blockers such as under furniture.
  • shadowQuality is how fine the baked shadows are, from 0 to 1.

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).

  1. On the scene root, add a Light Probe Solver (see Scenes and hierarchy).
  2. 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.
  3. 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.
  4. Bake in the editor and save the scene. Bake again whenever you move walls, lights or volumes.

Goal: at play start, report whether a volume is baked and why it may light less than expected.

ProbeCheck.jx
#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);
}
  • isBaked is false when the volume was never baked, or was moved, resized or changed quality since its bake.
  • issue explains in words what is wrong; console.warn writes it to the script log as a warning.
  • Reading these members costs nothing.

Goal: walk the scene once and report how many Light Probe volumes are out of date.

ProbeReport.jx
#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.entities is a Map of every entity in the scene; walking it once at startup is fine.
  • instanceof LightProbeEntity keeps only Light Probe entities.
  • Run it while testing, then remove it: it does nothing a player needs.

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.

BakeLobby.jx
#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_only makes the whole script editor code: the player never downloads or runs it.
  • #pragma slot(... type=Button, on_event=onBakeLobby) adds a button that calls onBakeLobby when pressed.
  • Changing lightingQuality makes the old data stop lighting until the next bake, so the script bakes right away. A quality of 0.75 puts probes 0.5 m apart.
  • bake(onProgress) bakes every volume of the scene and resolves true or false; it is false when 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.

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-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
Light Probe comp-light-probe 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
lightingQuality 0.5 0 ≤ x ≤ 1
receiveBaked true
shadowQuality 0.5 0 ≤ x ≤ 1

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.

Run it in the browser, read its scripts, and download it as an XR Creator project.

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.

LightProbeEntity.jx
#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 });
}