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): texels on an edge two triangles share are not an overlap
esengine61737f7588fa
diff --git a/sdk/src/lightmap/atlas.ts b/sdk/src/lightmap/atlas.tsindex 6413cc147..30fdf5ddd 100644--- a/sdk/src/lightmap/atlas.ts+++ b/sdk/src/lightmap/atlas.ts@@ -238,7 +238,8 @@ export function rasterizeLumels(surfaces: readonly BakeSurface[],if (w0 < 0 || w1 < 0 || w2 < 0) continue;const at = y * size + x;claimed++;- if (seen.has(at)) { taken++; continue; }+ // A centre on an edge the triangles share is one texel, not a second layer.+ if (seen.has(at)) { if (w0 > 1e-6 && w1 > 1e-6 && w2 > 1e-6) taken++; continue; }seen.add(at);for (let k = 0; k < 3; k++) {position.push(w0 * wp[k] + w1 * wp[3 + k] + w2 * wp[6 + k]);diff --git a/sdk/tests/lightmap-bake.test.ts b/sdk/tests/lightmap-bake.test.tsindex a7dea849c..352a89faf 100644--- a/sdk/tests/lightmap-bake.test.ts+++ b/sdk/tests/lightmap-bake.test.ts@@ -256,6 +256,34 @@ describe('a baked lightmap', () => {});});+/** A quad whose lightmap UVs fill their square corner to corner, split on the diagonal. */+function tile(): MeshData {+ const flat = floor(1);+ const stride = 32;+ const vertices = new Uint8Array(4 * stride);+ const src = new DataView(flat.vertices.buffer);+ const view = new DataView(vertices.buffer);+ const uv = [[0, 0], [1, 0], [1, 1], [0, 1]];+ for (let i = 0; i < 4; i++) {+ for (let k = 0; k < 6; k++) view.setFloat32(i * stride + k * 4, src.getFloat32(i * 24 + k * 4, true), true);+ view.setFloat32(i * stride + 24, uv[i][0], true);+ view.setFloat32(i * stride + 28, uv[i][1], true);+ }+ return {+ ...flat, vertices, vertexStride: stride,+ channels: [...flat.channels,+ { semantic: MeshChannel.TexCoord1, components: 2, type: MeshChannelType.Float32, offset: 24 }],+ };+}++describe('what a bake reports about a layout', () => {+ it('does not count texels on an edge two triangles share as laid twice', () => {+ // Three texels across: the diagonal runs through three of the nine centres.+ const result = bakeLightmap([{ mesh: tile(), transform: IDENTITY }], [], { ...LIT, texelsPerUnit: 1.5 });+ expect(result.shared[0]).toBe(0);+ });+});+describe('the indirect half of a bake', () => {it('lets the sky in only where it can see the sky', () => {// A roof half a unit over the middle of an open floor, and no lamp: whatdiff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex c27bbcb39..2ee672b1e 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1278,6 +1278,8 @@ export const NOTED = {{ note: 'The editor stays responsive while it bakes' },'feat(bake): baked light is a lit surface\'s indirect light':{ note: 'Baked light is a lit surface\'s indirect light' },+ 'fix(bake): texels on an edge two triangles share are not an overlap':+ { note: 'A model whose second UV set cannot be baked into' },'fix(eht): the generator writes LF on every platform':{ internal: 'The engine header tool is a repository generator; on Windows it rewrote every generated file with CRLF, which only a contributor there ever saw.' },};