reze-engine 0.58.1 → 0.58.3

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 (54) 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 +25 -2
  5. package/dist/engine.d.ts.map +1 -1
  6. package/dist/engine.js +199 -35
  7. package/dist/graph/style-group.d.ts +7 -0
  8. package/dist/graph/style-group.d.ts.map +1 -1
  9. package/dist/light-grid.d.ts +25 -0
  10. package/dist/light-grid.d.ts.map +1 -0
  11. package/dist/light-grid.js +91 -0
  12. package/dist/model.d.ts +9 -0
  13. package/dist/model.d.ts.map +1 -1
  14. package/dist/model.js +6 -0
  15. package/dist/pmx-loader.d.ts.map +1 -1
  16. package/dist/pmx-loader.js +11 -6
  17. package/dist/shaders/cast-api.d.ts +1 -1
  18. package/dist/shaders/cast-layout.d.ts +5 -3
  19. package/dist/shaders/cast-layout.d.ts.map +1 -1
  20. package/dist/shaders/cast-layout.js +5 -3
  21. package/dist/shaders/directives.d.ts +3 -0
  22. package/dist/shaders/directives.d.ts.map +1 -1
  23. package/dist/shaders/directives.js +5 -0
  24. package/dist/shaders/lights.d.ts +14 -9
  25. package/dist/shaders/lights.d.ts.map +1 -1
  26. package/dist/shaders/lights.js +118 -65
  27. package/dist/shaders/passes/composite.d.ts +1 -1
  28. package/dist/shaders/passes/composite.d.ts.map +1 -1
  29. package/dist/shaders/passes/composite.js +2 -0
  30. package/dist/shaders/passes/grid.d.ts.map +1 -1
  31. package/dist/shaders/passes/grid.js +2 -0
  32. package/dist/shaders/passes/particles.d.ts +20 -1
  33. package/dist/shaders/passes/particles.d.ts.map +1 -1
  34. package/dist/shaders/passes/particles.js +36 -1
  35. package/dist/shaders/passes/trails.d.ts.map +1 -1
  36. package/dist/shaders/passes/trails.js +2 -1
  37. package/dist/shaders/points-api.d.ts +11 -0
  38. package/dist/shaders/points-api.d.ts.map +1 -0
  39. package/dist/shaders/points-api.js +58 -0
  40. package/package.json +1 -1
  41. package/src/effect-points.ts +67 -0
  42. package/src/engine.ts +215 -35
  43. package/src/graph/style-group.ts +12 -1
  44. package/src/light-grid.ts +139 -0
  45. package/src/model.ts +12 -0
  46. package/src/pmx-loader.ts +13 -6
  47. package/src/shaders/cast-layout.ts +5 -3
  48. package/src/shaders/directives.ts +8 -0
  49. package/src/shaders/lights.ts +118 -65
  50. package/src/shaders/passes/composite.ts +2 -0
  51. package/src/shaders/passes/grid.ts +2 -0
  52. package/src/shaders/passes/particles.ts +46 -2
  53. package/src/shaders/passes/trails.ts +2 -1
  54. package/src/shaders/points-api.ts +66 -0
@@ -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
@@ -36,6 +36,15 @@ type ParticleSource = {
36
36
  * where every stacked fragment is otherwise shaded in full; the prepass is
37
37
  * the shape of that rejection, done by hand and cheaply. */
38
38
  cover: boolean;
39
+ /** The effect defines `particleCount() -> u32`: how many of the pool are
40
+ * live this frame, as a function of its dials. The step is dispatched and
41
+ * the quads drawn for that many slots and no more, through indirect
42
+ * arguments a one-thread kernel writes first. A pool sized for its densest
43
+ * setting then costs its current setting: a lawn's spare 1.3M slots were
44
+ * read, written and issued as degenerate quads every frame, and that
45
+ * traffic alone was a third of the frame. The live slots are always the
46
+ * first N — an author whose live set is not a prefix has no use for this. */
47
+ live: boolean;
39
48
  /** The side of this effect's grid, or 0 when it declared none. Particles READ
40
49
  * the grid; the kernel that steps it lives in the grid pass. A blade of grass
41
50
  * bending where a foot pressed is the whole case: the bend has to persist and
@@ -44,15 +53,25 @@ type ParticleSource = {
44
53
  };
45
54
  /** Where the shading stage's five scene-light bindings start — see scene-light-api.ts. */
46
55
  export declare const PARTICLE_LIGHT_BINDING = 10;
56
+ /** The effect's named points (`#points`), in both stages — see points-api.ts. */
57
+ export declare const PARTICLE_POINTS_BINDING = 15;
58
+ /** The indirect arguments a `particleCount` effect writes — compute stage only.
59
+ * Eight u32: the step's dispatch (groups, 1, 1, pad) then the quads' draw
60
+ * (6, count, 0, 0), so the draw reads at byte 16. */
61
+ export declare const PARTICLE_INDIRECT_BINDING = 16;
62
+ export declare const PARTICLE_INDIRECT_BYTES = 32;
63
+ export declare const PARTICLE_INDIRECT_DRAW_OFFSET = 16;
47
64
  /** Bytes per particle. Explicitly padded — see the struct below. */
48
65
  export declare const PARTICLE_STRIDE = 48;
49
66
  /** Does the source define the particle contract? All three are required
50
- * together; `cover` is optional and only means anything to a cutout. */
67
+ * together; `cover` is optional and only means anything to a cutout, and
68
+ * `count` is optional and bounds the frame's work — see particleCount. */
51
69
  export declare function particleEntryPoints(wgsl: string): {
52
70
  init: boolean;
53
71
  step: boolean;
54
72
  shade: boolean;
55
73
  cover: boolean;
74
+ count: boolean;
56
75
  };
57
76
  /**
58
77
  * Spawn, age, recycle.
@@ -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;;;;;;;kFAO8E;IAC9E,IAAI,EAAE,OAAO,CAAA;IACb;;;wEAGoE;IACpE,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,0FAA0F;AAC1F,eAAO,MAAM,sBAAsB,KAAK,CAAA;AACxC,iFAAiF;AACjF,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC;;sDAEsD;AACtD,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAC3C,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC,eAAO,MAAM,6BAA6B,KAAK,CAAA;AAE/C,oEAAoE;AACpE,eAAO,MAAM,eAAe,KAAK,CAAA;AAwDjC;;2EAE2E;AAC3E,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,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAQlI;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CA0ExF;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,14 @@ 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;
49
+ /** The indirect arguments a `particleCount` effect writes — compute stage only.
50
+ * Eight u32: the step's dispatch (groups, 1, 1, pad) then the quads' draw
51
+ * (6, count, 0, 0), so the draw reads at byte 16. */
52
+ export const PARTICLE_INDIRECT_BINDING = 16;
53
+ export const PARTICLE_INDIRECT_BYTES = 32;
54
+ export const PARTICLE_INDIRECT_DRAW_OFFSET = 16;
46
55
  /** Bytes per particle. Explicitly padded — see the struct below. */
47
56
  export const PARTICLE_STRIDE = 48;
48
57
  const CAMERA_STRUCT = /* wgsl */ `
@@ -96,13 +105,15 @@ fn rzProject(p: vec3f) -> vec3f {
96
105
  fn rzCamPos() -> vec3f { return cam.camPos; }
97
106
  `;
98
107
  /** Does the source define the particle contract? All three are required
99
- * together; `cover` is optional and only means anything to a cutout. */
108
+ * together; `cover` is optional and only means anything to a cutout, and
109
+ * `count` is optional and bounds the frame's work — see particleCount. */
100
110
  export function particleEntryPoints(wgsl) {
101
111
  return {
102
112
  init: /\bfn\s+particleInit\s*\(/.test(wgsl),
103
113
  step: /\bfn\s+particleStep\s*\(/.test(wgsl),
104
114
  shade: /\bfn\s+particleShade\s*\(/.test(wgsl),
105
115
  cover: /\bfn\s+particleCover\s*\(/.test(wgsl),
116
+ count: /\bfn\s+particleCount\s*\(/.test(wgsl),
106
117
  };
107
118
  }
108
119
  /**
@@ -138,8 +149,31 @@ ${src.paramsDecl}
138
149
  // Stubbed: this module cannot read an attachment the scene pass writes — see
139
150
  // id-api.ts. The author's whole file compiles here, so the names must exist.
140
151
  idApi(false, 0, 0) + castDistanceStub() + sceneLightApi(false, 0, 0) +
152
+ // The named points, for real: particleInit is where a flame is put on a wick.
153
+ pointsApi(true, 0, PARTICLE_POINTS_BINDING) +
154
+ (src.live
155
+ ? `@group(0) @binding(${PARTICLE_INDIRECT_BINDING}) var<storage, read_write> _rzIndirect: array<u32, 8>;\n`
156
+ : "") +
141
157
  "\n// ── user effect ──\n" +
142
158
  src.wgsl +
159
+ (src.live
160
+ ? /* wgsl */ `
161
+ // The frame's live count, from the author's dials, into the arguments the
162
+ // step dispatch and both draws read. One thread; runs before the step.
163
+ @compute @workgroup_size(1)
164
+ fn rzCount() {
165
+ let n = min(particleCount(), pu.count);
166
+ _rzIndirect[0] = (n + 63u) / 64u;
167
+ _rzIndirect[1] = 1u;
168
+ _rzIndirect[2] = 1u;
169
+ _rzIndirect[3] = 0u;
170
+ _rzIndirect[4] = 6u;
171
+ _rzIndirect[5] = n;
172
+ _rzIndirect[6] = 0u;
173
+ _rzIndirect[7] = 0u;
174
+ }
175
+ `
176
+ : "") +
143
177
  /* wgsl */ `
144
178
  @compute @workgroup_size(64)
145
179
  fn main(@builtin(global_invocation_id) gid: vec3u) {
@@ -212,6 +246,7 @@ ${src.paramsDecl}
212
246
  // The sun's shadow and the world's ambient, for real: the shadow pass has
213
247
  // run by the time this draws, inside the scene pass. See scene-light-api.ts.
214
248
  sceneLightApi(true, 0, PARTICLE_LIGHT_BINDING) +
249
+ pointsApi(true, 0, PARTICLE_POINTS_BINDING) +
215
250
  "\n// ── user effect ──\n" +
216
251
  src.wgsl +
217
252
  /* 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.3",
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
+ }