reze-engine 0.69.5 → 0.69.7

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/dist/engine.js CHANGED
@@ -34,6 +34,7 @@ import { MIRROR_DOWNSAMPLE_WGSL, MIRROR_MASK_DOWNSAMPLE_WGSL, MIRROR_MAT_BYTES,
34
34
  import { packHalf } from "./hdr";
35
35
  import { evalIrradianceSH, projectIrradianceSH, gradientIrradianceSH } from "./ibl";
36
36
  import { LYRIC_ATLAS_MAX_H, LYRIC_ATLAS_MAX_W, LYRICS_FLOATS, packLyrics } from "./shaders/lyrics-api";
37
+ import { effectTextFont, effectTextWgsl, rasterEffectText, EFFECT_TEXT_PX } from "./shaders/text-api";
37
38
  import { sceneTargets as sceneTargetsFor, sceneColorFormats, setMrtIds, mrtIdsEnabled, SCENE_ID_FORMAT, } from "./shaders/passes/scene-contract";
38
39
  import { LIGHT_GRID_BASE, LIGHT_HEADER, LIGHT_STRIDE, LIGHTS_FLOATS, MAX_LIGHTS, buildLightEmitShader, hasLightEmit, } from "./shaders/lights";
39
40
  import { buildLightGrid } from "./light-grid";
@@ -683,6 +684,13 @@ const TEXTURE_EXTENSION_GUESSES = [".png", ".jpg", ".jpeg", ".bmp", ".tga", ".dd
683
684
  function paramValue(p, given) {
684
685
  if (p.kind === "bone")
685
686
  return isBoneValue(given) ? given : { bone: typeof p.value === "string" ? p.value : "", model: null };
687
+ if (p.kind === "text")
688
+ return typeof given === "string" ? given : typeof p.value === "string" ? p.value : "";
689
+ // A lag is filled from the dial it trails, every frame.
690
+ if (p.kind === "lag")
691
+ return 0;
692
+ if (typeof given === "string")
693
+ given = undefined;
686
694
  if (given !== undefined)
687
695
  return p.kind === "int" && typeof given === "number" ? Math.round(given) : given;
688
696
  if (p.kind === "color" && typeof p.value === "string") {
@@ -716,6 +724,8 @@ function castSubjectKey(subjects) {
716
724
  return subjects ? [...subjects].sort().join("\u0000") : "*";
717
725
  }
718
726
  const EFFECT_PARAMS_BINDING = 7;
727
+ /** The field module's binding for an effect's words — see text-api. */
728
+ const EFFECT_TEXT_BINDING = 33;
719
729
  const EFFECT_PARAMS_BINDING_GRID = 9;
720
730
  /**
721
731
  * How one field draw lands on the ones before it: OVER, into a premultiplied
@@ -3625,6 +3635,7 @@ export class Engine {
3625
3635
  { binding: 19, resource: { buffer: this.midiBuffer } },
3626
3636
  { binding: 24, resource: { buffer: this.lyricsBuffer } },
3627
3637
  { binding: 25, resource: this.lyricsTextureView },
3638
+ { binding: EFFECT_TEXT_BINDING, resource: owner.text?.view ?? this.trailFallbackView },
3628
3639
  // The size uniform for the pair THIS effect draws into.
3629
3640
  { binding: 14, resource: { buffer: this.fieldUniformBuffers[owner.fieldLayer] } },
3630
3641
  { binding: 22, resource: { buffer: owner.fieldClock ?? this.fieldUniformBuffers[owner.fieldLayer] } },
@@ -4118,6 +4129,15 @@ export class Engine {
4118
4129
  }
4119
4130
  continue;
4120
4131
  }
4132
+ if (p.kind === "text") {
4133
+ // The rect of the string it shows in the effect's picture: u0, vTop,
4134
+ // u1, vBottom — read through rzText_NAME().
4135
+ const offset = Math.ceil(cursor / 16) * 16;
4136
+ layout.set(p.name, { offset: offset / 4, comps: 4 });
4137
+ fields.push(` ${p.name}: vec4f,`);
4138
+ cursor = offset + 16;
4139
+ continue;
4140
+ }
4121
4141
  const isVec = p.kind === "color" || p.kind === "vec3" || p.kind === "point";
4122
4142
  const align = isVec ? 16 : 4;
4123
4143
  const offset = Math.ceil(cursor / align) * align;
@@ -4135,6 +4155,9 @@ export class Engine {
4135
4155
  paramBindings.set(name, value);
4136
4156
  continue;
4137
4157
  }
4158
+ // Words get their rect once the picture is set, after the mounts build.
4159
+ if (typeof value === "string")
4160
+ continue;
4138
4161
  if (typeof value === "number")
4139
4162
  paramsData[slot.offset] = value;
4140
4163
  else {
@@ -4162,10 +4185,12 @@ export class Engine {
4162
4185
  * one states the number it can spare. Empty when nothing is declared: WGSL
4163
4186
  * has no empty struct, and a binding nothing reads is a layout mismatch.
4164
4187
  */
4165
- const paramsWgsl = (binding) => entries.length
4166
- ? `struct EffectParams {\n${fields.join("\n")}\n}\n@group(0) @binding(${binding}) var<uniform> params: EffectParams;\n${boneWgsl}`
4188
+ const textNames = d.params.filter((p) => p.kind === "text").map((p) => p.name);
4189
+ const paramsWgsl = (binding, text = false) => entries.length
4190
+ ? `struct EffectParams {\n${fields.join("\n")}\n}\n@group(0) @binding(${binding}) var<uniform> params: EffectParams;\n${boneWgsl}` +
4191
+ effectTextWgsl(textNames, text, EFFECT_TEXT_BINDING, "_rzGridSamp")
4167
4192
  : "";
4168
- const paramsDecl = paramsWgsl(EFFECT_PARAMS_BINDING);
4193
+ const paramsDecl = paramsWgsl(EFFECT_PARAMS_BINDING, true);
4169
4194
  // ── Compile with validation captured, not thrown at the console. Line
4170
4195
  // numbers in diagnostics are rebased to the USER's source.
4171
4196
  // The composite is STATIC: user field code compiles in its own half-res
@@ -4367,6 +4392,16 @@ export class Engine {
4367
4392
  paramLayout: layout,
4368
4393
  paramsBuffer,
4369
4394
  paramsData,
4395
+ text: textNames.length
4396
+ ? {
4397
+ font: d.font,
4398
+ strings: new Set(entries.flatMap(([, v]) => (typeof v === "string" && v ? [v] : []))),
4399
+ rects: new Map(),
4400
+ texture: null,
4401
+ view: null,
4402
+ shown: new Map(entries.flatMap(([n, v]) => (typeof v === "string" ? [[n, v]] : []))),
4403
+ }
4404
+ : null,
4370
4405
  paramBindings,
4371
4406
  paramTracks: new Map(),
4372
4407
  hasMirror: d.mirror,
@@ -4409,6 +4444,9 @@ export class Engine {
4409
4444
  sim: { start: null, time: null },
4410
4445
  simStep: 0,
4411
4446
  simReset: false,
4447
+ seededCast: -1,
4448
+ paramsTouched: false,
4449
+ simNudge: false,
4412
4450
  dissolve: d.dissolve ? dissolveConstants(authored) : null,
4413
4451
  ground: d.ground ? { color: new Vec3(...d.ground.color), noise: d.ground.noise } : null,
4414
4452
  // Its OWN resolution, no longer the scene's: an effect that never asked
@@ -4442,6 +4480,9 @@ export class Engine {
4442
4480
  trails,
4443
4481
  lights,
4444
4482
  };
4483
+ // Before the swap binds it, so the field's first frame already has words.
4484
+ if (instance.text)
4485
+ this.layoutEffectText(instance);
4445
4486
  return { ok: true, instance, warnings };
4446
4487
  }
4447
4488
  /**
@@ -4484,6 +4525,7 @@ export class Engine {
4484
4525
  const [identity, gamma] = await this.compositePipelines(false, false);
4485
4526
  for (const e of this.effects) {
4486
4527
  e.paramsBuffer?.destroy();
4528
+ e.text?.texture?.destroy();
4487
4529
  e.lights?.uniform.destroy();
4488
4530
  e.fieldClock?.destroy();
4489
4531
  }
@@ -4549,6 +4591,7 @@ export class Engine {
4549
4591
  // that was running is only torn down now.
4550
4592
  for (const e of this.effects) {
4551
4593
  e.paramsBuffer?.destroy();
4594
+ e.text?.texture?.destroy();
4552
4595
  e.lights?.uniform.destroy();
4553
4596
  e.fieldClock?.destroy();
4554
4597
  }
@@ -5133,8 +5176,9 @@ export class Engine {
5133
5176
  const scheduled = e.window !== null;
5134
5177
  // A scheduled pool that has not moved holds still: a paused transport, or
5135
5178
  // a time outside every window. A dispatch at dt 0 would still run the
5136
- // author's step, and not every step is a function of dt.
5137
- if (scheduled && !e.simReset && e.simStep === 0)
5179
+ // author's step, and not every step is a function of dt — so it runs
5180
+ // only when a dial moved, which is when the step's answer changed.
5181
+ if (scheduled && !e.simReset && e.simStep === 0 && !e.simNudge)
5138
5182
  continue;
5139
5183
  // Entering its window, or going back in it: the pool starts empty, and
5140
5184
  // every slot spawns on this dispatch from the effect's own local time.
@@ -5170,14 +5214,22 @@ export class Engine {
5170
5214
  count.dispatchWorkgroups(1);
5171
5215
  count.end();
5172
5216
  }
5173
- const cp = encoder.beginComputePass({ label: "particles" });
5174
- cp.setPipeline(p.compute);
5175
- cp.setBindGroup(0, bind);
5176
- if (p.live)
5177
- cp.dispatchWorkgroupsIndirect(p.live.indirect, 0);
5178
- else
5179
- cp.dispatchWorkgroups(Math.ceil(p.count / 64));
5180
- cp.end();
5217
+ // A reset runs the pool TWICE: once to spawn every slot, once to step
5218
+ // what spawned, at dt 0. A dispatch either inits a slot or steps it, and
5219
+ // an effect that poses in its step (Pochita's bones, which its triangles
5220
+ // are drawn from) has no pose after the init alone. Playing, the next
5221
+ // frame's step supplied it; paused at a clip's start no next frame
5222
+ // steps, and the pet stayed collapsed — invisible — until play.
5223
+ for (let pass = e.simReset ? 2 : 1; pass > 0; pass--) {
5224
+ const cp = encoder.beginComputePass({ label: "particles" });
5225
+ cp.setPipeline(p.compute);
5226
+ cp.setBindGroup(0, bind);
5227
+ if (p.live)
5228
+ cp.dispatchWorkgroupsIndirect(p.live.indirect, 0);
5229
+ else
5230
+ cp.dispatchWorkgroups(Math.ceil(p.count / 64));
5231
+ cp.end();
5232
+ }
5181
5233
  }
5182
5234
  }
5183
5235
  /**
@@ -5874,7 +5926,7 @@ export class Engine {
5874
5926
  continue;
5875
5927
  const scheduled = e.window !== null;
5876
5928
  // Held still like the particles, for the same reason.
5877
- if (scheduled && !e.simReset && e.simStep === 0)
5929
+ if (scheduled && !e.simReset && e.simStep === 0 && !e.simNudge)
5878
5930
  continue;
5879
5931
  if (e.simReset) {
5880
5932
  // Back to how install left it: both textures empty and frame 0 again,
@@ -5932,8 +5984,10 @@ export class Engine {
5932
5984
  // value changes, so a plain value written over it would stick until then.
5933
5985
  if (fx.paramTracks.has(name))
5934
5986
  return;
5935
- if (this.writeEffectParam(fx, name, value))
5987
+ if (this.writeEffectParam(fx, name, value)) {
5936
5988
  this.device.queue.writeBuffer(fx.paramsBuffer, 0, fx.paramsData);
5989
+ fx.paramsTouched = true;
5990
+ }
5937
5991
  // A bone, or a point that now follows someone, lands on the next frame's
5938
5992
  // evaluation; resolving it now as well means a paused scene shows it too.
5939
5993
  if (fx.paramBindings.has(name))
@@ -5952,7 +6006,12 @@ export class Engine {
5952
6006
  fx.paramBindings.set(name, value);
5953
6007
  return false;
5954
6008
  }
5955
- if (isBoneValue(value))
6009
+ if (decl.kind === "text")
6010
+ return typeof value === "string" ? this.showEffectText(fx, name, value) : false;
6011
+ // A lag is its source's, trailing; nothing writes it by hand.
6012
+ if (decl.kind === "lag")
6013
+ return false;
6014
+ if (isBoneValue(value) || typeof value === "string")
5956
6015
  return false;
5957
6016
  if (typeof value === "number") {
5958
6017
  fx.paramsData[slot.offset] = decl.kind === "int" ? Math.round(value) : value;
@@ -5987,8 +6046,11 @@ export class Engine {
5987
6046
  fx.paramTracks.delete(name);
5988
6047
  return true;
5989
6048
  }
5990
- const holds = decl.kind === "bool" || decl.kind === "enum" || decl.kind === "bone";
6049
+ if (decl.kind === "lag")
6050
+ return false;
6051
+ const holds = decl.kind === "bool" || decl.kind === "enum" || decl.kind === "bone" || decl.kind === "text";
5991
6052
  const bones = [];
6053
+ const texts = [];
5992
6054
  const sorted = [...keys].sort((a, b) => a.time - b.time);
5993
6055
  const track = [];
5994
6056
  for (const k of sorted) {
@@ -5998,6 +6060,13 @@ export class Engine {
5998
6060
  continue;
5999
6061
  v = bones.push(k.value) - 1;
6000
6062
  }
6063
+ else if (decl.kind === "text") {
6064
+ if (typeof k.value !== "string")
6065
+ continue;
6066
+ v = texts.push(k.value) - 1;
6067
+ }
6068
+ else if (typeof k.value === "string")
6069
+ continue;
6001
6070
  else if (typeof k.value === "number")
6002
6071
  v = k.value;
6003
6072
  else if (isBoneValue(k.value))
@@ -6011,7 +6080,11 @@ export class Engine {
6011
6080
  ...(!holds && k.curve && k.ease !== "hold" ? { b: k.curve } : {}),
6012
6081
  });
6013
6082
  }
6014
- fx.paramTracks.set(name, { keys: track, bones, last: null });
6083
+ fx.paramTracks.set(name, { keys: track, bones, texts, last: null });
6084
+ // Every word a key can show goes into the picture now, so playing past a
6085
+ // key is a rect write and never a redraw.
6086
+ if (fx.text && texts.some((t) => t && !fx.text.strings.has(t)))
6087
+ this.layoutEffectText(fx);
6015
6088
  this.evaluateEffectParams();
6016
6089
  return true;
6017
6090
  }
@@ -6039,6 +6112,11 @@ export class Engine {
6039
6112
  if (bone)
6040
6113
  fx.paramBindings.set(name, bone);
6041
6114
  }
6115
+ else if (decl?.kind === "text") {
6116
+ const words = typeof v === "number" ? track.texts[v] : undefined;
6117
+ if (words !== undefined)
6118
+ dirty = this.showEffectText(fx, name, words) || dirty;
6119
+ }
6042
6120
  else if (typeof v === "number") {
6043
6121
  dirty = this.writeEffectParam(fx, name, v) || dirty;
6044
6122
  }
@@ -6050,11 +6128,148 @@ export class Engine {
6050
6128
  }
6051
6129
  if (fx.paramBindings.size)
6052
6130
  dirty = this.resolveParamBindings(fx) || dirty;
6053
- if (dirty)
6131
+ for (const p of fx.paramDecls) {
6132
+ if (p.kind !== "lag")
6133
+ continue;
6134
+ transport ?? (transport = this.transportTime());
6135
+ dirty = this.evaluateLag(fx, p, transport) || dirty;
6136
+ }
6137
+ if (dirty) {
6054
6138
  this.device.queue.writeBuffer(fx.paramsBuffer, 0, fx.paramsData);
6139
+ fx.paramsTouched = true;
6140
+ }
6055
6141
  }
6056
6142
  this.applyXray();
6057
6143
  }
6144
+ /**
6145
+ * A `lag` dial at time t: its source, trailing — what a game's health bar
6146
+ * draws as the chunk just lost. After the source falls it HOLDS where it was
6147
+ * for `hold` seconds, then drains at `rate` a second until it meets the
6148
+ * source again; a rise is met at once.
6149
+ *
6150
+ * Sampled from the source's KEYS, never from what the frames before this one
6151
+ * happened to see, so a scrub, a loop and a frame-by-frame export all draw
6152
+ * the same chunk. A source with no keys has no past: the lag is the source.
6153
+ */
6154
+ evaluateLag(fx, p, t) {
6155
+ const slot = fx.paramLayout.get(p.name);
6156
+ const src = p.source ? fx.paramLayout.get(p.source) : undefined;
6157
+ if (!slot || !src)
6158
+ return false;
6159
+ const d = fx.paramsData;
6160
+ let v = d[src.offset];
6161
+ const track = p.source ? fx.paramTracks.get(p.source) : undefined;
6162
+ if (track && track.keys.length > 0) {
6163
+ const hold = p.hold ?? 0;
6164
+ const rate = Math.max(p.rate ?? 1, 1e-6);
6165
+ const decl = fx.paramDecls.find((q) => q.name === p.source);
6166
+ const range = decl?.min !== undefined && decl.max !== undefined ? Math.abs(decl.max - decl.min) : 1;
6167
+ // Far enough back that anything older has drained past the full range.
6168
+ const span = hold + range / rate;
6169
+ const at = (s) => {
6170
+ const sv = sampleParamTrack(track.keys, s);
6171
+ if (typeof sv !== "number")
6172
+ return;
6173
+ v = Math.max(v, sv - rate * Math.max(0, t - s - hold));
6174
+ };
6175
+ // A fine grid, plus every key in the window exactly — a hit is a key,
6176
+ // and the instant before it is the value the chunk holds.
6177
+ const step = 1 / 120;
6178
+ for (let s = t; s >= t - span; s -= step)
6179
+ at(s);
6180
+ for (const k of track.keys) {
6181
+ if (k.t > t || k.t < t - span)
6182
+ continue;
6183
+ at(k.t);
6184
+ at(k.t - 1e-4);
6185
+ }
6186
+ }
6187
+ if (d[slot.offset] === v)
6188
+ return false;
6189
+ d[slot.offset] = v;
6190
+ return true;
6191
+ }
6192
+ /** Show `words` on a text dial: its rect into the block. A string the
6193
+ * picture has never held is set into it first, which redraws the picture
6194
+ * and writes the block itself. Returns whether the caller still has to. */
6195
+ showEffectText(fx, name, words) {
6196
+ const t = fx.text;
6197
+ if (!t)
6198
+ return false;
6199
+ t.shown.set(name, words);
6200
+ if (words && !t.strings.has(words)) {
6201
+ this.layoutEffectText(fx);
6202
+ return false;
6203
+ }
6204
+ return this.writeTextRect(fx, name, words);
6205
+ }
6206
+ writeTextRect(fx, name, words) {
6207
+ const slot = fx.paramLayout.get(name);
6208
+ if (!slot || !fx.text)
6209
+ return false;
6210
+ const r = fx.text.rects.get(words) ?? [0, 0, 0, 0];
6211
+ const d = fx.paramsData;
6212
+ let moved = false;
6213
+ for (let k = 0; k < 4; k++) {
6214
+ if (d[slot.offset + k] === r[k])
6215
+ continue;
6216
+ d[slot.offset + k] = r[k];
6217
+ moved = true;
6218
+ }
6219
+ return moved;
6220
+ }
6221
+ /**
6222
+ * Set every string an effect's text dials can show into its picture, upload
6223
+ * it and point each dial at its row. Re-binds only when the picture changes
6224
+ * SIZE. Once the face has loaded, a second pass sets it again — a web font
6225
+ * the page has not fetched yet draws in the fallback the first time.
6226
+ */
6227
+ layoutEffectText(fx, fontLoaded = false) {
6228
+ const t = fx.text;
6229
+ if (!t || !this.device)
6230
+ return;
6231
+ // What the dials show now and what their keys can show — rebuilt rather
6232
+ // than added to, so typing a name does not keep every half-typed word.
6233
+ t.strings = new Set([...t.shown.values(), ...[...fx.paramTracks.values()].flatMap((k) => k.texts)].filter((w) => w.length > 0));
6234
+ const sheet = rasterEffectText([...t.strings], t.font);
6235
+ t.rects = sheet?.rects ?? new Map();
6236
+ const w = sheet?.width ?? 1;
6237
+ const h = sheet?.height ?? 1;
6238
+ if (!t.texture || t.texture.width !== w || t.texture.height !== h) {
6239
+ t.texture?.destroy();
6240
+ t.texture = this.device.createTexture({
6241
+ label: "effect text",
6242
+ size: [w, h],
6243
+ format: "r8unorm",
6244
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
6245
+ });
6246
+ t.view = t.texture.createView();
6247
+ if (this.effects.includes(fx))
6248
+ this.rebuildFieldBindGroup();
6249
+ }
6250
+ // premultipliedAlpha, as the lyric atlas: white glyphs on a clear canvas
6251
+ // arrive with coverage in red, antialiased edges intact.
6252
+ if (sheet) {
6253
+ this.device.queue.copyExternalImageToTexture({ source: sheet.source }, { texture: t.texture, premultipliedAlpha: true }, [w, h]);
6254
+ }
6255
+ for (const [name, words] of t.shown)
6256
+ this.writeTextRect(fx, name, words);
6257
+ if (fx.paramsBuffer)
6258
+ this.device.queue.writeBuffer(fx.paramsBuffer, 0, fx.paramsData);
6259
+ const fonts = typeof document !== "undefined" ? document.fonts : undefined;
6260
+ if (!fontLoaded && fonts && t.font) {
6261
+ const css = effectTextFont(t.font, EFFECT_TEXT_PX);
6262
+ if (!fonts.check(css, [...t.strings].join(""))) {
6263
+ fonts
6264
+ .load(css, [...t.strings].join(""))
6265
+ .then(() => {
6266
+ if (this.effects.includes(fx))
6267
+ this.layoutEffectText(fx, true);
6268
+ })
6269
+ .catch(() => { });
6270
+ }
6271
+ }
6272
+ }
6058
6273
  /**
6059
6274
  * Each `#xray` effect's window, onto every character it is aimed at: a
6060
6275
  * rectangle on the frame from its X, Y, WIDTH and HEIGHT dials (fractions of
@@ -6314,6 +6529,8 @@ export class Engine {
6314
6529
  const transport = this.transportTime();
6315
6530
  for (const fx of this.effects) {
6316
6531
  fx.simReset = false;
6532
+ fx.simNudge = fx.paramsTouched;
6533
+ fx.paramsTouched = false;
6317
6534
  const keyed = fx.influenceTrack ? sampleParamTrack(fx.influenceTrack, transport) : null;
6318
6535
  const level = typeof keyed === "number" ? Math.min(1, Math.max(0, keyed)) : fx.influence;
6319
6536
  if (!fx.window || fx.window.length === 0) {
@@ -6329,6 +6546,17 @@ export class Engine {
6329
6546
  fx.sim = sim.clock;
6330
6547
  fx.simStep = sim.step;
6331
6548
  fx.simReset = sim.reset;
6549
+ // A pool held still is seeded ONCE, against whoever was in the cast on
6550
+ // that frame. A scene opened paused at its first frame seeds before her
6551
+ // model has loaded, so an effect that spawns off the cast (chicks round
6552
+ // her feet) is born empty — and a held pool is never stepped again to
6553
+ // ask. So the seed is taken again when the cast it read has changed. The
6554
+ // cast was written earlier this frame (updateCameraUniforms).
6555
+ const cast = fx.subjectMask * 16 + fx.subjectCount;
6556
+ if (sim.clock.start !== null && !fx.simReset && fx.simStep === 0 && cast !== fx.seededCast)
6557
+ fx.simReset = true;
6558
+ if (fx.simReset || fx.simStep > 0)
6559
+ fx.seededCast = cast;
6332
6560
  // Its own clock, expressed the way the mounts read it. Every mount
6333
6561
  // derives time from the epoch against sceneClock, so this one write moves
6334
6562
  // the field, the particles, the ribbons, lightEmit and the grid together
@@ -6907,6 +7135,8 @@ export class Engine {
6907
7135
  { binding: 24, visibility: GPUShaderStage.FRAGMENT, buffer: { type: "read-only-storage" } },
6908
7136
  // The lyric line atlas, for rzLyricText.
6909
7137
  { binding: 25, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: "float", viewDimension: "2d" } },
7138
+ // This effect's own words, for rzText_NAME — a 1x1 when it has none.
7139
+ { binding: EFFECT_TEXT_BINDING, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: "float", viewDimension: "2d" } },
6910
7140
  { binding: 14, visibility: GPUShaderStage.FRAGMENT, buffer: { type: "uniform" } },
6911
7141
  // This effect's own clock — see the field shader's note on why it is
6912
7142
  // not viewU[6].x.
@@ -45,11 +45,16 @@ export type EffectParamOption = {
45
45
  */
46
46
  export type EffectParamDecl = {
47
47
  name: string;
48
- kind: "float" | "color" | "vec3" | "bool" | "enum" | "int" | "point" | "bone";
49
- /** Numbers for float/vec3/int/point, 0 or 1 for bool, the option's index for
50
- * enum, a bone's NAME for bone; `#rrggbb` for a colour, which the host
51
- * converts. */
48
+ kind: "float" | "color" | "vec3" | "bool" | "enum" | "int" | "point" | "bone" | "text" | "lag";
49
+ /** Numbers for float/vec3/int/point/lag, 0 or 1 for bool, the option's index
50
+ * for enum, a bone's NAME for bone, the words for text; `#rrggbb` for a
51
+ * colour, which the host converts. */
52
52
  value: number | [number, number, number] | string;
53
+ /** lag only: the float dial it trails, how many seconds it holds after that
54
+ * dial falls, and how much it then drains per second. */
55
+ source?: string;
56
+ hold?: number;
57
+ rate?: number;
53
58
  /** float and int only, and only when the author gave a range. */
54
59
  min?: number;
55
60
  max?: number;
@@ -154,6 +159,15 @@ export type EffectDirectives = {
154
159
  width: string;
155
160
  height: string;
156
161
  } | null;
162
+ /**
163
+ * `#font <css font, without the size> [tracking <em>]` — the face every
164
+ * `#param text` dial of this effect is set in, e.g. `#font 500 Georgia, serif
165
+ * tracking 0.12`. Null sets them in the platform's serif.
166
+ */
167
+ font: {
168
+ css: string;
169
+ tracking: number;
170
+ } | null;
157
171
  /**
158
172
  * How long ONE firing of this effect lasts, in seconds. 0 = undeclared.
159
173
  *
@@ -1 +1 @@
1
- {"version":3,"file":"directives.d.ts","sourceRoot":"","sources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BD;;;+BAG+B;AAC/B,eAAO,MAAM,cAAc,QAAmC,CAAA;AAG9D;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,QAA8B,CAAA;AAmCzD,MAAM,MAAM,eAAe,GAAG;IAAE,UAAU,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAEhF,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAsW7D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKpD"}
@@ -45,6 +45,7 @@ const SPEC = {
45
45
  mirror: 0,
46
46
  stepped: 0,
47
47
  xray: 4,
48
+ font: "rest",
48
49
  duration: 1,
49
50
  ground: "rest",
50
51
  };
@@ -118,6 +119,7 @@ export function parseDirectives(wgsl) {
118
119
  mirror: false,
119
120
  stepped: false,
120
121
  xray: null,
122
+ font: null,
121
123
  duration: 0,
122
124
  };
123
125
  const errors = [];
@@ -234,6 +236,26 @@ export function parseDirectives(wgsl) {
234
236
  d.params.push({ name, kind: "bone", value: rest[0], ...labels });
235
237
  return;
236
238
  }
239
+ if (kind === "text") {
240
+ // Words, set by the engine into a picture the field module reads
241
+ // through rzText_NAME(uv). The default is the rest of the line up to
242
+ // its note, spaces kept as one.
243
+ d.params.push({ name, kind: "text", value: rest.join(" "), ...labels });
244
+ return;
245
+ }
246
+ if (kind === "lag") {
247
+ // A float dial trailing another: what a game's health bar draws as
248
+ // the chunk just lost. Derived by the engine, so a host draws no
249
+ // control for it.
250
+ const hold = num(rest[1]);
251
+ const rate = num(rest[2]);
252
+ if (rest.length !== 3 || !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(rest[0]) || hold === null || hold < 0 || rate === null || rate <= 0) {
253
+ errors.push(`${at}: #param lag ${name} takes the dial it trails, a hold in seconds and a drain per second, like "HEALTH 0.8 0.6"`);
254
+ return;
255
+ }
256
+ d.params.push({ name, kind: "lag", value: 0, source: rest[0], hold, rate, ...labels });
257
+ return;
258
+ }
237
259
  if (kind === "enum") {
238
260
  // Each choice is `id` or `id|中文`; a leading `*` marks the default,
239
261
  // else the first is.
@@ -291,7 +313,7 @@ export function parseDirectives(wgsl) {
291
313
  d.params.push({ name, kind: "float", value: v, ...(lo !== null && hi !== null ? { min: lo, max: hi } : {}), ...labels });
292
314
  return;
293
315
  }
294
- errors.push(`${at}: #param kind must be float, int, color, vec3, point, bone, bool or enum`);
316
+ errors.push(`${at}: #param kind must be float, int, color, vec3, point, bone, bool, enum, text or lag`);
295
317
  return;
296
318
  }
297
319
  case "halfres":
@@ -369,6 +391,18 @@ export function parseDirectives(wgsl) {
369
391
  case "xray":
370
392
  d.xray = { x: args[0], y: args[1], width: args[2], height: args[3] };
371
393
  return;
394
+ case "font": {
395
+ const words = args.join(" ");
396
+ const m = /^(.*?)(?:\s+tracking\s+(-?[\d.]+))?$/.exec(words);
397
+ const css = (m?.[1] ?? "").trim();
398
+ const tracking = m?.[2] !== undefined ? num(m[2]) : 0;
399
+ if (!css || tracking === null) {
400
+ errors.push(`${at}: #font takes a CSS font without its size, like "500 Georgia, serif", and optionally "tracking 0.1"`);
401
+ return;
402
+ }
403
+ d.font = { css, tracking };
404
+ return;
405
+ }
372
406
  case "duration": {
373
407
  // SECONDS, like every other time a directive states (see #dissolve).
374
408
  // The document above works in frames and converts once; an author
@@ -406,6 +440,14 @@ export function parseDirectives(wgsl) {
406
440
  errors.push(`#xray: ${name} has to be a #param float`);
407
441
  }
408
442
  }
443
+ // A lag trails a number that has to be there.
444
+ for (const p of d.params) {
445
+ if (p.kind !== "lag")
446
+ continue;
447
+ const src = d.params.find((q) => q.name === p.source);
448
+ if (src?.kind !== "float" && src?.kind !== "int")
449
+ errors.push(`#param lag ${p.name}: ${p.source} has to be a #param float or int`);
450
+ }
409
451
  // Duplicates are an author editing one line and forgetting another; last-wins
410
452
  // is a coin toss they never see resolved.
411
453
  const names = new Set();
@@ -0,0 +1,32 @@
1
+ import type { LyricRect } from "./lyrics-api";
2
+ /** The font size the rows are set at, in texels. A boss's name drawn 60 pixels
3
+ * tall on a 4K frame is still minified from this. */
4
+ export declare const EFFECT_TEXT_PX = 96;
5
+ export type EffectTextFont = {
6
+ css: string;
7
+ tracking: number;
8
+ } | null;
9
+ /** The CSS font for a size: `#font`'s words with the size put where CSS wants
10
+ * it — after style, variant and weight, before the family. */
11
+ export declare function effectTextFont(font: EffectTextFont, px: number): string;
12
+ export type EffectTextSheet = {
13
+ source: HTMLCanvasElement | OffscreenCanvas;
14
+ width: number;
15
+ height: number;
16
+ /** Where each string sits: u0, vTop, u1, vBottom, in 0..1. */
17
+ rects: Map<string, LyricRect>;
18
+ };
19
+ /**
20
+ * Set `strings` into one sheet, a row each. Every row is the font's full box
21
+ * (its ascent and descent, not the string's own ink), so two strings in one
22
+ * face have one height and their aspects compare. A string too wide for the
23
+ * sheet is set smaller in its own row rather than cut. Null without a canvas.
24
+ */
25
+ export declare function rasterEffectText(strings: readonly string[], font: EffectTextFont): EffectTextSheet | null;
26
+ /**
27
+ * rzText_NAME(uv) and rzTextAspect_NAME() for each text dial. uv runs 0..1
28
+ * across the string's own box, y up, like rzLyricText; the answer is glyph
29
+ * coverage. textureSampleLevel, so it is legal after any branch.
30
+ */
31
+ export declare function effectTextWgsl(names: readonly string[], real: boolean, binding: number, sampler: string): string;
32
+ //# sourceMappingURL=text-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-api.d.ts","sourceRoot":"","sources":["../../src/shaders/text-api.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C;sDACsD;AACtD,eAAO,MAAM,cAAc,KAAK,CAAA;AAKhC,MAAM,MAAM,cAAc,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAA;AAErE;+DAC+D;AAC/D,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAMvE;AAkBD,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAA;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CAC9B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,GAAG,eAAe,GAAG,IAAI,CAyCzG;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CA4BhH"}