@moku-labs/game 0.15.101 → 0.15.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/app/page.d.mts +1 -1
- package/dist/app/page.mjs +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/assets.d.mts +1 -1
- package/dist/{commands-DFCBw6F2.d.mts → commands-TSyhs2-E.d.mts} +19 -10
- package/dist/control.d.mts +10 -6
- package/dist/control.mjs +2 -2
- package/dist/{define-6cjZwkJu.d.mts → define-DNF9A0ce.d.mts} +2 -2
- package/dist/{headless-WyPk3UrP.d.mts → headless-CEG1oR5D.d.mts} +1 -1
- package/dist/{index-Bz6p2alA.d.mts → index-DDZ9K9qO.d.mts} +24 -4
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/inspect.d.mts +6 -6
- package/dist/inspect.mjs +2 -2
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{run-B5if0jxE.mjs → run-pCQlIaNP.mjs} +46 -3
- package/dist/{runtime-BDCv5mp-.d.mts → runtime-CcHPrVBm.d.mts} +1 -1
- package/dist/{session-D0AYRm5T.mjs → session-ClUqpGId.mjs} +138 -2
- package/dist/{sources-Cqqz-0-b.mjs → sources-BJyIJf_X.mjs} +1 -1
- package/dist/{src-DsyJR7Ds.mjs → src-DVJ0d04R.mjs} +433 -65
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-Co-6A6Y8.d.mts → types-BvgY7Ncf.d.mts} +23 -5
- package/dist/{types-Cx_-n0Ts.d.mts → types-C1B7-x7p.d.mts} +1 -1
- package/dist/{types-DyohsXF_.d.mts → types-C612npUH.d.mts} +2 -2
- package/dist/{types-Dx2qRDFg.d.mts → types-CMag4vDu.d.mts} +4 -4
- package/dist/{types-BzVQAaSX.d.mts → types-Ce5W0gZe.d.mts} +45 -7
- package/dist/{visual-D5L3ZtuQ.d.mts → visual-PsEr2KD-.d.mts} +6 -6
- package/dist/visual.d.mts +1 -1
- package/dist/visual.mjs +2 -2
- package/llms.txt +6 -6
- package/package.json +1 -1
|
@@ -35,13 +35,13 @@ const createCore$1 = coreConfig.createCore;
|
|
|
35
35
|
*/
|
|
36
36
|
/**
|
|
37
37
|
* Reads the source and raises the high-water mark. A source that goes back cannot move game time
|
|
38
|
-
* back, and a fractional reading is cut to whole milliseconds.
|
|
38
|
+
* back, and a fractional reading is cut to whole milliseconds. The shift of `advance` is added.
|
|
39
39
|
*
|
|
40
40
|
* @param state - Clock state.
|
|
41
41
|
* @returns The highest moment ever returned, in epoch milliseconds.
|
|
42
42
|
*/
|
|
43
43
|
function readNow(state) {
|
|
44
|
-
const moment = Math.trunc(state.source.now());
|
|
44
|
+
const moment = Math.trunc(state.source.now() + state.shift);
|
|
45
45
|
if (moment > state.last) state.last = moment;
|
|
46
46
|
return state.last;
|
|
47
47
|
}
|
|
@@ -67,8 +67,8 @@ function deliverElapsed(state) {
|
|
|
67
67
|
for (const listener of listeners) listener({ now: moment });
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Arms the single timer for a due moment. The delay is counted from the RAW source reading
|
|
71
|
-
* from trusted time: the source's timer runs on the device clock, so after the device clock was
|
|
70
|
+
* Arms the single timer for a due moment. The delay is counted from the RAW source reading plus
|
|
71
|
+
* the shift of `advance`, not from trusted time: the source's timer runs on the device clock, so after the device clock was
|
|
72
72
|
* moved back the wait is longer than `moment - now()`. A moment further than the longest timer
|
|
73
73
|
* waits in steps: the timer fires early and `fireDue` arms it again.
|
|
74
74
|
*
|
|
@@ -76,7 +76,8 @@ function deliverElapsed(state) {
|
|
|
76
76
|
* @param moment - Due moment in epoch milliseconds.
|
|
77
77
|
*/
|
|
78
78
|
function arm(state, moment) {
|
|
79
|
-
const
|
|
79
|
+
const raw = Math.trunc(state.source.now() + state.shift);
|
|
80
|
+
const delayMs = Math.min(MAX_TIMER_MS, Math.max(0, moment - raw));
|
|
80
81
|
state.dueAt = moment;
|
|
81
82
|
state.handle = state.source.setTimer(() => fireDue(state), delayMs);
|
|
82
83
|
}
|
|
@@ -98,6 +99,26 @@ function fireDue(state) {
|
|
|
98
99
|
deliverElapsed(state);
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
102
|
+
* Moves the clock forward by `ms`: the shift every reading adds grows, and the pending moment is
|
|
103
|
+
* delivered at once when it is due now, or armed again for the rest of its wait.
|
|
104
|
+
*
|
|
105
|
+
* @param state - Clock state.
|
|
106
|
+
* @param ms - Milliseconds forward.
|
|
107
|
+
* @returns The trusted moment after the move.
|
|
108
|
+
* @throws {RangeError} When `ms` is not a finite number above 0.
|
|
109
|
+
*/
|
|
110
|
+
function advanceBy$1(state, ms) {
|
|
111
|
+
if (!Number.isFinite(ms) || ms <= 0) throw new RangeError(`[game] clock.advance moves the clock forward, not by ${ms} ms.\n Pass a finite number of milliseconds above 0.`);
|
|
112
|
+
state.shift += ms;
|
|
113
|
+
const moment = state.dueAt;
|
|
114
|
+
const now = readNow(state);
|
|
115
|
+
if (moment === void 0) return now;
|
|
116
|
+
cancelPending(state);
|
|
117
|
+
if (now >= moment) deliverElapsed(state);
|
|
118
|
+
else arm(state, moment);
|
|
119
|
+
return now;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
101
122
|
* Removes one listener. A second removal of the same listener does nothing.
|
|
102
123
|
*
|
|
103
124
|
* @param state - Clock state.
|
|
@@ -130,6 +151,7 @@ function createClockApi(ctx) {
|
|
|
130
151
|
poke: () => {
|
|
131
152
|
deliverElapsed(ctx.state);
|
|
132
153
|
},
|
|
154
|
+
advance: (ms) => advanceBy$1(ctx.state, ms),
|
|
133
155
|
dueAt: () => ctx.state.dueAt,
|
|
134
156
|
pending: () => ctx.state.dueAt === void 0 ? 0 : 1,
|
|
135
157
|
listeners: () => ctx.state.listeners.length
|
|
@@ -141,8 +163,8 @@ function createClockApi(ctx) {
|
|
|
141
163
|
* @file clock plugin — state factory.
|
|
142
164
|
*/
|
|
143
165
|
/**
|
|
144
|
-
* Creates the initial clock state: the configured source or the system source, no due
|
|
145
|
-
* no timer handle, no listeners.
|
|
166
|
+
* Creates the initial clock state: the configured source or the system source, no shift, no due
|
|
167
|
+
* moment, no timer handle, no listeners.
|
|
146
168
|
*
|
|
147
169
|
* @param ctx - Minimal context.
|
|
148
170
|
* @param ctx.config - Resolved plugin config.
|
|
@@ -152,6 +174,7 @@ function createClockState(ctx) {
|
|
|
152
174
|
return {
|
|
153
175
|
source: ctx.config.source ?? systemSource(),
|
|
154
176
|
last: 0,
|
|
177
|
+
shift: 0,
|
|
155
178
|
dueAt: void 0,
|
|
156
179
|
handle: void 0,
|
|
157
180
|
listeners: []
|
|
@@ -9131,6 +9154,7 @@ function collectMatch(_value, entity) {
|
|
|
9131
9154
|
*/
|
|
9132
9155
|
var SystemWalk = class {
|
|
9133
9156
|
ctx;
|
|
9157
|
+
hidesAside;
|
|
9134
9158
|
/** The step handed back for every row: always the one row array. */
|
|
9135
9159
|
step;
|
|
9136
9160
|
/** The one row: the entity, then one stored value per name, sized at registration. */
|
|
@@ -9151,14 +9175,19 @@ var SystemWalk = class {
|
|
|
9151
9175
|
started = false;
|
|
9152
9176
|
/** The first store's size at the first step: a dev build compares it; -1 when not watched. */
|
|
9153
9177
|
size = -1;
|
|
9178
|
+
/** The entities of the running aside build this run passes over, read at the first step; `undefined` for none. */
|
|
9179
|
+
aside = void 0;
|
|
9154
9180
|
/**
|
|
9155
9181
|
* Prepares the walk of one system.
|
|
9156
9182
|
*
|
|
9157
9183
|
* @param ctx - Domain context of the world plugin.
|
|
9158
9184
|
* @param plan - The system's resolved query.
|
|
9185
|
+
* @param hidesAside - True for a feature's system: it passes over the entities of a scene built aside until the
|
|
9186
|
+
* commit (F155).
|
|
9159
9187
|
*/
|
|
9160
|
-
constructor(ctx, plan) {
|
|
9188
|
+
constructor(ctx, plan, hidesAside = false) {
|
|
9161
9189
|
this.ctx = ctx;
|
|
9190
|
+
this.hidesAside = hidesAside;
|
|
9162
9191
|
this.names = plan.names;
|
|
9163
9192
|
this.written = plan.written;
|
|
9164
9193
|
this.step = {
|
|
@@ -9191,13 +9220,14 @@ var SystemWalk = class {
|
|
|
9191
9220
|
return this;
|
|
9192
9221
|
}
|
|
9193
9222
|
/**
|
|
9194
|
-
* Keeps one key of the first store when the entity carries every other name.
|
|
9223
|
+
* Keeps one key of the first store when the entity carries every other name and is not built aside.
|
|
9195
9224
|
*
|
|
9196
9225
|
* @param entity - The key.
|
|
9197
9226
|
*/
|
|
9198
9227
|
keep(entity) {
|
|
9199
9228
|
const stores = this.stores;
|
|
9200
9229
|
const count = stores.length;
|
|
9230
|
+
if (this.aside?.has(entity) === true) return;
|
|
9201
9231
|
for (let index = 1; index < count; index += 1) if (stores[index]?.has(entity) !== true) return;
|
|
9202
9232
|
this.entities[this.count] = entity;
|
|
9203
9233
|
this.count += 1;
|
|
@@ -9227,8 +9257,8 @@ var SystemWalk = class {
|
|
|
9227
9257
|
}
|
|
9228
9258
|
/**
|
|
9229
9259
|
* Reads the stores of this run and collects the entities that carry every name, in the first
|
|
9230
|
-
* store's order
|
|
9231
|
-
* while the rows are consumed.
|
|
9260
|
+
* store's order; a feature's system passes over the entities of a scene built aside. Structural
|
|
9261
|
+
* changes are queued until the phase ends, so the matches stay true while the rows are consumed.
|
|
9232
9262
|
*/
|
|
9233
9263
|
start() {
|
|
9234
9264
|
const all = this.ctx.state.ecs.stores;
|
|
@@ -9242,6 +9272,7 @@ var SystemWalk = class {
|
|
|
9242
9272
|
}
|
|
9243
9273
|
const first = stores[0];
|
|
9244
9274
|
if (first === void 0) return;
|
|
9275
|
+
this.aside = this.hidesAside ? this.ctx.state.projection.building?.entities : void 0;
|
|
9245
9276
|
collecting.walk = this;
|
|
9246
9277
|
first.forEach(collectMatch);
|
|
9247
9278
|
collecting.walk = void 0;
|
|
@@ -9316,7 +9347,7 @@ function mayMatch(stores, entry) {
|
|
|
9316
9347
|
*/
|
|
9317
9348
|
function systemRows(ctx, entry) {
|
|
9318
9349
|
if (entry.plan.names.length === 0) return NO_ROWS;
|
|
9319
|
-
entry.walk ??= new SystemWalk(ctx, entry.plan);
|
|
9350
|
+
entry.walk ??= new SystemWalk(ctx, entry.plan, entry.hidesAside);
|
|
9320
9351
|
return entry.walk.reset();
|
|
9321
9352
|
}
|
|
9322
9353
|
/**
|
|
@@ -9694,23 +9725,24 @@ function storeSlots(count) {
|
|
|
9694
9725
|
/**
|
|
9695
9726
|
* Registers a system at the end of its phase list and returns the remover. In phase `sync` it goes
|
|
9696
9727
|
* before `renderer.sync`, which stays last. Its query and its `scenes` are read here, once: a
|
|
9697
|
-
* later change to the definition is not seen. A dev build checks
|
|
9698
|
-
* the
|
|
9728
|
+
* later change to the definition is not seen. A dev build checks the `scenes` against the scenes
|
|
9729
|
+
* the features declare, once the world started.
|
|
9730
|
+
*
|
|
9731
|
+
* The rows of a feature's system (`hidesAside`) pass over the entities of a scene built aside
|
|
9732
|
+
* until the commit, so it meets the coming scene whole, in one frame (F155); `world.query()`,
|
|
9733
|
+
* `get` and `has` inside its `run` still read them. The engine's own systems lay that scene out
|
|
9734
|
+
* and draw it, and see it.
|
|
9699
9735
|
*
|
|
9700
9736
|
* @param ctx - Domain context of the world plugin.
|
|
9701
9737
|
* @param definition - The system.
|
|
9738
|
+
* @param hidesAside - True for a system a feature brought.
|
|
9702
9739
|
* @returns The remover; calling it twice is a no-op.
|
|
9703
9740
|
* @throws {Error} When a system of that name is already registered, and in a dev build for a
|
|
9704
9741
|
* name in `scenes` that no feature declares.
|
|
9705
9742
|
*/
|
|
9706
|
-
function registerSystem(ctx, definition) {
|
|
9743
|
+
function registerSystem(ctx, definition, hidesAside = false) {
|
|
9707
9744
|
const state = ctx.state.ecs;
|
|
9708
|
-
for (const phase of [
|
|
9709
|
-
"input",
|
|
9710
|
-
"animate",
|
|
9711
|
-
"layout",
|
|
9712
|
-
"sync"
|
|
9713
|
-
]) if (state.systems[phase].some((entry) => entry.definition.name === definition.name)) throw new Error(`[game] System "${definition.name}" is registered twice.\n Give the second system another name, or remove the first one.`);
|
|
9745
|
+
for (const phase of WORLD_PHASES) if (state.systems[phase].some((entry) => entry.definition.name === definition.name)) throw new Error(`[game] System "${definition.name}" is registered twice.\n Give the second system another name, or remove the first one.`);
|
|
9714
9746
|
if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__) checkScenes(state.scene, definition);
|
|
9715
9747
|
const plan = planOf(ctx, definition.query);
|
|
9716
9748
|
const entry = {
|
|
@@ -9720,7 +9752,8 @@ function registerSystem(ctx, definition) {
|
|
|
9720
9752
|
stores: storeSlots(plan.names.length),
|
|
9721
9753
|
scenes: definition.scenes === void 0 ? void 0 : [...definition.scenes],
|
|
9722
9754
|
skipped: false,
|
|
9723
|
-
|
|
9755
|
+
hidesAside,
|
|
9756
|
+
walk: plan.names.length === 0 ? void 0 : new SystemWalk(ctx, plan, hidesAside)
|
|
9724
9757
|
};
|
|
9725
9758
|
const list = state.systems[definition.phase];
|
|
9726
9759
|
const draws = list.findIndex((known) => known.definition.name === DRAWS_SYSTEM);
|
|
@@ -9913,6 +9946,7 @@ function createEcsApi(ctx) {
|
|
|
9913
9946
|
const state = ctx.state.ecs;
|
|
9914
9947
|
const api = {
|
|
9915
9948
|
system: (definition) => registerSystem(ctx, definition),
|
|
9949
|
+
featureSystem: (definition) => registerSystem(ctx, definition, true),
|
|
9916
9950
|
spawn: (owner, components) => {
|
|
9917
9951
|
const entity = reserveEntity(state, owner);
|
|
9918
9952
|
queueOrApply(ctx, {
|
|
@@ -10144,7 +10178,7 @@ function registerFeatures(ctx, ecs, projection) {
|
|
|
10144
10178
|
declareScenes(ctx.state.ecs.scene, features);
|
|
10145
10179
|
for (const feature of features) {
|
|
10146
10180
|
registerEach(ctx, feature, "components", isComponentEntry, (entry) => registerType(ctx, entry));
|
|
10147
|
-
registerEach(ctx, feature, "systems", isSystemEntry, (entry) => ecs.
|
|
10181
|
+
registerEach(ctx, feature, "systems", isSystemEntry, (entry) => ecs.featureSystem(entry));
|
|
10148
10182
|
registerEach(ctx, feature, "projections", isProjectionEntry, (entry) => projection.register(entry));
|
|
10149
10183
|
}
|
|
10150
10184
|
}
|
|
@@ -27018,7 +27052,7 @@ const MAX_RADIUS = 30;
|
|
|
27018
27052
|
/** The radius of a kernel, in sigmas. */
|
|
27019
27053
|
const RADIUS_SIGMAS = 3;
|
|
27020
27054
|
/** The widest blur, in texels of the shot: its radius is the widest the uniform holds. */
|
|
27021
|
-
const MAX_SIGMA = MAX_RADIUS / RADIUS_SIGMAS;
|
|
27055
|
+
const MAX_SIGMA$1 = MAX_RADIUS / RADIUS_SIGMAS;
|
|
27022
27056
|
/** Taps a side of an exact box: each averages two source pixels, at 2 texels from the next. */
|
|
27023
27057
|
const BOX_TAPS = 2;
|
|
27024
27058
|
/** Taps a side of any other hop, spread evenly over it. */
|
|
@@ -27108,7 +27142,7 @@ function gaussianTaps(sigma) {
|
|
|
27108
27142
|
* ```
|
|
27109
27143
|
*/
|
|
27110
27144
|
function sigmaOf(blur, width, frameWidth) {
|
|
27111
|
-
return frameWidth > 0 ? Math.min(blur * width / frameWidth, MAX_SIGMA) : 0;
|
|
27145
|
+
return frameWidth > 0 ? Math.min(blur * width / frameWidth, MAX_SIGMA$1) : 0;
|
|
27112
27146
|
}
|
|
27113
27147
|
/**
|
|
27114
27148
|
* The uniform of a hop. A hop of a factor of 4 takes two taps a side at +-1 source pixel: an exact box of 4 x 4. The
|
|
@@ -44524,23 +44558,37 @@ function endBuild(ctx, build, how) {
|
|
|
44524
44558
|
build.resolve();
|
|
44525
44559
|
}
|
|
44526
44560
|
/**
|
|
44527
|
-
* Tells whether the floor on the swap lets a built scene commit: no floor, or the clock
|
|
44528
|
-
*
|
|
44529
|
-
*
|
|
44530
|
-
* is
|
|
44561
|
+
* Tells whether the floor on the swap lets a built scene commit: no floor, or the clock or the game time passed it and
|
|
44562
|
+
* the look was drawn once. On a device both run together; the stepped frames of a visual test move the game time while
|
|
44563
|
+
* its fake clock stands (F86), so the floor passes there after `holdMs` of frames (F156). The count is the look's, never
|
|
44564
|
+
* the build's, so a switch slower than the floor is many frames past it and the floor adds no frame. While it holds, the
|
|
44565
|
+
* loop is kept awake: it may stop at `idleFps: 0` during a long floor. No floor is one read; no allocation either way.
|
|
44531
44566
|
*
|
|
44532
44567
|
* @param ctx - Domain context of the plugin.
|
|
44533
44568
|
* @param frame - The frame counter now.
|
|
44569
|
+
* @param elapsed - The game time now, in ms.
|
|
44534
44570
|
* @returns True when the build may commit.
|
|
44535
44571
|
*/
|
|
44536
|
-
function holdOver(ctx, frame) {
|
|
44572
|
+
function holdOver(ctx, frame, elapsed) {
|
|
44537
44573
|
const hold = ctx.state.leaving?.hold;
|
|
44538
44574
|
if (hold === void 0) return true;
|
|
44539
|
-
if (ctx.deps.clock.now() >= hold.until && frame >= hold.frame + HOLD_FRAMES) return true;
|
|
44575
|
+
if ((ctx.deps.clock.now() >= hold.until || elapsed >= hold.elapsedUntil) && frame >= hold.frame + HOLD_FRAMES) return true;
|
|
44540
44576
|
ctx.deps.time.wake();
|
|
44541
44577
|
return false;
|
|
44542
44578
|
}
|
|
44543
44579
|
/**
|
|
44580
|
+
* Tells whether a running build may commit now: every part of it is done and the floor on the swap
|
|
44581
|
+
* passed. Two calls, no allocation.
|
|
44582
|
+
*
|
|
44583
|
+
* @param ctx - Domain context of the plugin.
|
|
44584
|
+
* @param frame - The frame counter now.
|
|
44585
|
+
* @param elapsed - The game time now, in ms.
|
|
44586
|
+
* @returns True when the build may commit.
|
|
44587
|
+
*/
|
|
44588
|
+
function readyToCommit(ctx, frame, elapsed) {
|
|
44589
|
+
return ctx.deps.world.projection.built() && holdOver(ctx, frame, elapsed);
|
|
44590
|
+
}
|
|
44591
|
+
/**
|
|
44544
44592
|
* The `signals` callback of a running build: counts the frame and commits the build the frame
|
|
44545
44593
|
* every part of it is done and the floor on the swap passed. A world that stopped running live
|
|
44546
44594
|
* during the build or its wait (a walk that went fast, as the restore of a repro walks its route,
|
|
@@ -44552,15 +44600,15 @@ function holdOver(ctx, frame) {
|
|
|
44552
44600
|
* @param ctx - Domain context of the plugin.
|
|
44553
44601
|
* @param build - The running build.
|
|
44554
44602
|
* @param frame - The frame counter of this frame.
|
|
44603
|
+
* @param elapsed - The game time of this frame, in ms.
|
|
44555
44604
|
*/
|
|
44556
|
-
function stepBuild(ctx, build, frame) {
|
|
44605
|
+
function stepBuild(ctx, build, frame, elapsed) {
|
|
44557
44606
|
build.frames += 1;
|
|
44558
|
-
|
|
44559
|
-
if (world.ecs.mode() !== "live") {
|
|
44607
|
+
if (ctx.deps.world.ecs.mode() !== "live") {
|
|
44560
44608
|
endBuild(ctx, build, "mount");
|
|
44561
44609
|
return;
|
|
44562
44610
|
}
|
|
44563
|
-
if (
|
|
44611
|
+
if (readyToCommit(ctx, frame, elapsed)) endBuild(ctx, build, "commit");
|
|
44564
44612
|
}
|
|
44565
44613
|
/**
|
|
44566
44614
|
* Drops the running build on an abort of its node (a restore, the inbox, a stop of the runner):
|
|
@@ -44614,7 +44662,7 @@ function startBuildRecord(ctx, scene, named, budgetMs, settle) {
|
|
|
44614
44662
|
*/
|
|
44615
44663
|
function watchBuild(ctx, build, signal) {
|
|
44616
44664
|
const onAbort = () => abortBuild(ctx, build);
|
|
44617
|
-
const offFrame = ctx.deps.time.onFrame("signals", (time) => stepBuild(ctx, build, time.frame));
|
|
44665
|
+
const offFrame = ctx.deps.time.onFrame("signals", (time) => stepBuild(ctx, build, time.frame, time.elapsed));
|
|
44618
44666
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
44619
44667
|
build.off = () => {
|
|
44620
44668
|
offFrame();
|
|
@@ -44657,7 +44705,8 @@ function buildAside(ctx, scene, named, signal) {
|
|
|
44657
44705
|
resolve,
|
|
44658
44706
|
reject
|
|
44659
44707
|
});
|
|
44660
|
-
|
|
44708
|
+
const { frame, elapsed } = ctx.deps.time.snapshot();
|
|
44709
|
+
if (readyToCommit(ctx, frame, elapsed)) {
|
|
44661
44710
|
endBuild(ctx, build, "commit");
|
|
44662
44711
|
return;
|
|
44663
44712
|
}
|
|
@@ -45190,8 +45239,8 @@ function leftScene(ctx, run) {
|
|
|
45190
45239
|
return ctx.state.scenes.get(current);
|
|
45191
45240
|
}
|
|
45192
45241
|
/**
|
|
45193
|
-
* Stamps the floor of a loader on the look of a switch that starts now: the clock moment the
|
|
45194
|
-
* frame counter, read once here (`snapshot()` copies). A loader without one leaves the look as it is.
|
|
45242
|
+
* Stamps the floor of a loader on the look of a switch that starts now: the clock moment and the game time the swap may
|
|
45243
|
+
* happen at, and the frame counter, read once here (`snapshot()` copies). A loader without one leaves the look as it is.
|
|
45195
45244
|
*
|
|
45196
45245
|
* @param ctx - Domain context of the plugin.
|
|
45197
45246
|
* @param leaving - The look of the switch.
|
|
@@ -45199,9 +45248,11 @@ function leftScene(ctx, run) {
|
|
|
45199
45248
|
*/
|
|
45200
45249
|
function stampHold(ctx, leaving, loader) {
|
|
45201
45250
|
if (loader.holdMs === void 0) return;
|
|
45251
|
+
const { frame, elapsed } = ctx.deps.time.snapshot();
|
|
45202
45252
|
leaving.hold = {
|
|
45203
45253
|
until: ctx.deps.clock.now() + loader.holdMs,
|
|
45204
|
-
|
|
45254
|
+
elapsedUntil: elapsed + loader.holdMs,
|
|
45255
|
+
frame
|
|
45205
45256
|
};
|
|
45206
45257
|
}
|
|
45207
45258
|
/**
|
|
@@ -50227,7 +50278,11 @@ function propertyOf(target, name) {
|
|
|
50227
50278
|
*/
|
|
50228
50279
|
function listedDefinition(input, stage) {
|
|
50229
50280
|
const candidate = propertyOf(stage, "filter");
|
|
50230
|
-
|
|
50281
|
+
const { stages } = input;
|
|
50282
|
+
for (let index = 0; index < stages.length; index += 1) {
|
|
50283
|
+
const listed = stages[index];
|
|
50284
|
+
if (listed !== void 0 && listed.filter === candidate) return listed.filter;
|
|
50285
|
+
}
|
|
50231
50286
|
}
|
|
50232
50287
|
/**
|
|
50233
50288
|
* The uniform of a definition by its name.
|
|
@@ -50237,7 +50292,11 @@ function listedDefinition(input, stage) {
|
|
|
50237
50292
|
* @returns The uniform, or `undefined`.
|
|
50238
50293
|
*/
|
|
50239
50294
|
function uniformNamed(definition, name) {
|
|
50240
|
-
|
|
50295
|
+
const { uniforms } = definition;
|
|
50296
|
+
for (let index = 0; index < uniforms.length; index += 1) {
|
|
50297
|
+
const uniform = uniforms[index];
|
|
50298
|
+
if (uniform?.name === name) return uniform;
|
|
50299
|
+
}
|
|
50241
50300
|
}
|
|
50242
50301
|
/**
|
|
50243
50302
|
* Tells whether a step's value fits the form of a uniform: a number for a number or a colour, a
|
|
@@ -50254,7 +50313,11 @@ function uniformNamed(definition, name) {
|
|
|
50254
50313
|
function fitsForm(uniform, value) {
|
|
50255
50314
|
if (uniform.form !== "vector") return typeof value === "number";
|
|
50256
50315
|
if (!Array.isArray(value) || value.length !== uniform.size) return false;
|
|
50257
|
-
|
|
50316
|
+
const entries = value;
|
|
50317
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
50318
|
+
const entry = entries[index];
|
|
50319
|
+
if (typeof entry !== "number" || !Number.isFinite(entry)) return false;
|
|
50320
|
+
}
|
|
50258
50321
|
return true;
|
|
50259
50322
|
}
|
|
50260
50323
|
/**
|
|
@@ -50273,11 +50336,12 @@ function stepProblem(input, step, index) {
|
|
|
50273
50336
|
const id = propertyOf(propertyOf(stage, "filter"), "id") ?? propertyOf(stage, "componentName");
|
|
50274
50337
|
return `input "${name}" names stage "${String(id)}", which is not in its stages: only listed stages are checked and warmed up before they draw.`;
|
|
50275
50338
|
}
|
|
50276
|
-
const scale = propertyOf(step, "scale");
|
|
50339
|
+
const scale = typeof step === "object" && step !== null && "scale" in step ? step.scale : propertyOf(step, "scale");
|
|
50277
50340
|
if (typeof scale !== "number" || !Number.isFinite(scale) || scale <= 0 || scale > 1) return `input "${name}": step ${index} has scale ${String(scale)}; a scale is a share of the input's resolution above 0 and at most 1.`;
|
|
50278
50341
|
const uniforms = propertyOf(step, "uniforms");
|
|
50279
50342
|
if (typeof uniforms !== "object" || uniforms === null) return void 0;
|
|
50280
|
-
for (const key
|
|
50343
|
+
for (const key in uniforms) {
|
|
50344
|
+
if (!Object.hasOwn(uniforms, key)) continue;
|
|
50281
50345
|
const uniform = uniformNamed(definition, key);
|
|
50282
50346
|
if (uniform === void 0) return `input "${name}": step ${index} gives "${key}", which stage "${definition.id}" does not declare.`;
|
|
50283
50347
|
if (!fitsForm(uniform, Reflect.get(uniforms, key))) return `input "${name}": step ${index} gives "${key}" a value of another form.`;
|
|
@@ -50295,8 +50359,8 @@ function stepsProblem(input, steps) {
|
|
|
50295
50359
|
if (!Array.isArray(steps)) return `input "${input.name}": chain must return an array of steps.`;
|
|
50296
50360
|
const list = steps;
|
|
50297
50361
|
if (list.length > MAX_STEPS) return `input "${input.name}": chain returned ${list.length} steps; at most ${MAX_STEPS}.`;
|
|
50298
|
-
for (
|
|
50299
|
-
const problem = stepProblem(input,
|
|
50362
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
50363
|
+
const problem = stepProblem(input, list[index], index);
|
|
50300
50364
|
if (problem !== void 0) return problem;
|
|
50301
50365
|
}
|
|
50302
50366
|
}
|
|
@@ -50340,14 +50404,11 @@ function writeStep(place, step) {
|
|
|
50340
50404
|
* @param places - The places of the input, changed in place.
|
|
50341
50405
|
* @param at - The slot of the step.
|
|
50342
50406
|
* @param step - The step.
|
|
50343
|
-
* @returns The place,
|
|
50407
|
+
* @returns The place: the one at the slot when kept, a new one, put in the slot, when built for this step.
|
|
50344
50408
|
*/
|
|
50345
50409
|
function placeFor(pixi, retired, places, at, step) {
|
|
50346
50410
|
const kept = places[at];
|
|
50347
|
-
if (kept?.definition === step.stage.filter) return
|
|
50348
|
-
place: kept,
|
|
50349
|
-
built: false
|
|
50350
|
-
};
|
|
50411
|
+
if (kept?.definition === step.stage.filter) return kept;
|
|
50351
50412
|
if (kept !== void 0) retired.push(kept.body);
|
|
50352
50413
|
const place = {
|
|
50353
50414
|
definition: step.stage.filter,
|
|
@@ -50355,10 +50416,25 @@ function placeFor(pixi, retired, places, at, step) {
|
|
|
50355
50416
|
scale: step.scale
|
|
50356
50417
|
};
|
|
50357
50418
|
places[at] = place;
|
|
50358
|
-
return
|
|
50359
|
-
|
|
50360
|
-
|
|
50361
|
-
|
|
50419
|
+
return place;
|
|
50420
|
+
}
|
|
50421
|
+
/**
|
|
50422
|
+
* Retires the places of an input past its steps, by index, and cuts them off: `splice` would answer an array of them
|
|
50423
|
+
* in every frame.
|
|
50424
|
+
*
|
|
50425
|
+
* @param retired - The bodies to destroy after the frame.
|
|
50426
|
+
* @param places - The places of the input, changed in place.
|
|
50427
|
+
* @param count - How many steps the chain returned.
|
|
50428
|
+
* @returns True when a place was retired.
|
|
50429
|
+
*/
|
|
50430
|
+
function retireLeft(retired, places, count) {
|
|
50431
|
+
if (places.length <= count) return false;
|
|
50432
|
+
for (let at = count; at < places.length; at += 1) {
|
|
50433
|
+
const left = places[at];
|
|
50434
|
+
if (left !== void 0) retired.push(left.body);
|
|
50435
|
+
}
|
|
50436
|
+
places.length = count;
|
|
50437
|
+
return true;
|
|
50362
50438
|
}
|
|
50363
50439
|
/**
|
|
50364
50440
|
* Walks the steps of one input with its places: a place that draws the step's stage is kept and
|
|
@@ -50376,19 +50452,19 @@ function placeSteps(pixi, inputs, index, steps) {
|
|
|
50376
50452
|
const places = inputs.places[index] ?? [];
|
|
50377
50453
|
let changed = false;
|
|
50378
50454
|
let rebuilt = false;
|
|
50379
|
-
for (
|
|
50380
|
-
const
|
|
50381
|
-
if (
|
|
50455
|
+
for (let at = 0; at < steps.length; at += 1) {
|
|
50456
|
+
const step = steps[at];
|
|
50457
|
+
if (step === void 0) continue;
|
|
50458
|
+
const before = places[at];
|
|
50459
|
+
const place = placeFor(pixi, inputs.retired, places, at, step);
|
|
50460
|
+
if (place !== before) rebuilt = true;
|
|
50382
50461
|
if (writeStep(place, step)) changed = true;
|
|
50383
50462
|
if (place.scale !== step.scale) {
|
|
50384
50463
|
place.scale = step.scale;
|
|
50385
50464
|
changed = true;
|
|
50386
50465
|
}
|
|
50387
50466
|
}
|
|
50388
|
-
|
|
50389
|
-
inputs.retired.push(left.body);
|
|
50390
|
-
rebuilt = true;
|
|
50391
|
-
}
|
|
50467
|
+
if (retireLeft(inputs.retired, places, steps.length)) rebuilt = true;
|
|
50392
50468
|
if (rebuilt) inputs.slot = Object.freeze({
|
|
50393
50469
|
...inputs.slot,
|
|
50394
50470
|
stages: stagesOf(inputs)
|
|
@@ -50413,7 +50489,10 @@ function evaluate(ectx, pixi, instance, inputs, resolution, backResolution) {
|
|
|
50413
50489
|
const kind = ectx.state.kinds.get(instance.kindId);
|
|
50414
50490
|
let changed = resolution !== inputs.resolution || backResolution !== inputs.backResolution;
|
|
50415
50491
|
let passes = 1;
|
|
50416
|
-
|
|
50492
|
+
const declared = instance.definition.inputs;
|
|
50493
|
+
for (let index = 0; index < declared.length; index += 1) {
|
|
50494
|
+
const input = declared[index];
|
|
50495
|
+
if (input === void 0) continue;
|
|
50417
50496
|
let steps;
|
|
50418
50497
|
inputs.context.resolution = input.from === "back" ? backResolution : resolution;
|
|
50419
50498
|
try {
|
|
@@ -74516,6 +74595,295 @@ void main() {
|
|
|
74516
74595
|
},
|
|
74517
74596
|
padding: "spread"
|
|
74518
74597
|
});
|
|
74598
|
+
//#endregion
|
|
74599
|
+
//#region src/plugins/effects/set/stages.ts
|
|
74600
|
+
/**
|
|
74601
|
+
* @file effects/set — the shared stages a chain member of the set draws its second texture with: `BloomDown` (what is
|
|
74602
|
+
* above a threshold, boxed down in one pass) and `BloomBlur` (a 13-tap blur in two dimensions, one pass). Each is a
|
|
74603
|
+
* `defineFilter` that draws alone, listed in a member's `inputs` and named by its chain's steps; none is a root
|
|
74604
|
+
* export (a game that wants a chain writes its own stages). Before each body the set head and `inputTexel()`.
|
|
74605
|
+
*/
|
|
74606
|
+
/**
|
|
74607
|
+
* The WGSL the stages put between the set head and their bodies: `inputTexel()`, one texel of the input in the 0..1 of
|
|
74608
|
+
* `inputPlace`. Live a stage's input is a share of a pooled texture, its clamp half a texel in from the frame, so one
|
|
74609
|
+
* texel of uv (`uInputPixel.zw`) over the clamp's span is one texel of the frame on both axes.
|
|
74610
|
+
*/
|
|
74611
|
+
const STAGE_WGSL = `fn inputTexel() -> vec2<f32> {
|
|
74612
|
+
return gfu.uInputPixel.zw / (gfu.uInputClamp.zw - gfu.uInputClamp.xy);
|
|
74613
|
+
}
|
|
74614
|
+
|
|
74615
|
+
`;
|
|
74616
|
+
/** The GLSL twin of `STAGE_WGSL`. */
|
|
74617
|
+
const STAGE_GLSL = `vec2 inputTexel() {
|
|
74618
|
+
return uInputPixel.zw / (uInputClamp.zw - uInputClamp.xy);
|
|
74619
|
+
}
|
|
74620
|
+
|
|
74621
|
+
`;
|
|
74622
|
+
/**
|
|
74623
|
+
* A stage's WGSL body with the set head and `inputTexel()` before it. A call, so a bundle that drops the stage drops
|
|
74624
|
+
* the text too.
|
|
74625
|
+
*
|
|
74626
|
+
* @param body - The stage's WGSL body.
|
|
74627
|
+
* @returns The head, the helper, then the body.
|
|
74628
|
+
* @example
|
|
74629
|
+
* ```ts
|
|
74630
|
+
* withStageWgsl("@fragment fn mainFragment").includes("fn inputTexel()"); // true
|
|
74631
|
+
* ```
|
|
74632
|
+
*/
|
|
74633
|
+
function withStageWgsl(body) {
|
|
74634
|
+
return withSetWgsl(STAGE_WGSL + body);
|
|
74635
|
+
}
|
|
74636
|
+
/**
|
|
74637
|
+
* A stage's GLSL body with the set head and `inputTexel()` before it, for the same reason as `withStageWgsl`.
|
|
74638
|
+
*
|
|
74639
|
+
* @param body - The stage's GLSL body.
|
|
74640
|
+
* @returns The head, the helper, then the body.
|
|
74641
|
+
* @example
|
|
74642
|
+
* ```ts
|
|
74643
|
+
* withStageGlsl("void main() {}").includes("vec2 inputTexel()"); // true
|
|
74644
|
+
* ```
|
|
74645
|
+
*/
|
|
74646
|
+
function withStageGlsl(body) {
|
|
74647
|
+
return withSetGlsl(STAGE_GLSL + body);
|
|
74648
|
+
}
|
|
74649
|
+
/**
|
|
74650
|
+
* The WGSL body of `BloomDown`: drawn at ¼ or ⅛ of the view's input, it reads that input with 4 taps on the diagonals
|
|
74651
|
+
* of its pixel, `reach` texels out on each axis (1 at ¼, 2 at ⅛: the centres of the four quarters of its footprint).
|
|
74652
|
+
* Each tap stands on the corner of 4 texels, so the linear sampler reads a 2 × 2 block. Each tap is cut by
|
|
74653
|
+
* `threshold` of its own alpha, premultiplied, `max(c.rgb − threshold × c.a, 0)`, so a half-transparent edge is cut at
|
|
74654
|
+
* its share of the threshold, and its alpha is its brightest channel: light covers as much as it shines, and where
|
|
74655
|
+
* nothing is bright the cut is transparent black. The four cuts are averaged. The corner turns a quarter each tap.
|
|
74656
|
+
*/
|
|
74657
|
+
const BLOOM_DOWN_WGSL = `@fragment
|
|
74658
|
+
fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
|
74659
|
+
let n = inputPlace(uv);
|
|
74660
|
+
let d = fu.reach * inputTexel();
|
|
74661
|
+
var sum = vec4<f32>(0.0);
|
|
74662
|
+
var corner = vec2<f32>(1.0);
|
|
74663
|
+
|
|
74664
|
+
for (var k = 0; k < 4; k++) {
|
|
74665
|
+
let c = sampleInput(n + corner * d);
|
|
74666
|
+
let cut = max(c.rgb - fu.threshold * c.a, vec3<f32>(0.0));
|
|
74667
|
+
let light = max(max(cut.r, cut.g), cut.b);
|
|
74668
|
+
sum += vec4<f32>(cut, light);
|
|
74669
|
+
corner = vec2<f32>(-corner.y, corner.x);
|
|
74670
|
+
}
|
|
74671
|
+
|
|
74672
|
+
return sum * 0.25;
|
|
74673
|
+
}
|
|
74674
|
+
`;
|
|
74675
|
+
/** The GLSL twin of `BLOOM_DOWN_WGSL`. */
|
|
74676
|
+
const BLOOM_DOWN_GLSL = `void main() {
|
|
74677
|
+
vec2 n = inputPlace(vTextureCoord);
|
|
74678
|
+
vec2 d = reach * inputTexel();
|
|
74679
|
+
vec4 sum = vec4(0.0);
|
|
74680
|
+
vec2 corner = vec2(1.0);
|
|
74681
|
+
|
|
74682
|
+
for (int k = 0; k < 4; k++) {
|
|
74683
|
+
vec4 c = sampleInput(n + corner * d);
|
|
74684
|
+
vec3 cut = max(c.rgb - threshold * c.a, vec3(0.0));
|
|
74685
|
+
float light = max(max(cut.r, cut.g), cut.b);
|
|
74686
|
+
sum += vec4(cut, light);
|
|
74687
|
+
corner = vec2(-corner.y, corner.x);
|
|
74688
|
+
}
|
|
74689
|
+
|
|
74690
|
+
finalColor = sum * 0.25;
|
|
74691
|
+
}
|
|
74692
|
+
`;
|
|
74693
|
+
/**
|
|
74694
|
+
* The WGSL body of `BloomBlur`, a blur in two dimensions, in one pass at the scale of its input: the centre and two
|
|
74695
|
+
* rings of 6 taps, the inner one at `0.5 × sigma` texels, the outer one at `sigma`. A tap `d` texels out weighs
|
|
74696
|
+
* `exp(−d² / (2 × sigma²))`: `exp(−1 / 8)` on the inner ring, `exp(−1 / 2)` on the outer, 1 at the centre, and the sum
|
|
74697
|
+
* is divided by the 13 weights' sum. The outer ring stands at 15° + 60° × k, the inner one 30° further, turned 60° a
|
|
74698
|
+
* tap: at the chain's sigmas (8, 5.25 at the phone's 2.625) no tap stands on a texel's row or column, so the linear
|
|
74699
|
+
* sampler reads the 4 texels around each. The chain caps sigma at 8.
|
|
74700
|
+
*/
|
|
74701
|
+
const BLOOM_BLUR_WGSL = `@fragment
|
|
74702
|
+
fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
|
74703
|
+
let n = inputPlace(uv);
|
|
74704
|
+
let far = fu.sigma * inputTexel();
|
|
74705
|
+
let near = far * 0.5;
|
|
74706
|
+
let nearWeight = exp(-0.125);
|
|
74707
|
+
let farWeight = exp(-0.5);
|
|
74708
|
+
var sum = sampleInput(n);
|
|
74709
|
+
var outer = vec2<f32>(0.9659258, 0.258819);
|
|
74710
|
+
|
|
74711
|
+
for (var k = 0; k < 6; k++) {
|
|
74712
|
+
let inner = vec2<f32>(0.8660254 * outer.x - 0.5 * outer.y, 0.5 * outer.x + 0.8660254 * outer.y);
|
|
74713
|
+
sum += sampleInput(n + inner * near) * nearWeight + sampleInput(n + outer * far) * farWeight;
|
|
74714
|
+
outer = vec2<f32>(0.5 * outer.x - 0.8660254 * outer.y, 0.8660254 * outer.x + 0.5 * outer.y);
|
|
74715
|
+
}
|
|
74716
|
+
|
|
74717
|
+
return sum / (1.0 + 6.0 * (nearWeight + farWeight));
|
|
74718
|
+
}
|
|
74719
|
+
`;
|
|
74720
|
+
/** The GLSL twin of `BLOOM_BLUR_WGSL`. */
|
|
74721
|
+
const BLOOM_BLUR_GLSL = `void main() {
|
|
74722
|
+
vec2 n = inputPlace(vTextureCoord);
|
|
74723
|
+
vec2 far = sigma * inputTexel();
|
|
74724
|
+
vec2 near = far * 0.5;
|
|
74725
|
+
float nearWeight = exp(-0.125);
|
|
74726
|
+
float farWeight = exp(-0.5);
|
|
74727
|
+
vec4 sum = sampleInput(n);
|
|
74728
|
+
vec2 outer = vec2(0.9659258, 0.258819);
|
|
74729
|
+
|
|
74730
|
+
for (int k = 0; k < 6; k++) {
|
|
74731
|
+
vec2 inner = vec2(0.8660254 * outer.x - 0.5 * outer.y, 0.5 * outer.x + 0.8660254 * outer.y);
|
|
74732
|
+
sum += sampleInput(n + inner * near) * nearWeight + sampleInput(n + outer * far) * farWeight;
|
|
74733
|
+
outer = vec2(0.5 * outer.x - 0.8660254 * outer.y, 0.8660254 * outer.x + 0.5 * outer.y);
|
|
74734
|
+
}
|
|
74735
|
+
|
|
74736
|
+
finalColor = sum / (1.0 + 6.0 * (nearWeight + farWeight));
|
|
74737
|
+
}
|
|
74738
|
+
`;
|
|
74739
|
+
/** The whole WGSL `BloomDown` is defined with: the set head, the stages' helper, then the body. */
|
|
74740
|
+
const BLOOM_DOWN_SOURCE = /*#__PURE__*/ withStageWgsl(BLOOM_DOWN_WGSL);
|
|
74741
|
+
/** The whole GLSL `BloomDown` is defined with. */
|
|
74742
|
+
const BLOOM_DOWN_GLSL_SOURCE = /*#__PURE__*/ withStageGlsl(BLOOM_DOWN_GLSL);
|
|
74743
|
+
/** The whole WGSL `BloomBlur` is defined with. */
|
|
74744
|
+
const BLOOM_BLUR_SOURCE = /*#__PURE__*/ withStageWgsl(BLOOM_BLUR_WGSL);
|
|
74745
|
+
/** The whole GLSL `BloomBlur` is defined with. */
|
|
74746
|
+
const BLOOM_BLUR_GLSL_SOURCE = /*#__PURE__*/ withStageGlsl(BLOOM_BLUR_GLSL);
|
|
74747
|
+
/**
|
|
74748
|
+
* The first stage of `Bloom`: what is above `threshold` of the view's input, premultiplied, boxed down to the step's
|
|
74749
|
+
* scale in one pass. 4 samples, `reach` texels out.
|
|
74750
|
+
*/
|
|
74751
|
+
const BloomDown = /*#__PURE__*/ defineFilter("effects.bloomDown", {
|
|
74752
|
+
wgsl: BLOOM_DOWN_SOURCE,
|
|
74753
|
+
glsl: BLOOM_DOWN_GLSL_SOURCE,
|
|
74754
|
+
uniforms: {
|
|
74755
|
+
threshold: .7,
|
|
74756
|
+
reach: 1
|
|
74757
|
+
}
|
|
74758
|
+
});
|
|
74759
|
+
/** The second stage of `Bloom`: a blur of `sigma` texels in both dimensions at once, 13 samples. */
|
|
74760
|
+
const BloomBlur = /*#__PURE__*/ defineFilter("effects.bloomBlur", {
|
|
74761
|
+
wgsl: BLOOM_BLUR_SOURCE,
|
|
74762
|
+
glsl: BLOOM_BLUR_GLSL_SOURCE,
|
|
74763
|
+
uniforms: { sigma: 0 }
|
|
74764
|
+
});
|
|
74765
|
+
//#endregion
|
|
74766
|
+
//#region src/plugins/effects/set/bloom.ts
|
|
74767
|
+
/**
|
|
74768
|
+
* @file effects/set — `Bloom`: light around the bright parts of a view. The one member with a chain: its input `bright`
|
|
74769
|
+
* is the view's light above `threshold`, cut and boxed down to ¼ (⅛ for a wide radius) in one pass and blurred there in
|
|
74770
|
+
* one more; the body adds it back by `strength`. 3 passes at any radius and resolution. A chain member never rides the
|
|
74771
|
+
* quad: a value change runs the chain again and redraws the kept picture's filter (stage 3).
|
|
74772
|
+
*/
|
|
74773
|
+
/** The most texels the blur's sigma may reach: past it the rings stand too far apart on the boxed-down light. */
|
|
74774
|
+
const MAX_SIGMA = 8;
|
|
74775
|
+
/** The scale of the ladder for a radius of at most `MAX_SIGMA` texels at it. */
|
|
74776
|
+
const QUARTER = 1 / 4;
|
|
74777
|
+
/** The scale of the ladder for a wider radius: one more halving, so sigma stays under its cap longer. */
|
|
74778
|
+
const EIGHTH = 1 / 8;
|
|
74779
|
+
/**
|
|
74780
|
+
* The WGSL body of `Bloom`: the view's own pixel, plus the blurred light of `bright` at the same place times
|
|
74781
|
+
* `strength`, at least 0. Both are premultiplied, so the sum is too; over an opaque pixel the light adds to its colour.
|
|
74782
|
+
*/
|
|
74783
|
+
const BLOOM_WGSL = `@fragment
|
|
74784
|
+
fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
|
74785
|
+
let c = sampleInput(inputPlace(uv));
|
|
74786
|
+
|
|
74787
|
+
return c + sampleBright(uv) * max(fu.strength, 0.0);
|
|
74788
|
+
}
|
|
74789
|
+
`;
|
|
74790
|
+
/** The GLSL twin of `BLOOM_WGSL`. */
|
|
74791
|
+
const BLOOM_GLSL = `void main() {
|
|
74792
|
+
vec4 c = sampleInput(inputPlace(vTextureCoord));
|
|
74793
|
+
|
|
74794
|
+
finalColor = c + sampleBright(vTextureCoord) * max(strength, 0.0);
|
|
74795
|
+
}
|
|
74796
|
+
`;
|
|
74797
|
+
/**
|
|
74798
|
+
* Makes one ladder: the cut boxed down to `scale`, then the blur at the same scale.
|
|
74799
|
+
*
|
|
74800
|
+
* @param scale - The scale both steps draw at.
|
|
74801
|
+
* @param reach - How far out the down step's taps stand, in texels of the view's input: a quarter of its footprint,
|
|
74802
|
+
* `1 / (4 × scale)`. A whole number, written as one: a fraction in a uniform comes back boxed at each read of a frame.
|
|
74803
|
+
* @returns The ladder, its steps frozen, its uniform objects open to the chain.
|
|
74804
|
+
*/
|
|
74805
|
+
function ladderAt(scale, reach) {
|
|
74806
|
+
const down = {
|
|
74807
|
+
threshold: 0,
|
|
74808
|
+
reach
|
|
74809
|
+
};
|
|
74810
|
+
const blur = { sigma: 0 };
|
|
74811
|
+
return {
|
|
74812
|
+
steps: Object.freeze([Object.freeze({
|
|
74813
|
+
stage: BloomDown,
|
|
74814
|
+
scale,
|
|
74815
|
+
uniforms: down
|
|
74816
|
+
}), Object.freeze({
|
|
74817
|
+
stage: BloomBlur,
|
|
74818
|
+
scale,
|
|
74819
|
+
uniforms: blur
|
|
74820
|
+
})]),
|
|
74821
|
+
scale,
|
|
74822
|
+
down,
|
|
74823
|
+
blur
|
|
74824
|
+
};
|
|
74825
|
+
}
|
|
74826
|
+
/**
|
|
74827
|
+
* Makes the two ladders of the chain, once. A function: the module-scope rule sees no collection literal, and a bundle
|
|
74828
|
+
* that drops `Bloom` drops the call and the stages with it.
|
|
74829
|
+
*
|
|
74830
|
+
* @returns The ladder at ¼ and the one at ⅛.
|
|
74831
|
+
*/
|
|
74832
|
+
function bloomLadders() {
|
|
74833
|
+
return {
|
|
74834
|
+
quarter: ladderAt(QUARTER, 1),
|
|
74835
|
+
eighth: ladderAt(EIGHTH, 2)
|
|
74836
|
+
};
|
|
74837
|
+
}
|
|
74838
|
+
/** The two ladders, made at module scope once: the chain answers one of them, written in place, on every call. */
|
|
74839
|
+
const LADDERS = /*#__PURE__*/ bloomLadders();
|
|
74840
|
+
/**
|
|
74841
|
+
* The chain of `bright`: the ladder at ⅛ when the radius in texels at ¼ is over `MAX_SIGMA`, otherwise the one at ¼;
|
|
74842
|
+
* sigma is the radius in texels at the ladder's scale, capped at `MAX_SIGMA`, so past it the bloom stops widening.
|
|
74843
|
+
* The answer is one of two arrays made once, its threshold and sigma written in place: the engine copies what it
|
|
74844
|
+
* reads, and a strength tween, which runs the chain in every frame, allocates nothing here.
|
|
74845
|
+
*
|
|
74846
|
+
* @param value - The stored value of the `Bloom`.
|
|
74847
|
+
* @param context - The resolution of the view's input.
|
|
74848
|
+
* @returns The two steps, the same array for every call of a ladder.
|
|
74849
|
+
*/
|
|
74850
|
+
function bloomChain(value, context) {
|
|
74851
|
+
const texels = value.radius * context.resolution;
|
|
74852
|
+
const ladder = texels * QUARTER > MAX_SIGMA ? LADDERS.eighth : LADDERS.quarter;
|
|
74853
|
+
ladder.down.threshold = value.threshold;
|
|
74854
|
+
ladder.blur.sigma = Math.min(Math.max(texels * ladder.scale, 0), MAX_SIGMA);
|
|
74855
|
+
return ladder.steps;
|
|
74856
|
+
}
|
|
74857
|
+
/**
|
|
74858
|
+
* Light around the bright parts of a view and its subtree: what is above `threshold` (0..1) of its light, blurred
|
|
74859
|
+
* `radius` CSS px wide, added back by `strength` (0..2). For a reward, a gem, a lit lamp: an object, not the screen
|
|
74860
|
+
* (over the A26's screen its passes fill 1.9 Mpx a frame at 2.625). List it in a feature's `filters`, as a game's own
|
|
74861
|
+
* filter. It reads a second texture drawn by a chain of two stages, the light cut and boxed down to ¼ (⅛ when the
|
|
74862
|
+
* radius is over 8 texels at ¼: radius 16 at the phone's 2.625, 32 at 2) and blurred there: 3 passes at any radius.
|
|
74863
|
+
* A still view is kept as a picture; a tween of any field runs the chain again and redraws the picture's filter, 3
|
|
74864
|
+
* passes, in every frame it moves: it never draws on the view's quad. Past a sigma of 8 texels at ⅛ the bloom stops
|
|
74865
|
+
* widening.
|
|
74866
|
+
*
|
|
74867
|
+
* @example
|
|
74868
|
+
* ```ts
|
|
74869
|
+
* // features/shop/feature.ts lists it: filters: [Bloom]. A reward card blooms gold, then a motion fades it out.
|
|
74870
|
+
* Bloom.filter.inputs[0]?.chain({ ...Bloom().value }, { resolution: 2 }).length; // 2
|
|
74871
|
+
* view.tween(Bloom, { strength: 0 }, { ms: 400 });
|
|
74872
|
+
* ```
|
|
74873
|
+
*/
|
|
74874
|
+
const Bloom = /*#__PURE__*/ defineFilter("effects.bloom", {
|
|
74875
|
+
wgsl: /* @__PURE__ */ withSetWgsl(BLOOM_WGSL),
|
|
74876
|
+
glsl: /* @__PURE__ */ withSetGlsl(BLOOM_GLSL),
|
|
74877
|
+
uniforms: {
|
|
74878
|
+
strength: .6,
|
|
74879
|
+
threshold: .7,
|
|
74880
|
+
radius: 16
|
|
74881
|
+
},
|
|
74882
|
+
inputs: { bright: {
|
|
74883
|
+
stages: [BloomDown, BloomBlur],
|
|
74884
|
+
chain: bloomChain
|
|
74885
|
+
} }
|
|
74886
|
+
});
|
|
74519
74887
|
/**
|
|
74520
74888
|
* A view eaten away by a noise of `scale` cells across: `progress` 0 keeps all of it, 1 none, and the edge of what is
|
|
74521
74889
|
* left glows in `edgeColor` over `edge` (0..1 of the noise). The noise has no time: the same cells go first at every
|
|
@@ -75117,4 +75485,4 @@ const screen = [
|
|
|
75117
75485
|
uiPlugin
|
|
75118
75486
|
];
|
|
75119
75487
|
//#endregion
|
|
75120
|
-
export {
|
|
75488
|
+
export { HAPTIC_KINDS as $, PASS_KINDS as $t, types_exports as A, Traced as At, types_exports$10 as B, Glow as Bt, defineFeature as C, PointerOver as Ct, defineBundles as D, Tappable as Dt, music as E, Swipeable as Et, types_exports$5 as F, Emitter as Ft, types_exports$15 as G, audioPlugin as Gt, types_exports$12 as H, Outline as Ht, types_exports$6 as I, Alpha as It, uiPlugin as J, animPlugin as Jt, types_exports$16 as K, scenesPlugin as Kt, types_exports$7 as L, Blur as Lt, types_exports$2 as M, messageArgument as Mt, types_exports$3 as N, messageDuration as Nt, load as O, Touchable as Ot, types_exports$4 as P, effectsPlugin as Pt, platformPlugin as Q, rendererPlugin as Qt, types_exports$8 as R, ColorMatrix as Rt, tr as S, Pointer as St, defineEmitter as T, Pressed as Tt, types_exports$13 as U, defineFilter as Ut, types_exports$11 as V, Noise as Vt, types_exports$14 as W, debugPlugin as Wt, defineMotion as X, Animation as Xt, resolve as Y, AnimPlayer as Yt, textPlugin as Z, Frames as Zt, guide as _, modelPlugin as _n, inputPlugin as _t, Vignette as a, PROBLEM_RULES as an, parallel as at, projection as b, timePlugin as bn, Held as bt, RevealLine as c, DEMAND_REASONS as cn, set as ct, Flash as d, refuseStart as dn, spawned as dt, frameAt as en, defineAnimation as et, Dissolve as f, contribution as fn, stagger as ft, defineEffect as g, type as gn, wait as gt, cubicBezier as h, to as hn, use as ht, screen as i, PERF_LOG_VERSION as in, mark as it, types_exports$1 as j, i18nPlugin as jt, ready as k, Traceable as kt, Grade as l, worldPlugin as ln, sfx as lt, Aura as m, slot as mn, tween as mt, createPlugin as n, PERF_CAUSES as nn, frames as nt, Shine as o, SHADER_WHATS as on, play$1 as ot, Bloom as p, exit as pn, stopSfx as pt, types_exports$17 as q, assetsPlugin as qt, defineGame as r, PERF_GAP_BUCKETS as rn, haptic as rt, RevealRound as s, CANVAS_RESTARTS as sn, sequence as st, createApp as t, MONITOR_SECTIONS as tn, external as tt, Fold as u, flowPlugin as un, spawn as ut, hint as v, SaveUnreadableError as vn, Draggable as vt, flattenFeatures as w, Pressable as wt, defineScene as x, clockPlugin as xn, Hovered as xt, schedule as y, lifecyclePlugin as yn, DropTarget as yt, types_exports$9 as z, Displacement as zt };
|