Skip to content

2D Lighting & Shadows

Estella lights 2D scenes with Light sources and ShadowCaster2D occluders. A light is just an entity with a Light component; a renderer receives light only when it’s drawn with a Lit-2D material. This keeps lighting opt-in and cheap — most sprites stay unlit, and the ones you want lit get a lit material.

Give an entity a Light component and pick a type:

import { defineSystem, Commands, Transform, Light, LightType, lightAimRotation } from 'esengine';
const addSun = defineSystem([Commands()], (cmds) => {
cmds.spawn()
// A light aims along its entity's forward, so the sun is aimed by turning it.
.insert(Transform, {
position: { x: 0, y: 0, z: 0 },
rotation: lightAimRotation({ x: -1, y: -1, z: -1 }),
})
.insert(Light, {
type: LightType.Directional,
color: { r: 1, g: 0.95, b: 0.8, a: 1 },
intensity: 1.2,
});
});

Light fields (with defaults):

Field Default Description
type Point LightType: Point, Directional, Ambient, or Spot.
color {1,1,1,1} Light color, RGBA 0..1.
intensity 1 Brightness multiplier.
radius 200 Falloff reach in world units (Point / Spot).
innerRadius 0 Radius held at full strength before the falloff starts (Point / Spot).
falloff 1 Falloff shape: 1 is linear, higher pools near the light, lower reaches further.
inverseSquare false Fall off as 1/distance² in metres, as a real lamp does (Point / Spot).
shadowStrength 1 How much of this light its shadows remove; 0.6 leaves a shadow that is dark rather than black.
cookie — A texture whose alpha is this light’s shape (Point / Spot).
cookieSize {0,0} How big the cookie is drawn, in world units; 0 covers the light’s own reach.
innerAngle 30 Spot cone inner angle, degrees (full brightness inside).
outerAngle 45 Spot cone outer angle, degrees (falls to zero by here).
shadowSoftness 0 Shadow edge softness (light-source size); 0 = hard edge.
shadowDistance 0 Directional shadow reach; 0 = no directional shadow.
layerMin / layerMax -128 / 127 The sprite layers a Point / Spot / Directional light reaches (see Which layers a light reaches).
sourceAngle 0.53 Directional only: the angular diameter of the source in degrees (the sun is 0.53); 0 = hard edge.
meshShadows false Cast a shadow map over 3D meshes (Directional, Spot, Point).
shadowExtent 0 Directional only: radius the mesh shadow map covers, centred on the meshes that cast shadows and not moving with the camera; 0 fits the view.
cascadeSplit 0.75 Directional only: where the cascades are cut along the view. 0 cuts it evenly, 1 makes each cascade a fixed multiple farther than the last, which spends the most texels near the camera; in between mixes the two.
shadowBias 1.5 Mesh shadow maps: how many texels of the map a surface is moved toward the light and off itself before it is tested. Raise it where a surface speckles with its own shadow (acne); lower it where a shadow lifts off the foot of what casts it.
shadowSlopeFloor 0.15 Mesh shadow maps: the least light a surface grazed by it is treated as facing, which caps how much extra bias a steep surface gets. Lower clears acne on walls the light skims; higher keeps their shadows attached.
followEnvironmentSun false Directional only: take direction and strength from the environment’s sun, and light the sky without it.
aimFollowedSun false With followEnvironmentSun: aim by this light’s Transform instead of the panorama’s sun.
hemisphere false Ambient only: light from above in color, from below in groundColor, blended by which way a surface faces.
groundColor #5a4d40 Ambient only: what a surface facing straight down receives with hemisphere on. Scaled by intensity.
environment — Ambient only: a baked .esenv environment. It replaces the flat term, hemisphere included.
environmentRotation 0 Ambient only: turn the environment about the up axis, in degrees.
drawEnvironment false Ambient only: also draw the environment as the sky behind the scene.
reflectionScale 1 Ambient only: scale what baked reflection probes show (1 = as baked).
reflectionSaturation 1 Ambient only: how much colour baked reflection probes keep (0 = grey).
diffuseScale 1 Ambient only: scale the light the environment gives surfaces, not what they reflect of it or the sky drawn behind them (1 = as the sky gives it).
diffuseTint {1,1,1,1} Ambient only: tint the light the environment gives surfaces, not what they reflect of it (white = as the sky gives it).
bakedTint {1,1,1,1} Ambient only: multiplies baked indirect light (lightmaps, probe volumes) — a day or weather scales the bake here.
enabled true Turn the light off without removing it.
Type Behavior
Directional A uniform light along the entity’s forward, like the sun — position doesn’t matter, only the rotation.
Point Radiates from the entity’s position and falls off to nothing at radius.
Spot A cone from the position along the entity’s forward, full-bright within innerAngle and fading to the edge at outerAngle, out to radius.
Ambient A flat base light added everywhere, regardless of position — use a low intensity so shaded areas aren’t pure black.
// A warm point light
.insert(Light, { type: LightType.Point, radius: 320, intensity: 1.5,
color: { r: 1, g: 0.7, b: 0.3, a: 1 } });
// A flashlight cone, aimed down the screen by the entity it sits on
.insert(Transform, { rotation: lightAimRotation({ x: 0, y: -1, z: 0 }) })
.insert(Light, { type: LightType.Spot,
innerAngle: 18, outerAngle: 34, radius: 500, intensity: 2 });
// A dim ambient fill so nothing is fully black
.insert(Light, { type: LightType.Ambient, intensity: 0.25 });

The 2D Lighting example: a spot light lighting a grid of dark boxes

The 2D Lighting example: a light pooling on dark boxes, with the rest of the scene unlit.

A frame carries 112 lights at once: sixteen the lighting loop reads for every pixel, and up to 96 more that are tiled. A street at night with a lamp every few metres, a corridor of neon, a room of candles — each is just a point or spot Light, and all of them light what they reach.

How it works, so that you can predict it: the sixteen the loop reads directly are the sun (directional lights), then anything that casts a shadow, then the brightest. Every other point or spot light without a shadow map goes into the tiled set. The screen is divided into a 16 × 12 grid; for each tile the engine records which lights’ spheres (radius) can reach it, and a pixel shades only the lights recorded for its own tile. The cost follows the lights near a pixel, not the lights in the scene — a hundred lamps cost what the handful in view cost.

What to keep in mind:

  • Tiled lights do not cast 3D shadows. (2D lights are different: the 2D shadow mask serves tiled lights too, see Casting shadows.) A shadow-casting light that does not make the sixteen is turned away (the Light Status in the editor says so), since the loop is the only place a shadow map is read. Give the lights that matter shadows and let the many be the glow.
  • radius is the reach. The tile masks are built from it; a light with a huge radius touches every tile and costs like it.
  • Planar reflections are drawn with the sixteen only: their camera is not the one the tiles were made for.
  • 2D lights ride the same set, so a 2D scene with fifty torches is lit too.

Details of a directional Light showing its status, lights in frame, colour, intensity, shadow strength and layer range

A directional Light: its status and how many lights reach the frame (1 of 112) sit above the fields.

A light lights every sprite it reaches, whatever layer the sprite is on. That is wrong for a lamp inside a hut, which has no business lighting the roof drawn over it. Give the light a Layer Min and Layer Max (layerMin, layerMax) and it lights only the sprites whose layer is in that range:

// The floor and the furniture are layers 1 to 4, the roof is 7: the lamp reaches everything up to 6.
world.insert(lamp, Light, { type: 0, color: { r: 1, g: 0.78, b: 0.45, a: 1 }, intensity: 1.5, radius: 330, layerMax: 6 });

The default, -128 to 127, is every layer. The roof still takes the scene’s ambient light, which is not a range-limited lamp but the sky, so it is dark by night and bright by day, and only the lamp’s glow is kept off it.

  • Sprites carry the layer, and only sprites: a lit Sprite (the Lit checkbox, or a material built from the Lit or Sway template) is tested against it. A mesh, a tilemap, a particle or a skeleton has no layer to test and is lit as it always was.
  • A custom lit sprite shader takes part by calling applyLighting2DLayer(albedo, N, worldPos, v_lightLayer) instead of applyLighting2D, with flat in highp float v_lightLayer; declared. A shader that keeps calling applyLighting2D is lit by every light, as before.
  • Directional lights take a range too, so a sun can leave an interior layer alone.
  • It costs a comparison per light per pixel, and nothing where no light has a range.

A Point or Spot light fades from its own centre to nothing at radius, in a straight line. Two fields bend that line, and neither moves where the light ends:

  • innerRadius holds the light at full strength out to a radius of its own, and the fade happens in the band that is left. A lamp with a bright core is innerRadius most of the way to radius; a light with none is the straight line it always was.
  • falloff is the power the remaining ramp is raised to. 1 is linear. Above it the light pools near its source and the outer reach dims quickly — closer to how light actually behaves. Below it the light stays bright most of the way out and then ends, which is the look a stylised 2D scene often wants.
// A lantern: a bright core, then a quick fade.
entity.insert(Light, {
type: LightType.Point, radius: 400, innerRadius: 120, falloff: 2.5, intensity: 1.4,
});

Both default to the straight line, so a scene written before them renders exactly as it did.

inverseSquare makes a Point or Spot light fall off as a real one does, as the inverse square of the distance — Unreal’s Use Inverse Squared Falloff, and what a glTF or three.js point light is. intensity is then the light reaching a surface one metre away (the project’s units per metre say what a metre is), four times dimmer at two metres, and radius is only where the light is let go: the last of it eases to nothing over the far end, by the same window glTF and three.js use. A lamp pools under itself instead of washing a room evenly. innerRadius and falloff do not apply.

// A shed lamp: as bright 1 m away as a sun of 3.
entity.insert(Light, { type: LightType.Point, intensity: 3, radius: 13, inverseSquare: true });

A glTF’s punctual lights import this way (candela over π, their range scaled with the model), and a bake falls light off the same way the frame does.

A light is a circle, or a cone. Real ones are neither: a lantern throws a ragged glow, a window throws a shaft, a torch flickers in a shape a falloff curve cannot describe. Hand a light a cookie — a texture whose alpha is the shape — and that is what it lights.

entity.insert(Light, {
type: LightType.Point, radius: 300, intensity: 1.6,
cookie: 'assets/textures/lantern-glow.png',
});
  • The alpha is the shape. The cookie’s colour is not read: a light’s colour is the light’s, and two places to set it is one too many.
  • It is drawn where the light is, turned by the entity’s rotation and sized by cookieSize — or, when that is zero, covering the light’s own reach.
  • It multiplies the falloff rather than replacing it, so a shaped light still fades out at radius and still respects innerRadius and falloff.
  • Four shaped lights fit a frame. Past that a light lights the scene without a shape, the same way a fifth shadow-caster keeps lighting without casting.

The shape is drawn into a screen-space mask, one channel per shaped light — the same machine the 2D shadows use, which is why a cookie costs one quad rather than a texture slot per light.

By default a Sprite draws with an unlit material and ignores every light. The simplest way to light one is the lit flag — no material, no shader:

app.world.spawn()
.insert(Transform, { position: { x: 0, y: 0, z: 0 } })
.insert(Sprite, { texture: hero, lit: true });

In the editor this is the Lit checkbox on the Sprite component. The sprite is lit with a flat normal — every 2D light type, falloff, and shadow works out of the box.

When you need more than the flag (a tint parameter, a normal map, custom surface logic), use a material whose shader declares the Lit-2D domain. The engine injects the lighting uniforms and helpers, and the vertex stage is optional for 2D shaders — you write only the fragment:

#pragma shader "MyLit"
#pragma version 300 es
#pragma domain Lit
#pragma fragment
precision mediump float;
in vec4 v_color;
in vec2 v_texCoord;
in highp vec2 v_worldPos;
uniform sampler2D u_textures[8];
out vec4 fragColor;
// #pragma domain Lit makes the engine inject the LightConstants block and the
// applyLighting2D() helper — you just call it with your base color and a normal.
void main() {
vec4 base = texture(u_textures[0], v_texCoord) * v_color;
vec3 N = vec3(0.0, 0.0, 1.0); // flat normal, facing the camera
vec3 lit = applyLighting2D(base.rgb, N, v_worldPos);
fragColor = vec4(lit, base.a);
}
#pragma end

In the editor, New Material (Lit) in the Content Browser creates exactly this — a ready lit material with a tint and an optional normal map. From code, compile and assign it as in Materials & Shaders:

import { Material, defineSystem, Query, Mut, Sprite } from 'esengine';
const litMat = Material.create({ shader: Material.compileShader(myLitSource) });
const applyLit = defineSystem([Query(Mut(Sprite))], (q) => {
for (const [, sprite] of q) sprite.material = litMat;
});

You can also build a lit material visually — set the Material Graph’s domain to Lit — see the material graph section.

The N you pass to applyLighting2D is the surface normal. Passing a constant vec3(0, 0, 1) gives flat, evenly-lit surfaces. For per-pixel relief, sample a normal map in the shader and use that as N instead — the same base color then catches highlights and shadow from each light’s direction. Add the normal texture as a #pragma param … texture on your lit material (see Materials & Shaders).

applyLighting2D is the shorthand for a surface that reflects nothing. The general form takes the same lights through a microfacet BRDF, and a Lit-2D shader can call it directly:

highp vec3 P = vec3(v_worldPos, 0.0);
highp vec3 lit = applyLightingPBR(
base.rgb, // albedo
N, // surface normal
P, // world position
viewDirection(P), // toward the camera, from the frame block
u_metallic, // 0 = dielectric, 1 = metal
u_roughness, // 0 = mirror, 1 = fully diffuse
u_specular, // glTF's specularFactor: 0 removes the highlight
1.0 // ambient occlusion
);

applyLighting2D(albedo, N, worldPos) is exactly this call with metallic = 0, roughness = 1 and specular = 0 — so a lit sprite keeps drawing the pixels it always did, and a surface that wants a highlight asks for one.

viewDirection(worldPos) answers with the unit vector pointing at the camera; it reads the eye position the engine puts in the frame block each frame, so an orthographic camera returns a constant and a perspective one varies per pixel.

A metal has no diffuse term at all — it only reflects. What it reflects is the scene’s ambient light, treated as an environment arriving equally from every direction, so an Ambient Light is what keeps a metal from being black everywhere no light happens to point. Raise its color to give metals something to show.

A flat ambient is an environment with no detail — every direction the same colour. Import an equirectangular .hdr panorama and the same light becomes one that has detail: sky above, ground below, whatever the file holds.

How What happens
Drag a .hdr onto the Content Browser The source is copied in and baked.
Put one in the project folder The editor notices and bakes it.
estella import-hdr <file> [outDir] The same bake, on the command line. --face-size <n> sets the sharpest reflection.

The bake writes two products beside the source: <name>.esenv, which holds the whole diffuse half as nine numbers — no texture at all — and <name>_env.png, a prefiltered reflection with one mip per roughness.

Point an Ambient light at the .esenv and both halves arrive: a surface takes its fill light from the direction it faces, and a metal reflects the panorama rather than one flat colour.

cmds.spawn().insert(Light, {
type: LightType.Ambient,
environment: 'assets/sky.esenv',
intensity: 1,
});

color and intensity still scale it, so an environment is tinted and dimmed the way the flat term is. A light with no environment stays exactly what it was: the coefficients are zero, and the same expression is the flat term again.

A ShadowCaster2D box (below) shadows in the XY plane, which is what a 2D scene means by a shadow. Geometry with height needs the other kind: turn on meshShadows on a Directional, Spot, or Point light. The frame renders mesh depth from that light’s views, so geometry blocks the light reaching other surfaces.

cmds.spawn()
.insert(Transform, { rotation: lightAimRotation({ x: 0.5, y: 0, z: -1 }) }) // where the rays lean
.insert(Light, {
type: LightType.Directional,
meshShadows: true,
});
  • One directional light can cast alongside point and spot lights. They share an atlas and a sixteen-tile limit: a spot needs one tile, a point needs all six cube faces, and a directional light can use several cascades. A point that cannot fit all six faces receives none; cascades may be reduced. Atlas space is a separate limit because a directional tile occupies a larger block.
  • Only MeshRenderer geometry the GPU holds casts and receives. Sprites are lit by the same light but shadow through ShadowCaster2D, which is the 2D answer.
  • Coverage follows the camera. shadowExtent fixes it instead, to one map of that radius over the meshes that cast shadows, trading sharpness for reach. Give a far backdrop castShadows: false and it does not pull the map away from what stands in front of it.

Add a ShadowCaster2D to an entity to make it block light and cast a shadow:

import { ShadowCaster2D } from 'esengine';
cmds.spawn()
.insert(Transform, { position: { x: 100, y: 0, z: 0 } })
.insert(Sprite, { /* … a lit material … */ })
.insert(ShadowCaster2D, { size: { x: 64, y: 64 } });
ShadowCaster2D field Default Description
size {32,32} The occluder’s size in world units.
path [] The occluder’s outline in local units (three points or more, in order round the shape); when set it replaces the size box.
enabled true Toggle shadow casting.

Shadow quality is controlled on the light, not the caster:

  • shadowSoftness — the light-source size. 0 is a crisp hard edge; larger values give a soft penumbra (a bigger, closer light casts softer shadows). The penumbra is that many silhouettes added up, so how smooth it is and what it costs is a quality setting: the profile’s shadowSoftSamples (1 to 32; 8 low, 12 medium, 16 high; Project Settings → Rendering → Quality). Fewer is cheaper and shows the edge as bands; sixteen is where they stop reading as separate shadows.
  • shadowDistance — for a Directional light, how far its shadows extend; 0 leaves a directional light shadow-free.
  • shadowStrength — how much of the light a shadow takes away, 0..1. A 2D scene usually wants less than all of it: real shade is lit by everything that bounced, and 1 is the only value that cannot be.

Shadows are drawn, not solved per pixel: each frame the engine takes the edges of every enabled caster, draws what they hide from each casting light into a screen-sized mask, and a lit surface reads one texel of it. So the number of occluders is a number of triangles rather than a shader constant — a room may have as many walls as it needs, and adding one costs a few triangles rather than a test on every pixel of the screen.

What IS capped is how many lights that meet cast at once. The mask has eight channels (two masks of four; four in a frame where some light has a shape, since the second mask takes the shape mask’s texture unit), and a channel is only wrong where two lights could both be: a pixel reads the channel of each light that reaches it, so two lights may share one whenever neither’s reach touches the other’s shadow. A camp of torches spread round a clearing is as many casting lights as it has torches; only lights whose reach and shadows overlap each need a channel of their own, so eight lights in one place fill the masks and a ninth among them does not. Every light can cast, the sixteen the lighting loop reads and the ones past them that are shaded through the screen tiles alike (up to 96 more, the brightest first).

A light left without a channel still lights the scene and stops shadowing — the room stays lit, and what is missing is a shadow rather than the light. The first lights in brightness order are placed first, so it is the dimmest of a crowd that goes without. A sun (a directional light with shadowDistance) is everywhere, so it takes a channel to itself and leaves seven for the rest. The profiler’s render.shadow2d.unplaced counts the lights that went without. To make room, give the ones whose shadows nobody looks at no shadow (shadowDistance of 0 on a sun), or a smaller radius so they stop overlapping their neighbours.

Blob shadows: a disc instead of a shadow map

Section titled “Blob shadows: a disc instead of a shadow map”

A shadow map costs a pass from the light and a read in every lit pixel. Where that is too much (a phone, a crowd, a game whose light never moves) a BlobShadow on the entity puts a soft dark disc on the ground under it instead: no map, no light, no extra pass.

cmds.spawn()
.insert(Transform, { position: { x: 0, y: 40, z: 0 } })
.insert(MeshRenderer, { mesh })
.insert(BlobShadow, { radius: 60, opacity: 0.6, groundY: 0 });
Field Meaning
radius, opacity, softness Size on the ground, darkness at the centre, and how soft the edge is (0 hard, 1 fading from the centre).
groundY Height of the flat ground. For ground that is not flat, setBlobShadowGround(app, (x, z) => height) gives the height under each thing (return null to fall back to groundY).
fadeHeight, shrink The shadow fades out as the thing rises this far above the ground, and shrinks by this share on the way (a jumping character’s shadow gets smaller and fainter). 0 never fades.
lift How far above the ground the disc is drawn, so it does not flicker against it.

The disc is hidden by what stands in front of it and draws no depth of its own. It is not the light’s shadow: it does not stretch with the sun, fall across steps or land on a wall, so use it where a grounding cue is enough, and a real shadow where the shape of the shadow matters. The disc is an entity of its own that is never saved with the scene.

There is one lighting model: a lit 3D surface, a lit sprite and a material’s applyLightingPBR all go through the same BRDF. What changes with the device is how much of the engine’s lighting a shader is compiled with. The quality level’s lighting says it: at full a lit mesh takes the lights past the sixteen of the light block, soft shadows from a source with size, hair shadows and the 2D light masks; at direct it is compiled as #pragma lighting direct asks, with the sixteen lights and hard shadows only. low and medium are direct (a phone takes medium when the project names no level), high is full, and with the quality system off everything is full. Change it per level under Project Settings → Rendering → Quality → 3D lighting, or in code:

quality: { profiles: { medium: { lighting: 'full' } } }

Most of what direct saves is not the work it skips but the size of the shader: a program carrying the tiled lights and the soft-shadow search keeps more registers in use and runs fewer pixels at once even where none of it executes. On a Snapdragon 8 Elite, a full-screen lit floor drawn fifteen times over under a sun at the default sourceAngle, with the same settings otherwise:

full direct
Built-in mesh shader, soft-shadowed sun 57 ms 24 ms
Built-in mesh shader, hard-shadowed sun (sourceAngle: 0) 33 ms 25 ms
A material with specular 0, soft-shadowed sun 41 ms under 17 ms (the 60 fps cap)

Sprites keep their 2D lighting at every level: the 2D shadow and shape masks are how a 2D scene draws its shadows.

What the level does not decide is what a surface is. A highlight belongs to the material: a material whose specular is 0 skips the lobe for every light (the measurement above), and a whole scene of matte surfaces is cheaper for it. Past that, the cheapest shadows are a blob shadow under each moving thing and baked light for what stands still.

A frame carries 112 lights: sixteen read for every pixel and 96 tiled (see Many lights). Past that the dimmest are dropped — by brightness, with a warning naming what was refused — and that ceiling is not a quality setting. Tiled lights cast no 3D shadows, and every light still costs its share of every pixel it reaches.

A bake is the way past it. Light that never moves is computed once, offline, and stored as a texture; at run time the surface reads a texel instead of summing lights. A hundred lamps then cost exactly what one costs, and what they cost is a sample.

The engine reads a bake through two things, and you give it both:

  • A mesh with a second UV set. The first UV set is how the art is wrapped, and it overlaps on purpose — two arms share the texels of one arm. A bake cannot: each surface needs its own patch, or one wall’s light lands on another. Both importers carry the channel through when a model has one (TEXCOORD_1 in glTF, a second UV layer in FBX), so this is a question for whoever authored the model.
  • A MeshLightmap component. lightmap is the atlas, and scaleOffset is the rectangle of it this object occupies — xy scales the second UV set, zw offsets it. (1, 1, 0, 0) reads the whole texture, which is what a bake of a single object produces. The rectangle is per entity and not per mesh, because the same mesh placed twice is lit twice, differently.

What the bake MEANS depends on the renderer’s lit flag, and the two are worth telling apart:

lit With a MeshLightmap Without
on Real-time light plus the bake, which carries the indirect term Real-time light only
off The bake is all of the surface’s light Unlit — the texture as authored

The second row is the one a bake is for. A scene whose lights all went into the atlas draws with lit off and pays for no lights at all — on a phone, that is the difference between a lit room and a slideshow.

An object whose geometry carries the channel but has no MeshLightmap draws exactly as it did before: the rectangle is zero, and the shader reads that as “no bake” rather than as an atlas of black.

The editor bakes one: Lighting → Bake Lighting writes the atlas beside the scene and fills in every MeshLightmap, and node pipeline/bin/estella.mjs bake-scene <scene> does the same thing from the command line. A bake authored elsewhere (Blender’s Cycles, a Substance bake, any renderer that writes a lightmap and its UV layout) is still read exactly as well — the component is the contract, not the baker.

A room lit by what it looks like now: runtime capture

Section titled “A room lit by what it looks like now: runtime capture”

A bake sees only what it can hold: a mesh without a lightmap UV set is black to it, so lamps that light the walls of a shed put none of that light back into its probes. Set capture on a LightProbeVolume and it is filled at run time instead: the scene is drawn from the box’s centre all round — the walls as the lights light them now, the sky through the openings — and that is the light everything inside reads, in place of a bake. It is Unreal’s real-time Sky Light or Reflection Capture, and the “interior environment” a hand-built renderer captures inside a building.

entity.insert(LightProbeVolume, { halfExtents: { x: 22, y: 7, z: 11 }, capture: true, captureInterval: 2 });
  • One face is drawn a frame, small (32 pixels), so a capture costs six small extra scene draws spread over six frames.
  • captureInterval recaptures every so many seconds (0 = once). Each capture sees the room lit by the last one, so a few are a few bounces.
  • The box is one point of light: it is right for a room, not for a long hall whose ends differ — use several boxes.
  • What a shiny surface inside the box reflects is the capture too, projected onto the box’s walls: a chrome tap in the shed shows the shed, not the sky outside. A scene with baked ReflectionProbes keeps those; the frame binds one reflection atlas.
  • Keep the box’s centre clear: the capture is taken from there, and an object around that point (a mirror ball at the centre) is all it sees.

Large volumes: sparse bricks, and what a weak GPU reads

Section titled “Large volumes: sparse bricks, and what a weak GPU reads”

A probe volume’s grid is stored as bricks of 4 x 4 x 4 cells in a 3D atlas, and found through an indirection cell per brick, the shape Unreal’s volumetric lightmap takes. With BakedLighting.probeLevels above 1 (Probe levels in the Lighting panel, 1 to 4) the bake keeps the volume’s spacing only in bricks with geometry near them and samples the open air at 2, 4 or 8 times it: a large volume with a fine spacing along its floor and walls bakes with far fewer probes, and the cap on a volume’s probes grows eight times a level. Where a fine brick meets a coarse one its face takes the coarse brick’s light, so there is no seam where the spacing changes. A grid whose bricks would all be fine is written dense, as with one level.

To see what a bake laid down, select the volume in the editor: a sparse grid shows its bricks, the finest in violet and the coarser ones in amber (2x), pale yellow (4x) and grey (8x); a dense one shows a cross at every probe. Both are read from the grid the engine loaded, so what you see is what the frame reads, not what the component’s spacing would ask for now.

A mesh without lightmap UVs reads the grid where each pixel stands: ten texture reads a lookup (the indirection cell, then one filtered read per coefficient). A mesh with them, and every mesh at the low quality level (probesPerPixel: false in its profile), reads one value where it stands instead, and no atlas is held on the GPU: a long mesh reaching from a lit yard into a dark shed is then lit as one. get_stats and the frame stats report probes: the draws that read per pixel and per object, and the bytes the atlas takes.

A lightmap is the diffuse half. The other half is what a mirror shows, and without a probe that is always the sky — indoors, a chrome ball reflects the clouds through the ceiling.

ReflectionProbe is the answer, and it is the same shape as LightProbeVolume: a box, filled by the same bake.

world.insert(room, ReflectionProbe, { halfExtents: { x: 400, y: 220, z: 400 } });

The baker captures the sphere seen from the probe’s position, prefilters it for every roughness, and writes every probe of the scene into ONE atlas beside the lightmap — reflection names it and slot says which column is this one’s. Both fields are the baker’s to write; what you place is the box.

Three things worth knowing:

  • The reflection is projected onto the box, so it slides across a wall as the eye moves instead of being painted on. Size the box to the room, not to the object.
  • Where two boxes overlap the smaller wins — a cupboard inside a hall reflects what the cupboard was baked to say.
  • Do not put a probe inside a shiny object. The capture is taken from that point; standing inside the ball, all it sees is the inside of the ball.

Skinned meshes take no bake: bones move a character, and a bake cannot hold one still long enough to light it. A character in a baked room is lit in real time, by the lights that stayed behind.

By default the engine renders gamma-space — colors blend as-authored, the way 2D pipelines classically have. A project can switch to the linear-light pipeline: textures decode from sRGB to linear on sample (in hardware), lights and tints blend in linear light, and the finished frame encodes back to sRGB in the final blit.

Physically-correct blending changes how light accumulates: falloffs stop crushing to black, and overlapping lights add like light instead of paint. Unlit art round-trips unchanged — decode followed by encode is an identity — so switching does not repaint your sprites; the difference shows wherever colors mix.

Linear mode is also the door to HDR: where float render targets are available (WebGPU always; WebGL2 with EXT_color_buffer_float), the post-process chain runs in half-float, so a light with intensity above 1 pushes real over-range energy into bloom and tonemap — bright lights glow.

Enable it in Settings → Project → Rendering → Color space → Linear. Shaders compile against the mode, so it is fixed at engine boot — the editor prompts for a reload. The setting rides the project manifest: the viewport, Play, and every export — web, desktop, WeChat, playable — boot the same pipeline. Code-first projects pass it at app creation:

const app = createWebApp(module, { colorSpace: 'linear' });

The colour pickers show what the screen shows either way. In a linear project a Sprite’s or a Light’s colour is stored as sRGB and decoded by the engine, while a resident mesh’s MeshRenderer.color and a material’s colours reach the shader as they are, so those are stored linear: 0.25 in a scene file is what the picker shows as #89. Writing a mesh’s colour from code takes the linear value.

intensity has no factor of pi in it: a directional light of 1 facing a surface gives it its full colour, where three.js (r155 and later) divides diffuse light by pi. Numbers carried over from a three.js scene are therefore about three times too bright. Divide its light intensities by pi. Its HemisphereLight is an Ambient light with hemisphere on.

Add PlanarReflection to a flat entity with a resident MeshRenderer mesh and a lit/PBR material. Its world origin and selected local axis define the reflecting plane. The current camera is mirrored across that plane; geometry on its opposite side, the receiving entity, and screen-space UI are excluded from the capture. Water, mirrors and polished floors use the same capture; this is not a water simulation.

import { PlanarReflection, ReflectionAxis, ReflectionQuality,
ReflectionUpdate, refreshPlanarReflection, planarReflectionStatus } from 'esengine';
world.insert(surface, PlanarReflection, {
axis: ReflectionAxis.Y,
quality: ReflectionQuality.Custom,
resolutionScale: 0.5,
maxSize: 1024,
update: ReflectionUpdate.EveryFrame,
});
// For OnDemand, request a refresh after changing the reflected scene:
refreshPlanarReflection(app, surface);
const capture = planarReflectionStatus(app, surface, cameraEntity);

The reflection is filtered by the surface’s roughness (nine taps, a pixel and a half at the least and wider as the surface gets rougher), so a damp road shows a soft reflection where a puddle’s stays crisp, and a reflected sun or sky hot spot is brought under a soft ceiling of 1.5 by its brightest channel (a knee from 0.75, hue kept) instead of clipping toward white.

The existing material controls tint, metallic response, Fresnel and roughness. The captured radiance replaces the environment’s specular input for this draw; it is not added over an already reflected sky. The roughness filter is a small spatial approximation, not a prefiltered GGX convolution. An unlit material does not sample PBR reflections. Use an actual flat mesh, rather than a thick box, so the reflecting geometry agrees with its plane.

One visible surface is captured per view, selected by stable entity ID. Additional surfaces report budget-excluded. Each camera owns a separate capture; inactive views release their targets, resizing refreshes them, and a device rebuild forces a recapture. Captures run without post-processing, host draw callbacks or recursion. World-space 2D light masks are not regenerated for the reflected camera.

Project quality defaults are ¼ / 512, ½ / 1024 and 1× / 2048 for low, medium and high, all updating every frame. Override planarReflectionScale, planarReflectionMaxSize, and planarReflectionUpdatesPerSecond in a quality profile; zero updates-per-second means every frame. Custom fixed-rate and on-demand updates affect only the capture, never the main scene’s frame rate.

Details exposes capture settings, quality overrides, a transient plane preview and live capture size/draw/resource diagnostics. View 0 is the manual/editor view; runtime diagnostics use the camera’s runtime entity ID.

Open examples/planar-reflection: Space toggles capture, 1/2/3 selects project quality, and a moving object demonstrates dynamic reflection. WebGL2/WebGPU headless checks cover geometry placement, clipping, layers and update policies; physical mobile-device frame-time acceptance remains pending.

A 2D light in the editor viewport — its reach and the shadows its casters throw

A Light previewed in the editor — its reach pool and the shadows the pillars cast (turn on Preview FX to light the scene in edit mode).

  • Add a light via Create… → Light, or add a Light component to an existing entity in the Details panel.
  • Lights are drawn as gizmos in edit mode — an icon plus the reach circle and the direction / cone — so you can aim and size them by eye. See The Editor.
  • Tune color (a color picker), intensity, radius, and the spot angles live in Details; the results update in the viewport immediately.
  • All of a light’s visual fields (color, intensity, radius, the angles, and the shadow settings) are animatable — key them in the Sequencer for flickering torches, day/night cycles, or a pulsing beacon.