reze-engine 0.68.16 → 0.68.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/engine.d.ts +5 -4
  2. package/dist/engine.d.ts.map +1 -1
  3. package/dist/engine.js +15 -18
  4. package/dist/graph/presets/pool_floor.d.ts +3 -0
  5. package/dist/graph/presets/pool_floor.d.ts.map +1 -0
  6. package/dist/graph/presets/pool_floor.js +42 -0
  7. package/dist/graph/presets/water.d.ts +3 -0
  8. package/dist/graph/presets/water.d.ts.map +1 -0
  9. package/dist/graph/presets/water.js +31 -0
  10. package/dist/physics/autofit.d.ts +147 -0
  11. package/dist/physics/autofit.d.ts.map +1 -0
  12. package/dist/physics/autofit.js +501 -0
  13. package/dist/shaders/agx-lut.d.ts +11 -0
  14. package/dist/shaders/agx-lut.d.ts.map +1 -0
  15. package/dist/shaders/agx-lut.js +29 -0
  16. package/dist/shaders/dfg_lut.d.ts +3 -0
  17. package/dist/shaders/dfg_lut.d.ts.map +1 -0
  18. package/dist/shaders/dfg_lut.js +129 -0
  19. package/dist/shaders/ltc_mag_lut.d.ts +3 -0
  20. package/dist/shaders/ltc_mag_lut.d.ts.map +1 -0
  21. package/dist/shaders/ltc_mag_lut.js +1033 -0
  22. package/dist/shaders/passes/field-blit.d.ts +26 -0
  23. package/dist/shaders/passes/field-blit.d.ts.map +1 -0
  24. package/dist/shaders/passes/field-blit.js +65 -0
  25. package/dist/shaders/passes/ghosts.d.ts +22 -0
  26. package/dist/shaders/passes/ghosts.d.ts.map +1 -0
  27. package/dist/shaders/passes/ghosts.js +75 -0
  28. package/dist/shaders/passes/ground-noise.d.ts +7 -0
  29. package/dist/shaders/passes/ground-noise.d.ts.map +1 -0
  30. package/dist/shaders/passes/ground-noise.js +88 -0
  31. package/dist/shaders/passes/sim.d.ts +34 -0
  32. package/dist/shaders/passes/sim.d.ts.map +1 -0
  33. package/dist/shaders/passes/sim.js +169 -0
  34. package/dist/shaders/score-api.d.ts +10 -0
  35. package/dist/shaders/score-api.d.ts.map +1 -0
  36. package/dist/shaders/score-api.js +114 -0
  37. package/dist/shaders/shadow-api.d.ts +29 -0
  38. package/dist/shaders/shadow-api.d.ts.map +1 -0
  39. package/dist/shaders/shadow-api.js +112 -0
  40. package/package.json +1 -1
  41. package/src/engine.ts +14 -18
  42. package/dist/_dbg-loader.mjs +0 -1100
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 3×3 PCF over one cascade's map, for a point already in that cascade's NDC.
3
+ *
4
+ * Shared with the materials, so an effect's shadow and her own shadow soften
5
+ * alike. The sampler is linear-filtered, which makes each tap a 2×2 bilinear
6
+ * compare. Unrolled — Safari's Metal backend doesn't unroll nested shadow
7
+ * loops reliably. The body expects `ndc` in scope and returns.
8
+ */
9
+ export declare const pcf9: (map: string, ts: string, sampler?: string) => string;
10
+ /** Bindings the real accessor takes, from `binding` upward. */
11
+ export declare const SHADOW_API_BINDINGS = 5;
12
+ /**
13
+ * `rzShadow(p)`: how much of the sun reaches world point `p` — 1 lit, 0 in a
14
+ * caster's shadow, soft in between.
15
+ *
16
+ * With `on`, declares five bindings from `binding`:
17
+ * +0 the light uniform (the sun's direction, and in .w the shadow switch)
18
+ * +1 the cascade view-projections, then the caster sphere
19
+ * +2 the near cascade's map +3 the far cascade's map
20
+ * +4 the comparison sampler
21
+ *
22
+ * It takes a POINT and no normal. The materials' sampleShadow also rejects a
23
+ * surface facing away from the sun, which is right for skin and wrong for a
24
+ * blade of grass or a petal: those are thin, lit through, and shaded by their
25
+ * own N·L. The point is nudged toward the sun instead, which lifts a blade's
26
+ * root off a stage floor that casts into the same map.
27
+ */
28
+ export declare function shadowApi(on: boolean, group: number, binding: number): string;
29
+ //# sourceMappingURL=shadow-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shadow-api.d.ts","sourceRoot":"","sources":["../../src/shaders/shadow-api.ts"],"names":[],"mappings":"AAcA;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,gBAAyB,WActE,CAAA;AAED,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,IAAI,CAAA;AAEpC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAyD7E"}
@@ -0,0 +1,112 @@
1
+ import { SHADOW_CASCADES } from "../shadow-cascades";
2
+ // The sun's shadow, as an effect author sees it.
3
+ //
4
+ // A lawn standing in a character's shadow has to darken where the floor under
5
+ // it does, or the figure floats: the ground catcher draws her shadow, and the
6
+ // blades drawn over it hide it. The map is already there — the materials and
7
+ // the ground read it every frame — so this hands the same lookup to effects.
8
+ //
9
+ // Bound for real in the particle SHADING stage only. That is where geometry an
10
+ // effect draws inside the scene pass is shaded, and the shadow pass has already
11
+ // run by then. Every other module that compiles the author's file gets the
12
+ // stub, which answers 1: lit is what a point with no occlusion information is,
13
+ // the same answer sampleShadow gives outside every cascade.
14
+ /**
15
+ * 3×3 PCF over one cascade's map, for a point already in that cascade's NDC.
16
+ *
17
+ * Shared with the materials, so an effect's shadow and her own shadow soften
18
+ * alike. The sampler is linear-filtered, which makes each tap a 2×2 bilinear
19
+ * compare. Unrolled — Safari's Metal backend doesn't unroll nested shadow
20
+ * loops reliably. The body expects `ndc` in scope and returns.
21
+ */
22
+ export const pcf9 = (map, ts, sampler = "shadowSampler") => /* wgsl */ `
23
+ let suv = vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5);
24
+ let cmpZ = ndc.z - 0.001;
25
+ let ts = ${ts};
26
+ let s00 = textureSampleCompareLevel(${map}, ${sampler}, suv + vec2f(-ts, -ts), cmpZ);
27
+ let s10 = textureSampleCompareLevel(${map}, ${sampler}, suv + vec2f(0.0, -ts), cmpZ);
28
+ let s20 = textureSampleCompareLevel(${map}, ${sampler}, suv + vec2f( ts, -ts), cmpZ);
29
+ let s01 = textureSampleCompareLevel(${map}, ${sampler}, suv + vec2f(-ts, 0.0), cmpZ);
30
+ let s11 = textureSampleCompareLevel(${map}, ${sampler}, suv, cmpZ);
31
+ let s21 = textureSampleCompareLevel(${map}, ${sampler}, suv + vec2f( ts, 0.0), cmpZ);
32
+ let s02 = textureSampleCompareLevel(${map}, ${sampler}, suv + vec2f(-ts, ts), cmpZ);
33
+ let s12 = textureSampleCompareLevel(${map}, ${sampler}, suv + vec2f(0.0, ts), cmpZ);
34
+ let s22 = textureSampleCompareLevel(${map}, ${sampler}, suv + vec2f( ts, ts), cmpZ);
35
+ return (s00 + s10 + s20 + s01 + s11 + s21 + s02 + s12 + s22) * (1.0 / 9.0);
36
+ `;
37
+ /** Bindings the real accessor takes, from `binding` upward. */
38
+ export const SHADOW_API_BINDINGS = 5;
39
+ /**
40
+ * `rzShadow(p)`: how much of the sun reaches world point `p` — 1 lit, 0 in a
41
+ * caster's shadow, soft in between.
42
+ *
43
+ * With `on`, declares five bindings from `binding`:
44
+ * +0 the light uniform (the sun's direction, and in .w the shadow switch)
45
+ * +1 the cascade view-projections, then the caster sphere
46
+ * +2 the near cascade's map +3 the far cascade's map
47
+ * +4 the comparison sampler
48
+ *
49
+ * It takes a POINT and no normal. The materials' sampleShadow also rejects a
50
+ * surface facing away from the sun, which is right for skin and wrong for a
51
+ * blade of grass or a petal: those are thin, lit through, and shaded by their
52
+ * own N·L. The point is nudged toward the sun instead, which lifts a blade's
53
+ * root off a stage floor that casts into the same map.
54
+ */
55
+ export function shadowApi(on, group, binding) {
56
+ if (!on) {
57
+ return /* wgsl */ `
58
+ fn rzShadow(p: vec3f) -> f32 { return 1.0; }
59
+ `;
60
+ }
61
+ const n = SHADOW_CASCADES.length;
62
+ return /* wgsl */ `
63
+ // The first two vec4s of the light uniform: world ambient, then the sun.
64
+ struct _RzShadowSun { ambient: vec4f, direction: vec4f, }
65
+ // The cascades' matrices, inner to outer, then every caster in one sphere
66
+ // (x, y, z, radius): radius 0 = nothing casts, negative = do not test.
67
+ struct _RzShadowBlock { viewProj: array<mat4x4f, ${n}>, casters: vec4f, }
68
+ @group(${group}) @binding(${binding}) var<uniform> _rzShadowSun: _RzShadowSun;
69
+ @group(${group}) @binding(${binding + 1}) var<uniform> _rzShadowVP: _RzShadowBlock;
70
+ @group(${group}) @binding(${binding + 2}) var _rzShadowNear: texture_depth_2d;
71
+ @group(${group}) @binding(${binding + 3}) var _rzShadowFar: texture_depth_2d;
72
+ @group(${group}) @binding(${binding + 4}) var _rzShadowCmp: sampler_comparison;
73
+
74
+ fn _rzShadowNearTaps(ndc: vec3f) -> f32 {
75
+ ${pcf9("_rzShadowNear", `1.0 / ${SHADOW_CASCADES[0].mapSize}.0`, "_rzShadowCmp")}
76
+ }
77
+
78
+ fn _rzShadowFarTaps(ndc: vec3f) -> f32 {
79
+ ${pcf9("_rzShadowFar", `1.0 / ${SHADOW_CASCADES[n - 1].mapSize}.0`, "_rzShadowCmp")}
80
+ }
81
+
82
+ fn rzShadow(p: vec3f) -> f32 {
83
+ // The scene's one shadow switch, on the sun — see sampleShadow.
84
+ let castAmt = _rzShadowSun.direction.w;
85
+ if (castAmt <= 0.0) { return 1.0; }
86
+ let toSun = normalize(-_rzShadowSun.direction.xyz);
87
+ // Can anything cast onto this point at all? The ground's test, for the same
88
+ // two reasons: most of a lawn is nowhere near her, and a scene with no
89
+ // models never renders the map, whose untouched zeroes compare as shadowed.
90
+ let cs = _rzShadowVP.casters;
91
+ if (cs.w == 0.0) { return 1.0; }
92
+ if (cs.w > 0.0) {
93
+ let toCaster = cs.xyz - p;
94
+ let along = dot(toCaster, toSun);
95
+ let perp = length(toCaster - toSun * along);
96
+ if (along <= -cs.w || perp > cs.w) { return 1.0; }
97
+ }
98
+ let q = p + toSun * 0.08;
99
+ let c0 = _rzShadowVP.viewProj[0] * vec4f(q, 1.0);
100
+ let n0 = c0.xyz / max(c0.w, 1e-6);
101
+ if (all(abs(n0.xy) < vec2f(0.98)) && n0.z > 0.0 && n0.z < 1.0) {
102
+ return mix(1.0, _rzShadowNearTaps(n0), castAmt);
103
+ }
104
+ let c1 = _rzShadowVP.viewProj[${n - 1}] * vec4f(q, 1.0);
105
+ let n1 = c1.xyz / max(c1.w, 1e-6);
106
+ if (all(abs(n1.xy) < vec2f(0.98)) && n1.z > 0.0 && n1.z < 1.0) {
107
+ return mix(1.0, _rzShadowFarTaps(n1), castAmt);
108
+ }
109
+ return 1.0;
110
+ }
111
+ `;
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.68.16",
3
+ "version": "0.68.17",
4
4
  "description": "A lightweight WebGPU engine for real-time 3D MMD/PMX model rendering",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/engine.ts CHANGED
@@ -18466,23 +18466,18 @@ export class Engine {
18466
18466
  return true
18467
18467
  }
18468
18468
 
18469
- /** The model at one cast slot — the subject rzSubject(index) reads. */
18470
- private castSubjectName(index: number, subjects: readonly string[] | null = null): string | null {
18469
+ /** The models an effect's rzSubject(i) reads, in its own index order: the
18470
+ * ones it is aimed at, or the whole cast when it is aimed at nobody. */
18471
+ private castSubjectNames(subjects: readonly string[] | null = null): string[] {
18472
+ const names: string[] = []
18471
18473
  let n = 0
18472
- let local = 0
18473
- let found: string | null = null
18474
18474
  this.forEachInstance((inst) => {
18475
- if (found !== null || n >= MAX_EFFECT_SUBJECTS || inst.isStage || inst.isPlane || inst.isProp || !inst.model.visible)
18476
- return
18475
+ if (n >= MAX_EFFECT_SUBJECTS || inst.isStage || inst.isPlane || inst.isProp || !inst.model.visible) return
18477
18476
  n++
18478
- // The effect's OWN index, which is what its shaders count in: an effect
18479
- // aimed at the third dancer finds her at 0, so a #dissolve on it takes HER
18480
- // apart rather than whoever stands at the head of the cast.
18481
18477
  if (subjects && !subjects.includes(inst.name)) return
18482
- if (local === index) found = inst.name
18483
- local++
18478
+ names.push(inst.name)
18484
18479
  })
18485
- return found
18480
+ return names
18486
18481
  }
18487
18482
 
18488
18483
  /** One effect's four durations: its dials where it declares them, the
@@ -18507,8 +18502,8 @@ export class Engine {
18507
18502
  *
18508
18503
  * Two things ask for one. A cycle set on a model (setModelDissolveCycle) runs
18509
18504
  * on the scene clock and repeats, as it always has. An effect declaring
18510
- * `#dissolve` takes ITS OWN subject 0 apart on its own terms — the first model
18511
- * it is aimed at, the head of the cast when it is aimed at nobody in
18505
+ * `#dissolve` takes every one of ITS subjects apart on its own terms — the
18506
+ * models it is aimed at, the whole cast when it is aimed at nobody in
18512
18507
  * particular: scheduled, the cycle on each clip's clock with her whole between
18513
18508
  * clips; unscheduled, the same repeating cycle as before. Where both ask, the more dissolved wins — two
18514
18509
  * answers about one body, and half a body is not one of them.
@@ -18521,14 +18516,15 @@ export class Engine {
18521
18516
  for (const fx of this.effects) {
18522
18517
  if (!fx.dissolve) continue
18523
18518
  const cycle = dissolveCycleOf(this.dissolveTimingsOf(fx, fx.dissolve))
18524
- const subject = this.castSubjectName(0, fx.subjects)
18525
- if (!cycle || !subject) continue
18519
+ if (!cycle) continue
18520
+ let v: number
18526
18521
  if (fx.window && fx.window.length > 0) {
18527
18522
  transport ??= this.transportTime()
18528
- put(subject, scheduledDissolve(fx.window, cycle, transport))
18523
+ v = scheduledDissolve(fx.window, cycle, transport)
18529
18524
  } else {
18530
- put(subject, sampleDissolveCycle(cycle, this.sceneClock))
18525
+ v = sampleDissolveCycle(cycle, this.sceneClock)
18531
18526
  }
18527
+ for (const subject of this.castSubjectNames(fx.subjects)) put(subject, v)
18532
18528
  }
18533
18529
  for (const name of this.dissolveTouched) if (!want.has(name)) this.setModelDissolve(name, 1)
18534
18530
  this.dissolveTouched = new Set(want.keys())