reze-engine 0.69.4 → 0.69.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine.d.ts +50 -4
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +321 -18
- package/dist/graph/slots.d.ts.map +1 -1
- package/dist/graph/slots.js +6 -2
- package/dist/shaders/directives.d.ts +32 -4
- package/dist/shaders/directives.d.ts.map +1 -1
- package/dist/shaders/directives.js +55 -1
- package/dist/shaders/materials/common.d.ts +10 -1
- package/dist/shaders/materials/common.d.ts.map +1 -1
- package/dist/shaders/materials/common.js +24 -1
- package/dist/shaders/passes/depth-prepass.d.ts.map +1 -1
- package/dist/shaders/passes/depth-prepass.js +4 -2
- package/dist/shaders/passes/outline.d.ts.map +1 -1
- package/dist/shaders/passes/outline.js +7 -1
- package/dist/shaders/passes/shadow.d.ts +1 -1
- package/dist/shaders/passes/shadow.d.ts.map +1 -1
- package/dist/shaders/text-api.d.ts +32 -0
- package/dist/shaders/text-api.d.ts.map +1 -0
- package/dist/shaders/text-api.js +132 -0
- package/package.json +1 -1
- package/src/engine.ts +329 -25
- package/src/graph/slots.ts +6 -2
- package/src/shaders/directives.ts +78 -5
- package/src/shaders/materials/common.ts +25 -1
- package/src/shaders/passes/depth-prepass.ts +4 -2
- package/src/shaders/passes/outline.ts +7 -1
- package/src/shaders/text-api.ts +144 -0
|
@@ -44,6 +44,8 @@ const SPEC = {
|
|
|
44
44
|
dissolve: 0,
|
|
45
45
|
mirror: 0,
|
|
46
46
|
stepped: 0,
|
|
47
|
+
xray: 4,
|
|
48
|
+
font: "rest",
|
|
47
49
|
duration: 1,
|
|
48
50
|
ground: "rest",
|
|
49
51
|
};
|
|
@@ -116,6 +118,8 @@ export function parseDirectives(wgsl) {
|
|
|
116
118
|
ground: null,
|
|
117
119
|
mirror: false,
|
|
118
120
|
stepped: false,
|
|
121
|
+
xray: null,
|
|
122
|
+
font: null,
|
|
119
123
|
duration: 0,
|
|
120
124
|
};
|
|
121
125
|
const errors = [];
|
|
@@ -232,6 +236,26 @@ export function parseDirectives(wgsl) {
|
|
|
232
236
|
d.params.push({ name, kind: "bone", value: rest[0], ...labels });
|
|
233
237
|
return;
|
|
234
238
|
}
|
|
239
|
+
if (kind === "text") {
|
|
240
|
+
// Words, set by the engine into a picture the field module reads
|
|
241
|
+
// through rzText_NAME(uv). The default is the rest of the line up to
|
|
242
|
+
// its note, spaces kept as one.
|
|
243
|
+
d.params.push({ name, kind: "text", value: rest.join(" "), ...labels });
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (kind === "lag") {
|
|
247
|
+
// A float dial trailing another: what a game's health bar draws as
|
|
248
|
+
// the chunk just lost. Derived by the engine, so a host draws no
|
|
249
|
+
// control for it.
|
|
250
|
+
const hold = num(rest[1]);
|
|
251
|
+
const rate = num(rest[2]);
|
|
252
|
+
if (rest.length !== 3 || !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(rest[0]) || hold === null || hold < 0 || rate === null || rate <= 0) {
|
|
253
|
+
errors.push(`${at}: #param lag ${name} takes the dial it trails, a hold in seconds and a drain per second, like "HEALTH 0.8 0.6"`);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
d.params.push({ name, kind: "lag", value: 0, source: rest[0], hold, rate, ...labels });
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
235
259
|
if (kind === "enum") {
|
|
236
260
|
// Each choice is `id` or `id|中文`; a leading `*` marks the default,
|
|
237
261
|
// else the first is.
|
|
@@ -289,7 +313,7 @@ export function parseDirectives(wgsl) {
|
|
|
289
313
|
d.params.push({ name, kind: "float", value: v, ...(lo !== null && hi !== null ? { min: lo, max: hi } : {}), ...labels });
|
|
290
314
|
return;
|
|
291
315
|
}
|
|
292
|
-
errors.push(`${at}: #param kind must be float, int, color, vec3, point, bone, bool or
|
|
316
|
+
errors.push(`${at}: #param kind must be float, int, color, vec3, point, bone, bool, enum, text or lag`);
|
|
293
317
|
return;
|
|
294
318
|
}
|
|
295
319
|
case "halfres":
|
|
@@ -364,6 +388,21 @@ export function parseDirectives(wgsl) {
|
|
|
364
388
|
case "stepped":
|
|
365
389
|
d.stepped = true;
|
|
366
390
|
return;
|
|
391
|
+
case "xray":
|
|
392
|
+
d.xray = { x: args[0], y: args[1], width: args[2], height: args[3] };
|
|
393
|
+
return;
|
|
394
|
+
case "font": {
|
|
395
|
+
const words = args.join(" ");
|
|
396
|
+
const m = /^(.*?)(?:\s+tracking\s+(-?[\d.]+))?$/.exec(words);
|
|
397
|
+
const css = (m?.[1] ?? "").trim();
|
|
398
|
+
const tracking = m?.[2] !== undefined ? num(m[2]) : 0;
|
|
399
|
+
if (!css || tracking === null) {
|
|
400
|
+
errors.push(`${at}: #font takes a CSS font without its size, like "500 Georgia, serif", and optionally "tracking 0.1"`);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
d.font = { css, tracking };
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
367
406
|
case "duration": {
|
|
368
407
|
// SECONDS, like every other time a directive states (see #dissolve).
|
|
369
408
|
// The document above works in frames and converts once; an author
|
|
@@ -394,6 +433,21 @@ export function parseDirectives(wgsl) {
|
|
|
394
433
|
}
|
|
395
434
|
}
|
|
396
435
|
});
|
|
436
|
+
// #xray names four dials, which have to be there and be numbers.
|
|
437
|
+
if (d.xray) {
|
|
438
|
+
for (const name of [d.xray.x, d.xray.y, d.xray.width, d.xray.height]) {
|
|
439
|
+
if (d.params.find((p) => p.name === name)?.kind !== "float")
|
|
440
|
+
errors.push(`#xray: ${name} has to be a #param float`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
// A lag trails a number that has to be there.
|
|
444
|
+
for (const p of d.params) {
|
|
445
|
+
if (p.kind !== "lag")
|
|
446
|
+
continue;
|
|
447
|
+
const src = d.params.find((q) => q.name === p.source);
|
|
448
|
+
if (src?.kind !== "float" && src?.kind !== "int")
|
|
449
|
+
errors.push(`#param lag ${p.name}: ${p.source} has to be a #param float or int`);
|
|
450
|
+
}
|
|
397
451
|
// Duplicates are an author editing one line and forgetting another; last-wins
|
|
398
452
|
// is a coin toss they never see resolved.
|
|
399
453
|
const names = new Set();
|
|
@@ -6,7 +6,16 @@
|
|
|
6
6
|
export declare const JELLY_VERTEX_WGSL = "\nfn _rzJellyTurn(q: vec2f, a: f32) -> vec2f {\n let c = cos(a);\n let s = sin(a);\n return vec2f(c * q.x - s * q.y, s * q.x + c * q.y);\n}\n\n/**\n * Where the jelly puts an iris vertex. The iris is the part of the eye the eye\n * bones carry, so it is moved as a whole, in bind space before skinning:\n * scaled about its centre (the CPU composes the blink's spring, the lid's\n * press and her motion's knock into one scale), turned and drifted a hair on\n * the spring, brought forward a hair, and rolled about the eye bone with a\n * closing expression \u2014 inside the white, which stays where it is. A highlight\n * layer (this draw's material is one of jelly[1].w's) takes the iris's move,\n * then its own scale, turn and tremble, before the roll. Vertices take it by their weight on the eye bones\n * (jelly[2].w, jelly[3].w), so nothing else on the face moves.\n */\nfn rzJellyVertex(p: vec3f, joints: vec4<u32>, nw: vec4f) -> vec3f {\n let j = objectLight.jelly;\n let ids = u32(j[1].w);\n let mid = u32(material.materialId);\n let hl = mid > 0u && (mid == (ids & 4095u) || mid == (ids >> 12u));\n var out = p;\n for (var e = 0u; e < 2u; e++) {\n let bone = j[2u + e].w;\n if (bone < 0.0) { continue; }\n let b = u32(bone);\n let w = dot(nw, select(vec4f(0.0), vec4f(1.0), joints == vec4<u32>(b)));\n if (w <= 0.0) { continue; }\n let c = j[e].xyz;\n // A rig that carries both eyes on one bone: each vertex follows its own side.\n if (j[2].w == j[3].w && e == 0u && distance(p.xy, j[1].xy) < distance(p.xy, j[0].xy)) { continue; }\n if (j[2].w == j[3].w && e == 1u && distance(p.xy, j[0].xy) <= distance(p.xy, j[1].xy)) { continue; }\n let t = j[4u + e];\n let m = j[6u + e];\n let h = j[10u + e];\n var q = _rzJellyTurn((p.xy - c.xy) * t.xy, t.z) + m.xy;\n // Forward is \u2212Z (MMD faces \u2212Z).\n var push = h.z;\n if (hl) {\n // Sliding over the iris's dome on its own, a highlight sheet a hair in\n // front of it would sink into it where the dome bulges more and the two\n // fight for depth; so it comes forward by as far as it slid \u2014 a slope of\n // one, steeper than the dome anywhere it draws.\n let before = q;\n q = _rzJellyTurn(q * h.xy, t.w) + m.zw;\n push += length(q - before);\n }\n var moved = vec3f(c.xy + q, p.z - push);\n let roll = j[8u + e];\n if (roll.w != 0.0) {\n let d = moved - roll.xyz;\n let rd = _rzJellyTurn(d.yz, roll.w);\n moved = roll.xyz + vec3f(d.x, rd.x, rd.y);\n }\n out = mix(p, moved, w);\n }\n return out;\n}\n";
|
|
7
7
|
/** A model's ObjectLight as WGSL declares it (see the layout below). One copy
|
|
8
8
|
* for every pass that binds it, so their layouts cannot drift. */
|
|
9
|
-
export declare const OBJECT_LIGHT_STRUCT_WGSL = "struct ObjectLight { layers: vec4u, ambient: vec4f, sh: array<vec4f, 9>, fill: vec4f, jelly: array<vec4f, 12>, bloom: vec4f }";
|
|
9
|
+
export declare const OBJECT_LIGHT_STRUCT_WGSL = "struct ObjectLight { layers: vec4u, ambient: vec4f, sh: array<vec4f, 9>, fill: vec4f, jelly: array<vec4f, 12>, bloom: vec4f, xray: array<vec4f, 4>, xrayMask: array<vec4u, 16> }";
|
|
10
|
+
/**
|
|
11
|
+
* The see-through window (#xray): a rectangle on the frame, in pixels —
|
|
12
|
+
* xray[0] is (left, top, right, bottom), xray[3].x is 1 while a window is open
|
|
13
|
+
* on this model — and which of the model's materials it cuts: a bit a
|
|
14
|
+
* material, by its 1-based draw index (materialId), up to 512. Tested against
|
|
15
|
+
* the fragment's own position, so it sits where the lens is, whatever moves
|
|
16
|
+
* behind it. Declared after the pass's own `objectLight` binding.
|
|
17
|
+
*/
|
|
18
|
+
export declare const XRAY_WGSL = "\nfn rz_xray_inside(fp: vec4f) -> bool {\n if (objectLight.xray[3].x < 0.5) { return false; }\n let r = objectLight.xray[0];\n return fp.x >= r.x && fp.y >= r.y && fp.x <= r.z && fp.y <= r.w;\n}\nfn rz_xray_cut(fp: vec4f, materialId: f32) -> bool {\n let i = u32(materialId);\n if (i >= 512u) { return false; }\n let word = objectLight.xrayMask[i / 128u][(i / 32u) % 4u];\n if (((word >> (i % 32u)) & 1u) == 0u) { return false; }\n return rz_xray_inside(fp);\n}\n";
|
|
10
19
|
export declare const COMMON_BINDINGS_WGSL: string;
|
|
11
20
|
export declare function commonFsOutWgsl(): string;
|
|
12
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/shaders/materials/common.ts"],"names":[],"mappings":"AA4BA;;;;uBAIuB;AACvB,eAAO,MAAM,iBAAiB,8iFA4D7B,CAAA;AAED;mEACmE;AACnE,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/shaders/materials/common.ts"],"names":[],"mappings":"AA4BA;;;;uBAIuB;AACvB,eAAO,MAAM,iBAAiB,8iFA4D7B,CAAA;AAED;mEACmE;AACnE,eAAO,MAAM,wBAAwB,qLAC+I,CAAA;AAEpL;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,4dAarB,CAAA;AAED,eAAO,MAAM,oBAAoB,QAkQhC,CAAC;AA2JF,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAGD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,orMAgHzB,CAAA;AAQD,eAAO,MAAM,4BAA4B,QAC6H,CAAA"}
|
|
@@ -91,7 +91,29 @@ fn rzJellyVertex(p: vec3f, joints: vec4<u32>, nw: vec4f) -> vec3f {
|
|
|
91
91
|
`;
|
|
92
92
|
/** A model's ObjectLight as WGSL declares it (see the layout below). One copy
|
|
93
93
|
* for every pass that binds it, so their layouts cannot drift. */
|
|
94
|
-
export const OBJECT_LIGHT_STRUCT_WGSL = "struct ObjectLight { layers: vec4u, ambient: vec4f, sh: array<vec4f, 9>, fill: vec4f, jelly: array<vec4f, 12>, bloom: vec4f }";
|
|
94
|
+
export const OBJECT_LIGHT_STRUCT_WGSL = "struct ObjectLight { layers: vec4u, ambient: vec4f, sh: array<vec4f, 9>, fill: vec4f, jelly: array<vec4f, 12>, bloom: vec4f, xray: array<vec4f, 4>, xrayMask: array<vec4u, 16> }";
|
|
95
|
+
/**
|
|
96
|
+
* The see-through window (#xray): a rectangle on the frame, in pixels —
|
|
97
|
+
* xray[0] is (left, top, right, bottom), xray[3].x is 1 while a window is open
|
|
98
|
+
* on this model — and which of the model's materials it cuts: a bit a
|
|
99
|
+
* material, by its 1-based draw index (materialId), up to 512. Tested against
|
|
100
|
+
* the fragment's own position, so it sits where the lens is, whatever moves
|
|
101
|
+
* behind it. Declared after the pass's own `objectLight` binding.
|
|
102
|
+
*/
|
|
103
|
+
export const XRAY_WGSL = /* wgsl */ `
|
|
104
|
+
fn rz_xray_inside(fp: vec4f) -> bool {
|
|
105
|
+
if (objectLight.xray[3].x < 0.5) { return false; }
|
|
106
|
+
let r = objectLight.xray[0];
|
|
107
|
+
return fp.x >= r.x && fp.y >= r.y && fp.x <= r.z && fp.y <= r.w;
|
|
108
|
+
}
|
|
109
|
+
fn rz_xray_cut(fp: vec4f, materialId: f32) -> bool {
|
|
110
|
+
let i = u32(materialId);
|
|
111
|
+
if (i >= 512u) { return false; }
|
|
112
|
+
let word = objectLight.xrayMask[i / 128u][(i / 32u) % 4u];
|
|
113
|
+
if (((word >> (i % 32u)) & 1u) == 0u) { return false; }
|
|
114
|
+
return rz_xray_inside(fp);
|
|
115
|
+
}
|
|
116
|
+
`;
|
|
95
117
|
export const COMMON_BINDINGS_WGSL = /* wgsl */ `
|
|
96
118
|
|
|
97
119
|
struct CameraUniforms {
|
|
@@ -291,6 +313,7 @@ fn _rzCastShadow(wp: vec3f) -> f32 {
|
|
|
291
313
|
// outlines write.
|
|
292
314
|
${OBJECT_LIGHT_STRUCT_WGSL}
|
|
293
315
|
@group(1) @binding(1) var<uniform> objectLight: ObjectLight;
|
|
316
|
+
${XRAY_WGSL}
|
|
294
317
|
|
|
295
318
|
${JELLY_VERTEX_WGSL}
|
|
296
319
|
/** The light arriving at a surface of this object facing n: its own ambient
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depth-prepass.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/depth-prepass.ts"],"names":[],"mappings":"AAgCA,wBAAgB,2BAA2B,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"depth-prepass.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/depth-prepass.ts"],"names":[],"mappings":"AAgCA,wBAAgB,2BAA2B,IAAI,MAAM,CAgGpD"}
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
// one: the fragment outputs below depend on whether the device carries the id
|
|
27
27
|
// attachment, and that answer does not exist at import time. The constant could
|
|
28
28
|
// not have taken the outputs at all, which is most of why it did not have them.
|
|
29
|
-
import { DISSOLVE_WGSL, JELLY_VERTEX_WGSL } from "../materials/common";
|
|
29
|
+
import { DISSOLVE_WGSL, JELLY_VERTEX_WGSL, OBJECT_LIGHT_STRUCT_WGSL, XRAY_WGSL } from "../materials/common";
|
|
30
30
|
import { sceneFsOutWgsl, sceneIdPadWgsl } from "./scene-contract";
|
|
31
31
|
export function transparentDepthPrepassWgsl() {
|
|
32
32
|
return /* wgsl */ `
|
|
@@ -53,8 +53,9 @@ struct MaterialUniforms {
|
|
|
53
53
|
@group(1) @binding(0) var<storage, read> skinMats: array<mat4x4f>;
|
|
54
54
|
// The model's ObjectLight, for its jelly eyes: depth goes down where the colour
|
|
55
55
|
// pass will draw the iris.
|
|
56
|
-
|
|
56
|
+
${OBJECT_LIGHT_STRUCT_WGSL}
|
|
57
57
|
@group(1) @binding(1) var<uniform> objectLight: ObjectLight;
|
|
58
|
+
${XRAY_WGSL}
|
|
58
59
|
${JELLY_VERTEX_WGSL}
|
|
59
60
|
@group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
|
|
60
61
|
@group(2) @binding(1) var<uniform> material: MaterialUniforms;
|
|
@@ -116,6 +117,7 @@ override CUTOFF: f32 = 0.5;
|
|
|
116
117
|
// her: you would see sky through her, which is the failure this line exists
|
|
117
118
|
// to prevent.
|
|
118
119
|
if (material.dissolve < 0.9995 && rz_dissolve_threshold(in.restPos) > material.dissolve) { discard; }
|
|
120
|
+
if (rz_xray_cut(in.position, material.materialId)) { discard; }
|
|
119
121
|
var out: PrepassOut;
|
|
120
122
|
out.color = vec4f(0.0);
|
|
121
123
|
out.mask = vec4f(0.0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outline.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/outline.ts"],"names":[],"mappings":"AAqBA;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAA;AAC5C;yCACyC;AACzC,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC;mEACmE;AACnE,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC;;yCAEyC;AACzC,eAAO,MAAM,0BAA0B,KAAK,CAAA;AAC5C,eAAO,MAAM,wBAAwB,KAAK,CAAA;AAC1C,uCAAuC;AACvC,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAE3C,wBAAgB,iBAAiB,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"outline.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/outline.ts"],"names":[],"mappings":"AAqBA;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAA;AAC5C;yCACyC;AACzC,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC;mEACmE;AACnE,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC;;yCAEyC;AACzC,eAAO,MAAM,0BAA0B,KAAK,CAAA;AAC5C,eAAO,MAAM,wBAAwB,KAAK,CAAA;AAC1C,uCAAuC;AACvC,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAE3C,wBAAgB,iBAAiB,IAAI,MAAM,CA+P1C"}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// fragment outputs depend on whether the device carries the id attachment, and
|
|
16
16
|
// a string baked at import cannot know what the device said.
|
|
17
17
|
import { sceneFsOutWgsl, sceneIdPadWgsl } from "./scene-contract";
|
|
18
|
-
import { DISSOLVE_WGSL, OBJECT_LIGHT_STRUCT_WGSL } from "../materials/common";
|
|
18
|
+
import { DISSOLVE_WGSL, OBJECT_LIGHT_STRUCT_WGSL, XRAY_WGSL } from "../materials/common";
|
|
19
19
|
/**
|
|
20
20
|
* Where `dissolve` sits in the outline's own uniform, in bytes.
|
|
21
21
|
*
|
|
@@ -75,6 +75,9 @@ struct MaterialUniforms {
|
|
|
75
75
|
* material's own alpha still holds — a line its author made sheer stays so. */
|
|
76
76
|
colorOverride: vec4f,
|
|
77
77
|
shadowColor: vec4f,
|
|
78
|
+
/** x: the material's 1-based draw index, as the colour pass's materialId —
|
|
79
|
+
* what lets the see-through window cut a garment's line and keep hers. */
|
|
80
|
+
xray: vec4f,
|
|
78
81
|
};
|
|
79
82
|
|
|
80
83
|
struct OutlineLight { direction: vec4f, color: vec4f, };
|
|
@@ -87,6 +90,7 @@ struct OutlineLights { ambientColor: vec4f, lights: array<OutlineLight, 4>, };
|
|
|
87
90
|
@group(1) @binding(0) var<storage, read> skinMats: array<mat4x4f>;
|
|
88
91
|
${OBJECT_LIGHT_STRUCT_WGSL}
|
|
89
92
|
@group(1) @binding(1) var<uniform> objectLight: ObjectLight;
|
|
93
|
+
${XRAY_WGSL}
|
|
90
94
|
@group(2) @binding(0) var<uniform> material: MaterialUniforms;
|
|
91
95
|
@group(2) @binding(1) var diffuseTexture: texture_2d<f32>;
|
|
92
96
|
/** A look's outline tint (ShaderGraph.outline.tint): one of its images, white
|
|
@@ -265,6 +269,8 @@ ${sceneFsOutWgsl({ name: "FSOut", aux: "mask" })}
|
|
|
265
269
|
// bind-pose position — three passes, one rule, or they disagree about which
|
|
266
270
|
// pieces are still there.
|
|
267
271
|
if (material.dissolve < 0.9995 && rz_dissolve_threshold(input.restPos) > material.dissolve) { discard; }
|
|
272
|
+
// The see-through window cuts the lines of what it cuts, and keeps hers.
|
|
273
|
+
if (rz_xray_cut(input.position, material.xray.x)) { discard; }
|
|
268
274
|
let tex = textureSample(diffuseTexture, edgeSampler, input.uv);
|
|
269
275
|
let texA = tex.a;
|
|
270
276
|
if (texA < 0.05) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SHADOW_DEPTH_SHADER_WGSL = "\n\n/** Clump size, in object-space units \u2014 MMD's are roughly centimetres.\n *\n * Raised from 0.42: at that size the pieces are near enough to speckle that a\n * departure reads as a fade rather than as a body coming apart, which is the\n * thing the clumping exists to avoid. Hand-sized pieces are visible ones. */\nconst RZ_DISSOLVE_GRAIN: f32 = 1.2;\n/** How much the clumps pull a fragment off its own grit value \u2014 the whole of\n * the LOOK, and none of the rate. See rz_dissolve_threshold. */\nconst RZ_DISSOLVE_CLUMP: f32 = 0.6;\n/** Grit cell, as a fraction of a clump. See rz_dissolve_threshold: this is what\n * keeps a material SMALLER than a clump from having one threshold for all of\n * it, and it has to be smaller than the SMALLEST material a model carries \u2014\n * an eye highlight, a button, a buckle \u2014 not merely small. Two and a half\n * millimetres on a normal model, which is under all of them. */\nconst RZ_DISSOLVE_GRIT: f32 = 0.021;\n/** How wide the glowing front is, in threshold units. Thin: the front is a\n * rim, and a wide one lights whole limbs at once. */\nconst RZ_DISSOLVE_EDGE: f32 = 0.11;\n/** What the front burns with. Emission, added after lighting and after the\n * graph \u2014 a colour that ramps or takes a shadow reads as paint, not as heat.\n * Above 1 on purpose: it is meant to reach the bloom pyramid. Blue-violet,\n * the same light the motes leaving her are drawn and lit with. */\nconst RZ_BURN_COLOR: vec3f = vec3f(0.45, 0.62, 2.40);\n\nfn rz_dissolve_hash(p: vec3f) -> f32 {\n // INTEGER, for exactly the reason _hash33 in nodes.ts is, and its comment\n // says it: above 24 bits an f32 loses the low ones. The float hash this\n // replaces multiplied three terms into the hundreds of millions and took\n // fract() of the product \u2014 which past 2^24 is not noise, it is a quantised\n // staircase, and wherever that staircase landed on zero the threshold was\n // zero. A surface whose threshold is zero never crosses it: it stays behind\n // while the rest of her leaves, and it sits inside the burning front the\n // whole time she is gone. Those were the white pieces that would not go.\n //\n // Floored first, unlike _hash33: vec3i() truncates toward zero, so -0.5 and\n // +0.5 are the same cell, and half this model is at negative x.\n var h = vec3u(vec3i(floor(p)) + vec3i(32768));\n h = h * vec3u(1664525u, 1013904223u, 2654435761u);\n h = (h.yzx ^ h) * vec3u(2246822519u, 3266489917u, 668265263u);\n h = h ^ (h >> vec3u(16u));\n return f32((h.x ^ h.y ^ h.z) & 16777215u) * (1.0 / 16777216.0);\n}\n\n/** Value noise over that hash \u2014 smooth within a flake, uncorrelated between. */\nfn rz_dissolve_field(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 c000 = rz_dissolve_hash(i);\n let c100 = rz_dissolve_hash(i + vec3f(1.0, 0.0, 0.0));\n let c010 = rz_dissolve_hash(i + vec3f(0.0, 1.0, 0.0));\n let c110 = rz_dissolve_hash(i + vec3f(1.0, 1.0, 0.0));\n let c001 = rz_dissolve_hash(i + vec3f(0.0, 0.0, 1.0));\n let c101 = rz_dissolve_hash(i + vec3f(1.0, 0.0, 1.0));\n let c011 = rz_dissolve_hash(i + vec3f(0.0, 1.0, 1.0));\n let c111 = rz_dissolve_hash(i + vec3f(1.0, 1.0, 1.0));\n let x00 = mix(c000, c100, u.x);\n let x10 = mix(c010, c110, u.x);\n let x01 = mix(c001, c101, u.x);\n let x11 = mix(c011, c111, u.x);\n return mix(mix(x00, x10, u.y), mix(x01, x11, u.y), u.z);\n}\n\n/**\n * The threshold this fragment is measured against.\n *\n * NOISE ALONE, so the whole body comes apart at once \u2014 a hand, a shoulder and\n * an ankle all thinning together rather than a line travelling up her. It was\n * tilted by height at first, on the argument that a sweep reads as something\n * happening TO her; what it actually reads as is a wipe, and a wipe has a\n * direction, an edge and a speed the rest of the effect knows nothing about.\n * Everywhere at once is also the honest match for what leaves: the motes are\n * shed from every limb in the same breath.\n *\n * TWO SCALES. Clumps alone meant every fragment of a material SMALLER than one\n * cell shared a single threshold: an eye highlight, a brow, a button, a hair\n * clip. All of it sat inside the glowing front at once, so the piece flashed\n * white as a whole and then popped \u2014 the two things a disintegration must never\n * do. The grit is a per-cell hash at a fraction of the clump, so a part a few\n * millimetres across still comes apart in pieces.\n *\n * THE GRIT IS THE BASE, though, and the clumps only push a fragment off it.\n * That ordering is what makes the dissolve smooth, and it is not obvious: the\n * two used to be WEIGHTED AND ADDED, and a sum is not uniformly distributed\n * however uniform each half is. It piles up in the middle, so most of the\n * surface had a threshold near a half \u2014 all of it went as the dissolve swept\n * through the middle, and what remained was the thin tail near zero. That tail\n * was the second stage everyone could see: a body that mostly vanished, then a\n * scatter of glowing scraps, then nothing.\n *\n * WRAPPED, not added. Offsetting a uniform value and taking fract() leaves it\n * EXACTLY uniform, where scaling a sum back into range only flattens the middle\n * \u2014 measured over four hundred thousand samples, the sum removed 12% of her per\n * step at the halfway mark and 0.1% at each end (a 110x swing), the scaled sum\n * still swung 89x, and the wrap is flat: 5.0% per step from the first flake to\n * the last, a ratio of 1.0.\n *\n * That flatness IS the smoothness. An uneven rate is what produced the two\n * stages you could see \u2014 a body that mostly vanished at once, then a scatter of\n * scraps that took as long again to follow.\n *\n * The clumping survives the wrap: neighbouring fragments share a clump value,\n * so the offset moves them together. What wraps past 1 comes back at 0 and goes\n * at the other end instead, which costs a little speckle in a region and buys\n * an even rate everywhere.\n */\nfn rz_dissolve_threshold(restPos: vec3f) -> f32 {\n let grit = rz_dissolve_hash(floor(restPos / (RZ_DISSOLVE_GRAIN * RZ_DISSOLVE_GRIT)));\n let clump = rz_dissolve_field(restPos / RZ_DISSOLVE_GRAIN) - 0.5;\n return fract(grit + clump * RZ_DISSOLVE_CLUMP);\n}\n\nstruct LightVP { viewProj: mat4x4f, };\n@group(0) @binding(0) var<uniform> lp: LightVP;\n@group(0) @binding(1) var<storage, read> skinMats: array<mat4x4f>;\n@group(0) @binding(2) var texSampler: sampler;\n@group(1) @binding(0) var diffuseTexture: texture_2d<f32>;\n// The head of the material block and the one field at its tail \u2014 the same\n// reach the depth prepass takes, and for the same reason: a shadow cast by a\n// body that is no longer drawn is the tell that the vanishing is a trick.\nstruct MaterialDiffuse {\n diffuse: vec4f,\n _skip0: vec4f,\n _skip1: vec4f,\n _skip2: f32,\n materialId: f32,\n _skip3: f32,\n dissolve: f32,\n};\n@group(1) @binding(1) var<uniform> material: MaterialDiffuse;\n// The model's ObjectLight, for its jelly eyes: the map must hold the iris where\n// the colour pass draws it.\nstruct ObjectLight { layers: vec4u, ambient: vec4f, sh: array<vec4f, 9>, fill: vec4f, jelly: array<vec4f, 12>, bloom: vec4f }\n@group(0) @binding(3) var<uniform> objectLight: ObjectLight;\n\nfn _rzJellyTurn(q: vec2f, a: f32) -> vec2f {\n let c = cos(a);\n let s = sin(a);\n return vec2f(c * q.x - s * q.y, s * q.x + c * q.y);\n}\n\n/**\n * Where the jelly puts an iris vertex. The iris is the part of the eye the eye\n * bones carry, so it is moved as a whole, in bind space before skinning:\n * scaled about its centre (the CPU composes the blink's spring, the lid's\n * press and her motion's knock into one scale), turned and drifted a hair on\n * the spring, brought forward a hair, and rolled about the eye bone with a\n * closing expression \u2014 inside the white, which stays where it is. A highlight\n * layer (this draw's material is one of jelly[1].w's) takes the iris's move,\n * then its own scale, turn and tremble, before the roll. Vertices take it by their weight on the eye bones\n * (jelly[2].w, jelly[3].w), so nothing else on the face moves.\n */\nfn rzJellyVertex(p: vec3f, joints: vec4<u32>, nw: vec4f) -> vec3f {\n let j = objectLight.jelly;\n let ids = u32(j[1].w);\n let mid = u32(material.materialId);\n let hl = mid > 0u && (mid == (ids & 4095u) || mid == (ids >> 12u));\n var out = p;\n for (var e = 0u; e < 2u; e++) {\n let bone = j[2u + e].w;\n if (bone < 0.0) { continue; }\n let b = u32(bone);\n let w = dot(nw, select(vec4f(0.0), vec4f(1.0), joints == vec4<u32>(b)));\n if (w <= 0.0) { continue; }\n let c = j[e].xyz;\n // A rig that carries both eyes on one bone: each vertex follows its own side.\n if (j[2].w == j[3].w && e == 0u && distance(p.xy, j[1].xy) < distance(p.xy, j[0].xy)) { continue; }\n if (j[2].w == j[3].w && e == 1u && distance(p.xy, j[0].xy) <= distance(p.xy, j[1].xy)) { continue; }\n let t = j[4u + e];\n let m = j[6u + e];\n let h = j[10u + e];\n var q = _rzJellyTurn((p.xy - c.xy) * t.xy, t.z) + m.xy;\n // Forward is \u2212Z (MMD faces \u2212Z).\n var push = h.z;\n if (hl) {\n // Sliding over the iris's dome on its own, a highlight sheet a hair in\n // front of it would sink into it where the dome bulges more and the two\n // fight for depth; so it comes forward by as far as it slid \u2014 a slope of\n // one, steeper than the dome anywhere it draws.\n let before = q;\n q = _rzJellyTurn(q * h.xy, t.w) + m.zw;\n push += length(q - before);\n }\n var moved = vec3f(c.xy + q, p.z - push);\n let roll = j[8u + e];\n if (roll.w != 0.0) {\n let d = moved - roll.xyz;\n let rd = _rzJellyTurn(d.yz, roll.w);\n moved = roll.xyz + vec3f(d.x, rd.x, rd.y);\n }\n out = mix(p, moved, w);\n }\n return out;\n}\n\n\nstruct VSOut {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f,\n /** Bind-pose position, for the dissolve test \u2014 object space, as everywhere.\n * A flake that is gone must stop casting. */\n @location(1) restPos: vec3f,\n};\n\n@vertex fn vs(@location(0) position: vec3f, @location(1) normal: vec3f, @location(2) uv: vec2f,\n @location(3) joints0: vec4<u32>, @location(4) weights0: vec4<f32>) -> VSOut {\n let ws = weights0.x + weights0.y + weights0.z + weights0.w;\n let inv = select(1.0, 1.0 / ws, ws > 0.0001);\n let nw = select(vec4f(1.0,0.0,0.0,0.0), weights0 * inv, ws > 0.0001);\n var pos4 = vec4f(position, 1.0);\n if (objectLight.jelly[0].w > 0.0) { pos4 = vec4f(rzJellyVertex(position, joints0, nw), 1.0); }\n var sp = vec4f(0.0);\n for (var i = 0u; i < 4u; i++) { sp += (skinMats[joints0[i]] * pos4) * nw[i]; }\n var out: VSOut;\n out.position = lp.viewProj * vec4f(sp.xyz, 1.0);\n out.uv = uv;\n out.restPos = position;\n return out;\n}\n\n@fragment fn fs(in: VSOut) {\n let alpha = textureSample(diffuseTexture, texSampler, in.uv).a * material.diffuse.a;\n if (alpha < 0.5) { discard; }\n // The dissolve, run as the colour pass runs it. A flake that is gone stops\n // casting: without this she leaves a whole shadow standing on the floor while\n // her body is in the air.\n if (material.dissolve < 0.9995 && rz_dissolve_threshold(in.restPos) > material.dissolve) { discard; }\n}\n";
|
|
1
|
+
export declare const SHADOW_DEPTH_SHADER_WGSL = "\n\n/** Clump size, in object-space units \u2014 MMD's are roughly centimetres.\n *\n * Raised from 0.42: at that size the pieces are near enough to speckle that a\n * departure reads as a fade rather than as a body coming apart, which is the\n * thing the clumping exists to avoid. Hand-sized pieces are visible ones. */\nconst RZ_DISSOLVE_GRAIN: f32 = 1.2;\n/** How much the clumps pull a fragment off its own grit value \u2014 the whole of\n * the LOOK, and none of the rate. See rz_dissolve_threshold. */\nconst RZ_DISSOLVE_CLUMP: f32 = 0.6;\n/** Grit cell, as a fraction of a clump. See rz_dissolve_threshold: this is what\n * keeps a material SMALLER than a clump from having one threshold for all of\n * it, and it has to be smaller than the SMALLEST material a model carries \u2014\n * an eye highlight, a button, a buckle \u2014 not merely small. Two and a half\n * millimetres on a normal model, which is under all of them. */\nconst RZ_DISSOLVE_GRIT: f32 = 0.021;\n/** How wide the glowing front is, in threshold units. Thin: the front is a\n * rim, and a wide one lights whole limbs at once. */\nconst RZ_DISSOLVE_EDGE: f32 = 0.11;\n/** What the front burns with. Emission, added after lighting and after the\n * graph \u2014 a colour that ramps or takes a shadow reads as paint, not as heat.\n * Above 1 on purpose: it is meant to reach the bloom pyramid. Blue-violet,\n * the same light the motes leaving her are drawn and lit with. */\nconst RZ_BURN_COLOR: vec3f = vec3f(0.45, 0.62, 2.40);\n\nfn rz_dissolve_hash(p: vec3f) -> f32 {\n // INTEGER, for exactly the reason _hash33 in nodes.ts is, and its comment\n // says it: above 24 bits an f32 loses the low ones. The float hash this\n // replaces multiplied three terms into the hundreds of millions and took\n // fract() of the product \u2014 which past 2^24 is not noise, it is a quantised\n // staircase, and wherever that staircase landed on zero the threshold was\n // zero. A surface whose threshold is zero never crosses it: it stays behind\n // while the rest of her leaves, and it sits inside the burning front the\n // whole time she is gone. Those were the white pieces that would not go.\n //\n // Floored first, unlike _hash33: vec3i() truncates toward zero, so -0.5 and\n // +0.5 are the same cell, and half this model is at negative x.\n var h = vec3u(vec3i(floor(p)) + vec3i(32768));\n h = h * vec3u(1664525u, 1013904223u, 2654435761u);\n h = (h.yzx ^ h) * vec3u(2246822519u, 3266489917u, 668265263u);\n h = h ^ (h >> vec3u(16u));\n return f32((h.x ^ h.y ^ h.z) & 16777215u) * (1.0 / 16777216.0);\n}\n\n/** Value noise over that hash \u2014 smooth within a flake, uncorrelated between. */\nfn rz_dissolve_field(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 c000 = rz_dissolve_hash(i);\n let c100 = rz_dissolve_hash(i + vec3f(1.0, 0.0, 0.0));\n let c010 = rz_dissolve_hash(i + vec3f(0.0, 1.0, 0.0));\n let c110 = rz_dissolve_hash(i + vec3f(1.0, 1.0, 0.0));\n let c001 = rz_dissolve_hash(i + vec3f(0.0, 0.0, 1.0));\n let c101 = rz_dissolve_hash(i + vec3f(1.0, 0.0, 1.0));\n let c011 = rz_dissolve_hash(i + vec3f(0.0, 1.0, 1.0));\n let c111 = rz_dissolve_hash(i + vec3f(1.0, 1.0, 1.0));\n let x00 = mix(c000, c100, u.x);\n let x10 = mix(c010, c110, u.x);\n let x01 = mix(c001, c101, u.x);\n let x11 = mix(c011, c111, u.x);\n return mix(mix(x00, x10, u.y), mix(x01, x11, u.y), u.z);\n}\n\n/**\n * The threshold this fragment is measured against.\n *\n * NOISE ALONE, so the whole body comes apart at once \u2014 a hand, a shoulder and\n * an ankle all thinning together rather than a line travelling up her. It was\n * tilted by height at first, on the argument that a sweep reads as something\n * happening TO her; what it actually reads as is a wipe, and a wipe has a\n * direction, an edge and a speed the rest of the effect knows nothing about.\n * Everywhere at once is also the honest match for what leaves: the motes are\n * shed from every limb in the same breath.\n *\n * TWO SCALES. Clumps alone meant every fragment of a material SMALLER than one\n * cell shared a single threshold: an eye highlight, a brow, a button, a hair\n * clip. All of it sat inside the glowing front at once, so the piece flashed\n * white as a whole and then popped \u2014 the two things a disintegration must never\n * do. The grit is a per-cell hash at a fraction of the clump, so a part a few\n * millimetres across still comes apart in pieces.\n *\n * THE GRIT IS THE BASE, though, and the clumps only push a fragment off it.\n * That ordering is what makes the dissolve smooth, and it is not obvious: the\n * two used to be WEIGHTED AND ADDED, and a sum is not uniformly distributed\n * however uniform each half is. It piles up in the middle, so most of the\n * surface had a threshold near a half \u2014 all of it went as the dissolve swept\n * through the middle, and what remained was the thin tail near zero. That tail\n * was the second stage everyone could see: a body that mostly vanished, then a\n * scatter of glowing scraps, then nothing.\n *\n * WRAPPED, not added. Offsetting a uniform value and taking fract() leaves it\n * EXACTLY uniform, where scaling a sum back into range only flattens the middle\n * \u2014 measured over four hundred thousand samples, the sum removed 12% of her per\n * step at the halfway mark and 0.1% at each end (a 110x swing), the scaled sum\n * still swung 89x, and the wrap is flat: 5.0% per step from the first flake to\n * the last, a ratio of 1.0.\n *\n * That flatness IS the smoothness. An uneven rate is what produced the two\n * stages you could see \u2014 a body that mostly vanished at once, then a scatter of\n * scraps that took as long again to follow.\n *\n * The clumping survives the wrap: neighbouring fragments share a clump value,\n * so the offset moves them together. What wraps past 1 comes back at 0 and goes\n * at the other end instead, which costs a little speckle in a region and buys\n * an even rate everywhere.\n */\nfn rz_dissolve_threshold(restPos: vec3f) -> f32 {\n let grit = rz_dissolve_hash(floor(restPos / (RZ_DISSOLVE_GRAIN * RZ_DISSOLVE_GRIT)));\n let clump = rz_dissolve_field(restPos / RZ_DISSOLVE_GRAIN) - 0.5;\n return fract(grit + clump * RZ_DISSOLVE_CLUMP);\n}\n\nstruct LightVP { viewProj: mat4x4f, };\n@group(0) @binding(0) var<uniform> lp: LightVP;\n@group(0) @binding(1) var<storage, read> skinMats: array<mat4x4f>;\n@group(0) @binding(2) var texSampler: sampler;\n@group(1) @binding(0) var diffuseTexture: texture_2d<f32>;\n// The head of the material block and the one field at its tail \u2014 the same\n// reach the depth prepass takes, and for the same reason: a shadow cast by a\n// body that is no longer drawn is the tell that the vanishing is a trick.\nstruct MaterialDiffuse {\n diffuse: vec4f,\n _skip0: vec4f,\n _skip1: vec4f,\n _skip2: f32,\n materialId: f32,\n _skip3: f32,\n dissolve: f32,\n};\n@group(1) @binding(1) var<uniform> material: MaterialDiffuse;\n// The model's ObjectLight, for its jelly eyes: the map must hold the iris where\n// the colour pass draws it.\nstruct ObjectLight { layers: vec4u, ambient: vec4f, sh: array<vec4f, 9>, fill: vec4f, jelly: array<vec4f, 12>, bloom: vec4f, xray: array<vec4f, 4>, xrayMask: array<vec4u, 16> }\n@group(0) @binding(3) var<uniform> objectLight: ObjectLight;\n\nfn _rzJellyTurn(q: vec2f, a: f32) -> vec2f {\n let c = cos(a);\n let s = sin(a);\n return vec2f(c * q.x - s * q.y, s * q.x + c * q.y);\n}\n\n/**\n * Where the jelly puts an iris vertex. The iris is the part of the eye the eye\n * bones carry, so it is moved as a whole, in bind space before skinning:\n * scaled about its centre (the CPU composes the blink's spring, the lid's\n * press and her motion's knock into one scale), turned and drifted a hair on\n * the spring, brought forward a hair, and rolled about the eye bone with a\n * closing expression \u2014 inside the white, which stays where it is. A highlight\n * layer (this draw's material is one of jelly[1].w's) takes the iris's move,\n * then its own scale, turn and tremble, before the roll. Vertices take it by their weight on the eye bones\n * (jelly[2].w, jelly[3].w), so nothing else on the face moves.\n */\nfn rzJellyVertex(p: vec3f, joints: vec4<u32>, nw: vec4f) -> vec3f {\n let j = objectLight.jelly;\n let ids = u32(j[1].w);\n let mid = u32(material.materialId);\n let hl = mid > 0u && (mid == (ids & 4095u) || mid == (ids >> 12u));\n var out = p;\n for (var e = 0u; e < 2u; e++) {\n let bone = j[2u + e].w;\n if (bone < 0.0) { continue; }\n let b = u32(bone);\n let w = dot(nw, select(vec4f(0.0), vec4f(1.0), joints == vec4<u32>(b)));\n if (w <= 0.0) { continue; }\n let c = j[e].xyz;\n // A rig that carries both eyes on one bone: each vertex follows its own side.\n if (j[2].w == j[3].w && e == 0u && distance(p.xy, j[1].xy) < distance(p.xy, j[0].xy)) { continue; }\n if (j[2].w == j[3].w && e == 1u && distance(p.xy, j[0].xy) <= distance(p.xy, j[1].xy)) { continue; }\n let t = j[4u + e];\n let m = j[6u + e];\n let h = j[10u + e];\n var q = _rzJellyTurn((p.xy - c.xy) * t.xy, t.z) + m.xy;\n // Forward is \u2212Z (MMD faces \u2212Z).\n var push = h.z;\n if (hl) {\n // Sliding over the iris's dome on its own, a highlight sheet a hair in\n // front of it would sink into it where the dome bulges more and the two\n // fight for depth; so it comes forward by as far as it slid \u2014 a slope of\n // one, steeper than the dome anywhere it draws.\n let before = q;\n q = _rzJellyTurn(q * h.xy, t.w) + m.zw;\n push += length(q - before);\n }\n var moved = vec3f(c.xy + q, p.z - push);\n let roll = j[8u + e];\n if (roll.w != 0.0) {\n let d = moved - roll.xyz;\n let rd = _rzJellyTurn(d.yz, roll.w);\n moved = roll.xyz + vec3f(d.x, rd.x, rd.y);\n }\n out = mix(p, moved, w);\n }\n return out;\n}\n\n\nstruct VSOut {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f,\n /** Bind-pose position, for the dissolve test \u2014 object space, as everywhere.\n * A flake that is gone must stop casting. */\n @location(1) restPos: vec3f,\n};\n\n@vertex fn vs(@location(0) position: vec3f, @location(1) normal: vec3f, @location(2) uv: vec2f,\n @location(3) joints0: vec4<u32>, @location(4) weights0: vec4<f32>) -> VSOut {\n let ws = weights0.x + weights0.y + weights0.z + weights0.w;\n let inv = select(1.0, 1.0 / ws, ws > 0.0001);\n let nw = select(vec4f(1.0,0.0,0.0,0.0), weights0 * inv, ws > 0.0001);\n var pos4 = vec4f(position, 1.0);\n if (objectLight.jelly[0].w > 0.0) { pos4 = vec4f(rzJellyVertex(position, joints0, nw), 1.0); }\n var sp = vec4f(0.0);\n for (var i = 0u; i < 4u; i++) { sp += (skinMats[joints0[i]] * pos4) * nw[i]; }\n var out: VSOut;\n out.position = lp.viewProj * vec4f(sp.xyz, 1.0);\n out.uv = uv;\n out.restPos = position;\n return out;\n}\n\n@fragment fn fs(in: VSOut) {\n let alpha = textureSample(diffuseTexture, texSampler, in.uv).a * material.diffuse.a;\n if (alpha < 0.5) { discard; }\n // The dissolve, run as the colour pass runs it. A flake that is gone stops\n // casting: without this she leaves a whole shadow standing on the floor while\n // her body is in the air.\n if (material.dissolve < 0.9995 && rz_dissolve_threshold(in.restPos) > material.dissolve) { discard; }\n}\n";
|
|
2
2
|
//# sourceMappingURL=shadow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadow.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/shadow.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"shadow.d.ts","sourceRoot":"","sources":["../../../src/shaders/passes/shadow.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,wBAAwB,srWA0DpC,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { LyricRect } from "./lyrics-api";
|
|
2
|
+
/** The font size the rows are set at, in texels. A boss's name drawn 60 pixels
|
|
3
|
+
* tall on a 4K frame is still minified from this. */
|
|
4
|
+
export declare const EFFECT_TEXT_PX = 96;
|
|
5
|
+
export type EffectTextFont = {
|
|
6
|
+
css: string;
|
|
7
|
+
tracking: number;
|
|
8
|
+
} | null;
|
|
9
|
+
/** The CSS font for a size: `#font`'s words with the size put where CSS wants
|
|
10
|
+
* it — after style, variant and weight, before the family. */
|
|
11
|
+
export declare function effectTextFont(font: EffectTextFont, px: number): string;
|
|
12
|
+
export type EffectTextSheet = {
|
|
13
|
+
source: HTMLCanvasElement | OffscreenCanvas;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
/** Where each string sits: u0, vTop, u1, vBottom, in 0..1. */
|
|
17
|
+
rects: Map<string, LyricRect>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Set `strings` into one sheet, a row each. Every row is the font's full box
|
|
21
|
+
* (its ascent and descent, not the string's own ink), so two strings in one
|
|
22
|
+
* face have one height and their aspects compare. A string too wide for the
|
|
23
|
+
* sheet is set smaller in its own row rather than cut. Null without a canvas.
|
|
24
|
+
*/
|
|
25
|
+
export declare function rasterEffectText(strings: readonly string[], font: EffectTextFont): EffectTextSheet | null;
|
|
26
|
+
/**
|
|
27
|
+
* rzText_NAME(uv) and rzTextAspect_NAME() for each text dial. uv runs 0..1
|
|
28
|
+
* across the string's own box, y up, like rzLyricText; the answer is glyph
|
|
29
|
+
* coverage. textureSampleLevel, so it is legal after any branch.
|
|
30
|
+
*/
|
|
31
|
+
export declare function effectTextWgsl(names: readonly string[], real: boolean, binding: number, sampler: string): string;
|
|
32
|
+
//# sourceMappingURL=text-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-api.d.ts","sourceRoot":"","sources":["../../src/shaders/text-api.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C;sDACsD;AACtD,eAAO,MAAM,cAAc,KAAK,CAAA;AAKhC,MAAM,MAAM,cAAc,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAA;AAErE;+DAC+D;AAC/D,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAMvE;AAkBD,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAA;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CAC9B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,GAAG,eAAe,GAAG,IAAI,CAyCzG;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CA4BhH"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Words an effect is handed — `#param text NAME <default words>`.
|
|
2
|
+
//
|
|
3
|
+
// The engine sets every string an effect's text dials can show (each dial's
|
|
4
|
+
// value and every key on its track) into ONE picture per effect, a row a
|
|
5
|
+
// string, and a dial's slot in the params block holds the rect of the string it
|
|
6
|
+
// shows now. Changing the words, by hand or by a key, is a rect write; the
|
|
7
|
+
// picture is redrawn only when a string it has never held arrives.
|
|
8
|
+
//
|
|
9
|
+
// Canvas2D, as the lyric atlas: it sets every script the platform does, CJK
|
|
10
|
+
// included, which a glyph atlas cannot promise. The look — fill, edge, glow —
|
|
11
|
+
// is the author's, in WGSL, from the coverage rzText_NAME answers.
|
|
12
|
+
//
|
|
13
|
+
// FIELD MODULE ONLY, where the picture is bound. Every other module the file is
|
|
14
|
+
// spliced into gets stubs answering zero, so one effect file compiles in every
|
|
15
|
+
// mount it has.
|
|
16
|
+
/** The font size the rows are set at, in texels. A boss's name drawn 60 pixels
|
|
17
|
+
* tall on a 4K frame is still minified from this. */
|
|
18
|
+
export const EFFECT_TEXT_PX = 96;
|
|
19
|
+
const PAD = 8;
|
|
20
|
+
const MAX_W = 4096;
|
|
21
|
+
const MAX_H = 8192;
|
|
22
|
+
/** The CSS font for a size: `#font`'s words with the size put where CSS wants
|
|
23
|
+
* it — after style, variant and weight, before the family. */
|
|
24
|
+
export function effectTextFont(font, px) {
|
|
25
|
+
const css = font?.css ?? "serif";
|
|
26
|
+
const words = css.split(/\s+/);
|
|
27
|
+
let k = 0;
|
|
28
|
+
while (k < words.length - 1 && /^(normal|italic|oblique|small-caps|bold|bolder|lighter|\d{3})$/i.test(words[k]))
|
|
29
|
+
k++;
|
|
30
|
+
return [...words.slice(0, k), `${px}px`, words.slice(k).join(" ")].join(" ").trim();
|
|
31
|
+
}
|
|
32
|
+
function canvas2d(w, h) {
|
|
33
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
34
|
+
const canvas = new OffscreenCanvas(w, h);
|
|
35
|
+
const ctx = canvas.getContext("2d");
|
|
36
|
+
if (ctx)
|
|
37
|
+
return { canvas, ctx };
|
|
38
|
+
}
|
|
39
|
+
if (typeof document === "undefined")
|
|
40
|
+
return null;
|
|
41
|
+
const canvas = document.createElement("canvas");
|
|
42
|
+
canvas.width = w;
|
|
43
|
+
canvas.height = h;
|
|
44
|
+
const ctx = canvas.getContext("2d");
|
|
45
|
+
return ctx ? { canvas, ctx } : null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set `strings` into one sheet, a row each. Every row is the font's full box
|
|
49
|
+
* (its ascent and descent, not the string's own ink), so two strings in one
|
|
50
|
+
* face have one height and their aspects compare. A string too wide for the
|
|
51
|
+
* sheet is set smaller in its own row rather than cut. Null without a canvas.
|
|
52
|
+
*/
|
|
53
|
+
export function rasterEffectText(strings, font) {
|
|
54
|
+
const list = [...new Set(strings.filter((s) => s.length > 0))];
|
|
55
|
+
const probe = canvas2d(1, 1);
|
|
56
|
+
if (!probe)
|
|
57
|
+
return null;
|
|
58
|
+
const css = effectTextFont(font, EFFECT_TEXT_PX);
|
|
59
|
+
const tracking = (font?.tracking ?? 0) * EFFECT_TEXT_PX;
|
|
60
|
+
const setUp = (ctx, px) => {
|
|
61
|
+
ctx.font = px === EFFECT_TEXT_PX ? css : effectTextFont(font, px);
|
|
62
|
+
if ("letterSpacing" in ctx)
|
|
63
|
+
ctx.letterSpacing = `${(tracking * px) / EFFECT_TEXT_PX}px`;
|
|
64
|
+
ctx.textBaseline = "alphabetic";
|
|
65
|
+
ctx.textAlign = "left";
|
|
66
|
+
};
|
|
67
|
+
setUp(probe.ctx, EFFECT_TEXT_PX);
|
|
68
|
+
const box = probe.ctx.measureText("Hg国");
|
|
69
|
+
const ascent = Math.ceil(box.fontBoundingBoxAscent || EFFECT_TEXT_PX * 0.9);
|
|
70
|
+
const descent = Math.ceil(box.fontBoundingBoxDescent || EFFECT_TEXT_PX * 0.25);
|
|
71
|
+
const rowH = ascent + descent + PAD * 2;
|
|
72
|
+
const rows = list.map((s) => {
|
|
73
|
+
// Tracking adds after every glyph, the last one too; trim it off the box.
|
|
74
|
+
const w = probe.ctx.measureText(s).width - tracking;
|
|
75
|
+
const px = w + PAD * 2 > MAX_W ? Math.floor((EFFECT_TEXT_PX * (MAX_W - PAD * 2)) / w) : EFFECT_TEXT_PX;
|
|
76
|
+
return { s, px, w: Math.min(MAX_W, Math.ceil((w * px) / EFFECT_TEXT_PX) + PAD * 2) };
|
|
77
|
+
});
|
|
78
|
+
const width = Math.max(1, ...rows.map((r) => r.w));
|
|
79
|
+
const height = Math.max(1, Math.min(MAX_H, rows.length * rowH));
|
|
80
|
+
const sheet = canvas2d(width, height);
|
|
81
|
+
if (!sheet)
|
|
82
|
+
return null;
|
|
83
|
+
const { ctx } = sheet;
|
|
84
|
+
ctx.clearRect(0, 0, width, height);
|
|
85
|
+
ctx.fillStyle = "#ffffff";
|
|
86
|
+
const rects = new Map();
|
|
87
|
+
rows.forEach((r, i) => {
|
|
88
|
+
const top = i * rowH;
|
|
89
|
+
if (top + rowH > height)
|
|
90
|
+
return;
|
|
91
|
+
setUp(ctx, r.px);
|
|
92
|
+
// A smaller row stays centred on the same baseline band.
|
|
93
|
+
const base = top + rowH / 2 + ((ascent - descent) * r.px) / (2 * EFFECT_TEXT_PX);
|
|
94
|
+
ctx.fillText(r.s, PAD, base);
|
|
95
|
+
rects.set(r.s, [0, top / height, r.w / width, (top + rowH) / height]);
|
|
96
|
+
});
|
|
97
|
+
return { source: sheet.canvas, width, height, rects };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* rzText_NAME(uv) and rzTextAspect_NAME() for each text dial. uv runs 0..1
|
|
101
|
+
* across the string's own box, y up, like rzLyricText; the answer is glyph
|
|
102
|
+
* coverage. textureSampleLevel, so it is legal after any branch.
|
|
103
|
+
*/
|
|
104
|
+
export function effectTextWgsl(names, real, binding, sampler) {
|
|
105
|
+
if (names.length === 0)
|
|
106
|
+
return "";
|
|
107
|
+
if (!real) {
|
|
108
|
+
return names
|
|
109
|
+
.map((n) => `fn rzText_${n}(uv: vec2f) -> f32 { return 0.0; }\nfn rzTextAspect_${n}() -> f32 { return 1.0; }\n`)
|
|
110
|
+
.join("");
|
|
111
|
+
}
|
|
112
|
+
return (
|
|
113
|
+
/* wgsl */ `
|
|
114
|
+
@group(0) @binding(${binding}) var _rzEffectText: texture_2d<f32>;
|
|
115
|
+
|
|
116
|
+
fn _rzTextAt(r: vec4f, uv: vec2f) -> f32 {
|
|
117
|
+
if (r.z <= r.x || uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) { return 0.0; }
|
|
118
|
+
let at = vec2f(mix(r.x, r.z, uv.x), mix(r.w, r.y, uv.y));
|
|
119
|
+
return textureSampleLevel(_rzEffectText, ${sampler}, at, 0.0).r;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
fn _rzTextAspect(r: vec4f) -> f32 {
|
|
123
|
+
let h = r.w - r.y;
|
|
124
|
+
if (h <= 0.0) { return 1.0; }
|
|
125
|
+
let dim = vec2f(textureDimensions(_rzEffectText));
|
|
126
|
+
return ((r.z - r.x) * dim.x) / (h * dim.y);
|
|
127
|
+
}
|
|
128
|
+
` +
|
|
129
|
+
names
|
|
130
|
+
.map((n) => `fn rzText_${n}(uv: vec2f) -> f32 { return _rzTextAt(params.${n}, uv); }\nfn rzTextAspect_${n}() -> f32 { return _rzTextAspect(params.${n}); }\n`)
|
|
131
|
+
.join(""));
|
|
132
|
+
}
|