Spot light effects
Updated
Two components add to a Spot Light. A Spot Light Beam makes its cone visible in the air, like a stage light in a smoky room or a lighthouse at night. A Spot Light Projector shines an image through the light, like a gobo or a slide projector: a logo on a wall, leaves dappling a floor, a window pattern across a room. Both go on the Spot Light entity and follow the light’s own changes as they happen.
Before you start
Section titled “Before you start”- Both components work only with a Spot Light. Read that page first, especially how the entity’s rotation aims the light.
- The projector needs the light to cast shadows, through an enabled Light Shadow.
- Components are reached with
entity.getComponent(Class)and changed withsetProps. See Components.
Spot Light Beam
Section titled “Spot Light Beam”SpotLightBeamComponent (comp-spot-light-beam) shows the light’s beam as a filled shaft of its colour along its aim, as long as its length and as wide as the light’s angle. It is a soft glow, brightest at the lamp and on its axis, fading out over its last stretch so it shows no hard end.
| Prop | Type | Default | Description |
|---|---|---|---|
opacity |
number | 0.25 |
How bright the beam is, 0 to 1. The default is a subtle glow. |
length |
number | 0 |
Length in metres, 0–1000. 0 takes the light’s distance, or 5 m when it has none. |
It sends no events.
- Ending at the floor. Set
lengthto about where the beam meets the floor: it has faded out there, without shortening the light itself. - Follows the light. It refits when the light’s colour, angle or distance changes, never per frame. It shows nothing while the Spot Light is disabled or has a zero angle. It needs no shadows.
- From inside. The beam is computed per pixel from where the view ray enters the cone, so the camera’s near plane never cuts it as you walk in or out. The trade-off: objects between the camera and the beam do not hide it.
- XR. Each eye of a headset computes its own view of the beam, so both eyes agree.
Cost. One transparent, additive draw per beam. Every beam shares the same geometry and shader. Mind the fill rate on phones and headsets: a beam filling the view costs its work at every pixel.
Spot Light Projector
Section titled “Spot Light Projector”SpotLightProjectorComponent (comp-spot-light-projector) makes the light project an image. The image works as a stencil: it decides where light passes, and the light keeps its own colour.
- A transparent image (a PNG or an SVG with clear parts): the light shines where the image is opaque; where it is clear, the light is blocked.
- An opaque image (every JPG, a PNG with no transparency): its brightness is the stencil. White lets the light through, black blocks it, and grey dims it as much as it looks dark, so gradients show. A very bright light can wash the lighter greys out: lower its
intensityto see them.
Whether an image counts as transparent is decided once, when it loads: a single clear texel makes it transparent.
| Prop | Type | Default | Description |
|---|---|---|---|
src |
string | '' |
The image to project, a PNG, a JPG or an SVG: a URL, an asset reference or a data:image/ URL. Empty projects nothing. |
zoom |
number | 1 |
How far it zooms into the image, 0.001–10. 1 fills the cone, less shrinks the image with the light blocked around it, more zooms in. |
| Method | What it does |
|---|---|
load() |
Returns a promise that resolves once the current image has loaded or failed. |
It sends no events.
- Images. PNG, JPG (
.jpgor.jpeg) and SVG only. An image smaller than 512 × 512, or with no size of its own, is drawn at that size, so an SVG stays sharp. A file named as any other format warns and projects nothing.srcis an asset prop: it is preloaded and packaged with the project. - Rolling. The image turns with the light: rolling the Spot Light entity about its aim rolls what it projects.
- Moving. Rotate the entity, from a script or with an Animation Timeline, to sweep the projection across a scene.
Cost. The stencil is drawn when the image loads and when zoom changes, never per frame otherwise. Setting a projection makes every lit material compile once, since the image becomes part of the light’s calculation.
Examples
Section titled “Examples”1. Set up a beam and a projector
Section titled “1. Set up a beam and a projector”The entity Logo Projector is a Spot Light with an enabled Light Shadow, a Spot Light Beam and a Spot Light Projector.
#pragma lifecycle(startup)
async function startup() { const lamp = findEntity('Logo Projector');
// A faint shaft of light that fades out where it meets the wall, 6 m away. lamp.getComponent(SpotLightBeamComponent).setProps({ opacity: 0.15, length: 6 });
// Project the logo, slightly smaller than the cone. const projector = lamp.getComponent(SpotLightProjectorComponent); projector.setProps({ src: '/example-assets/bang.png', zoom: 0.8 }); await projector.load(); log('Logo is on the wall');}At startup a script gives a spot light's beam a faint opacity and a 6 m length, then projects an image on the wall through its Spot Light Projector.
See the faint shaft of light and the image it projects on the wall. Drag to orbit the camera, scroll to zoom.
setProps({ opacity, length })on the beam changes its look; it follows the light’s colour and angle by itself.- Setting
srcstarts loading the image.await projector.load()waits until it has loaded (or failed) before logging. zoom: 0.8leaves a ring of blocked light around the logo, so it reads as a clean shape on the wall.startupisasyncso it canawait.
2. A slide projector
Section titled “2. A slide projector”Every five seconds the projector shows the next image in a list.
#pragma lifecycle(startup)
const SLIDES = [ '/example-assets/lemon-decal.png', '/example-assets/bang.png', '/example-assets/alpha.png',];const SECONDS_PER_SLIDE = 5;
async function startup() { const projector = self.parent.getComponent(SpotLightProjectorComponent); let index = 0;
for (;;) { projector.setProps({ src: SLIDES[index] }); await projector.load(); // show it as soon as it is ready await new Promise((done) => delay(done, SECONDS_PER_SLIDE * 1000)); // then hold it index = (index + 1) % SLIDES.length; }}A script on a projector spot light shows the next image of a list every five seconds, waiting for each one to load.
Watch the slides change on the wall every five seconds. Drag to orbit the camera, scroll to zoom.
- This Behavior entity is a child of the Spot Light, so
self.parentis the light. delay(fn, ms)runsfnlater; wrapping it in aPromiselets the async loop wait. Scripts have nosetTimeout.await projector.load()waits for each new image, so the five seconds start only once it is showing.- When the script stops, its pending
delayis cancelled and the loop never resumes, so nothing leaks.
3. A sweeping searchlight
Section titled “3. A sweeping searchlight”The searchlight’s Spot Light has a Spot Light Beam. It sweeps left and right and its beam brightens when the player presses F.
#pragma lifecycle(startup, update)
const SWEEP = DEG_TO_RAD(40); // how far it turns each wayconst SPEED = 0.6; // radians of phase a second
let light;let beam;let baseYaw = 0;let phase = 0;
function startup() { light = self.parent; beam = light.getComponent(SpotLightBeamComponent); baseYaw = light.rotation.y; beam.setProps({ opacity: 0.2, length: 8.5 }); // ends where the beam meets the floor}
function update(dt) { phase += dt * SPEED; light.rotation.y = baseYaw + Math.sin(phase) * SWEEP;
if (Input.keyboard.isKeyReleased(Key.F)) { Tween.value(0.6, 0.2, (value) => beam.setProps({ opacity: value }), { duration: 1.5, ease: Ease.OutCubic }); }}A searchlight sweeps left and right with a visible beam, which flares when you press F: a Spot Light with a Spot Light Beam, turned by a Behavior script under it.
Watch the beam sweep, and press F to flare it (click the scene first so it has the keyboard). Drag to orbit the camera, scroll to zoom.
- Rotating the entity aims the light; the beam follows on its own because it is part of the same entity.
- Writing
rotation.ydirectly is fine for a purely visual object moved every frame. - The flash tweens the beam’s
opacityfrom bright back to normal throughsetProps. - The beam is not hidden by the floor, so
lengthends it where it meets the floor: the lamp is 4.3 m up and tilted about 31° down, which puts the floor about 8.5 m along the beam. The beam fades out at its end.
4. An iris that opens
Section titled “4. An iris that opens”When the show starts (signal show/start), the projected image grows from a pinpoint to full size.
#pragma lifecycle(startup)
let projector;
function startup() { projector = findEntity('Stage Projector').getComponent(SpotLightProjectorComponent); projector.setProps({ zoom: 0.05 }); // almost closed
on('show/start', async () => { await Tween.value(0.05, 1, (value) => projector.setProps({ zoom: value }), { duration: 1.2, ease: Ease.OutQuad, }); log('Iris open'); });}A stage spotlight projects a star pattern through its Spot Light Projector; pressing Start the show grows the image from a pinpoint to full size by tweening the projector's zoom.
Press Start the show and watch the stars open across the stage floor and wall. Drag to orbit the camera, scroll to zoom.
- A
zoombelow 1 shrinks the image inside the cone and blocks the light around it, so a tiny zoom looks like a closed iris. - Each
zoomchange redraws the stencil. A short opening is fine; do not animatezoomcontinuously, especially on mobile. emit('show/start')from any script, or a Signal Emitter, triggers it.
5. Switch a projector between images
Section titled “5. Switch a projector between images”Clicking a button entity (with a Selectable and a Signal Emitter whose signal is projector/next) switches between a day and a night pattern, and dims the beam at night.
#pragma lifecycle(startup)
const DAY = { src: '/example-assets/lemon-decal.png', zoom: 1 };const NIGHT = { src: '/example-assets/alpha.png', zoom: 1.4 };
async function startup() { const lamp = findEntity('Window Light'); const projector = lamp.getComponent(SpotLightProjectorComponent); const beam = lamp.getComponent(SpotLightBeamComponent); let night = false;
projector.setProps(DAY); await projector.load();
on('projector/next', async (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again night = !night; projector.setProps(night ? NIGHT : DAY); beam.setProps({ opacity: night ? 0.08 : 0.2 }); await projector.load(); log(night ? 'Night pattern' : 'Day pattern'); });}Clicking the button switches a projector between a day and a night pattern, zooming the night one and dimming the beam.
Click the blue button on the stand to switch between the day and night patterns. Drag elsewhere to orbit the camera, scroll to zoom.
- Both props change in one
setPropscall, so the new image and its zoom appear together. - The SVG window pattern stays sharp at any size; the PNG star field uses its transparency as the stencil.
- The beam is a separate component, changed independently.
Common mistakes
Section titled “Common mistakes”- The projector shows nothing. The Spot Light needs an enabled Light Shadow. Also check the file is a PNG, JPG or SVG.
- Putting the effects on a Point Light. Both components work only with a Spot Light.
- A beam that ends abruptly at a wall or seems to go through the floor. Set
lengthto about where the beam meets the surface. - Expecting objects to hide the beam. Objects between the camera and the beam do not cover it.
- Animating
zoomevery frame. Each change redraws the stencil. Animate briefly, or rotate the entity instead. - A projected gradient that looks flat. A very bright light washes out light greys. Lower the light’s
intensity. - Too many beams on mobile. Each one is a transparent draw over every pixel it covers.