Baked lighting
Bake a level's static lighting into lightmap atlases that the Low quality tier uses in place of Global Illumination, and keep the bake current.
The Low quality tier runs no Global Illumination. Baked lighting gives its static meshes the indirect light they would otherwise lose: the editor path-traces the level once, stores the result in lightmap atlases, and the renderer adds it to the lit image where Global Illumination is off.
Enable the baker
Baking is an editor tool in the Lightmap Baker Feature or Kit, off by default. Enable it in the Features & Kits window and restart the editor. A packaged game does not need the Feature or Kit: the baked files ship and the renderer samples them on its own.
What gets baked
A mesh is baked when all of these hold:
- Its transform's Mobility is Static.
- Its Bake Lightmap property (Details, Lighting) is on. It is on by default.
- It has a mesh: a mesh asset or a primitive shape.
Skinned meshes bake too, in their rest pose. A mesh whose import produced its own second UV set for lightmaps keeps it when the set is usable (inside the unit square, different from the first set, almost no overlap); every other mesh is unwrapped by the baker.
A Static mesh with Bake Lightmap off still blocks and bounces light for the meshes that are baked; it just gets no lightmap of its own.
Lightmap density
Lightmap Density (Details, Lighting) is the resolution in texels per world meter. 0 takes the project default, r.Lightmap.DefaultDensity (4). Each mesh instance gets a square tile whose edge is the square root of its world surface area times the density, rounded up to a multiple of 4 and clamped between r.Lightmap.Bake.MinResolution and r.Lightmap.Bake.MaxResolution. Doubling the density therefore quadruples the texels.
Bake settings
Place a Lightmap Bake Settings component on any actor in the level to choose the quality for that level; it is saved with the level. Without one, the r.Lightmap.Bake.* variables below apply.
| Property | Effect |
|---|---|
| Quality Preset | 0 Custom uses the values below. 1 Preview, 2 Medium, 3 High and 4 Production set the samples per texel, the bounces and the lightmap density together (Preview 16 samples, 1 bounce, half density; Production 1024 samples, 4 bounces, double density), and the rays of every Baked Probe Volume. |
| Samples Per Texel | Path samples per texel. |
| Indirect Bounces | Bounces after the first hit. |
| Denoise | Edge-aware denoise of each tile. |
| Directional Lightmaps | Also bake the dominant light direction, so normal maps and curved surfaces react to where the light comes from. Adds one atlas per atlas. |
| Spherical Harmonics | Bake four coefficients per colour channel (first-order spherical harmonics) and evaluate them with each pixel's normal. The most faithful with normal maps; adds three atlases per atlas. Wins over Directional Lightmaps. |
| Indirect Intensity | Scales the baked light. |
| Maximum Atlas Size, Minimum / Maximum Tile Resolution | Layout limits. |
Each mesh's Details panel shows its Lightmap Status and tile density in the Lighting section.
A mesh asset's Lightmap Density (its sidecar, or the Lightmap Density column of the property matrix on an Asset Browser selection) is the density every instance of the mesh takes when the instance's own Lightmap Density is 0. The sidecar's GI Card Resolution is a different setting: it caps the surface-cache cards of dynamic Global Illumination and has no effect on a bake.
Bake the level
Choose Build > Build Lighting, or press the sun button on the level toolbar. Progress, Cancel and a quality choice for the next build (the level's own settings, or Preview, Medium, High or Production) are in the Lightmap Baker panel under Window > Features and Kits; Build > Cancel Lighting Bake does the same.
The bake:
- Reads every enabled light and the scene's sky colour. Which part of each light is baked depends on its Mobility and the level's lighting mode.
- Unwraps each mesh instance into its own chart layout, so no two instances share lightmap texels.
- Packs the tiles into atlases up to
r.Lightmap.Bake.MaxAtlasSizewide, with a gutter around each tile. - Path-traces direct light where the mode asks for it,
r.Lightmap.Bake.Bouncesbounces of indirect light and the sky for every texel, then denoises each tile (r.Lightmap.Bake.Denoise). - Encodes the atlases as BC6H textures and writes them with a
.lightmapfile toAssets/Lightmaps/, named after the level. The.lightmapfile is built data: every bake rewrites it, it is never locked or edited, and it keys each entry on the actor's id, which is the id the level loads the actor with, so the entries still apply after a reload.
The bake assigns the set to the baked meshes. Save the level to keep the assignment. Build > Clear Baked Lighting removes it.
The bake uses each light's colour and intensity as the renderer does. Photometric units are converted the same way, but the baked result is a diffuse approximation: it carries no specular and no light cookies, IES profiles or light functions.
Lighting mode
World Settings > Lighting > Lighting Mode chooses how the level is lit.
| Mode | Behaviour |
|---|---|
| Dynamic GI (default) | Global Illumination runs as the quality tier allows. A baked set is drawn only where the tier has Global Illumination off, as described below. |
| Baked | Global Illumination is off on every tier, so the world SDF, the probe grid, the screen probes and the reflections that trace the SDF allocate nothing. The sky's diffuse light is off too, because the sky is part of the bake. Lights whose Mobility is Static are no longer drawn at runtime: their light lives in the lightmaps. Baked lightmaps are always drawn. |
What a bake stores follows the mode, so the renderer never adds a light twice:
| Light mobility | Dynamic GI level | Baked level |
|---|---|---|
| Static | Bounced light only. The light itself is still drawn every frame. | Direct and bounced light. The light is left out of the light loop. |
| Stationary | Bounced light only. | Bounced light only. The light and its shadows stay dynamic. |
| Movable | Bounced light only. | Not baked. |
Each Stationary light is given one channel (R, G, B or A) of a shadow mask for its static shadows, and at most four lights that can reach the same texel share the four channels. When more than four overlap, the bake logs a warning naming how many lights got no channel, and those lights keep their dynamic shadows.
The bake writes the mask as an extra RGBA8 atlas beside each lightmap atlas (.maskN), one visibility value per Stationary light per texel, and records which light owns which channel in the .lightmap. At runtime a Stationary sun multiplies its light by the mask on every lightmapped pixel, on top of the dynamic shadows, so a baked wall shadow stays sharp and reaches past the shadow cascades while a movable object's shadow still comes from the cascades. A Stationary point or spot light reads its channel the same way: its light is multiplied by the mask on lightmapped pixels, on top of its dynamic shadows.
The .lightmap file records the mode it was baked for, and changing a light's mobility or the level's mode marks the bake out of date. Rebake after switching modes. Baked lighting is dimmer than it used to be on the Low tier in a Dynamic GI level: earlier bakes stored each light's direct light as well, which the renderer then added a second time.
A level saved without the setting is Dynamic GI. There is no mode that mixes baked lighting with Global Illumination on the same pixels: two indirect terms would count the same bounce twice. In a Baked level, a Static light lights only the baked meshes; a Movable mesh gets that light only from a baked probe volume.
When the baked light is used
In a Dynamic GI level, r.Lightmap.Mode decides:
| Value | Behaviour |
|---|---|
0 | Never draw baked lighting. |
1 (default) | Draw it only when the active quality row has Global Illumination off, which is the Low tier. |
2 | Always draw it, on top of whatever Global Illumination adds. |
Where the baked light is added
r.Lightmap.ProxyPass chooses how a baked mesh receives its light:
| Value | Behaviour |
|---|---|
1 | A pass after lighting redraws each baked mesh's proxy geometry and adds the light, with a depth match against the G-Buffer. |
0 (default) | The G-Buffer fill samples the atlas itself, at the mesh's own second UV set. The light is added as emissive (albedo * (1 - metallic) * baked), so it works with alpha-tested materials and level-of-detail changes and costs no second geometry pass. |
With 0, the pixels of a lightmapped, uncoated Default Lit surface also lose their own diffuse sky ambient, because the bake already holds the sky. Classic and auto-instanced draws of the standard material take this path, on devices with a bindless texture table. Skinned meshes, foliage, terrain, graph materials, meshlet draws, directional or spherical-harmonic sets and every device without the table keep the proxy pass; a mesh with a lightmap is drawn by the ordinary triangle path rather than meshlets. One clear-coat value is reserved as the marker: a Default Lit material with a clear-coat roughness of exactly 1/255 and no clear coat reads as lightmapped to the lighting pass.
The mobile forward path always samples in the shading pass whatever r.Lightmap.ProxyPass says: its forward shader reads the same atlas through the bindless table and replaces the flat ambient with the baked diffuse, for static opaque surfaces with a plain lightmap tile. See the mobile rendering guide.
r.Lightmap.Intensity scales the baked light. The pass runs after direct lighting and before the sky, and a baked pixel multiplies the baked value by the surface's own albedo, so the lightmap follows material changes without a re-bake.
Baked probe volumes
Lightmaps light static meshes. A Movable mesh, a particle or anything else without a lightmap would otherwise get none of the baked bounce, so the bake can also fill Baked Probe Volume boxes: place a Baked Probe Volume component on an actor, size it to cover the area movable objects walk through, and choose its Probe Spacing (smaller follows walls and corners more closely and costs more probes, and a volume past 65,536 probes is skipped with a warning) and Rays Per Probe. Each probe stores the light arriving from every direction and the distance to the nearest surface, so a surface sampling it ignores probes on the far side of a wall.
The volumes are saved in the .lightmap file. At runtime a pass after lighting adds the volume's light to every pixel inside it that no lightmap already lights, multiplied by the surface's albedo, and fades out over one probe spacing outside the box. A pixel that a lightmap lights through the G-Buffer fill (r.Lightmap.ProxyPass 0, the default) is left alone, so a lightmapped mesh is never lit twice.
Quality presets and the command line
The Quality Preset on the Lightmap Bake Settings component sets the samples, bounces and density in one choice. To build lighting without opening the editor, run mbt bake-lighting --level Assets/Maps/Main.mmap --quality high. It starts the editor headless on the project, builds the level's lighting at that preset (overriding the preset on the level's component), saves the level and exits; mbt returns 0 only when the bake and the save succeeded. The Lightmap Baker Feature or Kit must be enabled in the project, and the editor of the chosen configuration (-c, default dev) must be built.
Keeping the bake current
Each baked entry remembers the transform, density and mesh it was baked against. When a baked mesh moves, or its density changes, the entry no longer matches: the renderer stops drawing it, so a stale layout never lights the wrong place, and the Lightmap Baker panel reports how many objects need a rebuild. Bake again to bring them back. The bake also remembers the sky, every enabled light, and each Static mesh's placement, density and material colours. When any of them changes, the level is out of date: a chip in the corner of the viewport says "Lighting needs a rebuild" (with the count of baked objects that moved); baked meshes are outlined in orange in the viewport, the Lightmap Baker panel says so, the toolbar button highlights and a warning is logged. Bake again to clear it.
Streaming worlds
In a world that streams by sectors, a bake groups the meshes of each streaming cell into atlases of their own, so a cell's lightmaps load with the cell and unload with it: the renderer uploads a cell's atlases when streaming makes the cell resident and releases them when it stops being resident. Meshes the baker could not place in a cell, and every mesh in a project with no streaming grid, go in an always-resident group.
The atlases kept resident across all cells are capped by r.Lightmap.StreamingBudgetMB. A cell whose atlases would pass the cap stays unloaded and its meshes fall back to the ordinary ambient light. The always-resident group does not count against the cap.
Console variables
| Variable | Default | Effect |
|---|---|---|
r.Lightmap.Mode | 1 | Whether baked lighting is drawn. |
r.Lightmap.Intensity | 1 | Scale of the baked light. |
r.Lightmap.ProxyPass | 0 | 0 samples baked light in the G-Buffer fill, 1 adds it with the proxy pass. |
r.Lightmap.DefaultDensity | 4 | Texels per meter for a mesh whose density is 0. |
r.Lightmap.StreamingBudgetMB | 512 | Most megabytes of lightmap atlases kept resident across streamed cells, 0 for no limit. |
r.Lightmap.Bake.SamplesPerTexel | 128 | Path samples per texel. |
r.Lightmap.Bake.Bounces | 2 | Indirect bounces. |
r.Lightmap.Bake.MaxAtlasSize | 2048 | Largest atlas edge. |
r.Lightmap.Bake.MinResolution | 16 | Smallest tile edge. |
r.Lightmap.Bake.MaxResolution | 512 | Largest tile edge. |
r.Lightmap.Bake.Denoise | 1 | Denoise each tile. |
r.Lightmap.Bake.Directional | 0 | Bake the dominant light direction. |
r.Lightmap.Bake.SphericalHarmonics | 0 | Bake first-order spherical harmonics. |
Limits
- Dynamic objects are lit by the ordinary ambient, not by the lightmap.
- Baked light is diffuse only; rect lights are not baked.
- Spherical harmonics are first order: a light shining straight at a surface bakes about a quarter dimmer at the peak than exact cosine lighting.
- The lightmap is drawn from the baked copy of each mesh's geometry. A mesh whose LOD differs from level 0 by more than a few centimeters at a pixel loses its baked light there.
Engine sources
This page describes behavior implemented in these files of the engine repository, checked against commit 65e34cc4a.
- Engine/Source/Gameplay/SceneRenderer/Api/Renderer/LightmapScene.h
- Engine/Source/Assets/AssetFormats/Api/AssetFormats/LightmapFormat.h
- Engine/Source/Assets/AssetFormats/Api/AssetFormats/LightmapAtlasPacker.h
- Engine/Source/Gameplay/SceneTypes/Api/Renderer/SceneEnvironment.h
- Engine/Source/Assets/AssetFormats/Api/AssetFormats/LightmapBakeTypes.h
- Engine/Source/Gameplay/SceneRenderer/Api/Renderer/BakedProbeVolumeScene.h
- Engine/Features/LightmapBaker/Api/LightmapBaker/BakedProbeVolumeComponent.h
- Engine/Source/Assets/AssetFormats/Api/AssetFormats/BakedProbeVolumeFormat.h