reze-engine 0.58.1 → 0.58.2

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.
Files changed (51) hide show
  1. package/dist/effect-points.d.ts +30 -0
  2. package/dist/effect-points.d.ts.map +1 -0
  3. package/dist/effect-points.js +49 -0
  4. package/dist/engine.d.ts +22 -1
  5. package/dist/engine.d.ts.map +1 -1
  6. package/dist/engine.js +99 -8
  7. package/dist/light-grid.d.ts +25 -0
  8. package/dist/light-grid.d.ts.map +1 -0
  9. package/dist/light-grid.js +91 -0
  10. package/dist/model.d.ts +9 -0
  11. package/dist/model.d.ts.map +1 -1
  12. package/dist/model.js +6 -0
  13. package/dist/pmx-loader.d.ts.map +1 -1
  14. package/dist/pmx-loader.js +11 -6
  15. package/dist/shaders/cast-api.d.ts +1 -1
  16. package/dist/shaders/cast-layout.d.ts +5 -3
  17. package/dist/shaders/cast-layout.d.ts.map +1 -1
  18. package/dist/shaders/cast-layout.js +5 -3
  19. package/dist/shaders/directives.d.ts +3 -0
  20. package/dist/shaders/directives.d.ts.map +1 -1
  21. package/dist/shaders/directives.js +5 -0
  22. package/dist/shaders/lights.d.ts +14 -9
  23. package/dist/shaders/lights.d.ts.map +1 -1
  24. package/dist/shaders/lights.js +118 -65
  25. package/dist/shaders/passes/composite.d.ts +1 -1
  26. package/dist/shaders/passes/composite.d.ts.map +1 -1
  27. package/dist/shaders/passes/composite.js +2 -0
  28. package/dist/shaders/passes/grid.d.ts.map +1 -1
  29. package/dist/shaders/passes/grid.js +2 -0
  30. package/dist/shaders/passes/particles.d.ts +2 -0
  31. package/dist/shaders/passes/particles.d.ts.map +1 -1
  32. package/dist/shaders/passes/particles.js +6 -0
  33. package/dist/shaders/passes/trails.d.ts.map +1 -1
  34. package/dist/shaders/passes/trails.js +2 -1
  35. package/dist/shaders/points-api.d.ts +11 -0
  36. package/dist/shaders/points-api.d.ts.map +1 -0
  37. package/dist/shaders/points-api.js +58 -0
  38. package/package.json +1 -1
  39. package/src/effect-points.ts +67 -0
  40. package/src/engine.ts +111 -7
  41. package/src/light-grid.ts +139 -0
  42. package/src/model.ts +12 -0
  43. package/src/pmx-loader.ts +13 -6
  44. package/src/shaders/cast-layout.ts +5 -3
  45. package/src/shaders/directives.ts +8 -0
  46. package/src/shaders/lights.ts +118 -65
  47. package/src/shaders/passes/composite.ts +2 -0
  48. package/src/shaders/passes/grid.ts +2 -0
  49. package/src/shaders/passes/particles.ts +6 -0
  50. package/src/shaders/passes/trails.ts +2 -1
  51. package/src/shaders/points-api.ts +66 -0
@@ -11,18 +11,27 @@ import { subjectMaskApi } from "./cast-api";
11
11
  // renderer that bolted a second key light onto a toon shader has shipped. A
12
12
  // light here brightens; it does not restate the shading.
13
13
  //
14
- // So there are no per-light shadows, no area lights and no clustering. The loop
15
- // runs over the lights a scene HAS, not over the cap, so a scene with four pays
16
- // for four; the cap only bounds the buffer and the worst case.
14
+ // So there are no per-light shadows and no area lights. A fragment walks the
15
+ // DOCUMENT's lamps through a world-space grid (see light-grid.ts): its cell
16
+ // names the lamps that can reach it, so a stage rig of fifty costs each pixel
17
+ // the handful standing near it. The lamps an EFFECT emits are placed by a
18
+ // compute pass every frame, which the grid never sees, and are walked in full.
17
19
  //
18
- // LAYOUT. A 4-float header (count, then padding that keeps the records
19
- // vec4-aligned), then MAX_LIGHTS records of 16 floats — four vec4s:
20
+ // LAYOUT, in 32-bit words, read by the shader as vec4u. A 16-word header:
21
+ //
22
+ // [0] light count (f32) [1] how many are the document's (f32)
23
+ // [4..6] grid origin (f32) [7] 1 / cell edge (f32)
24
+ // [8..10] grid dims (u32) [12..15] the OUTSIDE mask (u32 bits)
25
+ //
26
+ // then MAX_LIGHTS records of 16 floats — four vec4s:
20
27
  //
21
28
  // [0..2] position, world space [3] radius
22
29
  // [4..6] colour PREMULTIPLIED by intensity [7] type
23
30
  // [8..10] aim, unit, pointing away from the light [11] cos of the outer angle
24
31
  // [12] cos of the inner angle [13..15] spare
25
32
  //
33
+ // then the grid: LIGHT_MASK_WORDS words of lamp bits per cell.
34
+ //
26
35
  // Colour carries intensity because nothing reads them apart: every use is the
27
36
  // product, and storing two numbers that are only ever multiplied is two numbers
28
37
  // that can disagree.
@@ -38,9 +47,10 @@ import { lyricsApi } from "./lyrics-api";
38
47
  import { clockApi, trailSlotsApi, viewportApi } from "./passes/hosted-api";
39
48
  import { idApi } from "./id-api";
40
49
  import { sceneLightApi, worldAmbientWgsl } from "./scene-light-api";
41
- /** Floats before the first record. One is the count; the rest keep the records
42
- * vec4-aligned, which is what lets a future pass read them as vec4s. */
43
- export const LIGHT_HEADER = 4;
50
+ import { pointsApi } from "./points-api";
51
+ /** Words before the first record: the counts, the grid's placement and the
52
+ * outside mask, four vec4s — see the layout above. */
53
+ export const LIGHT_HEADER = 16;
44
54
  /** Floats per light — see the layout above. */
45
55
  export const LIGHT_STRIDE = 16;
46
56
  /**
@@ -54,15 +64,20 @@ export const LIGHT_STRIDE = 16;
54
64
  * interior brings a hundred or more, and the ceilings of sixteen and then
55
65
  * forty-eight each cut a real scene in half. Past this the extras are dropped.
56
66
  *
57
- * What it does NOT buy: a scene that genuinely lights a fragment from a hundred
58
- * lamps pays for a hundred iterations of the loop. The distance test below
59
- * rejects most of them in a few instructions, which is what makes a rig of this
60
- * size affordable at all; clustering is what replaces the linear walk when a
61
- * scene wants every one of them close enough to matter.
67
+ * A fragment pays for the document lamps its grid cell names, so the cost
68
+ * follows how many reach a place rather than how many the scene holds. It is
69
+ * also why the cap is 128: one vec4u of bits per cell.
62
70
  */
63
71
  export const MAX_LIGHTS = 128;
64
- /** Floats in the whole buffer. */
65
- export const LIGHTS_FLOATS = LIGHT_HEADER + MAX_LIGHTS * LIGHT_STRIDE;
72
+ /** Words of lamp bits per grid cell — one bit per lamp the cap allows. */
73
+ export const LIGHT_MASK_WORDS = MAX_LIGHTS / 32;
74
+ /** The grid's cell budget. 32k cells over a stage a couple of hundred units
75
+ * across is a cell of about four — finer than the lamps it separates. */
76
+ export const LIGHT_GRID_CELLS = 32768;
77
+ /** Where the grid starts, in words. */
78
+ export const LIGHT_GRID_BASE = LIGHT_HEADER + MAX_LIGHTS * LIGHT_STRIDE;
79
+ /** Words in the whole buffer: header, records, grid. */
80
+ export const LIGHTS_FLOATS = LIGHT_GRID_BASE + LIGHT_GRID_CELLS * LIGHT_MASK_WORDS;
66
81
  /**
67
82
  * The RzLight struct, declared in EVERY module a user's source is spliced into.
68
83
  *
@@ -153,7 +168,7 @@ ${viewportApi("viewU[6].w")}
153
168
  ${trailSlotsApi(cast.trailCount)}
154
169
  // The id accessors, stubbed: this module cannot read an attachment the
155
170
  // scene pass writes. See id-api.ts — the author's whole file compiles here.
156
- ${idApi(false, 0, 0) + castDistanceStub() + sceneLightApi(false, 0, 0)}
171
+ ${idApi(false, 0, 0) + castDistanceStub() + sceneLightApi(false, 0, 0) + pointsApi(false)}
157
172
  // The dials the author declared, if any. A lamp is exactly the thing someone
158
173
  // retunes — its colour and its reach — so an emitter reads params like every
159
174
  // other mount rather than being the one place a #param resolves to nothing.
@@ -217,51 +232,55 @@ fn lightEmitMain(@builtin(global_invocation_id) gid: vec3u) {
217
232
  }
218
233
  /** The rz*Light accessors, with the buffer declared at the given binding. */
219
234
  export function lightsApi(group, binding) {
235
+ const R = LIGHT_HEADER / 4;
236
+ const S = LIGHT_STRIDE / 4;
220
237
  return /* wgsl */ `
221
- @group(${group}) @binding(${binding}) var<storage, read> _rzLights: array<f32>;
238
+ // vec4u, so a record is four loads and a cell's lamp bits are one. Floats come
239
+ // out through bitcast; the bits must NOT pass through f32 on the way, where a
240
+ // mask that happens to spell a NaN is not guaranteed to survive a load.
241
+ @group(${group}) @binding(${binding}) var<storage, read> _rzLights: array<vec4u>;
222
242
 
223
243
  const RZ_MAX_LIGHTS: u32 = ${MAX_LIGHTS}u;
224
244
 
225
245
  /** How many positional lights the scene has. Zero is the ordinary case. */
226
- fn rzLightCount() -> u32 { return min(u32(_rzLights[0]), RZ_MAX_LIGHTS); }
246
+ fn rzLightCount() -> u32 { return min(u32(bitcast<f32>(_rzLights[0].x)), RZ_MAX_LIGHTS); }
247
+
248
+ /** How many of them the document placed — the ones the grid indexes. */
249
+ fn _rzLightDocCount() -> u32 { return min(u32(bitcast<f32>(_rzLights[0].y)), rzLightCount()); }
250
+
251
+ /** One vec4 of light i's record. */
252
+ fn _rzLightVec(i: u32, k: u32) -> vec4f { return bitcast<vec4f>(_rzLights[${R}u + i * ${S}u + k]); }
227
253
 
228
254
  /** Light i's world position. */
229
- fn rzLightPos(i: u32) -> vec3f {
230
- let b = ${LIGHT_HEADER}u + i * ${LIGHT_STRIDE}u;
231
- return vec3f(_rzLights[b], _rzLights[b + 1u], _rzLights[b + 2u]);
232
- }
255
+ fn rzLightPos(i: u32) -> vec3f { return _rzLightVec(i, 0u).xyz; }
233
256
 
234
257
  /** How far light i reaches. Its falloff is zero AT this distance, not merely
235
- * small, so the light has a bound a cull can be derived from later. */
236
- fn rzLightRadius(i: u32) -> f32 { return _rzLights[${LIGHT_HEADER}u + i * ${LIGHT_STRIDE}u + 3u]; }
258
+ * small, which is the bound the grid is built from. */
259
+ fn rzLightRadius(i: u32) -> f32 { return _rzLightVec(i, 0u).w; }
237
260
 
238
261
  /** Light i's colour, already multiplied by its intensity. */
239
- fn rzLightColor(i: u32) -> vec3f {
240
- let b = ${LIGHT_HEADER}u + i * ${LIGHT_STRIDE}u + 4u;
241
- return vec3f(_rzLights[b], _rzLights[b + 1u], _rzLights[b + 2u]);
242
- }
262
+ fn rzLightColor(i: u32) -> vec3f { return _rzLightVec(i, 1u).xyz; }
243
263
 
244
264
  /** Where light i points, away from itself. The zero vector for a point light. */
245
- fn rzLightAim(i: u32) -> vec3f {
246
- let b = ${LIGHT_HEADER}u + i * ${LIGHT_STRIDE}u + 8u;
247
- return vec3f(_rzLights[b], _rzLights[b + 1u], _rzLights[b + 2u]);
248
- }
265
+ fn rzLightAim(i: u32) -> vec3f { return _rzLightVec(i, 2u).xyz; }
249
266
 
250
267
  /** The cosines a spot fades between: x its outer edge, y its inner one. A point
251
268
  * light stores (-1, -1), which saturates the cone term to 1. */
252
- fn rzLightCone(i: u32) -> vec2f {
253
- let b = ${LIGHT_HEADER}u + i * ${LIGHT_STRIDE}u + 11u;
254
- return vec2f(_rzLights[b], _rzLights[b + 1u]);
269
+ fn rzLightCone(i: u32) -> vec2f { return vec2f(_rzLightVec(i, 2u).w, _rzLightVec(i, 3u).x); }
270
+
271
+ /** The document lamps that can reach p: its grid cell's bits, or the outside
272
+ * mask beyond the grid. Written so a NaN position fails the inside test. */
273
+ fn _rzLightCellMask(p: vec3f) -> vec4u {
274
+ let g = bitcast<vec4f>(_rzLights[1]);
275
+ let dims = _rzLights[2].xyz;
276
+ let c = floor((p - g.xyz) * g.w);
277
+ if (!(all(c >= vec3f(0.0)) && all(c < vec3f(dims)))) { return _rzLights[3]; }
278
+ let ci = vec3u(c);
279
+ return _rzLights[${LIGHT_GRID_BASE / 4}u + (ci.z * dims.y + ci.y) * dims.x + ci.x];
255
280
  }
256
281
 
257
282
  /**
258
- * Every positional light's contribution at a surface point, as light — not as a
259
- * finished colour. Multiply by whatever the surface's albedo is.
260
- *
261
- * WITH NO LIGHTS THIS RETURNS EXACTLY ZERO and the loop never runs, so a scene
262
- * that declares none is arithmetically identical to one compiled before lights
263
- * existed. That is the property the whole feature is gated on: adding this to
264
- * every material must cost nothing until someone asks for a light.
283
+ * One light's contribution at a surface point.
265
284
  *
266
285
  * FALLOFF IS RELATIVE TO THE RADIUS, and deliberately not physical.
267
286
  *
@@ -275,33 +294,67 @@ fn rzLightCone(i: u32) -> vec2f {
275
294
  * zero, and the curve between them is the same shape whatever the scene's
276
295
  * scale. Both dials now mean what they say, which for a composer beats being
277
296
  * right about photons. (1 - t²)² — smooth at both ends, exactly 0 at the
278
- * radius, so the bound a cull could be derived from is still real.
297
+ * radius, so the bound the grid is built from is real.
298
+ */
299
+ fn _rzLightOne(i: u32, p: vec3f, n: vec3f) -> vec3f {
300
+ let pr = _rzLightVec(i, 0u);
301
+ let d = pr.xyz - p;
302
+ let dist = length(d);
303
+ // Out of reach before anything else is computed. The grid is conservative —
304
+ // a cell's bit means the lamp CAN reach part of it — so this still runs.
305
+ if (dist >= pr.w) { return vec3f(0.0); }
306
+ let toLight = d / max(dist, 1e-4);
307
+ // Facing the light, and nothing behind it. No wrap or half-lambert: this
308
+ // layer adds light, and a wrapped term would lift the shadow side, which is
309
+ // the ramp's business and not this one's.
310
+ let ndl = max(dot(n, toLight), 0.0);
311
+ if (ndl <= 0.0) { return vec3f(0.0); }
312
+ let t = clamp(dist / max(pr.w, 1e-4), 0.0, 1.0);
313
+ let falloff = 1.0 - t * t;
314
+ // How far inside the cone this point sits: 1 within the inner angle, 0 past
315
+ // the outer one, squared for the same soft edge the falloff has. A point
316
+ // light's (-1, -1) divides by the floor and clamps to 1, so it pays one
317
+ // dot product and no branch.
318
+ let cone = rzLightCone(i);
319
+ let aim = clamp((dot(-toLight, rzLightAim(i)) - cone.x) / max(cone.y - cone.x, 1e-4), 0.0, 1.0);
320
+ return rzLightColor(i) * (ndl * falloff * falloff * aim * aim);
321
+ }
322
+
323
+ /** The lamps named by one word of a cell's bits, lowest first. */
324
+ fn _rzLightWord(bits0: u32, base: u32, p: vec3f, n: vec3f) -> vec3f {
325
+ var acc = vec3f(0.0);
326
+ var bits = bits0;
327
+ loop {
328
+ if (bits == 0u) { break; }
329
+ let i = base + firstTrailingBit(bits);
330
+ bits = bits & (bits - 1u);
331
+ acc = acc + _rzLightOne(i, p, n);
332
+ }
333
+ return acc;
334
+ }
335
+
336
+ /**
337
+ * Every positional light's contribution at a surface point, as light — not as a
338
+ * finished colour. Multiply by whatever the surface's albedo is.
339
+ *
340
+ * WITH NO LIGHTS THIS RETURNS EXACTLY ZERO and neither walk runs, so a scene
341
+ * that declares none is arithmetically identical to one compiled before lights
342
+ * existed. That is the property the whole feature is gated on: adding this to
343
+ * every material must cost nothing until someone asks for a light.
279
344
  */
280
345
  fn rzLightsDiffuse(p: vec3f, n: vec3f) -> vec3f {
281
346
  var acc = vec3f(0.0);
282
347
  let count = rzLightCount();
283
- for (var i = 0u; i < count; i = i + 1u) {
284
- let d = rzLightPos(i) - p;
285
- let dist = length(d);
286
- // Out of reach before anything else is computed. The falloff is already
287
- // exactly zero at the radius, so this changes no pixel — it is what keeps a
288
- // stage rig's far lamps off the bill at every fragment they do not light.
289
- if (dist >= rzLightRadius(i)) { continue; }
290
- let toLight = d / max(dist, 1e-4);
291
- // Facing the light, and nothing behind it. No wrap or half-lambert: this
292
- // layer adds light, and a wrapped term would lift the shadow side, which is
293
- // the ramp's business and not this one's.
294
- let ndl = max(dot(n, toLight), 0.0);
295
- if (ndl <= 0.0) { continue; }
296
- let t = clamp(dist / max(rzLightRadius(i), 1e-4), 0.0, 1.0);
297
- let falloff = 1.0 - t * t;
298
- // How far inside the cone this point sits: 1 within the inner angle, 0 past
299
- // the outer one, squared for the same soft edge the falloff has. A point
300
- // light's (-1, -1) divides by the floor and clamps to 1, so it pays one
301
- // dot product and no branch.
302
- let cone = rzLightCone(i);
303
- let aim = clamp((dot(-toLight, rzLightAim(i)) - cone.x) / max(cone.y - cone.x, 1e-4), 0.0, 1.0);
304
- acc = acc + rzLightColor(i) * (ndl * falloff * falloff * aim * aim);
348
+ let docs = _rzLightDocCount();
349
+ // The document's lamps: only those the grid says can reach this cell.
350
+ if (docs > 0u) {
351
+ let m = _rzLightCellMask(p);
352
+ acc = acc + _rzLightWord(m.x, 0u, p, n) + _rzLightWord(m.y, 32u, p, n) +
353
+ _rzLightWord(m.z, 64u, p, n) + _rzLightWord(m.w, 96u, p, n);
354
+ }
355
+ // The effects' lamps, which move every frame on the GPU: all of them.
356
+ for (var i = docs; i < count; i = i + 1u) {
357
+ acc = acc + _rzLightOne(i, p, n);
305
358
  }
306
359
  return acc;
307
360
  }
@@ -97,7 +97,7 @@ type CompositeEffectSource = {
97
97
  * Depends on `viewU` and `_rzCast` being declared by the including module, and
98
98
  * on nothing else: no textures, no samplers.
99
99
  */
100
- export declare const EFFECT_SCENE_API = "\n// \u2500\u2500 The effect API \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// Named rz*, for the engine. The prefix earns its place twice: user code is\n// concatenated into THIS module, so an unprefixed rzAnchor() would collide with\n// exactly the helper an author would write, and the old bg* prefix stopped being\n// true in 0.41.0 when effects gained a mount over the finished frame.\n//\n// The bg* names below are permanent aliases, not a deprecation with an end date.\n// A published link is immutable, so a scene pinned to a bg* effect has to keep\n// compiling forever. They are one-line and inlined; no new function gets one.\n\n/** Canvas size in pixels \u2014 for aspect correction. */\nfn rzResolution() -> vec2f { return viewU[6].zw; }\n\n/** The camera's world position. */\nfn rzCameraPos() -> vec3f { return viewU[10].xyz; }\n\n/** How many characters the SCENE holds, up to four \u2014 the number the cast api\n * narrows to this effect's own subjects. See subjectMaskApi. */\nfn _rzCastLive() -> i32 { return i32(viewU[10].w); }\n\n/**\n * A world point as the camera sees it: xy the uv it lands on, z its distance\n * along the VIEW AXIS in metres.\n *\n * The exact inverse of the ray this pass builds per pixel, so it is the cheap way\n * to work with anything anchored in the world. Marching a curve or a trail in 3D\n * costs a distance evaluation per sample per pixel; projecting its points once\n * and measuring in 2D costs a subtraction, which is the difference between a\n * ribbon that runs at 4K and one that does not.\n *\n * z is directly comparable to the depth handed to foreground(), so occlusion is\n * a single test: draw where your z is nearer than the scene's. It is returned\n * SIGNED and unclamped \u2014 behind the camera is negative, and worth rejecting\n * before you use the uv, which is meaningless there.\n */\nfn rzProject(p: vec3f) -> vec3f {\n let d = p - viewU[10].xyz;\n let z = dot(d, viewU[5].xyz);\n // Guard only the divide. z itself is returned as it is, so the caller can see\n // the sign; clamping it here would put points behind the lens on the horizon.\n let inv = 1.0 / select(z, 1e-4, z < 1e-4);\n let ndc = vec2f(dot(d, viewU[3].xyz) * inv / viewU[3].w, dot(d, viewU[4].xyz) * inv / viewU[4].w);\n return vec3f(ndc * 0.5 + 0.5, z);\n}\n\nfn rzCamPos() -> vec3f { return rzCameraPos(); }\nfn rzCameraRight() -> vec3f { return viewU[3].xyz; }\nfn rzCameraUp() -> vec3f { return viewU[4].xyz; }\nfn rzCameraForward() -> vec3f { return viewU[5].xyz; }\n\n// The cast \u2014 subjects, anchors, trails \u2014 is CAST_API, shared verbatim with the\n// particle and trail modules. It used to be written out here, a second time, and\n// the two copies had drifted: this one had rzAnchor and that one did not.\n\nconst RZ_SUBJECTS: i32 = 4;\nconst RZ_SAMPLES: i32 = 128;\n/** The anchor ADDRESS SPACE \u2014 how many an effect may declare, not how many it\n * did. RZ_TRAIL_SLOTS is the per-effect number and is not this one; the two\n * being one number was the old trail bug. */\nconst RZ_MAX_ANCHORS: i32 = 16;\nconst RZ_TRAIL_SAMPLES: i32 = 128;\n\nstruct RzSubject {\n /** On the FLOOR, under the body \u2014 where a ring or a magic circle belongs. */\n root: vec3f,\n /** At the hips, the middle of the body \u2014 where an aura belongs. */\n center: vec3f,\n /** Bounding sphere: xyz centre, w radius. Deliberately generous \u2014 cull with it. */\n bounds: vec4f,\n /**\n * How much of this character is still THERE: 1 whole, 0 gone.\n *\n * What setModelDissolve last set on them, which the material pass has already\n * acted on by the time an effect runs \u2014 so an effect drawing what LEAVES a\n * dissolving body (sparks, ash, a ghost) reads the same number the body was\n * taken apart with, rather than keeping a clock of its own and hoping the two\n * agree. 1 on a scene that never dissolves anybody.\n */\n dissolve: f32,\n /**\n * Where she LOOKS: a unit direction from between the eyes, in world space.\n * Exact while her eyes are on something (Engine.setEyeTracking); otherwise\n * the motion's own eye turn undone through the range map \u2014 an eye bone\n * turns a fraction of the way toward what it looks at, and this gives back\n * the whole of it. An effect that should go where the look goes \u2014 a beam,\n * a light \u2014 takes this rather than an eye bone's axis, and it holds in\n * either mode. Zero, with looking false, only for a model without eyes.\n */\n gaze: vec3f,\n looking: bool,\n /** False past the end of the cast, and every field is then zero. */\n valid: bool,\n}\n\nstruct RzAnchor {\n pos: vec3f,\n /** World units per second, from the previous frame. Direction for a trail,\n * magnitude for anything that should react to how hard someone is moving. */\n vel: vec3f,\n /** The bone's forward axis \u2014 which way a foot points, where a head looks. */\n fwd: vec3f,\n /** False when this rig has no such bone. Check it: the alternative is drawing\n * a hand effect at the world origin on every model that spells it differently. */\n valid: bool,\n}\n\n/**\n * How many characters THIS EFFECT is on, up to four.\n *\n * Not how many the scene holds. An effect applies to the whole cast unless the\n * scene says otherwise (Engine.setEffectSubjects), and where it says otherwise\n * this counts only the models named \u2014 so an effect aimed at one dancer sees one\n * subject, at index 0, and an author who wrote a loop over the cast gets the\n * targeting for free.\n *\n * Which is the whole design: the FILTER IS IN THE INDEX SPACE, not in the\n * shaders. There is no mask an effect can read, because an effect asking \"am I\n * allowed on this one\" is an effect that can get the answer wrong, and 18 of the\n * shipped built-ins would have had to be rewritten to ask at all.\n */\nfn rzSubjectCount() -> i32 {\n let live = _rzCastLive();\n let mask = _rzSubjectMask();\n var n = 0;\n for (var i = 0; i < live; i++) {\n if ((mask & (1u << u32(i))) != 0u) { n++; }\n }\n return n;\n}\n\n/** This effect's i-th subject \u2192 the scene's slot, or -1 past its own count.\n * Every accessor below goes through it, which is what keeps one effect's\n * subject 1 from being another's. */\nfn _rzSubjectSlot(i: i32) -> i32 {\n if (i < 0) { return -1; }\n let live = _rzCastLive();\n let mask = _rzSubjectMask();\n var n = 0;\n for (var s = 0; s < live; s++) {\n if ((mask & (1u << u32(s))) == 0u) { continue; }\n if (n == i) { return s; }\n n++;\n }\n return -1;\n}\n\n/** Which model this is, stable across a scene \u2014 for per-subject variation. */\nfn rzSubjectId(i: i32) -> u32 {\n let g = _rzSubjectSlot(i);\n if (g < 0) { return 0u; }\n return u32(_rzCast[g * 4 + 1].w);\n}\n\nfn rzSubject(i: i32) -> RzSubject {\n var s: RzSubject;\n let g = _rzSubjectSlot(i);\n s.valid = g >= 0;\n if (!s.valid) { return s; }\n let b = g * 4;\n s.root = _rzCast[b].xyz;\n s.dissolve = _rzCast[b].w;\n s.center = _rzCast[b + 1].xyz;\n s.bounds = _rzCast[b + 2];\n s.gaze = _rzCast[b + 3].xyz;\n s.looking = _rzCast[b + 3].w > 0.5;\n return s;\n}\n\n/**\n * Where a named bone is, this frame.\n *\n * The slot is the author's own: the Nth #anchor in their file, in the order\n * they wrote them. _rzSlot turns that into the scene's address, which is what\n * keeps two effects that both anchor to a wrist from reading each other's.\n */\nfn rzAnchor(subject: i32, slot: i32) -> RzAnchor {\n var a: RzAnchor;\n a.valid = false;\n let g = _rzSlot(slot);\n let s = _rzSubjectSlot(subject);\n if (s < 0 || g < 0 || g >= RZ_MAX_ANCHORS) { return a; }\n let b = 16 + (g * 4 + s) * 3;\n a.valid = _rzCast[b].w > 0.5;\n a.pos = _rzCast[b].xyz;\n a.vel = _rzCast[b + 1].xyz;\n a.fwd = _rzCast[b + 2].xyz;\n return a;\n}\n\n/**\n * How many samples of a path are recorded \u2014 0 for an anchor that asked for no\n * trail, and for one that has not moved yet.\n *\n * Bounded by the anchor cap, NOT by how many anchors asked for a trail. Those\n * are different index spaces: storage is addressed by anchor slot, so an\n * untrailed #anchor followed by a trailed one put the trail at index 1 with a\n * bound of 1 and rzTrail returned zero \u2014 a ribbon that silently did not draw.\n */\nfn rzTrailCount(subject: i32, slot: i32) -> i32 {\n let g = _rzSlot(slot);\n let s = _rzSubjectSlot(subject);\n if (s < 0 || g < 0 || g >= RZ_MAX_ANCHORS) { return 0; }\n return i32(_rzCast[16 + (g * 4 + s) * 3 + 2].w);\n}\n\n/** Sample i of a path: xyz where it was, w how many seconds ago. i = 0 is now. */\nfn rzTrail(subject: i32, slot: i32, i: i32) -> vec4f {\n let n = rzTrailCount(subject, slot);\n if (i < 0 || i >= n) { return vec4f(0.0); }\n let base = 208 + (_rzSlot(slot) * 4 + _rzSubjectSlot(subject)) * RZ_TRAIL_SAMPLES;\n return _rzCast[base + i];\n}\n\n\n// The hashes, the noise and rzFalloff \u2014 EFFECT_MATH_API, the same text the\n// particle and trail modules get. The field module used to be missing most of\n// it, so a helper an author wrote for one mount failed to compile in another\n// for no reason visible in the file.\n\nfn rzHash11(x: f32) -> f32 {\n var p = fract(x * 0.1031);\n p = p * (p + 33.33);\n return fract(p * (p + p));\n}\nfn rzHash21(p: vec2f) -> f32 {\n var p3 = fract(vec3f(p.x, p.y, p.x) * 0.1031);\n p3 = p3 + dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n/** Three independent randoms from one seed \u2014 the usual need when spawning. */\nfn rzHash13(x: f32) -> vec3f {\n return vec3f(rzHash11(x), rzHash11(x + 17.13), rzHash11(x + 41.71));\n}\n/**\n * Compact-support falloff: 1 at the centre, exactly 0 at r, smooth between.\n *\n * It reaches exactly zero rather than merely getting small, because a glow that\n * never quite ends has to be culled somewhere, and culling it wherever it looks\n * close enough is what put a visible hard edge on the first halo effect.\n */\nfn rzFalloff(d: f32, r: f32) -> f32 {\n let x = clamp(d / max(r, 1e-6), 0.0, 1.0);\n let f = 1.0 - x;\n return f * f * f;\n}\nfn rzHash31(p: vec3f) -> f32 {\n var p3 = fract(p * 0.1031);\n p3 = p3 + dot(p3, p3.zyx + 31.32);\n return fract((p3.x + p3.y) * p3.z);\n}\nfn rzValueNoise(p: vec3f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let u = f * f * (3.0 - 2.0 * f);\n let n000 = rzHash31(i);\n let n100 = rzHash31(i + vec3f(1.0, 0.0, 0.0));\n let n010 = rzHash31(i + vec3f(0.0, 1.0, 0.0));\n let n110 = rzHash31(i + vec3f(1.0, 1.0, 0.0));\n let n001 = rzHash31(i + vec3f(0.0, 0.0, 1.0));\n let n101 = rzHash31(i + vec3f(1.0, 0.0, 1.0));\n let n011 = rzHash31(i + vec3f(0.0, 1.0, 1.0));\n let n111 = rzHash31(i + vec3f(1.0, 1.0, 1.0));\n let x00 = mix(n000, n100, u.x);\n let x10 = mix(n010, n110, u.x);\n let x01 = mix(n001, n101, u.x);\n let x11 = mix(n011, n111, u.x);\n return mix(mix(x00, x10, u.y), mix(x01, x11, u.y), u.z);\n}\n/** Divergence-free flow \u2014 the field a wisp of smoke follows without a solver. */\nfn rzCurlNoise(p: vec3f) -> vec3f {\n let e = 0.1;\n let dx = vec3f(e, 0.0, 0.0);\n let dy = vec3f(0.0, e, 0.0);\n let dz = vec3f(0.0, 0.0, e);\n let x0 = rzValueNoise(p - dx); let x1 = rzValueNoise(p + dx);\n let y0 = rzValueNoise(p - dy); let y1 = rzValueNoise(p + dy);\n let z0 = rzValueNoise(p - dz); let z1 = rzValueNoise(p + dz);\n return normalize(vec3f((y1 - y0) - (z1 - z0), (z1 - z0) - (x1 - x0), (x1 - x0) - (y1 - y0)) + vec3f(1e-6));\n}\n\nstruct Particle {\n pos: vec3f,\n age: f32,\n vel: vec3f,\n life: f32,\n size: f32,\n rot: f32,\n seed: f32,\n // Aspect along the direction of travel. 1 or less is a square billboard; a\n // raindrop is 10 or 20. Zero-initialised, so an effect that never sets it gets\n // the square it expects.\n stretch: f32,\n}\n\n\n\nfn bgResolution() -> vec2f { return rzResolution(); }\nfn bgCameraPos() -> vec3f { return rzCameraPos(); }\nfn bgSubjectCount() -> i32 { return rzSubjectCount(); }\n\n/**\n * Where a character IS, in world space \u2014 at the hips, not on the floor.\n *\n * An effect that wants to RESPOND to the cast \u2014 a glow that follows someone,\n * dust kicked up where they are \u2014 needs to know where they are, and the ray and\n * the depth cannot tell it: they describe the pixel, not the scene.\n *\n * The value is model.position + \u30BB\u30F3\u30BF\u30FC + \u5168\u3066\u306E\u89AA. \u30BB\u30F3\u30BF\u30FC sits at hip\n * height on every standard MMD rig, so this is a point in the middle of the\n * body. It is NOT the contact point: a ripple drawn here appears at the waist.\n * Ground effects want the .xz of this and their own floor height, which is what\n * the effects that shipped against it already do.\n *\n * The comment here used to claim it was \"between the feet on the floor\", which\n * is where that habit came from. Left as it is regardless of the name: a\n * published link is immutable, so every shared scene pinning an effect that\n * reads this depends on it meaning exactly what it has always meant.\n *\n * Clamped rather than bounds-checked: an effect looping past the count reads the\n * last subject instead of sampling whatever follows the array, which is a wrong\n * ripple rather than an undefined one.\n *\n * THE INDEX IS THE EFFECT'S OWN, like every other cast accessor \u2014 Dry Ice, Water,\n * Holy Light and Bloody Ash all read this one and all of them should place their\n * fog, their ripple and their shaft under the model the scene aimed them at. The\n * mapping is the identity for an effect aimed at nobody in particular, which is\n * every scene published before one could be aimed.\n */\nfn rzSubjectHip(i: i32) -> vec3f { return viewU[11 + clamp(_rzSubjectSlot(i), 0, 3)].xyz; }\n\nfn bgSubjectPos(i: i32) -> vec3f { return rzSubjectHip(i); }\n\n/** Where in the WORLD the scene drew this pixel \u2014 the depth handed to\n * foreground() turned into a place. Without it an effect can only think in\n * distances from the lens, which is no use to anything that belongs somewhere:\n * fog lying on the ground has to know where the ground is.\n *\n * depth measures along the VIEW AXIS, not along the ray, so it is divided by\n * the ray's projection onto camera-forward before being walked out. At the far\n * plane (nothing drawn) this lands a very long way off, which is what a sky\n * should do to anything reading it. */\nfn rzWorldPos(ray: vec3f, depth: f32) -> vec3f {\n let axis = max(dot(normalize(ray), viewU[5].xyz), 1e-4);\n return rzCameraPos() + normalize(ray) * (depth / axis);\n}\n\nfn bgWorldPos(ray: vec3f, depth: f32) -> vec3f { return rzWorldPos(ray, depth); }\n\n/** What an effect returns for one of its lights. */\nstruct RzLight {\n pos: vec3f,\n color: vec3f,\n intensity: f32,\n radius: f32,\n}\n\n\n/** Color grading, applied to the tonemapped SCENE (not the background \u2014 see the\n * call site). The core is ASC CDL, the film-industry interchange standard:\n *\n * out = (in \u00B7 slope + offset) ^ power then saturation (SOP \u2192 SAT)\n *\n * Using the real standard rather than invented controls means a look authored\n * here maps onto any grading tool. slope/offset/power are derived on the CPU\n * from the UI's shadow/midtone/highlight colors (see setColorGrading), so the\n * per-pixel cost is one mul-add, one pow, one lerp. */\nfn grade(c: vec3f) -> vec3f {\n var x = pow(max(c * viewU[9].xyz + viewU[7].xyz, vec3f(0.0)), viewU[8].xyz);\n // Contrast pivots on 0.5 \u2014 display-referred midpoint, since we grade post-Filmic.\n x = (x - vec3f(0.5)) * viewU[7].w + vec3f(0.5);\n // Rec.709 luma, matching the ASC SAT node.\n let luma = dot(x, vec3f(0.2126, 0.7152, 0.0722));\n return max(mix(vec3f(luma), x, viewU[8].w), vec3f(0.0));\n}\n";
100
+ export declare const EFFECT_SCENE_API = "\n// \u2500\u2500 The effect API \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// Named rz*, for the engine. The prefix earns its place twice: user code is\n// concatenated into THIS module, so an unprefixed rzAnchor() would collide with\n// exactly the helper an author would write, and the old bg* prefix stopped being\n// true in 0.41.0 when effects gained a mount over the finished frame.\n//\n// The bg* names below are permanent aliases, not a deprecation with an end date.\n// A published link is immutable, so a scene pinned to a bg* effect has to keep\n// compiling forever. They are one-line and inlined; no new function gets one.\n\n/** Canvas size in pixels \u2014 for aspect correction. */\nfn rzResolution() -> vec2f { return viewU[6].zw; }\n\n/** The camera's world position. */\nfn rzCameraPos() -> vec3f { return viewU[10].xyz; }\n\n/** How many characters the SCENE holds, up to four \u2014 the number the cast api\n * narrows to this effect's own subjects. See subjectMaskApi. */\nfn _rzCastLive() -> i32 { return i32(viewU[10].w); }\n\n/**\n * A world point as the camera sees it: xy the uv it lands on, z its distance\n * along the VIEW AXIS in metres.\n *\n * The exact inverse of the ray this pass builds per pixel, so it is the cheap way\n * to work with anything anchored in the world. Marching a curve or a trail in 3D\n * costs a distance evaluation per sample per pixel; projecting its points once\n * and measuring in 2D costs a subtraction, which is the difference between a\n * ribbon that runs at 4K and one that does not.\n *\n * z is directly comparable to the depth handed to foreground(), so occlusion is\n * a single test: draw where your z is nearer than the scene's. It is returned\n * SIGNED and unclamped \u2014 behind the camera is negative, and worth rejecting\n * before you use the uv, which is meaningless there.\n */\nfn rzProject(p: vec3f) -> vec3f {\n let d = p - viewU[10].xyz;\n let z = dot(d, viewU[5].xyz);\n // Guard only the divide. z itself is returned as it is, so the caller can see\n // the sign; clamping it here would put points behind the lens on the horizon.\n let inv = 1.0 / select(z, 1e-4, z < 1e-4);\n let ndc = vec2f(dot(d, viewU[3].xyz) * inv / viewU[3].w, dot(d, viewU[4].xyz) * inv / viewU[4].w);\n return vec3f(ndc * 0.5 + 0.5, z);\n}\n\nfn rzCamPos() -> vec3f { return rzCameraPos(); }\nfn rzCameraRight() -> vec3f { return viewU[3].xyz; }\nfn rzCameraUp() -> vec3f { return viewU[4].xyz; }\nfn rzCameraForward() -> vec3f { return viewU[5].xyz; }\n\n// The cast \u2014 subjects, anchors, trails \u2014 is CAST_API, shared verbatim with the\n// particle and trail modules. It used to be written out here, a second time, and\n// the two copies had drifted: this one had rzAnchor and that one did not.\n\nconst RZ_SUBJECTS: i32 = 4;\nconst RZ_SAMPLES: i32 = 128;\n/** The anchor ADDRESS SPACE \u2014 how many an effect may declare, not how many it\n * did. RZ_TRAIL_SLOTS is the per-effect number and is not this one; the two\n * being one number was the old trail bug. */\nconst RZ_MAX_ANCHORS: i32 = 48;\nconst RZ_TRAIL_SAMPLES: i32 = 128;\n\nstruct RzSubject {\n /** On the FLOOR, under the body \u2014 where a ring or a magic circle belongs. */\n root: vec3f,\n /** At the hips, the middle of the body \u2014 where an aura belongs. */\n center: vec3f,\n /** Bounding sphere: xyz centre, w radius. Deliberately generous \u2014 cull with it. */\n bounds: vec4f,\n /**\n * How much of this character is still THERE: 1 whole, 0 gone.\n *\n * What setModelDissolve last set on them, which the material pass has already\n * acted on by the time an effect runs \u2014 so an effect drawing what LEAVES a\n * dissolving body (sparks, ash, a ghost) reads the same number the body was\n * taken apart with, rather than keeping a clock of its own and hoping the two\n * agree. 1 on a scene that never dissolves anybody.\n */\n dissolve: f32,\n /**\n * Where she LOOKS: a unit direction from between the eyes, in world space.\n * Exact while her eyes are on something (Engine.setEyeTracking); otherwise\n * the motion's own eye turn undone through the range map \u2014 an eye bone\n * turns a fraction of the way toward what it looks at, and this gives back\n * the whole of it. An effect that should go where the look goes \u2014 a beam,\n * a light \u2014 takes this rather than an eye bone's axis, and it holds in\n * either mode. Zero, with looking false, only for a model without eyes.\n */\n gaze: vec3f,\n looking: bool,\n /** False past the end of the cast, and every field is then zero. */\n valid: bool,\n}\n\nstruct RzAnchor {\n pos: vec3f,\n /** World units per second, from the previous frame. Direction for a trail,\n * magnitude for anything that should react to how hard someone is moving. */\n vel: vec3f,\n /** The bone's forward axis \u2014 which way a foot points, where a head looks. */\n fwd: vec3f,\n /** False when this rig has no such bone. Check it: the alternative is drawing\n * a hand effect at the world origin on every model that spells it differently. */\n valid: bool,\n}\n\n/**\n * How many characters THIS EFFECT is on, up to four.\n *\n * Not how many the scene holds. An effect applies to the whole cast unless the\n * scene says otherwise (Engine.setEffectSubjects), and where it says otherwise\n * this counts only the models named \u2014 so an effect aimed at one dancer sees one\n * subject, at index 0, and an author who wrote a loop over the cast gets the\n * targeting for free.\n *\n * Which is the whole design: the FILTER IS IN THE INDEX SPACE, not in the\n * shaders. There is no mask an effect can read, because an effect asking \"am I\n * allowed on this one\" is an effect that can get the answer wrong, and 18 of the\n * shipped built-ins would have had to be rewritten to ask at all.\n */\nfn rzSubjectCount() -> i32 {\n let live = _rzCastLive();\n let mask = _rzSubjectMask();\n var n = 0;\n for (var i = 0; i < live; i++) {\n if ((mask & (1u << u32(i))) != 0u) { n++; }\n }\n return n;\n}\n\n/** This effect's i-th subject \u2192 the scene's slot, or -1 past its own count.\n * Every accessor below goes through it, which is what keeps one effect's\n * subject 1 from being another's. */\nfn _rzSubjectSlot(i: i32) -> i32 {\n if (i < 0) { return -1; }\n let live = _rzCastLive();\n let mask = _rzSubjectMask();\n var n = 0;\n for (var s = 0; s < live; s++) {\n if ((mask & (1u << u32(s))) == 0u) { continue; }\n if (n == i) { return s; }\n n++;\n }\n return -1;\n}\n\n/** Which model this is, stable across a scene \u2014 for per-subject variation. */\nfn rzSubjectId(i: i32) -> u32 {\n let g = _rzSubjectSlot(i);\n if (g < 0) { return 0u; }\n return u32(_rzCast[g * 4 + 1].w);\n}\n\nfn rzSubject(i: i32) -> RzSubject {\n var s: RzSubject;\n let g = _rzSubjectSlot(i);\n s.valid = g >= 0;\n if (!s.valid) { return s; }\n let b = g * 4;\n s.root = _rzCast[b].xyz;\n s.dissolve = _rzCast[b].w;\n s.center = _rzCast[b + 1].xyz;\n s.bounds = _rzCast[b + 2];\n s.gaze = _rzCast[b + 3].xyz;\n s.looking = _rzCast[b + 3].w > 0.5;\n return s;\n}\n\n/**\n * Where a named bone is, this frame.\n *\n * The slot is the author's own: the Nth #anchor in their file, in the order\n * they wrote them. _rzSlot turns that into the scene's address, which is what\n * keeps two effects that both anchor to a wrist from reading each other's.\n */\nfn rzAnchor(subject: i32, slot: i32) -> RzAnchor {\n var a: RzAnchor;\n a.valid = false;\n let g = _rzSlot(slot);\n let s = _rzSubjectSlot(subject);\n if (s < 0 || g < 0 || g >= RZ_MAX_ANCHORS) { return a; }\n let b = 16 + (g * 4 + s) * 3;\n a.valid = _rzCast[b].w > 0.5;\n a.pos = _rzCast[b].xyz;\n a.vel = _rzCast[b + 1].xyz;\n a.fwd = _rzCast[b + 2].xyz;\n return a;\n}\n\n/**\n * How many samples of a path are recorded \u2014 0 for an anchor that asked for no\n * trail, and for one that has not moved yet.\n *\n * Bounded by the anchor cap, NOT by how many anchors asked for a trail. Those\n * are different index spaces: storage is addressed by anchor slot, so an\n * untrailed #anchor followed by a trailed one put the trail at index 1 with a\n * bound of 1 and rzTrail returned zero \u2014 a ribbon that silently did not draw.\n */\nfn rzTrailCount(subject: i32, slot: i32) -> i32 {\n let g = _rzSlot(slot);\n let s = _rzSubjectSlot(subject);\n if (s < 0 || g < 0 || g >= RZ_MAX_ANCHORS) { return 0; }\n return i32(_rzCast[16 + (g * 4 + s) * 3 + 2].w);\n}\n\n/** Sample i of a path: xyz where it was, w how many seconds ago. i = 0 is now. */\nfn rzTrail(subject: i32, slot: i32, i: i32) -> vec4f {\n let n = rzTrailCount(subject, slot);\n if (i < 0 || i >= n) { return vec4f(0.0); }\n let base = 592 + (_rzSlot(slot) * 4 + _rzSubjectSlot(subject)) * RZ_TRAIL_SAMPLES;\n return _rzCast[base + i];\n}\n\n\n// The hashes, the noise and rzFalloff \u2014 EFFECT_MATH_API, the same text the\n// particle and trail modules get. The field module used to be missing most of\n// it, so a helper an author wrote for one mount failed to compile in another\n// for no reason visible in the file.\n\nfn rzHash11(x: f32) -> f32 {\n var p = fract(x * 0.1031);\n p = p * (p + 33.33);\n return fract(p * (p + p));\n}\nfn rzHash21(p: vec2f) -> f32 {\n var p3 = fract(vec3f(p.x, p.y, p.x) * 0.1031);\n p3 = p3 + dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n/** Three independent randoms from one seed \u2014 the usual need when spawning. */\nfn rzHash13(x: f32) -> vec3f {\n return vec3f(rzHash11(x), rzHash11(x + 17.13), rzHash11(x + 41.71));\n}\n/**\n * Compact-support falloff: 1 at the centre, exactly 0 at r, smooth between.\n *\n * It reaches exactly zero rather than merely getting small, because a glow that\n * never quite ends has to be culled somewhere, and culling it wherever it looks\n * close enough is what put a visible hard edge on the first halo effect.\n */\nfn rzFalloff(d: f32, r: f32) -> f32 {\n let x = clamp(d / max(r, 1e-6), 0.0, 1.0);\n let f = 1.0 - x;\n return f * f * f;\n}\nfn rzHash31(p: vec3f) -> f32 {\n var p3 = fract(p * 0.1031);\n p3 = p3 + dot(p3, p3.zyx + 31.32);\n return fract((p3.x + p3.y) * p3.z);\n}\nfn rzValueNoise(p: vec3f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let u = f * f * (3.0 - 2.0 * f);\n let n000 = rzHash31(i);\n let n100 = rzHash31(i + vec3f(1.0, 0.0, 0.0));\n let n010 = rzHash31(i + vec3f(0.0, 1.0, 0.0));\n let n110 = rzHash31(i + vec3f(1.0, 1.0, 0.0));\n let n001 = rzHash31(i + vec3f(0.0, 0.0, 1.0));\n let n101 = rzHash31(i + vec3f(1.0, 0.0, 1.0));\n let n011 = rzHash31(i + vec3f(0.0, 1.0, 1.0));\n let n111 = rzHash31(i + vec3f(1.0, 1.0, 1.0));\n let x00 = mix(n000, n100, u.x);\n let x10 = mix(n010, n110, u.x);\n let x01 = mix(n001, n101, u.x);\n let x11 = mix(n011, n111, u.x);\n return mix(mix(x00, x10, u.y), mix(x01, x11, u.y), u.z);\n}\n/** Divergence-free flow \u2014 the field a wisp of smoke follows without a solver. */\nfn rzCurlNoise(p: vec3f) -> vec3f {\n let e = 0.1;\n let dx = vec3f(e, 0.0, 0.0);\n let dy = vec3f(0.0, e, 0.0);\n let dz = vec3f(0.0, 0.0, e);\n let x0 = rzValueNoise(p - dx); let x1 = rzValueNoise(p + dx);\n let y0 = rzValueNoise(p - dy); let y1 = rzValueNoise(p + dy);\n let z0 = rzValueNoise(p - dz); let z1 = rzValueNoise(p + dz);\n return normalize(vec3f((y1 - y0) - (z1 - z0), (z1 - z0) - (x1 - x0), (x1 - x0) - (y1 - y0)) + vec3f(1e-6));\n}\n\nstruct Particle {\n pos: vec3f,\n age: f32,\n vel: vec3f,\n life: f32,\n size: f32,\n rot: f32,\n seed: f32,\n // Aspect along the direction of travel. 1 or less is a square billboard; a\n // raindrop is 10 or 20. Zero-initialised, so an effect that never sets it gets\n // the square it expects.\n stretch: f32,\n}\n\n\n\nfn bgResolution() -> vec2f { return rzResolution(); }\nfn bgCameraPos() -> vec3f { return rzCameraPos(); }\nfn bgSubjectCount() -> i32 { return rzSubjectCount(); }\n\n/**\n * Where a character IS, in world space \u2014 at the hips, not on the floor.\n *\n * An effect that wants to RESPOND to the cast \u2014 a glow that follows someone,\n * dust kicked up where they are \u2014 needs to know where they are, and the ray and\n * the depth cannot tell it: they describe the pixel, not the scene.\n *\n * The value is model.position + \u30BB\u30F3\u30BF\u30FC + \u5168\u3066\u306E\u89AA. \u30BB\u30F3\u30BF\u30FC sits at hip\n * height on every standard MMD rig, so this is a point in the middle of the\n * body. It is NOT the contact point: a ripple drawn here appears at the waist.\n * Ground effects want the .xz of this and their own floor height, which is what\n * the effects that shipped against it already do.\n *\n * The comment here used to claim it was \"between the feet on the floor\", which\n * is where that habit came from. Left as it is regardless of the name: a\n * published link is immutable, so every shared scene pinning an effect that\n * reads this depends on it meaning exactly what it has always meant.\n *\n * Clamped rather than bounds-checked: an effect looping past the count reads the\n * last subject instead of sampling whatever follows the array, which is a wrong\n * ripple rather than an undefined one.\n *\n * THE INDEX IS THE EFFECT'S OWN, like every other cast accessor \u2014 Dry Ice, Water,\n * Holy Light and Bloody Ash all read this one and all of them should place their\n * fog, their ripple and their shaft under the model the scene aimed them at. The\n * mapping is the identity for an effect aimed at nobody in particular, which is\n * every scene published before one could be aimed.\n */\nfn rzSubjectHip(i: i32) -> vec3f { return viewU[11 + clamp(_rzSubjectSlot(i), 0, 3)].xyz; }\n\nfn bgSubjectPos(i: i32) -> vec3f { return rzSubjectHip(i); }\n\n/** Where in the WORLD the scene drew this pixel \u2014 the depth handed to\n * foreground() turned into a place. Without it an effect can only think in\n * distances from the lens, which is no use to anything that belongs somewhere:\n * fog lying on the ground has to know where the ground is.\n *\n * depth measures along the VIEW AXIS, not along the ray, so it is divided by\n * the ray's projection onto camera-forward before being walked out. At the far\n * plane (nothing drawn) this lands a very long way off, which is what a sky\n * should do to anything reading it. */\nfn rzWorldPos(ray: vec3f, depth: f32) -> vec3f {\n let axis = max(dot(normalize(ray), viewU[5].xyz), 1e-4);\n return rzCameraPos() + normalize(ray) * (depth / axis);\n}\n\nfn bgWorldPos(ray: vec3f, depth: f32) -> vec3f { return rzWorldPos(ray, depth); }\n\n/** What an effect returns for one of its lights. */\nstruct RzLight {\n pos: vec3f,\n color: vec3f,\n intensity: f32,\n radius: f32,\n}\n\n\n/** Color grading, applied to the tonemapped SCENE (not the background \u2014 see the\n * call site). The core is ASC CDL, the film-industry interchange standard:\n *\n * out = (in \u00B7 slope + offset) ^ power then saturation (SOP \u2192 SAT)\n *\n * Using the real standard rather than invented controls means a look authored\n * here maps onto any grading tool. slope/offset/power are derived on the CPU\n * from the UI's shadow/midtone/highlight colors (see setColorGrading), so the\n * per-pixel cost is one mul-add, one pow, one lerp. */\nfn grade(c: vec3f) -> vec3f {\n var x = pow(max(c * viewU[9].xyz + viewU[7].xyz, vec3f(0.0)), viewU[8].xyz);\n // Contrast pivots on 0.5 \u2014 display-referred midpoint, since we grade post-Filmic.\n x = (x - vec3f(0.5)) * viewU[7].w + vec3f(0.5);\n // Rec.709 luma, matching the ASC SAT node.\n let luma = dot(x, vec3f(0.2126, 0.7152, 0.0722));\n return max(mix(vec3f(luma), x, viewU[8].w), vec3f(0.0));\n}\n";
101
101
  export declare function buildCompositeShader(effect?: CompositeEffectSource | null): string;
102
102
  /**
103
103
  * The field pass: the user's background/foreground mounts at half resolution,
@@ -1 +1 @@
1
- {"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/composite.ts"],"names":[],"mappings":"AA4BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAgC+B;AAC/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAIhG;AAID,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAEzG,KAAK,qBAAqB,GAAG;IAC3B,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAA;IACZ,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAA;IAClB,4DAA4D;IAC5D,aAAa,EAAE,OAAO,CAAA;IACtB,oEAAoE;IACpE,aAAa,EAAE,OAAO,CAAA;IACtB;6DACyD;IACzD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAA;IAChB;mFAC+E;IAC/E,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;yEAGqE;IACrE,UAAU,EAAE,MAAM,CAAA;IAClB;;8EAE0E;IAC1E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CACjB,CAAA;AA+LD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,+ufAsI5B,CAAA;AA8MD,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,IAAI,GAAG,MAAM,CAclF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAyGtE;AAED,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,QAA6B,CAAA"}
1
+ {"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/composite.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAgC+B;AAC/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAIhG;AAID,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAEzG,KAAK,qBAAqB,GAAG;IAC3B,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAA;IACZ,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAA;IAClB,4DAA4D;IAC5D,aAAa,EAAE,OAAO,CAAA;IACtB,oEAAoE;IACpE,aAAa,EAAE,OAAO,CAAA;IACtB;6DACyD;IACzD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAA;IAChB;mFAC+E;IAC/E,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;yEAGqE;IACrE,UAAU,EAAE,MAAM,CAAA;IAClB;;8EAE0E;IAC1E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CACjB,CAAA;AA+LD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,+ufAsI5B,CAAA;AA8MD,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,IAAI,GAAG,MAAM,CAclF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CA0GtE;AAED,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,QAA6B,CAAA"}
@@ -6,6 +6,7 @@ import { clockApi, EFFECT_MATH_API, PARTICLE_STRUCT_WGSL, trailSlotsApi, viewpor
6
6
  import { audioApi } from "../audio-api";
7
7
  import { idApi } from "../id-api";
8
8
  import { sceneLightApi } from "../scene-light-api";
9
+ import { pointsApi } from "../points-api";
9
10
  import { castDistanceApi, CAST_FIELD_DIV } from "./cast-distance";
10
11
  import { lyricsApi, lyricsTextApi } from "../lyrics-api";
11
12
  import { midiApi } from "../midi-api";
@@ -683,6 +684,7 @@ export function buildFieldShader(effect) {
683
684
  trailSlotsApi(effect.trailCount) +
684
685
  idApi(effect.ids === true, 0, 23) +
685
686
  sceneLightApi(false, 0, 0) +
687
+ pointsApi(false) +
686
688
  // Distance to the cast, in SCREEN pixels: the field is half-res, so a field
687
689
  // texel is CAST_FIELD_DIV of them and the accessor scales on the way out.
688
690
  // An author writes the width they mean and never learns how it is built.
@@ -1 +1 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/grid.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAmC7C,eAAO,MAAM,QAAQ,OAAO,CAAA;AAC5B,uEAAuE;AACvE,eAAO,MAAM,UAAU,EAAE,gBAAgC,CAAA;AAEzD,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA6B1F;AAgBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,SAAK,GAAG,MAAM,CAqFpG"}
1
+ {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/grid.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAoC7C,eAAO,MAAM,QAAQ,OAAO,CAAA;AAC5B,uEAAuE;AACvE,eAAO,MAAM,UAAU,EAAE,gBAAgC,CAAA;AAEzD,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA6B1F;AAgBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,SAAK,GAAG,MAAM,CAsFpG"}
@@ -8,6 +8,7 @@ import { SCENE_TAP_STUB } from "../scene-tap";
8
8
  import { clockApi, trailSlotsApi, viewportApi } from "./hosted-api";
9
9
  import { idApi } from "../id-api";
10
10
  import { sceneLightApi } from "../scene-light-api";
11
+ import { pointsApi } from "../points-api";
11
12
  // A persistent grid an effect can step and read: the one thing an effect could
12
13
  // not have before, which is MEMORY.
13
14
  //
@@ -162,6 +163,7 @@ fn rzGrid(uv: vec2f) -> vec4f { return rzGridPrev(uv); }
162
163
  // id-api.ts. The author's whole file compiles here, so the names must exist.
163
164
  idApi(false, 0, 0) +
164
165
  sceneLightApi(false, 0, 0) +
166
+ pointsApi(false) +
165
167
  // Inlined rather than imported from cast-distance, and NOT for tidiness.
166
168
  //
167
169
  // This module and composite.ts import each other — grid takes
@@ -44,6 +44,8 @@ type ParticleSource = {
44
44
  };
45
45
  /** Where the shading stage's five scene-light bindings start — see scene-light-api.ts. */
46
46
  export declare const PARTICLE_LIGHT_BINDING = 10;
47
+ /** The effect's named points (`#points`), in both stages — see points-api.ts. */
48
+ export declare const PARTICLE_POINTS_BINDING = 15;
47
49
  /** Bytes per particle. Explicitly padded — see the struct below. */
48
50
  export declare const PARTICLE_STRIDE = 48;
49
51
  /** Does the source define the particle contract? All three are required
@@ -1 +1 @@
1
- {"version":3,"file":"particles.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/particles.ts"],"names":[],"mappings":"AA8BA,sEAAsE;AACtE,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,iFAAiF;IACjF,KAAK,EAAE,MAAM,CAAA;IACb;;mFAE+E;IAC/E,UAAU,EAAE,MAAM,CAAA;IAClB,+EAA+E;IAC/E,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB,CAAA;AAkCD,qDAAqD;AACrD;0EAC0E;AAC1E,KAAK,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAA;AAEpD,KAAK,cAAc,GAAG;IACpB,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,aAAa,CAAA;IACpB,qEAAqE;IACrE,KAAK,EAAE,OAAO,CAAA;IACd;;+BAE2B;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB;;;;;iEAK6D;IAC7D,KAAK,EAAE,OAAO,CAAA;IACd;;;wEAGoE;IACpE,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,0FAA0F;AAC1F,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,oEAAoE;AACpE,eAAO,MAAM,eAAe,KAAK,CAAA;AAwDjC;yEACyE;AACzE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAOlH;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAmDxF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CA0LvF"}
1
+ {"version":3,"file":"particles.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/particles.ts"],"names":[],"mappings":"AA+BA,sEAAsE;AACtE,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,iFAAiF;IACjF,KAAK,EAAE,MAAM,CAAA;IACb;;mFAE+E;IAC/E,UAAU,EAAE,MAAM,CAAA;IAClB,+EAA+E;IAC/E,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB,CAAA;AAkCD,qDAAqD;AACrD;0EAC0E;AAC1E,KAAK,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAA;AAEpD,KAAK,cAAc,GAAG;IACpB,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,aAAa,CAAA;IACpB,qEAAqE;IACrE,KAAK,EAAE,OAAO,CAAA;IACd;;+BAE2B;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB;;;;;iEAK6D;IAC7D,KAAK,EAAE,OAAO,CAAA;IACd;;;wEAGoE;IACpE,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,0FAA0F;AAC1F,eAAO,MAAM,sBAAsB,KAAK,CAAA;AACxC,iFAAiF;AACjF,eAAO,MAAM,uBAAuB,KAAK,CAAA;AAEzC,oEAAoE;AACpE,eAAO,MAAM,eAAe,KAAK,CAAA;AAwDjC;yEACyE;AACzE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAOlH;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAqDxF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CA2LvF"}
@@ -11,6 +11,7 @@ import { clockApi, EFFECT_MATH_API, PARTICLE_STRUCT_WGSL, trailSlotsApi, viewpor
11
11
  import { sceneIdFieldWgsl, sceneIdPadWgsl } from "./scene-contract";
12
12
  import { idApi } from "../id-api";
13
13
  import { sceneLightApi } from "../scene-light-api";
14
+ import { pointsApi } from "../points-api";
14
15
  /**
15
16
  * The trail accessors, in the PARTICLE module.
16
17
  *
@@ -43,6 +44,8 @@ fn _rzCastLive() -> i32 {
43
44
  }
44
45
  /** Where the shading stage's five scene-light bindings start — see scene-light-api.ts. */
45
46
  export const PARTICLE_LIGHT_BINDING = 10;
47
+ /** The effect's named points (`#points`), in both stages — see points-api.ts. */
48
+ export const PARTICLE_POINTS_BINDING = 15;
46
49
  /** Bytes per particle. Explicitly padded — see the struct below. */
47
50
  export const PARTICLE_STRIDE = 48;
48
51
  const CAMERA_STRUCT = /* wgsl */ `
@@ -138,6 +141,8 @@ ${src.paramsDecl}
138
141
  // Stubbed: this module cannot read an attachment the scene pass writes — see
139
142
  // id-api.ts. The author's whole file compiles here, so the names must exist.
140
143
  idApi(false, 0, 0) + castDistanceStub() + sceneLightApi(false, 0, 0) +
144
+ // The named points, for real: particleInit is where a flame is put on a wick.
145
+ pointsApi(true, 0, PARTICLE_POINTS_BINDING) +
141
146
  "\n// ── user effect ──\n" +
142
147
  src.wgsl +
143
148
  /* wgsl */ `
@@ -212,6 +217,7 @@ ${src.paramsDecl}
212
217
  // The sun's shadow and the world's ambient, for real: the shadow pass has
213
218
  // run by the time this draws, inside the scene pass. See scene-light-api.ts.
214
219
  sceneLightApi(true, 0, PARTICLE_LIGHT_BINDING) +
220
+ pointsApi(true, 0, PARTICLE_POINTS_BINDING) +
215
221
  "\n// ── user effect ──\n" +
216
222
  src.wgsl +
217
223
  /* wgsl */ `
@@ -1 +1 @@
1
- {"version":3,"file":"trails.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/trails.ts"],"names":[],"mappings":"AA8BA,KAAK,WAAW,GAAG;IACjB,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAA;IACb;oEACgE;IAChE,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAA;IAClB,8DAA8D;IAC9D,KAAK,EAAE,OAAO,GAAG,UAAU,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAA;IACd;sFACkF;IAClF,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAA;AAEnC,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAKjF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;IACJ,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,EAAE,CAAA;IACf;;;;kFAI8E;IAC9E,SAAS,EAAE,OAAO,CAAA;CACnB,GACA,MAAM,CA6ZR"}
1
+ {"version":3,"file":"trails.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/trails.ts"],"names":[],"mappings":"AA+BA,KAAK,WAAW,GAAG;IACjB,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAA;IACb;oEACgE;IAChE,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAA;IAClB,8DAA8D;IAC9D,KAAK,EAAE,OAAO,GAAG,UAAU,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAA;IACd;sFACkF;IAClF,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAA;AAEnC,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAKjF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;IACJ,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,EAAE,CAAA;IACf;;;;kFAI8E;IAC9E,SAAS,EAAE,OAAO,CAAA;CACnB,GACA,MAAM,CA6ZR"}
@@ -11,6 +11,7 @@ import { clockApi, EFFECT_MATH_API, PARTICLE_STRUCT_WGSL, trailSlotsApi, viewpor
11
11
  import { sceneIdFieldWgsl, sceneIdPadWgsl } from "./scene-contract";
12
12
  import { idApi } from "../id-api";
13
13
  import { sceneLightApi } from "../scene-light-api";
14
+ import { pointsApi } from "../points-api";
14
15
  /**
15
16
  * Sub-segments drawn between each pair of recorded samples.
16
17
  *
@@ -248,7 +249,7 @@ fn rzTurnRadius(a: vec3f, b: vec3f, c: vec3f) -> f32 {
248
249
  gridReadApi(0, 8, 9, src.gridSize) +
249
250
  // Stubbed: this module cannot read an attachment the scene pass writes — see
250
251
  // id-api.ts. The author's whole file compiles here, so the names must exist.
251
- idApi(false, 0, 0) + castDistanceStub() + sceneLightApi(false, 0, 0) +
252
+ idApi(false, 0, 0) + castDistanceStub() + sceneLightApi(false, 0, 0) + pointsApi(false) +
252
253
  "\n// ── user effect ──\n" +
253
254
  src.wgsl +
254
255
  /* wgsl */ `
@@ -0,0 +1,11 @@
1
+ /** How many points one effect can read. A candlelit hall is fifty. */
2
+ export declare const MAX_EFFECT_POINTS = 256;
3
+ /** Floats in a points buffer: a vec4 header (count), then two vec4s a point. */
4
+ export declare const POINTS_FLOATS: number;
5
+ /**
6
+ * rzPointCount / rzPoint. `bound` is false in every module that cannot read the
7
+ * buffer — the author's whole file is spliced into each module it has a mount
8
+ * in, so the names must resolve there too, and there they read as no points.
9
+ */
10
+ export declare function pointsApi(bound: boolean, group?: number, binding?: number): string;
11
+ //# sourceMappingURL=points-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"points-api.d.ts","sourceRoot":"","sources":["../../src/shaders/points-api.ts"],"names":[],"mappings":"AAmBA,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAEpC,gFAAgF;AAChF,eAAO,MAAM,aAAa,QAA4B,CAAA;AAUtD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,EAAE,OAAO,SAAI,GAAG,MAAM,CA2BxE"}
@@ -0,0 +1,58 @@
1
+ // Named points on the models, for an effect that puts something at each one.
2
+ //
3
+ // #points flame
4
+ //
5
+ // gives the effect every bone whose name starts with `flame`, on every model in
6
+ // the scene — a stage, its parts, a prop, a character — as RzPoint: where the
7
+ // bone stands and where its tail points, in world space, this frame. A candle
8
+ // stage carries a bone per wick; a flame effect draws one flame on each, sized
9
+ // and stood up by the tail.
10
+ //
11
+ // BONES, because a bone is MMD's own word for a named point in a model. A stage
12
+ // that brings its candles as bones needs no side file, a hand-made stage can
13
+ // add them in any PMX editor, and a candle a character carries moves with the
14
+ // hand that holds it.
15
+ //
16
+ // Not the cast's anchors: those name up to sixteen bones on four characters,
17
+ // one bone per name. A stage is not a character, and fifty wicks share a
18
+ // prefix rather than each having a name worth declaring.
19
+ /** How many points one effect can read. A candlelit hall is fifty. */
20
+ export const MAX_EFFECT_POINTS = 256;
21
+ /** Floats in a points buffer: a vec4 header (count), then two vec4s a point. */
22
+ export const POINTS_FLOATS = 4 + MAX_EFFECT_POINTS * 8;
23
+ const STRUCT = /* wgsl */ `
24
+ /** One named point: where the bone stands, and where its tail points to. */
25
+ struct RzPoint {
26
+ pos: vec3f,
27
+ tip: vec3f,
28
+ }
29
+ `;
30
+ /**
31
+ * rzPointCount / rzPoint. `bound` is false in every module that cannot read the
32
+ * buffer — the author's whole file is spliced into each module it has a mount
33
+ * in, so the names must resolve there too, and there they read as no points.
34
+ */
35
+ export function pointsApi(bound, group = 0, binding = 0) {
36
+ if (!bound) {
37
+ return (STRUCT +
38
+ /* wgsl */ `
39
+ fn rzPointCount() -> u32 { return 0u; }
40
+ fn rzPoint(i: u32) -> RzPoint { var p: RzPoint; return p; }
41
+ `);
42
+ }
43
+ return (STRUCT +
44
+ /* wgsl */ `
45
+ @group(${group}) @binding(${binding}) var<storage, read> _rzPoints: array<vec4f>;
46
+
47
+ /** How many named points the scene has for this effect, this frame. */
48
+ fn rzPointCount() -> u32 { return min(u32(_rzPoints[0].x), ${MAX_EFFECT_POINTS}u); }
49
+
50
+ /** Point i, world space. */
51
+ fn rzPoint(i: u32) -> RzPoint {
52
+ var p: RzPoint;
53
+ p.pos = _rzPoints[1u + i * 2u].xyz;
54
+ p.tip = _rzPoints[2u + i * 2u].xyz;
55
+ return p;
56
+ }
57
+ `);
58
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.58.1",
3
+ "version": "0.58.2",
4
4
  "description": "A lightweight WebGPU engine for real-time 3D MMD/PMX model rendering",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -0,0 +1,67 @@
1
+ import { POINTS_FLOATS } from "./shaders/points-api"
2
+
3
+ // The CPU half of `#points`: which bones match, and where they are this frame.
4
+
5
+ /** Indices of the bones whose names start with `prefix`, in rig order. By
6
+ * index, because fifty wicks may share one name and a name lookup keeps one. */
7
+ export function bonesWithPrefix(bones: { name: string }[], prefix: string): number[] {
8
+ const out: number[] = []
9
+ bones.forEach((b, i) => {
10
+ if (b.name.startsWith(prefix)) out.push(i)
11
+ })
12
+ return out
13
+ }
14
+
15
+ /** Where a model stands: the same scale, rotation and position the cast's
16
+ * anchors are placed by. */
17
+ export type PointPlacement = {
18
+ scale: number
19
+ rotation: { x: number; y: number; z: number; w: number }
20
+ position: { x: number; y: number; z: number }
21
+ }
22
+
23
+ function place(v: [number, number, number], at: PointPlacement): [number, number, number] {
24
+ const s = at.scale
25
+ const x = v[0] * s
26
+ const y = v[1] * s
27
+ const z = v[2] * s
28
+ // v + 2w(q×v) + 2q×(q×v)
29
+ const q = at.rotation
30
+ const tx = 2 * (q.y * z - q.z * y)
31
+ const ty = 2 * (q.z * x - q.x * z)
32
+ const tz = 2 * (q.x * y - q.y * x)
33
+ return [
34
+ x + q.w * tx + (q.y * tz - q.z * ty) + at.position.x,
35
+ y + q.w * ty + (q.z * tx - q.x * tz) + at.position.y,
36
+ z + q.w * tz + (q.x * ty - q.y * tx) + at.position.z,
37
+ ]
38
+ }
39
+
40
+ /**
41
+ * Point `slot`: the bone's head and its tail's end, posed by the bone's world
42
+ * matrix (model space, column-major) and placed by the model. A bone with no
43
+ * tail is a point with no length — its tip is its head.
44
+ */
45
+ export function writeBonePoint(
46
+ out: Float32Array,
47
+ slot: number,
48
+ world: Float32Array,
49
+ tail: [number, number, number] | undefined,
50
+ at: PointPlacement,
51
+ ): void {
52
+ const head: [number, number, number] = [world[12], world[13], world[14]]
53
+ const t = tail ?? [0, 0, 0]
54
+ const tip: [number, number, number] = [
55
+ head[0] + world[0] * t[0] + world[4] * t[1] + world[8] * t[2],
56
+ head[1] + world[1] * t[0] + world[5] * t[1] + world[9] * t[2],
57
+ head[2] + world[2] * t[0] + world[6] * t[1] + world[10] * t[2],
58
+ ]
59
+ const b = 4 + slot * 8
60
+ out.set(place(head, at), b)
61
+ out.set(place(tip, at), b + 4)
62
+ }
63
+
64
+ /** A zeroed points buffer's CPU copy. */
65
+ export function pointsData(): Float32Array {
66
+ return new Float32Array(POINTS_FLOATS)
67
+ }