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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(bake): a baked atlas ships at the size it was baked
esengineeb92961e64e7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b42c26072..92c69bb46 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,8 @@ published separately; it ships inside the editor.### Fixed+- **A baked atlas ships at the size it was baked.** Its import settings took the texture default of a 2048 cap, so a 4096 bake was halved on export and each object's light ran into its neighbours'. A bake now owns the atlas's import settings — linear, uncompressed, clamped, and never capped below the atlas — and puts them back on every bake, keeping the file's id.+- **Baked light lands where it was baked.** The atlas file was written with its first texel row on top, and the engine uploads a picture bottom-up, so every surface read its light from the mirror-image place in the atlas — mostly empty, so a lit surface in shadow went near black and showed only its reflection of the sky. ORCA Bistro's awnings in the shade came out grey and its hedges blue-black; now they are red and green. A bake now writes its file bottom-up, and a gate draws an atlas that differs only by row the way a shipped game loads it. Rebake a scene to pick it up.- **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.diff --git a/desktop b/desktopindex 268f92b08..ab0d05c64 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 268f92b0879c71b318c90c8b2f3fba9410c99019+Subproject commit ab0d05c649aca17059f9fafddfd001d8a6691d5ediff --git a/pipeline/bin/estella.mjs b/pipeline/bin/estella.mjsindex 3776454c0..3eb300ef5 100644--- a/pipeline/bin/estella.mjs+++ b/pipeline/bin/estella.mjs@@ -483,6 +483,7 @@ async function bakeScene(baker, meta, sceneFile, check) {}writeFileSync(atlasFile, result.atlasBytes);+ await baker.claimLightmapImage(atlasFile, result.size);for (const g of grids.values()) writeFileSync(path.join(sceneDir, g.name), g.text);if (reflectionText) {writeFileSync(reflectionFile, result.reflection.atlasBytes);diff --git a/pipeline/src/assets/lightmapBake.ts b/pipeline/src/assets/lightmapBake.tsindex a3122b3a3..33a49bbed 100644--- a/pipeline/src/assets/lightmapBake.ts+++ b/pipeline/src/assets/lightmapBake.ts@@ -9,11 +9,14 @@* the world the transforms come from, and this holds the meshes they name.*/import { readFileSync } from 'node:fs';+import { readFile, writeFile } from 'node:fs/promises';import { PNG } from 'pngjs';import { bakeLightmapSteps, bakeRunner, lightmapImage, decodeMesh, unwrapLightmapUV, builtinMeshTemplate, MeshChannel,type MeshData, type BakeSurface, type BakeLight, type BakeOptions,type BakeStep, type CapturedPanorama, type ProbeGrid } from 'esengine';import { encodeRgbaPng } from './png';+import { adoptOrphan } from './assetMeta';+import { META_EXT } from './contentPolicy';export { BakeKernelExecutor } from './lightmapKernel';import { bakeSceneReflections, bakeSky, irradianceSky, type BakeEnvironment,@@ -158,6 +161,24 @@ function builtinGeometry(ref: string, cache: Map<string, MeshData | null>): Meshreturn cache.get(ref) ?? null;}+/**+ * The import settings a bake owns on its atlas, reapplied every bake (uuid kept):+ * irradiance, so neither sRGB nor block-compressed; clamped, so a chart's edge+ * cannot wrap; and never downscaled — that bleeds each patch into its neighbours'.+ */+export async function claimLightmapImage(absFile: string, size: number): Promise<void> {+ const owned = { sRGB: false, compress: false, wrapMode: 'clamp' };+ if (await adoptOrphan(absFile, { ...owned, maxSize: Math.max(2048, size) }) !== 'has-meta') return;+ const metaFile = absFile + META_EXT;+ const meta = JSON.parse(await readFile(metaFile, 'utf8')) as { importer?: Record<string, unknown> };+ const importer = meta.importer ?? {};+ const cap = typeof importer.maxSize === 'number' ? importer.maxSize : 2048;+ const next = { ...importer, ...owned, maxSize: Math.max(cap, size) };+ if (JSON.stringify(next) === JSON.stringify(importer)) return;+ meta.importer = next;+ await writeFile(metaFile, JSON.stringify(meta, null, 2) + '\n');+}+/** sRGB to linear per byte value. A texture stores what a screen shows, and an* average taken before this is decoded is brighter than the surface is. */export const TO_LINEAR = Float64Array.from({ length: 256 }, (_, v) => {diff --git a/pipeline/tests/lightmap-bake.test.ts b/pipeline/tests/lightmap-bake.test.tsindex fa68bacbe..fc9daed28 100644--- a/pipeline/tests/lightmap-bake.test.ts+++ b/pipeline/tests/lightmap-bake.test.ts@@ -8,12 +8,12 @@* (an import setting, then a reimport) is one only the author can apply.*/import { describe, it, expect, beforeAll, afterAll } from 'vitest';-import { mkdtemp, rm, writeFile } from 'node:fs/promises';+import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';import { tmpdir } from 'node:os';import path from 'node:path';import { encodeMesh, unwrapLightmapUV, decodeLightmap, MeshChannel, MeshChannelType,type MeshData, type BakeLight } from 'esengine';-import { bakeSceneLightmap, type SceneBakeSurface } from '../src/assets/lightmapBake';+import { bakeSceneLightmap, claimLightmapImage, type SceneBakeSurface } from '../src/assets/lightmapBake';import { encodeRgbaPng } from '../src/assets/png';import { decodeRgbaPng } from '../src/assets/tilesetExtrude';@@ -240,3 +240,24 @@ describe('baking a scene', () => {expect(result.size).toBe(128);});});++describe('the atlas file a bake writes', () => {+ it('is imported as irradiance at full size, on its first bake and every one after', async () => {+ const png = path.join(dir, 'claimed_lightmap.png');+ await writeFile(png, encodeRgbaPng(1, 1, new Uint8Array([0, 0, 0, 255])));+ const meta = async () => JSON.parse(await readFile(`${png}.meta`, 'utf8'));++ await claimLightmapImage(png, 1024);+ const first = await meta();+ expect(first.importer).toMatchObject({ sRGB: false, compress: false, wrapMode: 'clamp', maxSize: 2048 });++ await writeFile(`${png}.meta`, JSON.stringify({ ...first, importer: { ...first.importer, sRGB: true, maxSize: 1024 } }));+ await claimLightmapImage(png, 4096);+ const grown = await meta();+ expect(grown.uuid).toBe(first.uuid);+ expect(grown.importer).toMatchObject({ sRGB: false, maxSize: 4096 });++ await claimLightmapImage(png, 1024);+ expect((await meta()).importer.maxSize).toBe(4096);+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 31cc41856..4eba334a9 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1292,6 +1292,10 @@ export const NOTED = {{ note: 'A bake uses every core, in C++' },'fix(bake): a baked atlas is read the way up it was baked':{ note: 'Baked light lands where it was baked' },+ 'fix(bake): a baked atlas ships at the size it was baked':+ { note: 'A baked atlas ships at the size it was baked' },+ 'fix(bake): the editor\'s atlas takes the import settings a bake owns':+ { note: 'A baked atlas ships at the size it was baked' },'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 reads the colour space from the engine host':