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(cook): a cutout texture has its colour carried into its clear texels, so a leaf has no pale edge
yhhfcf3c9fab9e6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0b1a73800..fba643897 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -62,6 +62,7 @@ published separately; it ships inside the editor.### Fixed+- **A leaf or a blade of grass no longer has a pale edge.** A cutout texture (one with a Mip Coverage) has the colour of its solid texels carried into its clear ones when it is cooked, as a model's cutouts already did: what an artist leaves under alpha 0, often white, was averaged in at every leaf's edge by the filter and the mips. The source image is not touched.- **A world's layers over an area are counted over the area.** The chunks of a procedural layer are walked over the part of the wanted radius that lies in the layer's extent, not over the whole radius, and a generated world on an area of terrain takes the terrain's bounds as its extent: a layer wanted a thousand chunk-widths out no longer costs seconds a frame.- **A level-of-detail group with only a cull size is no longer ignored.** A `LODGroup` with no stand-in mesh and a `cullSize` draws the renderer's own mesh while it is big enough and nothing once it is smaller, where it used to be dropped as if it were not there, so a tuft of grass had no distance to be drawn to.- **A river runs into a lake cleanly, and water casts no shadow.** A river whose spline ran on into a lake drew a bright seam across the lake's bed: the surface was drawn into the sun's shadow map, darkening everything under it but where the river's heights changed its shape. Water no longer stands in the light's way (`MeshRenderer.castShadows`, new and on by default, says whether a mesh does), a lake now holds the water over a river that runs into it, and the surf's slope fades out on the ridge between two shores instead of flipping on a line.diff --git a/pipeline/src/assets/textureCook.ts b/pipeline/src/assets/textureCook.tsindex 2e5dcc1de..5c46b7d67 100644--- a/pipeline/src/assets/textureCook.ts+++ b/pipeline/src/assets/textureCook.ts@@ -14,6 +14,7 @@ import {decideTextureCook, cookIntentDefeated, explainTextureCook, downscaledSize,type TextureCookDecision,} from './textureCookDecision';+import { bleedCutoutColor } from './modelImages';import { halveRgba, joinMipLevels, alphaCoverage, preserveAlphaCoverage } from './ktx2Mips';import { cookCachedAt, cookCacheFile, cookCacheHitAt, encoderIdentity } from './cookCache';@@ -163,9 +164,14 @@ export async function cookTexture(input: TextureCookInput): Promise<TextureCookOif (cook.reason === 'not-raster') defeatedByFormat = true;else warnings.push(`${path}: ${explainTextureCook(cook, size)}`);}+ // A cutout (one that asks for its coverage kept) has the colour of its solid texels carried into its clear ones, as a model's cutouts do: what a+ // painter leaves under alpha 0 is a mip's, and a filter's, to average in with the leaf, and the edge of every leaf shows it as a halo.+ const cutout = raster && tex.mipmaps && tex.mipCoverage > 0;+ const bled = (image: { rgba: Uint8Array; width: number; height: number }) =>+ cutout ? { ...image, rgba: bleedCutoutColor({ width: image.width, height: image.height, rgba: image.rgba }) } : image;// A texture that ships as an image ships the shrunk one.- if (cook.selected === 'raw' && scaled) {- const image = scaledImage();+ if (cook.selected === 'raw' && (scaled || cutout)) {+ const image = bled(scaled ? scaledImage() : decodePngImage(path, data));data = encodeRgbaPng(image.width, image.height, image.rgba);}if (cook.selected !== 'raw') {@@ -183,9 +189,9 @@ export async function cookTexture(input: TextureCookInput): Promise<TextureCookOconst supercompress = mode === 'uastc';const key = [source, JSON.stringify({ mode, srgb: tex.srgb, maxSize: tex.maxSize, scaled: scaled ? [size!.width, size!.height] : null,// `chain: 3` marks the rescaled chain that replaced the share-of-coverage one (chain 2): an entry cooked before it is re-encoded.- ...(coverage ? { mipCoverage: coverage, chain: 3 } : {}), ...(supercompress ? { supercompress } : {}), ...mips }), input.encoder!.id];+ ...(coverage ? { mipCoverage: coverage, chain: 3 } : {}), ...(cutout ? { bleed: 1 } : {}), ...(supercompress ? { supercompress } : {}), ...mips }), input.encoder!.id];const produce = (): Promise<Uint8Array> => {- const image = scaled ? scaledImage() : null;+ const image = scaled ? bled(scaledImage()) : cutout ? bled(decodePngImage(path, source)) : null;return coverage? encodeCoverageChain(enc, image ?? decodePngImage(path, source), tex.srgb, coverage): imagediff --git a/pipeline/tests/texture-cook.test.ts b/pipeline/tests/texture-cook.test.tsindex a050150a9..7d82538ea 100644--- a/pipeline/tests/texture-cook.test.ts+++ b/pipeline/tests/texture-cook.test.ts@@ -13,6 +13,7 @@ import { cookTexture, loadTextureEncoder } from '../src/assets/textureCook';import { cookAssets } from '../src/assets/cookAssets';import { readKtx2Layout } from '../src/assets/ktx2Mips';import { noisePng, solidPng } from './fixtures/solidPng.mjs';+import { decodePngImage, encodeRgbaPng } from '../src/assets/atlasPacker';describe('a texture compressed for the editor', () => {it('is pending until compressed, then answered from the cache a build reads', async () => {@@ -125,6 +126,27 @@ describe('a texture compressed for the editor', () => {}, 60_000);});+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.+ const rgba = new Uint8Array(8 * 8 * 4);+ for (let i = 0; i < 64; i++) rgba.set(i % 8 < 4 ? [20, 160, 30, 255] : [255, 255, 255, 0], i * 4);+ const png = encodeRgbaPng(8, 8, rgba);+ const cook = (importer: Record<string, unknown>) => cookTexture({+ root: '.', path: 'leaf.png', data: new Uint8Array(png), ext: '.png', importer, encoder: null,+ compressTextures: false, atlasTextures: false, drawnIn3D: true,+ });+ const cutout = await cook({ compress: false, mipmaps: true, mipCoverage: 0.5 });+ expect(cutout.ext).toBe('.png');+ const out = decodePngImage('leaf.png', cutout.data);+ // A clear texel beside the leaf is green and still clear; a solid one is exactly as it was.+ expect([...out.rgba.slice(5 * 4, 5 * 4 + 4)]).toEqual([20, 160, 30, 0]);+ expect([...out.rgba.slice(0, 4)]).toEqual([20, 160, 30, 255]);+ const plain = await cook({ compress: false, mipmaps: true });+ expect(Buffer.from(plain.data).equals(Buffer.from(png))).toBe(true);+ });+});+describe('a UASTC texture the cook ships', () => {it('is zstd-supercompressed, smaller than plain UASTC, and decodes to the same pixels', async () => {const r = mkdtempSync(path.join(tmpdir(), 'estella-texcook-zstd-'));diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 642dbc2f8..ad7ecb4e9 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -2836,6 +2836,8 @@ export const NOTED = {{"note":"A generated world's plants."},"feat(examples): Terrain & Water stones sit on the slope they stand on":{"note":"A generated world's plants."},+ "fix(cook): a cutout texture has its colour carried into its clear texels, so a leaf has no pale edge":+ {"note":"A leaf or a blade of grass no longer has a pale edge."},"feat(water): two tiled, scrolling detail normal maps give the surface its sparkle":{"note":"Sparkle on the water."},"fix(lod): a LODGroup with only a cull size is no longer ignored":