Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(bake): a coloured light bakes the colour it lights with

esenginef34749e5053e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6840f836e..5ff48da17 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ published separately; it ships inside the editor.
- **A shipped game samples normal maps and roughness maps as data.** The engine's own upload — a web export, a mini-game, a native build, the editor's Play — made every image an sRGB colour texture in a linear project whatever its import settings said, so every normal map was bent (a flat one by about fifty degrees) and every packed occlusion, roughness and metal map gamma-darkened, while the editor's viewport, which uploads through its own path, looked right. ORCA Bistro's Vespa came out as dark chrome in an exported game and blue in the editor. Khronos's NormalTangentTest now draws each normal-mapped bump as its geometric twin does.
- Normal maps stay on up close. The tangent frame taken from screen derivatives was refused below a fixed size, which shrinks with the fourth power of distance and scale, so in a metre-scale scene a surface a few metres from the camera silently lost its normal map.
+- A coloured light bakes the colour it lights with. In a linear project the frame linearizes a light's colour and the bake took it as written, so a warm sun baked a paler, pinker bounce than the one it cast in real time.
- The editor stays responsive while it bakes. The solve ran on the main process, so a bake of minutes left the window and the automation surface unanswered until it finished; it runs on a worker thread now.
## [0.75.0] - 2026-09-27
diff --git a/desktop b/desktop
index 660cd0cff..cb04bc37a 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 660cd0cff190a3dd566e3dbc4826812ec7fabf39
+Subproject commit cb04bc37aa4f52ed7c91aa86249e04a41f29dc16
diff --git a/pipeline/bin/estella.mjs b/pipeline/bin/estella.mjs
index 78974e6c1..d985aeca3 100644
--- a/pipeline/bin/estella.mjs
+++ b/pipeline/bin/estella.mjs
@@ -218,6 +218,12 @@ async function bakeScene(baker, meta, sceneFile, check) {
// Where an asset ref resolves to. Not relative to the SCENE: a ref is what the
// project's asset browser shows, and the editor resolves it against the root.
const projectRoot = bakeProjectRoot(sceneFile);
+ // The frame lights with the colour linearized in a linear project; so must the bake.
+ let linearColor = false;
+ try {
+ const manifest = JSON.parse(readFileSync(path.join(projectRoot, 'project.esproject'), 'utf8'));
+ linearColor = manifest.features?.rendering?.colorSpace === 'linear';
+ } catch { /* no project: the gamma pipeline, as the runtime defaults to */ }
const byUuid = bakeAssetIndex(projectRoot);
const resolveRef = (ref) => {
if (typeof ref !== 'string' || ref === '') return '';
@@ -314,7 +320,7 @@ async function bakeScene(baker, meta, sceneFile, check) {
}
const p = bakeVec(tf.position, BAKE_ZERO);
const made = baker.bakeLightOf(light.data, [p.x, p.y, p.z],
- bakeVec(tf.rotation, BAKE_IDENTITY_Q));
+ bakeVec(tf.rotation, BAKE_IDENTITY_Q), linearColor);
if (made?.lamp) lights.push(made.lamp);
else if (made?.ambient) {
ambient[0] += made.ambient[0];
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index b2f06af46..52b84abcc 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -10059,7 +10059,7 @@ AudioPlugin
## bakeLightOf — function @experimental
```
-(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }): BakeLightContribution | null
+(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }, linearColor?: boolean): BakeLightContribution | null
```
## bakeLightmap — function @experimental
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index a9b99503e..f641a434b 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -10275,7 +10275,7 @@ AudioPlugin
## bakeLightOf — function @experimental
```
-(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }): BakeLightContribution | null
+(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }, linearColor?: boolean): BakeLightContribution | null
```
## bakeLightmap — function @experimental
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index b47fd1038..d141fee67 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -10054,7 +10054,7 @@ AudioPlugin
## bakeLightOf — function @experimental
```
-(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }): BakeLightContribution | null
+(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }, linearColor?: boolean): BakeLightContribution | null
```
## bakeLightmap — function @experimental
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 24c8eee3b..3125691b3 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -10330,7 +10330,7 @@ AudioPlugin
## bakeLightOf — function @experimental
```
-(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }): BakeLightContribution | null
+(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }, linearColor?: boolean): BakeLightContribution | null
```
## bakeLightmap — function @experimental
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index e6b1b8869..06a26ed5d 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -10085,7 +10085,7 @@ AudioPlugin
## bakeLightOf — function @experimental
```
-(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }): BakeLightContribution | null
+(authored: AuthoredLight | undefined, position: readonly [number, number, number], rotation: { x: number; y: number; z: number; w: number; }, linearColor?: boolean): BakeLightContribution | null
```
## bakeLightmap — function @experimental
diff --git a/sdk/src/lightmap/lights.ts b/sdk/src/lightmap/lights.ts
index 86a316c53..1e5066dba 100644
--- a/sdk/src/lightmap/lights.ts
+++ b/sdk/src/lightmap/lights.ts
@@ -45,7 +45,8 @@ export function bakeLightForward(q: { x: number; y: number; z: number; w: number
*/
export function bakeLightOf(authored: AuthoredLight | undefined,
position: readonly [number, number, number],
- rotation: { x: number; y: number; z: number; w: number }):
+ rotation: { x: number; y: number; z: number; w: number },
+ linearColor = false):
BakeLightContribution | null {
const meta = COMPONENT_META['Light'];
const v = { ...(meta?.defaults as AuthoredLight | undefined),
@@ -54,7 +55,12 @@ export function bakeLightOf(authored: AuthoredLight | undefined,
const intensity = v.intensity ?? 1;
if (v.enabled === false || !(intensity > 0)) return null;
- const rgb: [number, number, number] = [v.color?.r ?? 1, v.color?.g ?? 1, v.color?.b ?? 1];
+ // A linear project lights with the colour linearized, as the frame does; a
+ // bake that took it as written would tint its light apart from the frame's.
+ const channel = (c: number): number => (!linearColor ? c
+ : c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
+ const rgb: [number, number, number] = [channel(v.color?.r ?? 1), channel(v.color?.g ?? 1),
+ channel(v.color?.b ?? 1)];
if ((v.type ?? 0) === LightType.Ambient) {
return { ambient: [rgb[0] * intensity, rgb[1] * intensity, rgb[2] * intensity] };
}
diff --git a/sdk/tests/lightmap-lights.test.ts b/sdk/tests/lightmap-lights.test.ts
new file mode 100644
index 000000000..16aef0210
--- /dev/null
+++ b/sdk/tests/lightmap-lights.test.ts
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file A light's colour reaches a bake as the frame lights with it: linearized
+ * in a linear project, as written in a gamma one.
+ */
+import { describe, it, expect } from 'vitest';
+import { bakeLightOf } from '../src/lightmap';
+
+const GREY = { type: 1, color: { r: 0.5, g: 0.5, b: 0.5, a: 1 }, intensity: 2 };
+const AT: [number, number, number] = [0, 0, 0];
+const FACING = { x: 0, y: 0, z: 0, w: 1 };
+
+describe('a baked light\'s colour', () => {
+ it('is linearized in a linear project, as the frame does', () => {
+ expect(bakeLightOf(GREY, AT, FACING, true)?.lamp?.color[0]).toBeCloseTo(0.21404, 4);
+ expect(bakeLightOf({ ...GREY, type: 2 }, AT, FACING, true)?.ambient?.[0]).toBeCloseTo(0.42808, 4);
+ });
+
+ it('is taken as written in a gamma project', () => {
+ expect(bakeLightOf(GREY, AT, FACING, false)?.lamp?.color[0]).toBe(0.5);
+ });
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 2ee672b1e..a2c8d8b86 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1278,6 +1278,10 @@ export const NOTED = {
{ note: 'The editor stays responsive while it bakes' },
'feat(bake): baked light is a lit surface\'s indirect light':
{ note: 'Baked light is a lit surface\'s indirect light' },
+ 'fix(bake): a coloured light bakes the colour it lights with':
+ { note: 'A coloured light bakes the colour it lights with' },
+ 'fix(bake): the collector bakes lights in the project\'s colour space':
+ { note: 'A coloured light bakes the colour it lights with' },
'fix(bake): texels on an edge two triangles share are not an overlap':
{ note: 'A model whose second UV set cannot be baked into' },
'fix(eht): the generator writes LF on every platform':