What it does
game.lights.add spawns a light with a position, a radius, a colour and an intensity, and returns its handle. The
handle's light3d fields are all live, so you change a light's colour, brightness, cone or flicker by assigning to
it. Give a light follow and it rides with an object, and dies with it; give it tags and a tag sweep removes it with
everything else. The sun, ambient and fog stay with render-3d; this pack is for every light that is local.
A light fades smoothly to nothing at its radius, using an inverse-square falloff windowed so it reaches zero exactly at the edge, which stops a light popping as it crosses a cull boundary. A cone in degrees turns it into a spot, aimed by yaw and pitch, with a soft rim or a full-brightness inner cone of your choosing. Flicker beats two sine waves together, so a torch wavers like fire.
Each frame the live lights are sorted by distance from the camera and the nearest are sent to the renderer, up to a
cap of 64 by default and 256 at most. A scene can hold more lights than that, and the ones dropped are the furthest
away. Past a couple of dozen lights render-3d switches to clustered shading, binning lights into cells of the view so
each pixel only considers the lights near it.
Features
- Lights as objects — spawned, followed, tweened, tagged and killed like any other object in the scene.
- Point and spot — a radius for a point light, plus a cone, an inner cone, a yaw and a pitch for a spot.
- Physical falloff — a windowed inverse square that fades to zero exactly at the radius.
- Flicker — depth and speed for torches, candles and faulty lamps.
- Nearest first — the closest lights to the camera are sent each frame, up to a cap you can raise to 256.
- Lights meshes and water — meshes, the water surface and lit CPU 3D particles share the same lights.
Good for
- Dungeons and caves, with flickering torches along the walls.
- Interiors, with a lamp over a table and lights in each room.
- Night driving and chases, with headlight spots that follow the car.
- Spells and weapons, with a glow in a hand or a muzzle flash.
- Light shows and stages, with many coloured lights across a scene.
Make it yours
Each light takes its position, radius, color, intensity, a cone and innerCone in degrees, dir and
pitch, flicker and flickerSpeed, an object to follow, an id, a layer and tags. The pack's option max sets how
many lights reach the renderer at once. Two different uses: a dungeon with a hundred wall torches, each a warm point
light with flicker, of which only the nearest are sent as the player walks; and a car at night with two narrow
white spots that follow it, aimed down the road, plus a red point light behind for its tail lights.
A quick look
A flickering torch, and a spot light swept round by turning its yaw:
const torch = game.lights.add({ x: 4, y: 3, z: -2, radius: 10, color: '#ffb060', intensity: 40, flicker: 0.3 });
const lamp = game.lights.add({ x: 0, y: 9, z: 0, radius: 24, cone: 18, color: '#ffe7b0', pitch: 70 });
game.step('sweep', dt => { lamp.light3d.dir += 0.6 * dt; }); // every field is live
Works with
render-3d— required to see anything: it binds the lights and shades with them, flat or clustered.beams-3d— a visible shaft of light through haze that follows a spot light.blob-shadows-3d— contact shadows that ground objects, since these lights cast none.lighting-2d— lights for 2D worlds.
Good to know
- These lights cast no shadows; only the sun does.
- There is no bounce light or light probes: it is direct light plus hemisphere ambient.
intensityis in inverse-square units, so a lamp meant to read twenty units away needs far more than one beside the bulb; check it at the distance it works at.- Spot cones are given in degrees to
add, but the livelight3d.conefield is in radians.






