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(pipeline): a fully opaque texture keeps its alpha through the mip chain, so a cutout material on it no longer vanishes at a distance
yhh430e10a9a520
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 925361546..97f2384d7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -48,6 +48,7 @@ published separately; it ships inside the editor.### Fixed+- **Opaque textures under a cutout material.** A texture whose alpha is fully opaque, used by a cutout material (a hair material or any alpha-cutoff one), no longer vanishes once it is minified. Coverage-preserving mip levels were scaling its alpha down onto the cutoff, so every level past the first was discarded; a level that already reaches the share it must keep is now left alone.- **Shadow program for a normal-mapped mesh with tangents.** A model with tangents and a normal map no longer stops its shadow program from linking when the sun casts shadows. The depth pass wrote no tangent varying while the fragment stage still read one, so the shader failed on WebGL2 and the logged error named no material; the depth variant now leaves the tangent frame out.- **Selection outline across a plane.** The selection outline of a mesh no longer draws a stray line across a large plane seen from close by: a triangle with a corner behind the camera was judged by a different rule than its neighbour, so their shared diagonal showed as an edge.- **Normal maps read against the frame they were baked in.** Imported meshes now carry a tangent at each vertex (a glTF's own direction, or one made from the UVs), and normal maps on them are read against that frame instead of one derived per pixel, which was wrong at UV seams and on stretched textures. Re-import a model to get them; one imported before keeps its old shading. A mesh whose vertices carry a tangent is drawn with an extra vertex attribute and one more varying; a shader of your own that calls `perturbNormal` picks the frame up with no change.diff --git a/pipeline/src/assets/ktx2Mips.ts b/pipeline/src/assets/ktx2Mips.tsindex 9a2931c62..566a8e43d 100644--- a/pipeline/src/assets/ktx2Mips.ts+++ b/pipeline/src/assets/ktx2Mips.ts@@ -94,10 +94,12 @@ export function alphaCoverage(rgba: Uint8Array, cutoff: number, scale = 1): numb/*** Scale @p rgba's alpha in place so the share of texels at or above @p cutoff is* @p coverage — what a mip level of a cutout needs, or averaging thins it level by- * level until distant foliage has no leaves. The scale is found by bisection.+ * level until distant foliage has no leaves. The scale is found by bisection. Only ever scales up: a level that already reaches the share is+ * left alone, because for a fully opaque image the smallest scale that still reaches 100% is the cutoff itself, which would bring every texel's alpha down onto it.*/export function preserveAlphaCoverage(rgba: Uint8Array, cutoff: number, coverage: number): void {- let lo = 0, hi = 4;+ if (alphaCoverage(rgba, cutoff) >= coverage) return;+ let lo = 1, hi = 4;for (let i = 0; i < 20; i++) {const mid = (lo + hi) / 2;if (alphaCoverage(rgba, cutoff, mid) < coverage) lo = mid; else hi = mid;diff --git a/pipeline/tests/ktx2-mips.test.ts b/pipeline/tests/ktx2-mips.test.tsindex 80f916648..1db6b2e5a 100644--- a/pipeline/tests/ktx2-mips.test.ts+++ b/pipeline/tests/ktx2-mips.test.ts@@ -127,6 +127,13 @@ describe('a cutout\'s mips keep its coverage', () => {expect(alphaCoverage(half.rgba, 0.5)).toBeGreaterThanOrEqual(0.25);});+ it('leaves the alpha of a fully opaque image alone, so a cutout material on it still draws at every level', () => {+ const opaque = new Uint8Array(8 * 8 * 4).fill(255);+ const half = halveRgba(opaque, 8, 8, false);+ preserveAlphaCoverage(half.rgba, 0.45, alphaCoverage(opaque, 0.45));+ for (let i = 3; i < half.rgba.length; i += 4) expect(half.rgba[i]).toBe(255);+ });+it('joins single levels into one chain, and refuses a level of the wrong size', async () => {const at = async (side: number) => enc.encodeToKtx2({ type: enc.ImageType.RGBA, data: leaves(side), width: side, height: side },{ mode: 'uastc', mipmaps: false });diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex ec29ae95d..195318a03 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -42,6 +42,8 @@ export const NOTED = {'fix(render): a mesh with tangents and a normal map links its shadow program when the sun casts shadows':{"note":"A model with tangents and a normal map no longer stops its shadow program from linking when the sun casts shadows. The depth pass wrote no tangent varying while the fragment stage still read one, so the shader failed on WebGL2 and the logged error named no material; the depth variant now leaves the tangent frame out."},'fix(editor): the spring-bone note uses the inset token, and a model import passes the Spring Bones setting through': { internal: 'A theme token for a line of Details and the import setting passed through to the importer, both inside the spring-bone work that has its own notes.' },+ 'fix(pipeline): a fully opaque texture keeps its alpha through the mip chain, so a cutout material on it no longer vanishes at a distance':+ {"note":"A texture whose alpha is fully opaque, used by a cutout material (a hair material or any alpha-cutoff one), no longer vanishes once it is minified. Coverage-preserving mip levels were scaling its alpha down onto the cutoff, so every level past the first was discarded; a level that already reaches the share it must keep is now left alone."},'fix: serialize binaryen optimization on windows': { internal: 'Uses one optimizer worker after wider builds reproduced heap corruption with four; release optimization flags stay unchanged.' },'feat: add budgeted 2d and 3d particle scene collisions': { note: 'Budgeted particle scene collisions.' },'feat(editor): add particle collision authoring and diagnostics': { note: 'Budgeted particle scene collisions.' },