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): an atlas's import settings are the bake's, and --check holds them

esengine624c08b3d0ec
diff --git a/examples/physics-3d/assets/scenes/main_lightmap.png.meta b/examples/physics-3d/assets/scenes/main_lightmap.png.meta
index eb4a34aad..f44e230b8 100644
--- a/examples/physics-3d/assets/scenes/main_lightmap.png.meta
+++ b/examples/physics-3d/assets/scenes/main_lightmap.png.meta
@@ -5,13 +5,15 @@
"importer": {
"maxSize": 2048,
"filterMode": "linear",
- "wrapMode": "repeat",
+ "wrapMode": "clamp",
"premultiplyAlpha": false,
"sliceBorder": {
"left": 0,
"right": 0,
"top": 0,
"bottom": 0
- }
+ },
+ "sRGB": false,
+ "compress": "off"
}
}
diff --git a/pipeline/bin/estella.mjs b/pipeline/bin/estella.mjs
index 7ba7e85ce..246c53f59 100644
--- a/pipeline/bin/estella.mjs
+++ b/pipeline/bin/estella.mjs
@@ -462,6 +462,13 @@ async function bakeScene(baker, meta, sceneFile, check) {
if (check) {
const staleAtlas = !existsSync(atlasFile)
|| Buffer.compare(readFileSync(atlasFile), Buffer.from(result.atlasBytes)) !== 0;
+ // The atlas's import settings are the bake's too: an atlas decoded as sRGB, or
+ // block-compressed, draws other light than the one that was baked.
+ let staleSettings = false;
+ if (existsSync(`${atlasFile}.meta`)) {
+ const importer = JSON.parse(readFileSync(`${atlasFile}.meta`, 'utf8')).importer ?? {};
+ staleSettings = JSON.stringify(baker.claimedLightmapImporter(importer, result.size)) !== JSON.stringify(importer);
+ }
const staleScene = readFileSync(sceneFile, 'utf8') !== document;
const staleGrids = [...grids.values()].some((g) => {
const file = path.join(sceneDir, g.name);
@@ -473,8 +480,8 @@ async function bakeScene(baker, meta, sceneFile, check) {
Buffer.from(result.reflection.atlasBytes)) !== 0
|| !existsSync(reflectionDocFile)
|| readFileSync(reflectionDocFile, 'utf8') !== reflectionText);
- if (staleAtlas || staleScene || staleGrids || staleReflections) {
- const what = [staleAtlas && 'the atlas', staleScene && 'the scene',
+ if (staleAtlas || staleSettings || staleScene || staleGrids || staleReflections) {
+ const what = [staleAtlas && 'the atlas', staleSettings && "the atlas's import settings", staleScene && 'the scene',
staleGrids && 'a probe grid',
staleReflections && 'the reflections'].filter(Boolean).join(' and ');
console.error(`bake-scene: ${rel} is not what a bake of it produces (${what} differ).`);
@@ -497,7 +504,7 @@ async function bakeScene(baker, meta, sceneFile, check) {
// An RGBM encoding of radiance, the three settings an HDR import gives its own
// atlas. Adopted here because this bake IS this file's importer, and a default
// meta would linearize the multiplier and then compress it.
- await meta.adoptOrphan(reflectionFile, { sRGB: false, compress: false, wrapMode: 'clamp' });
+ await meta.adoptOrphan(reflectionFile, { sRGB: false, compress: 'off', wrapMode: 'clamp' });
await meta.adoptOrphan(reflectionDocFile);
}
writeFileSync(sceneFile, document);
diff --git a/pipeline/src/assets/environmentImport.ts b/pipeline/src/assets/environmentImport.ts
index 7bc6feb93..71049967e 100644
--- a/pipeline/src/assets/environmentImport.ts
+++ b/pipeline/src/assets/environmentImport.ts
@@ -84,7 +84,7 @@ export const ENV_SKY_MAX_WIDTH = 2048;
/** The `.meta` settings every image an environment import writes carries: RGBM
* radiance, not a picture — sRGB would linearize what is already linear, and a
* block compressor would quantize the shared multiplier with the colour. */
-export const ENV_IMAGE_SETTINGS = { sRGB: false, compress: false, wrapMode: 'clamp' } as const;
+export const ENV_IMAGE_SETTINGS = { sRGB: false, compress: 'off', wrapMode: 'clamp' } as const;
/** Radiance above this clips. Sky detail lives well below it; a sun disc does not,
* and is meant to survive as a bright blob rather than as its true thousands. */
diff --git a/pipeline/src/assets/lightmapBake.ts b/pipeline/src/assets/lightmapBake.ts
index 24bc6a80d..7278e15b2 100644
--- a/pipeline/src/assets/lightmapBake.ts
+++ b/pipeline/src/assets/lightmapBake.ts
@@ -161,19 +161,24 @@ function builtinGeometry(ref: string, cache: Map<string, MeshData | null>): Mesh
return cache.get(ref) ?? null;
}
+/** @p importer with the settings a bake owns on an atlas of @p size applied — what
+ * claimLightmapImage writes, and what `bake-scene --check` holds a `.meta` to. */
+export function claimedLightmapImporter(importer: Record<string, unknown>, size: number): Record<string, unknown> {
+ const cap = typeof importer.maxSize === 'number' ? importer.maxSize : 2048;
+ return { ...importer, sRGB: false, compress: 'off', wrapMode: 'clamp', maxSize: Math.max(cap, size) };
+}
+
/**
* 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;
+ if (await adoptOrphan(absFile, claimedLightmapImporter({}, 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) };
+ const next = claimedLightmapImporter(importer, size);
if (JSON.stringify(next) === JSON.stringify(importer)) return;
meta.importer = next;
await writeFile(metaFile, JSON.stringify(meta, null, 2) + '\n');
diff --git a/pipeline/tests/lightmap-bake.test.ts b/pipeline/tests/lightmap-bake.test.ts
index 73fa06546..06b6bda72 100644
--- a/pipeline/tests/lightmap-bake.test.ts
+++ b/pipeline/tests/lightmap-bake.test.ts
@@ -249,7 +249,7 @@ describe('the atlas file a bake writes', () => {
await claimLightmapImage(png, 1024);
const first = await meta();
- expect(first.importer).toMatchObject({ sRGB: false, compress: false, wrapMode: 'clamp', maxSize: 2048 });
+ expect(first.importer).toMatchObject({ sRGB: false, compress: 'off', wrapMode: 'clamp', maxSize: 2048 });
await writeFile(`${png}.meta`, JSON.stringify({ ...first, importer: { ...first.importer, sRGB: true, maxSize: 1024 } }));
await claimLightmapImage(png, 4096);