reze-engine 0.50.12 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effect-schedule.d.ts +67 -0
- package/dist/effect-schedule.d.ts.map +1 -0
- package/dist/effect-schedule.js +96 -0
- package/dist/engine.d.ts +184 -7
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +500 -96
- package/dist/graph/presets/unlit.d.ts +3 -0
- package/dist/graph/presets/unlit.d.ts.map +1 -0
- package/dist/graph/presets/unlit.js +34 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/shaders/anchor-table.d.ts +1 -1
- package/dist/shaders/anchor-table.js +3 -3
- package/dist/shaders/cast-api.d.ts +1 -1
- package/dist/shaders/cast-api.js +2 -2
- package/dist/shaders/directives.d.ts +73 -0
- package/dist/shaders/directives.d.ts.map +1 -0
- package/dist/shaders/directives.js +238 -0
- package/dist/shaders/lights.d.ts +0 -10
- package/dist/shaders/lights.d.ts.map +1 -1
- package/dist/shaders/lights.js +11 -19
- package/dist/shaders/lyrics-api.d.ts +11 -2
- package/dist/shaders/lyrics-api.d.ts.map +1 -1
- package/dist/shaders/lyrics-api.js +11 -2
- package/dist/shaders/passes/composite.d.ts +5 -5
- package/dist/shaders/passes/composite.d.ts.map +1 -1
- package/dist/shaders/passes/composite.js +12 -5
- package/dist/shaders/passes/grid.d.ts +0 -2
- package/dist/shaders/passes/grid.d.ts.map +1 -1
- package/dist/shaders/passes/grid.js +0 -9
- package/dist/shaders/passes/particles.d.ts +0 -6
- package/dist/shaders/passes/particles.d.ts.map +1 -1
- package/dist/shaders/passes/particles.js +15 -19
- package/dist/shaders/passes/scene-contract.d.ts +1 -1
- package/dist/shaders/passes/trails.d.ts.map +1 -1
- package/dist/shaders/passes/trails.js +9 -4
- package/package.json +2 -2
- package/src/effect-schedule.ts +120 -0
- package/src/engine.ts +588 -95
- package/src/graph/presets/unlit.ts +37 -0
- package/src/index.ts +16 -0
- package/src/shaders/anchor-table.ts +3 -3
- package/src/shaders/cast-api.ts +2 -2
- package/src/shaders/directives.ts +289 -0
- package/src/shaders/lights.ts +11 -19
- package/src/shaders/lyrics-api.ts +11 -2
- package/src/shaders/passes/composite.ts +13 -6
- package/src/shaders/passes/grid.ts +0 -9
- package/src/shaders/passes/particles.ts +15 -21
- package/src/shaders/passes/scene-contract.ts +1 -1
- package/src/shaders/passes/trails.ts +9 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unlit.d.ts","sourceRoot":"","sources":["../../../src/graph/presets/unlit.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE5C,eAAO,MAAM,WAAW,EAAE,WAmBzB,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Unlit — the texture, at its own brightness, and nothing else.
|
|
2
|
+
//
|
|
3
|
+
// What FOOTAGE needs. A media plane carries pixels somebody already finished
|
|
4
|
+
// somewhere else: a gradient painted in Photoshop, a title card, a rendered
|
|
5
|
+
// element. Shading it is not a stylistic choice but a mistake — the scene's sun
|
|
6
|
+
// would dim one side of a card that has no side, and the world colour would
|
|
7
|
+
// tint artwork whose colour is the point. Blender's answer is the same one:
|
|
8
|
+
// wire the image straight into an Emission shader and let it out at the value
|
|
9
|
+
// it was authored at.
|
|
10
|
+
//
|
|
11
|
+
// Emission rather than Principled with roughness 1: emission is radiance, so it
|
|
12
|
+
// leaves the light loop entirely instead of being an unusually flat surface
|
|
13
|
+
// inside it. That is also what lets a card sit in front of a lamp without
|
|
14
|
+
// picking up its highlight.
|
|
15
|
+
export const UNLIT_GRAPH = {
|
|
16
|
+
version: 1,
|
|
17
|
+
name: "Unlit",
|
|
18
|
+
tags: ["unlit", "plane"],
|
|
19
|
+
nodes: [
|
|
20
|
+
{ id: "tex", type: "texture" },
|
|
21
|
+
// The PMX material colour still multiplies in, so a plane can be tinted or
|
|
22
|
+
// faded through the same dial every other material uses rather than needing
|
|
23
|
+
// one of its own.
|
|
24
|
+
{ id: "mat", type: "material_diffuse" },
|
|
25
|
+
{ id: "base", type: "mix/multiply", inputs: { fac: 1.0 } },
|
|
26
|
+
{ id: "emit", type: "emission", inputs: { strength: 1.0 } },
|
|
27
|
+
],
|
|
28
|
+
links: [
|
|
29
|
+
{ from: { node: "tex", socket: "color" }, to: { node: "base", socket: "a" } },
|
|
30
|
+
{ from: { node: "mat", socket: "color" }, to: { node: "base", socket: "b" } },
|
|
31
|
+
{ from: { node: "base", socket: "color" }, to: { node: "emit", socket: "color" } },
|
|
32
|
+
],
|
|
33
|
+
output: { node: "emit", socket: "color" },
|
|
34
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { parseMidi } from "./midi-loader";
|
|
|
4
4
|
export { parseHDR, type HdrImage } from "./hdr";
|
|
5
5
|
export { LYRIC_ATLAS_MAX_H, LYRIC_ATLAS_MAX_W, parseLRC, type LyricLine, type LyricRect } from "./shaders/lyrics-api";
|
|
6
6
|
export { sampleParamTrack, type ParamKey, type ParamValue } from "./param-track";
|
|
7
|
+
export { effectState, type EffectWindow, type EffectState } from "./effect-schedule";
|
|
7
8
|
export { compileGraph, validateGraph, assignStyleSlots, type CompileOptions, type CompileResult, type StyleSlot, } from "./graph/compile";
|
|
8
9
|
export type { ShaderGraph, GraphNode, GraphLink, ExposedParam, SocketValue, Diagnostic, } from "./graph/schema";
|
|
9
10
|
export { NODE_REGISTRY, type NodeSpec, type SockT } from "./graph/registry";
|
|
@@ -18,6 +19,8 @@ export { BODY_GRAPH } from "./graph/presets/body";
|
|
|
18
19
|
export { STOCKINGS_GRAPH } from "./graph/presets/stockings";
|
|
19
20
|
export { EYE_GRAPH } from "./graph/presets/eye";
|
|
20
21
|
export { FACE_GRAPH } from "./graph/presets/face";
|
|
22
|
+
export { UNLIT_GRAPH } from "./graph/presets/unlit";
|
|
23
|
+
export { parseDirectives, stripDirectives, DIRECTIVE_LINE, DIRECTIVE_NOTE, type EffectDirectives, type EffectParamDecl, } from "./shaders/directives";
|
|
21
24
|
export { Model, MATERIAL_MORPH_MULTIPLY, MATERIAL_MORPH_ADD, type ClipEventInfo, type RootMotionProfile, type Morph, type Morphing, type BoneMorphOffset, type MaterialMorphOffset, type UvMorphOffset, } from "./model";
|
|
22
25
|
export { Vec3, Quat, Mat4, easeInOut, type EulerOrder } from "./math";
|
|
23
26
|
export type { AnimationClip, AnimationPlayOptions, AnimationProgress, BlendEntry, BoneKeyframe, IkKeyframe, MorphKeyframe, BoneInterpolation, ControlPoint, } from "./animation";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,qBAAqB,EACrB,8BAA8B,EAC9B,sBAAsB,EACtB,qBAAqB,EACrB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,QAAQ,GACd,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACvG,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAGzC,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE/C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,QAAQ,EAA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track, or scrub one, should read the same curve the engine
|
|
11
11
|
// plays rather than reimplementing it a second time.
|
|
12
12
|
export { sampleParamTrack } from "./param-track";
|
|
13
|
+
// The strip an effect is scheduled by, and the pure evaluator behind it —
|
|
14
|
+
// exported so a caller can draw a lane against the same numbers the engine
|
|
15
|
+
// renders from, rather than a second copy of the ramp maths.
|
|
16
|
+
export { effectState } from "./effect-schedule";
|
|
13
17
|
export { compileGraph, validateGraph, assignStyleSlots, } from "./graph/compile";
|
|
14
18
|
export { NODE_REGISTRY } from "./graph/registry";
|
|
15
19
|
export { RENDER_CLASSES } from "./graph/render-class";
|
|
@@ -22,6 +26,11 @@ export { BODY_GRAPH } from "./graph/presets/body";
|
|
|
22
26
|
export { STOCKINGS_GRAPH } from "./graph/presets/stockings";
|
|
23
27
|
export { EYE_GRAPH } from "./graph/presets/eye";
|
|
24
28
|
export { FACE_GRAPH } from "./graph/presets/face";
|
|
29
|
+
export { UNLIT_GRAPH } from "./graph/presets/unlit";
|
|
30
|
+
// What an effect declares, and the source with those lines blanked. Exported
|
|
31
|
+
// because a host builds parameter controls from the declarations and needs the
|
|
32
|
+
// same answer the engine got — two parsers is how they disagree.
|
|
33
|
+
export { parseDirectives, stripDirectives, DIRECTIVE_LINE, DIRECTIVE_NOTE, } from "./shaders/directives";
|
|
25
34
|
export { Model, MATERIAL_MORPH_MULTIPLY, MATERIAL_MORPH_ADD, } from "./model";
|
|
26
35
|
export { Vec3, Quat, Mat4, easeInOut } from "./math";
|
|
27
36
|
export { LocomotionController, } from "./locomotion";
|
|
@@ -35,7 +35,7 @@ export declare function buildAnchorTable(requests: AnchorRequest[][], max: numbe
|
|
|
35
35
|
* TRAILED anchor, so its instance index counts 0,1,2… over trailed anchors only
|
|
36
36
|
* — while the cast buffer is addressed by DECLARATION slot. Those coincide
|
|
37
37
|
* exactly when every anchor is trailed, which is true of all 14 library effects
|
|
38
|
-
* and is why this stayed latent: declare
|
|
38
|
+
* and is why this stayed latent: declare `#anchor 頭` then `#anchor 左手首 trail`
|
|
39
39
|
* and ribbon 0 asked for the trail of 頭, which has none, so the ribbon silently
|
|
40
40
|
* did not draw.
|
|
41
41
|
*
|
|
@@ -73,7 +73,7 @@ export function buildAnchorTable(requests, max) {
|
|
|
73
73
|
* TRAILED anchor, so its instance index counts 0,1,2… over trailed anchors only
|
|
74
74
|
* — while the cast buffer is addressed by DECLARATION slot. Those coincide
|
|
75
75
|
* exactly when every anchor is trailed, which is true of all 14 library effects
|
|
76
|
-
* and is why this stayed latent: declare
|
|
76
|
+
* and is why this stayed latent: declare `#anchor 頭` then `#anchor 左手首 trail`
|
|
77
77
|
* and ribbon 0 asked for the trail of 頭, which has none, so the ribbon silently
|
|
78
78
|
* did not draw.
|
|
79
79
|
*
|
|
@@ -108,7 +108,7 @@ ${cases}
|
|
|
108
108
|
* folds away.
|
|
109
109
|
*/
|
|
110
110
|
export function anchorAliasWgsl(alias) {
|
|
111
|
-
// NO
|
|
111
|
+
// NO #anchor AT ALL. Every slot is unmapped, and rzAnchor() must report
|
|
112
112
|
// .valid false for all of them.
|
|
113
113
|
//
|
|
114
114
|
// This used to fall through to the identity branch below — `[].every()` is
|
|
@@ -120,7 +120,7 @@ export function anchorAliasWgsl(alias) {
|
|
|
120
120
|
// reading.
|
|
121
121
|
if (alias.length === 0) {
|
|
122
122
|
return `
|
|
123
|
-
/** No
|
|
123
|
+
/** No #anchor in this effect: every slot is unmapped, so rzAnchor() is invalid
|
|
124
124
|
* rather than reading whichever bone another effect declared first. */
|
|
125
125
|
fn _rzSlot(local: i32) -> i32 { return -1; }
|
|
126
126
|
`;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const CAST_API = "\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 /** 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/** Which model this is, stable across a scene \u2014 for per-subject variation. */\nfn rzSubjectId(i: i32) -> u32 {\n if (i < 0 || i >= rzSubjectCount()) { return 0u; }\n return u32(_rzCast[i * 3 + 1].w);\n}\n\nfn rzSubject(i: i32) -> RzSubject {\n var s: RzSubject;\n s.valid = i >= 0 && i < rzSubjectCount();\n if (!s.valid) { return s; }\n let b = i * 3;\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 return s;\n}\n\n/**\n * Where a named bone is, this frame.\n *\n * The slot is the author's own: the Nth
|
|
1
|
+
export declare const CAST_API = "\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 /** 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/** Which model this is, stable across a scene \u2014 for per-subject variation. */\nfn rzSubjectId(i: i32) -> u32 {\n if (i < 0 || i >= rzSubjectCount()) { return 0u; }\n return u32(_rzCast[i * 3 + 1].w);\n}\n\nfn rzSubject(i: i32) -> RzSubject {\n var s: RzSubject;\n s.valid = i >= 0 && i < rzSubjectCount();\n if (!s.valid) { return s; }\n let b = i * 3;\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 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 if (subject < 0 || subject >= rzSubjectCount() || g < 0 || g >= RZ_MAX_ANCHORS) { return a; }\n let b = 12 + (g * 4 + subject) * 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 if (subject < 0 || subject >= rzSubjectCount() || g < 0 || g >= RZ_MAX_ANCHORS) { return 0; }\n return i32(_rzCast[12 + (g * 4 + subject) * 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 = 204 + (_rzSlot(slot) * 4 + subject) * RZ_TRAIL_SAMPLES;\n return _rzCast[base + i];\n}\n";
|
|
2
2
|
//# sourceMappingURL=cast-api.d.ts.map
|
package/dist/shaders/cast-api.js
CHANGED
|
@@ -90,7 +90,7 @@ fn rzSubject(i: i32) -> RzSubject {
|
|
|
90
90
|
/**
|
|
91
91
|
* Where a named bone is, this frame.
|
|
92
92
|
*
|
|
93
|
-
* The slot is the author's own: the Nth
|
|
93
|
+
* The slot is the author's own: the Nth #anchor in their file, in the order
|
|
94
94
|
* they wrote them. _rzSlot turns that into the scene's address, which is what
|
|
95
95
|
* keeps two effects that both anchor to a wrist from reading each other's.
|
|
96
96
|
*/
|
|
@@ -113,7 +113,7 @@ fn rzAnchor(subject: i32, slot: i32) -> RzAnchor {
|
|
|
113
113
|
*
|
|
114
114
|
* Bounded by the anchor cap, NOT by how many anchors asked for a trail. Those
|
|
115
115
|
* are different index spaces: storage is addressed by anchor slot, so an
|
|
116
|
-
* untrailed
|
|
116
|
+
* untrailed #anchor followed by a trailed one put the trail at index 1 with a
|
|
117
117
|
* bound of 1 and rzTrail returned zero — a ribbon that silently did not draw.
|
|
118
118
|
*/
|
|
119
119
|
fn rzTrailCount(subject: i32, slot: i32) -> i32 {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** A knob an effect exposes, for a host to build a control from. */
|
|
2
|
+
export type EffectParamDecl = {
|
|
3
|
+
name: string;
|
|
4
|
+
kind: "float" | "color" | "vec3";
|
|
5
|
+
/** Numbers for float/vec3; `#rrggbb` for a colour, which the host converts. */
|
|
6
|
+
value: number | [number, number, number] | string;
|
|
7
|
+
/** float only, and only when the author gave a range. */
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
};
|
|
11
|
+
export type EffectDirectives = {
|
|
12
|
+
/** Bones this effect follows, in declaration order — slot 0 is the first. */
|
|
13
|
+
anchors: {
|
|
14
|
+
bone: string;
|
|
15
|
+
trail: boolean;
|
|
16
|
+
}[];
|
|
17
|
+
params: EffectParamDecl[];
|
|
18
|
+
/** Field layer: 0 full, 1 half. Full unless `#halfres` says otherwise. */
|
|
19
|
+
fieldLayer: 0 | 1;
|
|
20
|
+
/** The field layer composites additively rather than over. */
|
|
21
|
+
additiveLayer: boolean;
|
|
22
|
+
/** Particle blend, which is a different axis from the field layer's. */
|
|
23
|
+
particleBlend: "alpha" | "additive";
|
|
24
|
+
particles: number;
|
|
25
|
+
lights: number;
|
|
26
|
+
grid: number;
|
|
27
|
+
bloom: boolean;
|
|
28
|
+
/** This effect takes the cast apart — the host reads the timing. */
|
|
29
|
+
dissolve: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* How long ONE firing of this effect lasts, in seconds. 0 = undeclared.
|
|
32
|
+
*
|
|
33
|
+
* An effect is one of two things, and only its author knows which. A HIT has
|
|
34
|
+
* an arc — a circle flares, peaks and is gone — and its length is a fact
|
|
35
|
+
* about it, the way a video clip's length is a fact about the file. An
|
|
36
|
+
* AMBIENT effect (stars, fog, rain) has no length at all; it is a condition
|
|
37
|
+
* the scene is in.
|
|
38
|
+
*
|
|
39
|
+
* Declaring it is what lets a host place the effect instead of making someone
|
|
40
|
+
* construct it: dropping a hit on the timeline gives a strip already the
|
|
41
|
+
* right size, and an effect that declares nothing spans the scene. Every
|
|
42
|
+
* timeline works this way — a clip arrives at its own duration.
|
|
43
|
+
*/
|
|
44
|
+
duration: number;
|
|
45
|
+
};
|
|
46
|
+
/** A line that declares something, and what it declares. Exported because an
|
|
47
|
+
* editor highlights by the same rule the parser reads by — a highlighter with
|
|
48
|
+
* its own idea of what counts is one that paints a line as configuration that
|
|
49
|
+
* the engine then ignores. */
|
|
50
|
+
export declare const DIRECTIVE_LINE: RegExp;
|
|
51
|
+
/**
|
|
52
|
+
* Split a directive's arguments from a trailing note.
|
|
53
|
+
*
|
|
54
|
+
* `#anchor 左手首 trail — her sword hand` is one line doing two jobs, and
|
|
55
|
+
* refusing it is what made the old spelling dangerous: the note is the natural
|
|
56
|
+
* thing to write, so it has to be the accepted thing to write.
|
|
57
|
+
*/
|
|
58
|
+
export declare const DIRECTIVE_NOTE: RegExp;
|
|
59
|
+
export type DirectiveResult = {
|
|
60
|
+
directives: EffectDirectives;
|
|
61
|
+
errors: string[];
|
|
62
|
+
};
|
|
63
|
+
/** Read every declaration in a source. Errors name the line, one-based. */
|
|
64
|
+
export declare function parseDirectives(wgsl: string): DirectiveResult;
|
|
65
|
+
/**
|
|
66
|
+
* The source as the compiler should see it: every directive line blanked.
|
|
67
|
+
*
|
|
68
|
+
* Blanked rather than removed so line numbers survive — a diagnostic points at
|
|
69
|
+
* the line the author is looking at, which is the whole reason the engine
|
|
70
|
+
* rebases them in the first place.
|
|
71
|
+
*/
|
|
72
|
+
export declare function stripDirectives(wgsl: string): string;
|
|
73
|
+
//# sourceMappingURL=directives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../../src/shaders/directives.ts"],"names":[],"mappings":"AA8BA,oEAAoE;AACpE,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAA;IAChC,+EAA+E;IAC/E,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;IACjD,yDAAyD;IACzD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,6EAA6E;IAC7E,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;IAC3C,MAAM,EAAE,eAAe,EAAE,CAAA;IACzB,0EAA0E;IAC1E,UAAU,EAAE,CAAC,GAAG,CAAC,CAAA;IACjB,8DAA8D;IAC9D,aAAa,EAAE,OAAO,CAAA;IACtB,wEAAwE;IACxE,aAAa,EAAE,OAAO,GAAG,UAAU,CAAA;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAA;IACd,oEAAoE;IACpE,QAAQ,EAAE,OAAO,CAAA;IACjB;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAiBD;;;+BAG+B;AAC/B,eAAO,MAAM,cAAc,QAAmC,CAAA;AAG9D;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,QAA8B,CAAA;AAmBzD,MAAM,MAAM,eAAe,GAAG;IAAE,UAAU,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAEhF,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAqJ7D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKpD"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// What an effect DECLARES about itself — parsed once, in one place.
|
|
2
|
+
//
|
|
3
|
+
// An effect file is WGSL plus a handful of lines that configure how the engine
|
|
4
|
+
// mounts it: which resolution it draws at, how it blends, which bones it
|
|
5
|
+
// follows, what knobs it exposes. Those lines are not comments. They decide
|
|
6
|
+
// whether the file gets what it asks for, and the failure they used to have was
|
|
7
|
+
// the worst kind available.
|
|
8
|
+
//
|
|
9
|
+
// WHY `#` AND NOT `// @`. The old spelling put directives inside comments,
|
|
10
|
+
// which meant two things. Authors read them as comments and wrote notes on the
|
|
11
|
+
// same line — every parser was anchored to end-of-line, so the note silently
|
|
12
|
+
// unmade the directive, and three shipped effects ran at half the resolution
|
|
13
|
+
// their own first line said they needed while a fourth quietly stopped being
|
|
14
|
+
// additive. Nothing failed and nothing was reported, because nothing had been
|
|
15
|
+
// declared to fail. And it could not be fixed by being strict: a comment
|
|
16
|
+
// beginning with `@` is a legitimate thing to write, so an unrecognised one can
|
|
17
|
+
// only ever be a warning.
|
|
18
|
+
//
|
|
19
|
+
// WGSL has no `#` syntax of its own. A line starting with `#` is therefore
|
|
20
|
+
// unambiguously ours, an unknown one is an ERROR rather than a guess, and the
|
|
21
|
+
// sigil is the one every shader author already reads as "directive" from
|
|
22
|
+
// `#pragma`. The cost usually quoted for this — that the file stops being valid
|
|
23
|
+
// WGSL — is not a cost we pay: an effect calls rzSubject, rzTrail and reads
|
|
24
|
+
// `params`, none of which exist until the engine splices them in, so these
|
|
25
|
+
// files have never compiled anywhere else.
|
|
26
|
+
//
|
|
27
|
+
// STRIPPED BY BLANKING, not by deleting: the compiler sees an empty line where
|
|
28
|
+
// each directive was, so every diagnostic's line number still points at the
|
|
29
|
+
// line the author is looking at.
|
|
30
|
+
/** Every directive, with how many words follow it. `rest` means free-form. */
|
|
31
|
+
const SPEC = {
|
|
32
|
+
anchor: "rest",
|
|
33
|
+
param: "rest",
|
|
34
|
+
halfres: 0,
|
|
35
|
+
layer: 1,
|
|
36
|
+
blend: 1,
|
|
37
|
+
particles: 1,
|
|
38
|
+
lights: 1,
|
|
39
|
+
grid: 1,
|
|
40
|
+
bloom: 0,
|
|
41
|
+
dissolve: 0,
|
|
42
|
+
duration: 1,
|
|
43
|
+
};
|
|
44
|
+
/** A line that declares something, and what it declares. Exported because an
|
|
45
|
+
* editor highlights by the same rule the parser reads by — a highlighter with
|
|
46
|
+
* its own idea of what counts is one that paints a line as configuration that
|
|
47
|
+
* the engine then ignores. */
|
|
48
|
+
export const DIRECTIVE_LINE = /^[ \t]*#([a-zA-Z]+)[ \t]*(.*)$/;
|
|
49
|
+
const LINE = DIRECTIVE_LINE;
|
|
50
|
+
/**
|
|
51
|
+
* Split a directive's arguments from a trailing note.
|
|
52
|
+
*
|
|
53
|
+
* `#anchor 左手首 trail — her sword hand` is one line doing two jobs, and
|
|
54
|
+
* refusing it is what made the old spelling dangerous: the note is the natural
|
|
55
|
+
* thing to write, so it has to be the accepted thing to write.
|
|
56
|
+
*/
|
|
57
|
+
export const DIRECTIVE_NOTE = /(?:^|\s)(?:—|--|\/\/|#)\s/;
|
|
58
|
+
function argsOf(rest) {
|
|
59
|
+
// `^` as well as `\s`: the tag's own trailing space is eaten by LINE, so a
|
|
60
|
+
// note can begin at the very first character — which is what
|
|
61
|
+
// `#halfres — glyph edges` looks like by the time it reaches here.
|
|
62
|
+
const note = rest.search(DIRECTIVE_NOTE);
|
|
63
|
+
return (note >= 0 ? rest.slice(0, note) : rest).trim().split(/\s+/).filter(Boolean);
|
|
64
|
+
}
|
|
65
|
+
/** A number, or null. Empty is NULL, not zero: `Number("")` is 0, so a missing
|
|
66
|
+
* default silently became a real one — an author who wrote `#param float D`
|
|
67
|
+
* and meant to finish the line got a knob quietly pinned at zero. */
|
|
68
|
+
const num = (s) => {
|
|
69
|
+
if (!s || !s.trim())
|
|
70
|
+
return null;
|
|
71
|
+
const v = Number(s);
|
|
72
|
+
return Number.isFinite(v) ? v : null;
|
|
73
|
+
};
|
|
74
|
+
/** Read every declaration in a source. Errors name the line, one-based. */
|
|
75
|
+
export function parseDirectives(wgsl) {
|
|
76
|
+
const d = {
|
|
77
|
+
anchors: [],
|
|
78
|
+
params: [],
|
|
79
|
+
// FULL unless asked otherwise — the default is what an author gets for
|
|
80
|
+
// saying nothing, so it has to be the answer that cannot silently ruin an
|
|
81
|
+
// effect. `#halfres` is a claim about being cheap, which is a claim only
|
|
82
|
+
// the author can make.
|
|
83
|
+
fieldLayer: 0,
|
|
84
|
+
additiveLayer: false,
|
|
85
|
+
particleBlend: "alpha",
|
|
86
|
+
particles: 0,
|
|
87
|
+
lights: 0,
|
|
88
|
+
grid: 0,
|
|
89
|
+
bloom: false,
|
|
90
|
+
dissolve: false,
|
|
91
|
+
duration: 0,
|
|
92
|
+
};
|
|
93
|
+
const errors = [];
|
|
94
|
+
const lines = wgsl.split("\n");
|
|
95
|
+
lines.forEach((line, i) => {
|
|
96
|
+
const m = LINE.exec(line);
|
|
97
|
+
if (!m)
|
|
98
|
+
return;
|
|
99
|
+
const at = `line ${i + 1}`;
|
|
100
|
+
const tag = m[1].toLowerCase();
|
|
101
|
+
if (!(tag in SPEC)) {
|
|
102
|
+
errors.push(`${at}: #${m[1]} is not a directive. Known: ${Object.keys(SPEC).map((k) => `#${k}`).join(", ")}`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const args = argsOf(m[2]);
|
|
106
|
+
const want = SPEC[tag];
|
|
107
|
+
if (want !== "rest" && args.length !== want) {
|
|
108
|
+
errors.push(`${at}: #${tag} takes ${want} argument${want === 1 ? "" : "s"}, got ${args.length}`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
switch (tag) {
|
|
112
|
+
case "anchor": {
|
|
113
|
+
if (args.length < 1 || args.length > 2 || (args[1] && args[1] !== "trail")) {
|
|
114
|
+
errors.push(`${at}: #anchor takes a bone name and optionally the word "trail"`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
d.anchors.push({ bone: args[0], trail: args[1] === "trail" });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
case "param": {
|
|
121
|
+
const [kind, name, ...rest] = args;
|
|
122
|
+
if (!name || !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
123
|
+
errors.push(`${at}: #param needs a WGSL identifier for a name`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (kind === "color") {
|
|
127
|
+
if (!/^#[0-9a-fA-F]{6}$/.test(rest[0] ?? "")) {
|
|
128
|
+
errors.push(`${at}: #param color ${name} needs a default like #3b82f6`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
d.params.push({ name, kind: "color", value: rest[0] });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (kind === "vec3") {
|
|
135
|
+
const v = rest.slice(0, 3).map(num);
|
|
136
|
+
if (v.length !== 3 || v.some((x) => x === null)) {
|
|
137
|
+
errors.push(`${at}: #param vec3 ${name} needs three numbers`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
d.params.push({ name, kind: "vec3", value: v });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (kind === "float") {
|
|
144
|
+
const v = num(rest[0]);
|
|
145
|
+
if (v === null) {
|
|
146
|
+
errors.push(`${at}: #param float ${name} needs a default`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const lo = num(rest[1]);
|
|
150
|
+
const hi = num(rest[2]);
|
|
151
|
+
// A range is optional and all-or-nothing: half of one is a slider
|
|
152
|
+
// with an end nobody chose.
|
|
153
|
+
if ((rest[1] !== undefined) !== (rest[2] !== undefined) || (rest[1] !== undefined && (lo === null || hi === null))) {
|
|
154
|
+
errors.push(`${at}: #param float ${name} takes both a min and a max, or neither`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
d.params.push({ name, kind: "float", value: v, ...(lo !== null && hi !== null ? { min: lo, max: hi } : {}) });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
errors.push(`${at}: #param kind must be float, color or vec3`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
case "halfres":
|
|
164
|
+
d.fieldLayer = 1;
|
|
165
|
+
return;
|
|
166
|
+
case "layer":
|
|
167
|
+
if (args[0] !== "additive") {
|
|
168
|
+
errors.push(`${at}: #layer takes "additive" — over is the default`);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
d.additiveLayer = true;
|
|
172
|
+
return;
|
|
173
|
+
case "blend":
|
|
174
|
+
if (args[0] !== "additive") {
|
|
175
|
+
errors.push(`${at}: #blend takes "additive" — alpha is the default`);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
d.particleBlend = "additive";
|
|
179
|
+
return;
|
|
180
|
+
case "bloom":
|
|
181
|
+
d.bloom = true;
|
|
182
|
+
return;
|
|
183
|
+
case "dissolve":
|
|
184
|
+
d.dissolve = true;
|
|
185
|
+
return;
|
|
186
|
+
case "duration": {
|
|
187
|
+
// SECONDS, like every other time a directive states (see #dissolve).
|
|
188
|
+
// The document above works in frames and converts once; an author
|
|
189
|
+
// writing a shader is thinking about how long a flare takes, not about
|
|
190
|
+
// MMD's frame rate.
|
|
191
|
+
const n = num(args[0]);
|
|
192
|
+
if (n === null || n <= 0) {
|
|
193
|
+
errors.push(`${at}: #duration takes a length in seconds`);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
d.duration = n;
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
default: {
|
|
200
|
+
// The three that take a count.
|
|
201
|
+
const n = num(args[0]);
|
|
202
|
+
if (n === null || n < 0) {
|
|
203
|
+
errors.push(`${at}: #${tag} takes a number`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (tag === "particles")
|
|
207
|
+
d.particles = n;
|
|
208
|
+
else if (tag === "lights")
|
|
209
|
+
d.lights = n;
|
|
210
|
+
else if (tag === "grid")
|
|
211
|
+
d.grid = n;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
// Duplicates are an author editing one line and forgetting another; last-wins
|
|
217
|
+
// is a coin toss they never see resolved.
|
|
218
|
+
const names = new Set();
|
|
219
|
+
for (const p of d.params) {
|
|
220
|
+
if (names.has(p.name))
|
|
221
|
+
errors.push(`#param ${p.name} is declared twice`);
|
|
222
|
+
names.add(p.name);
|
|
223
|
+
}
|
|
224
|
+
return { directives: d, errors };
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The source as the compiler should see it: every directive line blanked.
|
|
228
|
+
*
|
|
229
|
+
* Blanked rather than removed so line numbers survive — a diagnostic points at
|
|
230
|
+
* the line the author is looking at, which is the whole reason the engine
|
|
231
|
+
* rebases them in the first place.
|
|
232
|
+
*/
|
|
233
|
+
export function stripDirectives(wgsl) {
|
|
234
|
+
return wgsl
|
|
235
|
+
.split("\n")
|
|
236
|
+
.map((line) => (LINE.test(line) ? "" : line))
|
|
237
|
+
.join("\n");
|
|
238
|
+
}
|
package/dist/shaders/lights.d.ts
CHANGED
|
@@ -12,16 +12,6 @@ export declare const LIGHT_STRIDE = 8;
|
|
|
12
12
|
export declare const MAX_LIGHTS = 16;
|
|
13
13
|
/** Floats in the whole buffer. */
|
|
14
14
|
export declare const LIGHTS_FLOATS: number;
|
|
15
|
-
/**
|
|
16
|
-
* `// @lights 3` — how many lights this effect emits.
|
|
17
|
-
*
|
|
18
|
-
* Declared, like every other mount: what the file says is what gets allocated,
|
|
19
|
-
* so an effect that emits none costs no slots and nobody pays for a cap they
|
|
20
|
-
* did not ask for. Clamped rather than rejected, the same choice `@particles`
|
|
21
|
-
* makes — an author asking for a hundred gets the most the engine will give and
|
|
22
|
-
* a scene that still runs.
|
|
23
|
-
*/
|
|
24
|
-
export declare function parseLightCount(wgsl: string, max: number): number;
|
|
25
15
|
/**
|
|
26
16
|
* The RzLight struct, declared in EVERY module a user's source is spliced into.
|
|
27
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lights.d.ts","sourceRoot":"","sources":["../../src/shaders/lights.ts"],"names":[],"mappings":"AAgCA;yEACyE;AACzE,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,+CAA+C;AAC/C,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B;;;;;GAKG;AACH,eAAO,MAAM,UAAU,KAAK,CAAA;AAC5B,kCAAkC;AAClC,eAAO,MAAM,aAAa,QAA2C,CAAA;AAErE;;;;;;;;GAQG;AACH,
|
|
1
|
+
{"version":3,"file":"lights.d.ts","sourceRoot":"","sources":["../../src/shaders/lights.ts"],"names":[],"mappings":"AAgCA;yEACyE;AACzE,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,+CAA+C;AAC/C,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B;;;;;GAKG;AACH,eAAO,MAAM,UAAU,KAAK,CAAA;AAC5B,kCAAkC;AAClC,eAAO,MAAM,aAAa,QAA2C,CAAA;AAErE;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,qJAQhC,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,idAa9B,CAAA;AAED,8CAA8C;AAC9C,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAC3B,MAAM,CA4ER;AAED,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAkEhE"}
|
package/dist/shaders/lights.js
CHANGED
|
@@ -42,21 +42,6 @@ export const LIGHT_STRIDE = 8;
|
|
|
42
42
|
export const MAX_LIGHTS = 16;
|
|
43
43
|
/** Floats in the whole buffer. */
|
|
44
44
|
export const LIGHTS_FLOATS = LIGHT_HEADER + MAX_LIGHTS * LIGHT_STRIDE;
|
|
45
|
-
/**
|
|
46
|
-
* `// @lights 3` — how many lights this effect emits.
|
|
47
|
-
*
|
|
48
|
-
* Declared, like every other mount: what the file says is what gets allocated,
|
|
49
|
-
* so an effect that emits none costs no slots and nobody pays for a cap they
|
|
50
|
-
* did not ask for. Clamped rather than rejected, the same choice `@particles`
|
|
51
|
-
* makes — an author asking for a hundred gets the most the engine will give and
|
|
52
|
-
* a scene that still runs.
|
|
53
|
-
*/
|
|
54
|
-
export function parseLightCount(wgsl, max) {
|
|
55
|
-
const m = /^\s*\/\/\s*@lights\s+(\d+)\s*$/m.exec(wgsl);
|
|
56
|
-
if (!m)
|
|
57
|
-
return 0;
|
|
58
|
-
return Math.max(1, Math.min(max, parseInt(m[1], 10)));
|
|
59
|
-
}
|
|
60
45
|
/**
|
|
61
46
|
* The RzLight struct, declared in EVERY module a user's source is spliced into.
|
|
62
47
|
*
|
|
@@ -134,8 +119,8 @@ export function buildLightEmitShader(wgsl, sceneApi, cast) {
|
|
|
134
119
|
// read_write HERE and read-only in the material shaders. Different passes, so
|
|
135
120
|
// the two never coexist: this compute runs before the scene pass that reads it.
|
|
136
121
|
@group(0) @binding(0) var<storage, read_write> _rzLightsOut: array<f32>;
|
|
137
|
-
// (time, base slot, count,
|
|
138
|
-
// here and not in the text.
|
|
122
|
+
// (time, base slot, count, weight) — see buildLightEmitShader on why the base
|
|
123
|
+
// is here and not in the text.
|
|
139
124
|
@group(0) @binding(1) var<uniform> _rzLightU: vec4f;
|
|
140
125
|
// The camera block and the cast — the two buffers the scene API reads. Same
|
|
141
126
|
// contents the field and grid modules bind, so an effect's lightEmit sees the
|
|
@@ -185,12 +170,19 @@ fn lightEmitMain(@builtin(global_invocation_id) gid: vec3u) {
|
|
|
185
170
|
let finite = l.pos.x == l.pos.x && l.pos.y == l.pos.y && l.pos.z == l.pos.z &&
|
|
186
171
|
l.radius == l.radius && l.intensity == l.intensity &&
|
|
187
172
|
l.color.x == l.color.x && l.color.y == l.color.y && l.color.z == l.color.z;
|
|
188
|
-
|
|
173
|
+
// Weight rides along with the sanitisation, which is already the one place
|
|
174
|
+
// this buffer is written: a lamp at half weight is half as bright, and one
|
|
175
|
+
// at zero never reaches here because the dispatch is skipped.
|
|
176
|
+
let c = select(vec3f(0.0), max(l.color * l.intensity, vec3f(0.0)), finite) * _rzLightU.w;
|
|
189
177
|
let b = ${LIGHT_HEADER}u + (u32(_rzLightU.y) + i) * ${LIGHT_STRIDE}u;
|
|
190
178
|
_rzLightsOut[b] = select(0.0, l.pos.x, finite);
|
|
191
179
|
_rzLightsOut[b + 1u] = select(0.0, l.pos.y, finite);
|
|
192
180
|
_rzLightsOut[b + 2u] = select(0.0, l.pos.z, finite);
|
|
193
|
-
|
|
181
|
+
// Radius goes to zero when the effect is OFF, and is left alone at every
|
|
182
|
+
// weight above it. Scaling it with the fade would shrink a dimming lamp's
|
|
183
|
+
// reach, which is a different thing than dimming it; zeroing it at nothing
|
|
184
|
+
// is what lets a material's distance cull drop the slot entirely.
|
|
185
|
+
_rzLightsOut[b + 3u] = select(0.0, max(l.radius, 0.0), finite && _rzLightU.w > 0.0);
|
|
194
186
|
// Colour carries intensity, exactly as the CPU writer stores it — one product,
|
|
195
187
|
// one place, so the two producers cannot disagree about what a slot means.
|
|
196
188
|
_rzLightsOut[b + 4u] = c.x;
|
|
@@ -5,8 +5,17 @@ export declare const LYRICS_FLOATS: number;
|
|
|
5
5
|
/** Bounds on the line atlas the host packs rasterised lines into. It is sized
|
|
6
6
|
* to the track that arrives rather than allocated at the maximum: a scene with
|
|
7
7
|
* no lyrics carries a 1×1 placeholder, and a song's atlas is as tall as its
|
|
8
|
-
* own lines need. 8192 is the smallest texture dimension WebGPU guarantees.
|
|
9
|
-
|
|
8
|
+
* own lines need. 8192 is the smallest texture dimension WebGPU guarantees.
|
|
9
|
+
*
|
|
10
|
+
* WIDTH IS WHAT DECIDES SHARPNESS on a long line. A lyric spans most of the
|
|
11
|
+
* frame — the shipped effect leaves 6% a side — so at 4K it is drawn across
|
|
12
|
+
* some 3400 pixels, and 2048 could only ever be stretched to cover them. That
|
|
13
|
+
* is the stair-stepped text on a 4K render, and no row height fixes it: the
|
|
14
|
+
* line is already as wide as the sheet. 1080p never showed it, because 1690
|
|
15
|
+
* pixels of line fit inside 2048. The atlas is r8unorm, one byte a texel, and
|
|
16
|
+
* only ever as wide as its own longest line — so this ceiling costs nothing
|
|
17
|
+
* until a song actually needs it. */
|
|
18
|
+
export declare const LYRIC_ATLAS_MAX_W = 4096;
|
|
10
19
|
export declare const LYRIC_ATLAS_MAX_H = 8192;
|
|
11
20
|
export type LyricLine = {
|
|
12
21
|
/** Seconds on the scene clock. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lyrics-api.d.ts","sourceRoot":"","sources":["../../src/shaders/lyrics-api.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,eAAe,MAAM,CAAA;AAClC,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,eAAO,MAAM,aAAa,QAAgD,CAAA;AAE1E
|
|
1
|
+
{"version":3,"file":"lyrics-api.d.ts","sourceRoot":"","sources":["../../src/shaders/lyrics-api.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,eAAe,MAAM,CAAA;AAClC,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,eAAO,MAAM,aAAa,QAAgD,CAAA;AAE1E;;;;;;;;;;;;sCAYsC;AACtC,eAAO,MAAM,iBAAiB,OAAO,CAAA;AACrC,eAAO,MAAM,iBAAiB,OAAO,CAAA;AAErC,MAAM,MAAM,SAAS,GAAG;IACtB,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,8EAA8E;IAC9E,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAExD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,CA+BpD;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,KAAK,CAAC,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,WAAW,CAAC,CAkB7F;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAsDhE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAgC5F"}
|
|
@@ -26,8 +26,17 @@ export const LYRICS_FLOATS = LYRIC_HEADER + LYRIC_LINES_MAX * LYRIC_STRIDE;
|
|
|
26
26
|
/** Bounds on the line atlas the host packs rasterised lines into. It is sized
|
|
27
27
|
* to the track that arrives rather than allocated at the maximum: a scene with
|
|
28
28
|
* no lyrics carries a 1×1 placeholder, and a song's atlas is as tall as its
|
|
29
|
-
* own lines need. 8192 is the smallest texture dimension WebGPU guarantees.
|
|
30
|
-
|
|
29
|
+
* own lines need. 8192 is the smallest texture dimension WebGPU guarantees.
|
|
30
|
+
*
|
|
31
|
+
* WIDTH IS WHAT DECIDES SHARPNESS on a long line. A lyric spans most of the
|
|
32
|
+
* frame — the shipped effect leaves 6% a side — so at 4K it is drawn across
|
|
33
|
+
* some 3400 pixels, and 2048 could only ever be stretched to cover them. That
|
|
34
|
+
* is the stair-stepped text on a 4K render, and no row height fixes it: the
|
|
35
|
+
* line is already as wide as the sheet. 1080p never showed it, because 1690
|
|
36
|
+
* pixels of line fit inside 2048. The atlas is r8unorm, one byte a texel, and
|
|
37
|
+
* only ever as wide as its own longest line — so this ceiling costs nothing
|
|
38
|
+
* until a song actually needs it. */
|
|
39
|
+
export const LYRIC_ATLAS_MAX_W = 4096;
|
|
31
40
|
export const LYRIC_ATLAS_MAX_H = 8192;
|
|
32
41
|
/**
|
|
33
42
|
* Parse an .lrc file: `[mm:ss.xx]` tags (several per line share the text),
|