reze-engine 0.69.5 → 0.69.6

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,7 @@ export class Engine {
4409
4444
  sim: { start: null, time: null },
4410
4445
  simStep: 0,
4411
4446
  simReset: false,
4447
+ seededCast: -1,
4412
4448
  dissolve: d.dissolve ? dissolveConstants(authored) : null,
4413
4449
  ground: d.ground ? { color: new Vec3(...d.ground.color), noise: d.ground.noise } : null,
4414
4450
  // Its OWN resolution, no longer the scene's: an effect that never asked
@@ -4442,6 +4478,9 @@ export class Engine {
4442
4478
  trails,
4443
4479
  lights,
4444
4480
  };
4481
+ // Before the swap binds it, so the field's first frame already has words.
4482
+ if (instance.text)
4483
+ this.layoutEffectText(instance);
4445
4484
  return { ok: true, instance, warnings };
4446
4485
  }
4447
4486
  /**
@@ -4484,6 +4523,7 @@ export class Engine {
4484
4523
  const [identity, gamma] = await this.compositePipelines(false, false);
4485
4524
  for (const e of this.effects) {
4486
4525
  e.paramsBuffer?.destroy();
4526
+ e.text?.texture?.destroy();
4487
4527
  e.lights?.uniform.destroy();
4488
4528
  e.fieldClock?.destroy();
4489
4529
  }
@@ -4549,6 +4589,7 @@ export class Engine {
4549
4589
  // that was running is only torn down now.
4550
4590
  for (const e of this.effects) {
4551
4591
  e.paramsBuffer?.destroy();
4592
+ e.text?.texture?.destroy();
4552
4593
  e.lights?.uniform.destroy();
4553
4594
  e.fieldClock?.destroy();
4554
4595
  }
@@ -5170,14 +5211,22 @@ export class Engine {
5170
5211
  count.dispatchWorkgroups(1);
5171
5212
  count.end();
5172
5213
  }
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();
5214
+ // A reset runs the pool TWICE: once to spawn every slot, once to step
5215
+ // what spawned, at dt 0. A dispatch either inits a slot or steps it, and
5216
+ // an effect that poses in its step (Pochita's bones, which its triangles
5217
+ // are drawn from) has no pose after the init alone. Playing, the next
5218
+ // frame's step supplied it; paused at a clip's start no next frame
5219
+ // steps, and the pet stayed collapsed — invisible — until play.
5220
+ for (let pass = e.simReset ? 2 : 1; pass > 0; pass--) {
5221
+ const cp = encoder.beginComputePass({ label: "particles" });
5222
+ cp.setPipeline(p.compute);
5223
+ cp.setBindGroup(0, bind);
5224
+ if (p.live)
5225
+ cp.dispatchWorkgroupsIndirect(p.live.indirect, 0);
5226
+ else
5227
+ cp.dispatchWorkgroups(Math.ceil(p.count / 64));
5228
+ cp.end();
5229
+ }
5181
5230
  }
5182
5231
  }
5183
5232
  /**
@@ -5952,7 +6001,12 @@ export class Engine {
5952
6001
  fx.paramBindings.set(name, value);
5953
6002
  return false;
5954
6003
  }
5955
- if (isBoneValue(value))
6004
+ if (decl.kind === "text")
6005
+ return typeof value === "string" ? this.showEffectText(fx, name, value) : false;
6006
+ // A lag is its source's, trailing; nothing writes it by hand.
6007
+ if (decl.kind === "lag")
6008
+ return false;
6009
+ if (isBoneValue(value) || typeof value === "string")
5956
6010
  return false;
5957
6011
  if (typeof value === "number") {
5958
6012
  fx.paramsData[slot.offset] = decl.kind === "int" ? Math.round(value) : value;
@@ -5987,8 +6041,11 @@ export class Engine {
5987
6041
  fx.paramTracks.delete(name);
5988
6042
  return true;
5989
6043
  }
5990
- const holds = decl.kind === "bool" || decl.kind === "enum" || decl.kind === "bone";
6044
+ if (decl.kind === "lag")
6045
+ return false;
6046
+ const holds = decl.kind === "bool" || decl.kind === "enum" || decl.kind === "bone" || decl.kind === "text";
5991
6047
  const bones = [];
6048
+ const texts = [];
5992
6049
  const sorted = [...keys].sort((a, b) => a.time - b.time);
5993
6050
  const track = [];
5994
6051
  for (const k of sorted) {
@@ -5998,6 +6055,13 @@ export class Engine {
5998
6055
  continue;
5999
6056
  v = bones.push(k.value) - 1;
6000
6057
  }
6058
+ else if (decl.kind === "text") {
6059
+ if (typeof k.value !== "string")
6060
+ continue;
6061
+ v = texts.push(k.value) - 1;
6062
+ }
6063
+ else if (typeof k.value === "string")
6064
+ continue;
6001
6065
  else if (typeof k.value === "number")
6002
6066
  v = k.value;
6003
6067
  else if (isBoneValue(k.value))
@@ -6011,7 +6075,11 @@ export class Engine {
6011
6075
  ...(!holds && k.curve && k.ease !== "hold" ? { b: k.curve } : {}),
6012
6076
  });
6013
6077
  }
6014
- fx.paramTracks.set(name, { keys: track, bones, last: null });
6078
+ fx.paramTracks.set(name, { keys: track, bones, texts, last: null });
6079
+ // Every word a key can show goes into the picture now, so playing past a
6080
+ // key is a rect write and never a redraw.
6081
+ if (fx.text && texts.some((t) => t && !fx.text.strings.has(t)))
6082
+ this.layoutEffectText(fx);
6015
6083
  this.evaluateEffectParams();
6016
6084
  return true;
6017
6085
  }
@@ -6039,6 +6107,11 @@ export class Engine {
6039
6107
  if (bone)
6040
6108
  fx.paramBindings.set(name, bone);
6041
6109
  }
6110
+ else if (decl?.kind === "text") {
6111
+ const words = typeof v === "number" ? track.texts[v] : undefined;
6112
+ if (words !== undefined)
6113
+ dirty = this.showEffectText(fx, name, words) || dirty;
6114
+ }
6042
6115
  else if (typeof v === "number") {
6043
6116
  dirty = this.writeEffectParam(fx, name, v) || dirty;
6044
6117
  }
@@ -6050,11 +6123,146 @@ export class Engine {
6050
6123
  }
6051
6124
  if (fx.paramBindings.size)
6052
6125
  dirty = this.resolveParamBindings(fx) || dirty;
6126
+ for (const p of fx.paramDecls) {
6127
+ if (p.kind !== "lag")
6128
+ continue;
6129
+ transport ?? (transport = this.transportTime());
6130
+ dirty = this.evaluateLag(fx, p, transport) || dirty;
6131
+ }
6053
6132
  if (dirty)
6054
6133
  this.device.queue.writeBuffer(fx.paramsBuffer, 0, fx.paramsData);
6055
6134
  }
6056
6135
  this.applyXray();
6057
6136
  }
6137
+ /**
6138
+ * A `lag` dial at time t: its source, trailing — what a game's health bar
6139
+ * draws as the chunk just lost. After the source falls it HOLDS where it was
6140
+ * for `hold` seconds, then drains at `rate` a second until it meets the
6141
+ * source again; a rise is met at once.
6142
+ *
6143
+ * Sampled from the source's KEYS, never from what the frames before this one
6144
+ * happened to see, so a scrub, a loop and a frame-by-frame export all draw
6145
+ * the same chunk. A source with no keys has no past: the lag is the source.
6146
+ */
6147
+ evaluateLag(fx, p, t) {
6148
+ const slot = fx.paramLayout.get(p.name);
6149
+ const src = p.source ? fx.paramLayout.get(p.source) : undefined;
6150
+ if (!slot || !src)
6151
+ return false;
6152
+ const d = fx.paramsData;
6153
+ let v = d[src.offset];
6154
+ const track = p.source ? fx.paramTracks.get(p.source) : undefined;
6155
+ if (track && track.keys.length > 0) {
6156
+ const hold = p.hold ?? 0;
6157
+ const rate = Math.max(p.rate ?? 1, 1e-6);
6158
+ const decl = fx.paramDecls.find((q) => q.name === p.source);
6159
+ const range = decl?.min !== undefined && decl.max !== undefined ? Math.abs(decl.max - decl.min) : 1;
6160
+ // Far enough back that anything older has drained past the full range.
6161
+ const span = hold + range / rate;
6162
+ const at = (s) => {
6163
+ const sv = sampleParamTrack(track.keys, s);
6164
+ if (typeof sv !== "number")
6165
+ return;
6166
+ v = Math.max(v, sv - rate * Math.max(0, t - s - hold));
6167
+ };
6168
+ // A fine grid, plus every key in the window exactly — a hit is a key,
6169
+ // and the instant before it is the value the chunk holds.
6170
+ const step = 1 / 120;
6171
+ for (let s = t; s >= t - span; s -= step)
6172
+ at(s);
6173
+ for (const k of track.keys) {
6174
+ if (k.t > t || k.t < t - span)
6175
+ continue;
6176
+ at(k.t);
6177
+ at(k.t - 1e-4);
6178
+ }
6179
+ }
6180
+ if (d[slot.offset] === v)
6181
+ return false;
6182
+ d[slot.offset] = v;
6183
+ return true;
6184
+ }
6185
+ /** Show `words` on a text dial: its rect into the block. A string the
6186
+ * picture has never held is set into it first, which redraws the picture
6187
+ * and writes the block itself. Returns whether the caller still has to. */
6188
+ showEffectText(fx, name, words) {
6189
+ const t = fx.text;
6190
+ if (!t)
6191
+ return false;
6192
+ t.shown.set(name, words);
6193
+ if (words && !t.strings.has(words)) {
6194
+ this.layoutEffectText(fx);
6195
+ return false;
6196
+ }
6197
+ return this.writeTextRect(fx, name, words);
6198
+ }
6199
+ writeTextRect(fx, name, words) {
6200
+ const slot = fx.paramLayout.get(name);
6201
+ if (!slot || !fx.text)
6202
+ return false;
6203
+ const r = fx.text.rects.get(words) ?? [0, 0, 0, 0];
6204
+ const d = fx.paramsData;
6205
+ let moved = false;
6206
+ for (let k = 0; k < 4; k++) {
6207
+ if (d[slot.offset + k] === r[k])
6208
+ continue;
6209
+ d[slot.offset + k] = r[k];
6210
+ moved = true;
6211
+ }
6212
+ return moved;
6213
+ }
6214
+ /**
6215
+ * Set every string an effect's text dials can show into its picture, upload
6216
+ * it and point each dial at its row. Re-binds only when the picture changes
6217
+ * SIZE. Once the face has loaded, a second pass sets it again — a web font
6218
+ * the page has not fetched yet draws in the fallback the first time.
6219
+ */
6220
+ layoutEffectText(fx, fontLoaded = false) {
6221
+ const t = fx.text;
6222
+ if (!t || !this.device)
6223
+ return;
6224
+ // What the dials show now and what their keys can show — rebuilt rather
6225
+ // than added to, so typing a name does not keep every half-typed word.
6226
+ t.strings = new Set([...t.shown.values(), ...[...fx.paramTracks.values()].flatMap((k) => k.texts)].filter((w) => w.length > 0));
6227
+ const sheet = rasterEffectText([...t.strings], t.font);
6228
+ t.rects = sheet?.rects ?? new Map();
6229
+ const w = sheet?.width ?? 1;
6230
+ const h = sheet?.height ?? 1;
6231
+ if (!t.texture || t.texture.width !== w || t.texture.height !== h) {
6232
+ t.texture?.destroy();
6233
+ t.texture = this.device.createTexture({
6234
+ label: "effect text",
6235
+ size: [w, h],
6236
+ format: "r8unorm",
6237
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
6238
+ });
6239
+ t.view = t.texture.createView();
6240
+ if (this.effects.includes(fx))
6241
+ this.rebuildFieldBindGroup();
6242
+ }
6243
+ // premultipliedAlpha, as the lyric atlas: white glyphs on a clear canvas
6244
+ // arrive with coverage in red, antialiased edges intact.
6245
+ if (sheet) {
6246
+ this.device.queue.copyExternalImageToTexture({ source: sheet.source }, { texture: t.texture, premultipliedAlpha: true }, [w, h]);
6247
+ }
6248
+ for (const [name, words] of t.shown)
6249
+ this.writeTextRect(fx, name, words);
6250
+ if (fx.paramsBuffer)
6251
+ this.device.queue.writeBuffer(fx.paramsBuffer, 0, fx.paramsData);
6252
+ const fonts = typeof document !== "undefined" ? document.fonts : undefined;
6253
+ if (!fontLoaded && fonts && t.font) {
6254
+ const css = effectTextFont(t.font, EFFECT_TEXT_PX);
6255
+ if (!fonts.check(css, [...t.strings].join(""))) {
6256
+ fonts
6257
+ .load(css, [...t.strings].join(""))
6258
+ .then(() => {
6259
+ if (this.effects.includes(fx))
6260
+ this.layoutEffectText(fx, true);
6261
+ })
6262
+ .catch(() => { });
6263
+ }
6264
+ }
6265
+ }
6058
6266
  /**
6059
6267
  * Each `#xray` effect's window, onto every character it is aimed at: a
6060
6268
  * rectangle on the frame from its X, Y, WIDTH and HEIGHT dials (fractions of
@@ -6329,6 +6537,17 @@ export class Engine {
6329
6537
  fx.sim = sim.clock;
6330
6538
  fx.simStep = sim.step;
6331
6539
  fx.simReset = sim.reset;
6540
+ // A pool held still is seeded ONCE, against whoever was in the cast on
6541
+ // that frame. A scene opened paused at its first frame seeds before her
6542
+ // model has loaded, so an effect that spawns off the cast (chicks round
6543
+ // her feet) is born empty — and a held pool is never stepped again to
6544
+ // ask. So the seed is taken again when the cast it read has changed. The
6545
+ // cast was written earlier this frame (updateCameraUniforms).
6546
+ const cast = fx.subjectMask * 16 + fx.subjectCount;
6547
+ if (sim.clock.start !== null && !fx.simReset && fx.simStep === 0 && cast !== fx.seededCast)
6548
+ fx.simReset = true;
6549
+ if (fx.simReset || fx.simStep > 0)
6550
+ fx.seededCast = cast;
6332
6551
  // Its own clock, expressed the way the mounts read it. Every mount
6333
6552
  // derives time from the epoch against sceneClock, so this one write moves
6334
6553
  // the field, the particles, the ribbons, lightEmit and the grid together
@@ -6907,6 +7126,8 @@ export class Engine {
6907
7126
  { binding: 24, visibility: GPUShaderStage.FRAGMENT, buffer: { type: "read-only-storage" } },
6908
7127
  // The lyric line atlas, for rzLyricText.
6909
7128
  { binding: 25, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: "float", viewDimension: "2d" } },
7129
+ // This effect's own words, for rzText_NAME — a 1x1 when it has none.
7130
+ { binding: EFFECT_TEXT_BINDING, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: "float", viewDimension: "2d" } },
6910
7131
  { binding: 14, visibility: GPUShaderStage.FRAGMENT, buffer: { type: "uniform" } },
6911
7132
  // This effect's own clock — see the field shader's note on why it is
6912
7133
  // 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":["../../src/shaders/directives.ts"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MA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,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"}