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(export): a 16-bit PNG ships as the file it is - a build shrank a 4096 heightmap to 2048 and decoded it to 8 bits, so exported ground stood in 256 steps where the editor drew 65536
yhh85dceb6c7d6c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 64243e35c..e1500aec1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,10 @@ published separately; it ships inside the editor.## [Unreleased]+### Fixed++- **A 16-bit heightmap keeps its depth and size in a build.** A texture is capped at its Max Size (2048 unless set) when a build cooks it, and the cap decodes a PNG to 8 bits a channel on the way. A `Terrain` heightmap of 4096 samples and 16 bits therefore shipped as 2048 samples of 256 steps: the exported ground was terraced and coarser than the same ground in the editor, which reads the file itself, and nothing said so. A PNG that holds 16 bits a channel now ships byte for byte.+## [0.103.0] - 2026-11-12### Addeddiff --git a/pipeline/src/assets/textureCook.ts b/pipeline/src/assets/textureCook.tsindex 9fe8df01e..e339ba5c3 100644--- a/pipeline/src/assets/textureCook.ts+++ b/pipeline/src/assets/textureCook.ts@@ -148,6 +148,11 @@ function looksPremultiplied(rgba: Uint8Array): boolean {return partial;}+/** Bits a channel a PNG holds (1 to 16), from its header; 8 for anything that is not a PNG. */+export function pngBitDepth(png: Uint8Array): number {+ return png.byteLength > 24 && png[1] === 0x50 && png[2] === 0x4e && png[3] === 0x47 ? png[24]! : 8;+}+function safePngDimensions(png: Uint8Array): { width: number; height: number } | null {try {return pngDimensions(png);@@ -210,6 +215,15 @@ export async function cookTexture(input: TextureCookInput): Promise<TextureCookO// maxSize downscale first — it applies even when a texture opts OUT of// compression (a huge UI sprite can ship as a smaller raw PNG), and the// ENCODED size is what block alignment is judged on.+ // A PNG of 16 bits a channel is numbers, not a picture: a heightmap, a field of measured values. Shrinking, filling and encoding all+ // decode to 8 bits first, so a build would ship 256 steps where the file holds 65536, a size smaller, and say nothing. It ships as it is.+ if (raster && pngBitDepth(data) === 16) {+ const cook = decideTextureCook({+ compressTextures: input.compressTextures, atlasTextures: input.atlasTextures, inAtlas: false, raster,+ compress: 'off', drawnIn3D: input.drawnIn3D, format: tex.format, size: safePngDimensions(data),+ });+ return { data, ext, cook, warnings, defeatedByFormat: false };+ }const sourceSize = raster ? safePngDimensions(data) : null;const scaled = !!((textureEnc || input.resizeTextures) && sourceSize && tex.maxSize > 0 &&tex.maxSize < Math.max(sourceSize.width, sourceSize.height));diff --git a/pipeline/tests/texture-cook.test.ts b/pipeline/tests/texture-cook.test.tsindex dc910d3aa..a18c90f2c 100644--- a/pipeline/tests/texture-cook.test.ts+++ b/pipeline/tests/texture-cook.test.ts@@ -131,6 +131,34 @@ describe('a texture compressed for the editor', () => {}, 60_000);});+describe('a PNG of 16 bits a channel', () => {+ it('ships as the file it is, whatever its size and settings: every other path would decode it to 8 bits', async () => {+ const root = mkdtempSync(path.join(tmpdir(), 'estella-png16-'));+ try {+ // A 16-bit grey PNG, 4 x 4, written by hand: the IHDR says depth 16, and the cook must not look further than that.+ const { deflateSync, crc32 } = await import('node:zlib');+ const chunk = (type: string, body: Buffer): Buffer => {+ const head = Buffer.alloc(8); head.writeUInt32BE(body.length, 0); head.write(type, 4, 'latin1');+ const tail = Buffer.alloc(4); tail.writeUInt32BE(crc32(Buffer.concat([head.subarray(4), body])) >>> 0, 0);+ return Buffer.concat([head, body, tail]);+ };+ const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(4096, 0); ihdr.writeUInt32BE(4, 4); ihdr[8] = 16; ihdr[9] = 0;+ const rows = Buffer.alloc(4 * (1 + 4096 * 2));+ for (let i = 0; i < rows.length; i++) rows[i] = i % (1 + 4096 * 2) === 0 ? 0 : (i * 37) & 255;+ const png = Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk('IHDR', ihdr), chunk('IDAT', deflateSync(rows)), chunk('IEND', Buffer.alloc(0))]);+ const out = await cookTexture({+ root, path: 'assets/height.png', data: png, ext: '.png', platform: 'web', importer: { maxSize: 2048 },+ compressTextures: true, atlasTextures: false, resizeTextures: true, drawnIn3D: true, encoder: null,+ } as Parameters<typeof cookTexture>[0]);+ expect(out.ext).toBe('.png');+ expect(Buffer.from(out.data).equals(png)).toBe(true);+ expect(out.cook.selected).toBe('raw');+ } finally {+ rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });+ }+ });+});+describe('a cutout texture the cook ships', () => {it('has the colour of its solid texels carried into its clear ones, and a texture that is no cutout keeps what is under its alpha', async () => {// Green on the left, and white under alpha 0 on the right: the white a mip would average in at the leaf's edge.diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 935105a20..a755eada8 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -4508,4 +4508,6 @@ export const NOTED = {{"note": "A wall under a roof is no longer sunlit along its top."},"feat(settings): a row for the cheaper dynamic GI, per quality level":{"note": "A quality level decides what the dynamic GI spends."},+ "fix(export): a 16-bit PNG ships as the file it is - a build shrank a 4096 heightmap to 2048 and decoded it to 8 bits, so exported ground stood in 256 steps where the editor drew 65536":+ {"note": "A 16-bit heightmap keeps its depth and size in a build."},};