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(text): a wide blurred shadow is one soft shape - a blur was always one ring of eight copies of the label at its own radius, which is a soft edge at two or three pixels and nine separate labels at eighteen: a title set large stood in blocks of dark squares; past three pixels the copies are as many rings as keep each within a stroke's thickness of its neighbours, sixty-four at the most
yhhbaab2a1065a1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ecd24b3b5..b0bd81874 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -33,6 +33,7 @@ published separately; it ships inside the editor.### Fixed+- **A wide blurred text shadow is one soft shape.** `Text.shadowBlur` was drawn as one ring of eight copies of the label at the blur's own radius, whatever that radius was. At two or three pixels that is a soft edge; at eighteen it is the label nine times over, fourteen pixels apart, and a title set large stood in blocks of dark squares round every stroke. Past three pixels a shadow is now as many rings of copies as keep each within a stroke's thickness of its neighbours (a share of the font size), sixty-four copies at the most, so it reads as one soft shape. A blur of three pixels or less is drawn as it was.- **A mesh scattered with no material keeps its own colours.** A `Foliage` field with no material is painted, since nothing reads the wind's weights then, and it painted every plant the stock green of grass from root to tip, whatever the mesh's own vertex colours said: a grey rock scattered along a shore came out a smooth green one, and a dark spruce a pale one. A mesh that has colours of its own is now painted in them, each plant a little lighter or darker by its shade; a mesh with no colour channel, or white throughout, is painted as before.- **A playable samples its textures as their import settings say.** A single-file playable was handed no manifest, which is the only way a texture's `.meta` reaches a package, so its wrap mode, its filter, whether it is colour and its 9-slice border were all lost and every texture took the defaults. A ground or a wall whose picture repeats then drew one copy of it and smeared its last row of pixels over everything past the first tile: cliffs came out one flat colour with level stripes along the waterline, while the same scene was right in the editor and in a web export. The settings of the textures a playable inlines now ride in the page and reach the runtime the way they reach every other package.- **Drawing a frame costs the CPU a third of what it did.** Issuing a frame's draws went through four costs the engine did not need. Every draw staged a light-probe block of its own, up to 16 KB of zeroes filled, copied and uploaded, though no probe lit it; a run no probe lights now reads the zero block. Every draw bound every texture unit its slots named, where the program it drew with read none of some (a shadow caster, most of all); a draw now binds only the units its program samples, read from the program once. The face to cull was set at every change of pipeline though it nearly never changed. And every vertex array bound asked the browser which index buffer it held, through a WebGL emulation (`FULL_ES3`) nothing in the engine used. Pipelines and other device objects are also found by index rather than searched for. On the Bistro scene at 640x360, where the CPU and not the GPU sets the pace, the renderer's CPU time a frame went from 11 to 14 ms down to 3.3 ms, the frame from 13.4 to 6.7 ms, and the WebGL calls a frame from 17,926 to 7,139; 52 pixel gates on WebGL2 and 23 on WebGPU draw what they did. `node tools/render-submit-cost.mjs` measures it: a synthetic grid in three spreads of material, or an example such as `--scene bistro`, with `--glcalls` and `--profile`.diff --git a/sdk/src/ui/text/text-renderer.ts b/sdk/src/ui/text/text-renderer.tsindex adef89ce2..01b9559e9 100644--- a/sdk/src/ui/text/text-renderer.ts+++ b/sdk/src/ui/text/text-renderer.ts@@ -112,6 +112,38 @@ const SHADOW_RING: ReadonlyArray<readonly [number, number, number]> = [[-0.55, 0.55, 1], [0, 0.78, 1], [0.55, 0.55, 1],];+/** The widest blur one ring of taps covers: past it its copies stand apart, and a shadow is the label eight times over. */+const SHADOW_RING_REACH = 3;+/** The most copies a blurred shadow is drawn as, however wide: each is the whole label again. */+const MOST_SHADOW_TAPS = 64;++/**+ * Where a blurred shadow's copies go, as offsets from the shadow's own place.+ *+ * A blur of a few pixels is one ring. A wider one is as many rings as keep each copy within a stroke's thickness of its neighbours+ * (a share of the font size, and never coarser than a quarter of the blur), so they read as one soft shape: a title set large with a+ * blur of eighteen pixels drew nine separate copies of itself fourteen pixels apart, blocks of dark squares round every stroke.+ */+export function shadowTaps(blur: number, fontSize: number): ReadonlyArray<readonly [number, number]> {+ if (blur <= SHADOW_RING_REACH) return SHADOW_RING.map(([x, y, r]) => [x * blur * r, y * blur * r] as const);+ const reach = blur * 0.78;+ let gap = Math.max(1.5, Math.min(blur / 4, fontSize * 0.07));+ const ringsOf = (g: number): number[] => {+ const rings = Math.max(1, Math.ceil(reach / g));+ return Array.from({ length: rings }, (_, k) => Math.max(6, Math.ceil((2 * Math.PI * reach * (k + 1) / rings) / g)));+ };+ let rings = ringsOf(gap);+ while (1 + rings.reduce((a, b) => a + b, 0) > MOST_SHADOW_TAPS) { gap *= 1.15; rings = ringsOf(gap); }+ const taps: [number, number][] = [[0, 0]];+ rings.forEach((count, k) => {+ const radius = reach * (k + 1) / rings.length;+ // Every other ring is turned half a step, so the copies of one do not line up with those of the next.+ const turn = (k % 2) * Math.PI / count;+ for (let i = 0; i < count; i++) taps.push([Math.cos(turn + 2 * Math.PI * i / count) * radius, Math.sin(turn + 2 * Math.PI * i / count) * radius]);+ });+ return taps;+}+/*** Per-tap alpha for `n` stacked copies that should composite to `target`.* Straight division under-shoots badly: eight layers of `a/8` reach@@ -328,11 +360,10 @@ export function drawTextWith(atlas: GlyphAtlas, sink: GlyphBatchSink, p: DrawTexconst color = decoration(p.shadow.color);const blur = p.shadow.blur ?? 0;if (blur > 0) {- const a = tapAlpha(color[3], SHADOW_RING.length);+ const taps = shadowTaps(blur, fontSizePx);+ const a = tapAlpha(color[3], taps.length);const tap: RGBA = [color[0], color[1], color[2], a];- for (const [rx, ry, r] of SHADOW_RING) {- emitPass(tap, dx + rx * blur * r, -dy + ry * blur * r, 0, false, baked ? TextGlyphMode.Mask : undefined);- }+ for (const [ox, oy] of taps) emitPass(tap, dx + ox, -dy + oy, 0, false, baked ? TextGlyphMode.Mask : undefined);} else {emitPass(color, dx, -dy, 0, false, baked ? TextGlyphMode.Mask : undefined);}diff --git a/sdk/tests/ui-text-renderer.test.ts b/sdk/tests/ui-text-renderer.test.tsindex a18859f88..6ca6ac158 100644--- a/sdk/tests/ui-text-renderer.test.ts+++ b/sdk/tests/ui-text-renderer.test.ts@@ -10,7 +10,7 @@ import { TEXT_VERTEX_FLOATS } from '../src/ui/text/submit';import {GlyphAtlas, type GlyphRasterizer, type AtlasPageStore, type RasterGlyph,} from '../src/ui/text/glyph-atlas';-import { drawTextWith, signatureOf, tapAlpha } from '../src/ui/text/text-renderer';+import { drawTextWith, shadowTaps, signatureOf, tapAlpha } from '../src/ui/text/text-renderer';import type { DrawTextParams } from '../src/ui/text/text-renderer';function makeAtlas(pageSize: number, spread = 6, metricsOnly = false): GlyphAtlas {@@ -245,6 +245,25 @@ describe('REARCH_GUI P1.3b: drawTextWith', () => {expect(sink).toHaveBeenCalledTimes(9); // 8 directions + fill});+ // One ring of eight is a blur of a few pixels. A title set large with a blur of eighteen drew its nine copies fourteen pixels+ // apart: the label over and over, in blocks, where a soft shadow was asked for.+ it('draws a wide blur as enough copies that none stands apart from the rest', () => {+ const small = shadowTaps(3, 24);+ expect(small.length).toBe(9);+ const wide = shadowTaps(18, 84);+ expect(wide.length).toBeGreaterThan(9);+ expect(wide.length).toBeLessThanOrEqual(64);+ // All within the blur, and each within a stroke's thickness of another.+ const stroke = 84 * 0.07 * 1.6;+ for (const [x, y] of wide) {+ expect(Math.hypot(x, y)).toBeLessThanOrEqual(18);+ const nearest = Math.min(...wide.filter((t) => t[0] !== x || t[1] !== y).map((t) => Math.hypot(t[0] - x, t[1] - y)));+ expect(nearest).toBeLessThanOrEqual(stroke);+ }+ // However wide the blur and small the type, the copies are counted: each is the whole label again.+ expect(shadowTaps(60, 12).length).toBeLessThanOrEqual(64);+ });+it('spreads a blurred shadow into a ring, still behind the fill', () => {const atlas = makeAtlas(1024);const sink = vi.fn();diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 38e0ba401..996508f1c 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -4772,4 +4772,6 @@ export const NOTED = {{"note": "Drawing a frame costs the CPU a third of what it did."},"fix(foliage): a mesh scattered with no material keeps its own colours - a field with no material painted every plant the stock green of grass from root to tip, a mesh's own vertex colours with it, so a grey rock came out a green one and a dark spruce a pale one; a mesh that has colours is painted in them, each plant by its shade, and one with none (or white throughout) is painted as before":{"note": "A mesh scattered with no material keeps its own colours."},+ "fix(text): a wide blurred shadow is one soft shape - a blur was always one ring of eight copies of the label at its own radius, which is a soft edge at two or three pixels and nine separate labels at eighteen: a title set large stood in blocks of dark squares; past three pixels the copies are as many rings as keep each within a stroke's thickness of its neighbours, sixty-four at the most":+ {"note": "A wide blurred text shadow is one soft shape."},};