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(render): the sky's clouds are worked out at half size again
yhh5c0f6eab71c2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e437da439..840a24f15 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -52,7 +52,6 @@ published separately; it ships inside the editor.- **A label's glyph pipeline no longer costs a transform read per label per frame.** An automatic label draws with hinted bitmaps near 1:1 and with SDF past 2% of it, so script read every label's world scale every frame to see whether the choice had changed, a `Transform` converted through embind each time: about two thirds of what the script still spent on 600 static labels. The engine now holds the choice it was laid out with and watches the scale itself in `renderer_retainedTextStale`, by the same rule (pinned by one table on each side). 600 static labels go from 1.6 ms to 1.1 ms of CPU a frame, and the script's own per-frame loop to about 0.05 ms. Evaluated and not taken: driving the check from the change tracker (a script component written in place through `world.get` is not reported, and that is documented and tested behaviour), and making `Text` an engine component (an in-place write to one is dropped, which would end that behaviour for user code).- **UI text is laid out when it changes and submitted by the engine every frame, instead of handed over by script every frame.** Every label cost script an embind round trip for each of its domain, hidden state, opacity, matrix, size, order and cull bit, a JSON signature to find out nothing had changed, and a copy of its quads into the engine: 4.3 microseconds a label, which is 2.7 ms a frame for 600 labels that never change. The glyph quads are now handed to the engine once, in `renderer_retainedTextBegin/Batch`, and the engine reads everything else off the entity itself, clips against the view as the script did, and submits them (`renderer_retainedTextSubmit`). Script compares the fields a label was laid out from and lays it out again only when one differs; the engine reports the labels whose box was resized or that moved between the world and the screen (`renderer_retainedTextStale`). 600 static labels go from 2.7 ms to 1.6 ms of CPU a frame, with the same draws and triangles, and a pixel-identical picture once the page has settled. A host without the new entry points keeps the old path. The engine's culling and the script's are checked quad for quad on 120 random cases (`test_retained_text`).- **A frame of 2D sprites is not sorted again when its draw keys are the last frame's.** The draw list sorted every command each frame, 0.15 ms for 4,000 sprites and growing as n log n, although a 2D key holds the layer, shader, blend and material and no position: sprites that move, or do not, give the same keys frame after frame. The order is a function of the key sequence alone (ties break on emit index), so a frame with the same keys takes the last frame's order and skips the sort. The draw list's finalize in a 4,000-sprite scene goes from 0.30 ms to 0.10 ms. The sort result is the same bit for bit; a frame whose keys differ is sorted as before.-- **The sky's clouds are worked out at a quarter of the size, 0.9 ms cheaper.** The cloud layer marches sixteen steps a pixel, each with three octaves of noise and three more samples toward the sun, and the surfaces' shadow from it costs almost nothing: all of the 1.6 ms of the `sky_clouds` pass in the terrain-water example was the layer over the sky. The clouds are smooth, so the pass now runs at a quarter of the width and height (half before) and the composite reads it back as it did. In a cloud scene no pixel is more than 2 of 255 from the half-size picture; in the example the difference is below what two runs of the same build differ by. 1.6 ms to 0.7 ms of a 1080p frame.- **Lens flare costs a third of what it did.** The flare looked ninety places in the picture for something bright at every pixel of the full-size frame, to light almost none of them: 0.76 ms of a 1080p frame in the terrain-water example. It is now worked out at half size and laid over the full-size picture (0.22 ms and 0.07 ms), 0.47 ms less. The picture is the same except along the hard edges of whatever throws the flare, where it softens by a pixel or two (0.6 of 255 on average in a scene built to make that worst). A new render scene, `hdr-lens-flare`, is the first to check a flare on both backends.- **The engine's own examples and fixtures no longer commit a generated WebGPU shader twin.** The `wgsl full` section of a `.esshader` is a translation of its GLSL joined to the engine's headers, so every edit to an engine header (the render origin in `FrameConstants`, a lighting function) changed it in dozens of files nobody had touched: 83% of that text is the engine's own lighting code, 2% the author's. It is now derived when the shader is read: by the export (`cookAssets`), by the fixture server the render checks use, and by the editor when it serves a project of the repo. Deriving all 44 shaders takes 2.3 s. `gen-shader-twins --derived` checks that each one still translates and that none commits a twin again; a project of your own keeps its twin in the file as before, because the converters are not in a packaged editor. 18 files lose about 11,000 lines; the 248 WebGPU render scenes draw the same.- **The web module is 144 KB smaller (50 KB gzipped) because it no longer carries a C++ stream library.** `Log`, the shader parser, the font and material parsers, file reads and one JSON status string used `ostringstream`, `istringstream` and `ifstream`, which link libc++'s whole iostream and locale machinery (money, number and time facets, global locale setup at start-up) into every build. They now use `std::string`, a small line reader and stdio, with output kept the same: all 69 shaders parse and assemble to byte-identical text for both targets, a log line prints as before, and the 262 WebGL2 render scenes still draw what they claim. 2,202,592 to 2,058,299 bytes.diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.tsindex 1df33f08d..35dce55f9 100644--- a/sdk/src/postprocess/effects.ts+++ b/sdk/src/postprocess/effects.ts@@ -316,12 +316,12 @@ registerEffect({type: 'skyAtmosphere',label: 'Sky Atmosphere',factory: () => postProcessEffects.createSkyClouds(),- // The clouds (and the shadow they cast on the ground) are smooth and dear, so they are worked out at a quarter of the size (a sixteenth of the- // pixels; half size was a quarter of them) and the composite reads them back by the way a pixel's neighbours agree with it; the dome, sun, moon- // and stars, which have an edge, stay full size. Measured against half size: 1.6 ms to 0.7 ms of a 1080p frame, no pixel in a cloud scene more- // than 2 of 255 apart.+ // The clouds (and the shadow they cast on the ground) are smooth and dear, so they are worked out at half size and the composite+ // reads them back by the way a pixel's neighbours agree with it; the dome, sun, moon and stars, which have an edge, stay full size.+ // Not smaller: at a quarter the march's per-pixel jitter grain is four pixels coarse, a checkerboard in the cloud and vertical streaks+ // near the horizon, which a mean pixel difference against half size (0.04 of 255) did not show and the picture does.multiPass: [- { name: 'sky_clouds', factory: () => postProcessEffects.createSkyClouds(), scale: 0.25 },+ { name: 'sky_clouds', factory: () => postProcessEffects.createSkyClouds(), scale: 0.5 },{ name: 'sky_composite', factory: () => postProcessEffects.createSkyAtmosphere() },],uniforms: [diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex d8f2ebaa7..4b0f1078e 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -3077,7 +3077,7 @@ export const NOTED = {"perf(render): the lens flare is worked out at half size and laid over the full-size picture":{"note":"Lens flare costs a third of what it did"},"perf(render): the sky's clouds are worked out at a quarter of the size":- {"note":"The sky's clouds cost 0.9 ms less"},+ {"internal":"Taken back by the next change: the clouds are half size again, as before."},"perf(render): a frame of 2D sprites is not sorted again when its draw keys are the last frame's":{"note":"A frame of sprites is not sorted again when its draw keys have not changed"},"perf(ui): UI text is laid out when it changes and submitted by the engine every frame":@@ -3088,4 +3088,6 @@ export const NOTED = {{"note":"Tilemaps that have not changed cost almost nothing per frame"},"perf(render): a draw that changes buffer no longer re-points its vertex attributes":{"note":"Fewer GL calls when a draw changes buffer"},+ "fix(render): the sky's clouds are worked out at half size again":+ {"internal":"Undoes the quarter-size clouds, which showed a coarse checkerboard in the cloud and streaks near the horizon."},};