reze-engine 0.69.8 → 0.70.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.
Files changed (45) hide show
  1. package/dist/_dbg-loader.mjs +1100 -0
  2. package/dist/camera-mount.d.ts +57 -0
  3. package/dist/camera-mount.d.ts.map +1 -0
  4. package/dist/camera-mount.js +249 -0
  5. package/dist/camera.d.ts +11 -0
  6. package/dist/camera.d.ts.map +1 -1
  7. package/dist/camera.js +31 -7
  8. package/dist/engine.d.ts +130 -2
  9. package/dist/engine.d.ts.map +1 -1
  10. package/dist/engine.js +476 -12
  11. package/dist/graph/compile.js +1 -1
  12. package/dist/graph/registry.d.ts.map +1 -1
  13. package/dist/graph/registry.js +19 -2
  14. package/dist/graph/slots.js +117 -117
  15. package/dist/index.d.ts +3 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/model.d.ts +35 -0
  18. package/dist/model.d.ts.map +1 -1
  19. package/dist/model.js +170 -0
  20. package/dist/shaders/materials/common.d.ts +11 -1
  21. package/dist/shaders/materials/common.d.ts.map +1 -1
  22. package/dist/shaders/materials/common.js +571 -548
  23. package/dist/shaders/passes/cull.d.ts +1 -1
  24. package/dist/shaders/passes/cull.d.ts.map +1 -1
  25. package/dist/shaders/passes/cull.js +4 -1
  26. package/dist/shaders/passes/motion-blur.d.ts +35 -0
  27. package/dist/shaders/passes/motion-blur.d.ts.map +1 -0
  28. package/dist/shaders/passes/motion-blur.js +166 -0
  29. package/dist/shaders/passes/particles.d.ts.map +1 -1
  30. package/dist/shaders/passes/particles.js +13 -2
  31. package/dist/shaders/passes/shadow.d.ts +1 -1
  32. package/dist/shaders/passes/shadow.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/src/camera-mount.ts +281 -0
  35. package/src/camera.ts +27 -4
  36. package/src/engine.ts +21741 -21249
  37. package/src/graph/compile.ts +1 -1
  38. package/src/graph/registry.ts +20 -3
  39. package/src/graph/slots.ts +304 -304
  40. package/src/index.ts +4 -1
  41. package/src/model.ts +193 -0
  42. package/src/shaders/materials/common.ts +706 -682
  43. package/src/shaders/passes/cull.ts +4 -1
  44. package/src/shaders/passes/motion-blur.ts +171 -0
  45. package/src/shaders/passes/particles.ts +14 -2
@@ -135,8 +135,11 @@ fn cs(@builtin(global_invocation_id) gid: vec3<u32>) {
135
135
  // and still its shadow, which the engine's pass casts for every material.
136
136
  let shown = (hidden[i] & 1u) == 0u;
137
137
  let graph = (hidden[i] & 2u) == 0u;
138
+ // bit 2: kept out of the camera alone — her own head under a POV mount, which
139
+ // her shadow and her mirror image still carry.
140
+ let toCamera = (hidden[i] & 4u) == 0u;
138
141
  let castsShadow = (dm.flags & DRAW_CASTS_SHADOW) != 0u;
139
- cameraArgs[i * 5u + 1u] = select(0u, 1u, (inCamera || off) && shown && graph);
142
+ cameraArgs[i * 5u + 1u] = select(0u, 1u, (inCamera || off) && shown && graph && toCamera);
140
143
  shadowArgs[i * 5u + 1u] = select(0u, 1u, ((inLight && castsShadow) || off) && shown);
141
144
  mirrorArgs[i * 5u + 1u] = select(0u, 1u, (inMirror || off) && shown && graph);
142
145
  }
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Motion blur: a per-pixel velocity buffer and a gather along it.
3
+ *
4
+ * TWO PASSES, both run only while it is on (Engine.setMotionBlur):
5
+ *
6
+ * · VELOCITY. Every model is drawn again against the scene's own depth (read
7
+ * only, compare "ahead or equal"), so exactly the visible surface writes:
8
+ * where its pixel is now minus where the same skinned vertex was last frame
9
+ * — last frame's skin matrices and last frame's camera. Its own pass and its
10
+ * own pipelines, so no scene pipeline changes and nothing costs anything
11
+ * while blur is off. The same skinned vertex path and @invariant position as
12
+ * the depth prepass, so it lands on the depths the scene wrote; the same
13
+ * alpha cutout, dissolve and x-ray tests, so a hair card's holes do not
14
+ * claim the card's motion. The target holds (velocity × coverage, coverage)
15
+ * so the MSAA resolve averages an edge into a fraction instead of garbage.
16
+ *
17
+ * · GATHER, on the resolved HDR before bloom and the view transform (bloom
18
+ * then blooms the streak, as a camera's would). Where no model drew — the
19
+ * ground, the sky, a game stage — the motion is the CAMERA's, rebuilt from
20
+ * depth: the pixel's world point this frame, projected through last frame's
21
+ * camera. The blur is the pixel's own velocity × the shutter, a straight
22
+ * average of samples along it, clamped to a few percent of the frame.
23
+ *
24
+ * What it does not do (yet): a fast arm smears within itself, not out over a
25
+ * still background, which would take a neighbourhood max velocity (tile max).
26
+ * Morphs carry no motion: a blink is not blurred.
27
+ */
28
+
29
+ import { DISSOLVE_WGSL, JELLY_VERTEX_WGSL, OBJECT_LIGHT_STRUCT_WGSL, XRAY_WGSL } from "../materials/common"
30
+
31
+ /** The velocity target: (velocity NDC xy × coverage, coverage, 1). */
32
+ export const MOTION_VELOCITY_FORMAT: GPUTextureFormat = "rgba16float"
33
+
34
+ export function motionVelocityWgsl(): string {
35
+ return /* wgsl */ `
36
+ ${DISSOLVE_WGSL}
37
+ struct CameraUniforms { view: mat4x4f, projection: mat4x4f, viewPos: vec3f, _p: f32, };
38
+ // The head of the material block, as the depth prepass declares it.
39
+ struct MaterialUniforms {
40
+ diffuseColor: vec3f,
41
+ alpha: f32,
42
+ _skip0: vec4f,
43
+ _skip1: vec4f,
44
+ _skip2: f32,
45
+ materialId: f32,
46
+ _skip3: f32,
47
+ dissolve: f32,
48
+ };
49
+ struct PrevCamera { viewProj: mat4x4f, };
50
+
51
+ @group(0) @binding(0) var<uniform> camera: CameraUniforms;
52
+ @group(0) @binding(1) var<uniform> prevCamera: PrevCamera;
53
+ @group(0) @binding(2) var diffuseSampler: sampler;
54
+ @group(1) @binding(0) var<storage, read> skinMats: array<mat4x4f>;
55
+ ${OBJECT_LIGHT_STRUCT_WGSL}
56
+ @group(1) @binding(1) var<uniform> objectLight: ObjectLight;
57
+ @group(1) @binding(2) var<storage, read> prevSkinMats: array<mat4x4f>;
58
+ ${XRAY_WGSL}
59
+ ${JELLY_VERTEX_WGSL}
60
+ @group(2) @binding(0) var diffuseTexture: texture_2d<f32>;
61
+ @group(2) @binding(1) var<uniform> material: MaterialUniforms;
62
+
63
+ struct VSOut {
64
+ @builtin(position) @invariant position: vec4f,
65
+ @location(0) uv: vec2f,
66
+ @location(1) restPos: vec3f,
67
+ @location(2) clipNow: vec4f,
68
+ @location(3) clipPrev: vec4f,
69
+ };
70
+
71
+ @vertex fn vs(
72
+ @location(0) position: vec3f,
73
+ @location(1) normal: vec3f,
74
+ @location(2) uv: vec2f,
75
+ @location(3) joints0: vec4<u32>,
76
+ @location(4) weights0: vec4<f32>,
77
+ ) -> VSOut {
78
+ let weightSum = weights0.x + weights0.y + weights0.z + weights0.w;
79
+ let invWeightSum = select(1.0, 1.0 / weightSum, weightSum > 0.0001);
80
+ let w = select(vec4f(1.0, 0.0, 0.0, 0.0), weights0 * invWeightSum, weightSum > 0.0001);
81
+ var pos4 = vec4f(position, 1.0);
82
+ if (objectLight.jelly[0].w > 0.0) { pos4 = vec4f(rzJellyVertex(position, joints0, w), 1.0); }
83
+ var skinned = vec4f(0.0);
84
+ var prev = vec4f(0.0);
85
+ for (var i = 0u; i < 4u; i++) {
86
+ skinned += (skinMats[joints0[i]] * pos4) * w[i];
87
+ prev += (prevSkinMats[joints0[i]] * pos4) * w[i];
88
+ }
89
+ var o: VSOut;
90
+ o.position = camera.projection * camera.view * vec4f(skinned.xyz, 1.0);
91
+ o.uv = uv;
92
+ o.restPos = position;
93
+ o.clipNow = o.position;
94
+ o.clipPrev = prevCamera.viewProj * vec4f(prev.xyz, 1.0);
95
+ return o;
96
+ }
97
+
98
+ @fragment fn fs(in: VSOut) -> @location(0) vec4f {
99
+ let a = material.alpha * textureSample(diffuseTexture, diffuseSampler, in.uv).a;
100
+ if (a < 0.5) { discard; }
101
+ if (material.dissolve < 0.9995 && rz_dissolve_threshold(in.restPos) > material.dissolve) { discard; }
102
+ if (rz_xray_cut(in.position, material.materialId)) { discard; }
103
+ let now = in.clipNow.xy / in.clipNow.w;
104
+ let prev = in.clipPrev.xy / max(in.clipPrev.w, 1e-5);
105
+ return vec4f(now - prev, 1.0, 1.0);
106
+ }
107
+ `
108
+ }
109
+
110
+ /** Uniforms of the gather, in floats: invViewProj (16), prevViewProj (16),
111
+ * (scale, maxPx, width, height), (depthClear, 0, 0, 0). */
112
+ export const MOTION_BLUR_UNIFORM_FLOATS = 40
113
+
114
+ export const MOTION_BLUR_WGSL = /* wgsl */ `
115
+ struct Uniforms {
116
+ invViewProj: mat4x4f,
117
+ prevViewProj: mat4x4f,
118
+ // x: shutter scale (this frame's motion → streak), y: longest streak in px,
119
+ // zw: target size in px.
120
+ params: vec4f,
121
+ // x: the depth a cleared pixel holds (the far plane, either end).
122
+ depth: vec4f,
123
+ };
124
+ @group(0) @binding(0) var hdr: texture_2d<f32>;
125
+ @group(0) @binding(1) var velocity: texture_2d<f32>;
126
+ @group(0) @binding(2) var depthTex: texture_depth_multisampled_2d;
127
+ @group(0) @binding(3) var<uniform> u: Uniforms;
128
+ @group(0) @binding(4) var linearSampler: sampler;
129
+
130
+ struct VOut { @builtin(position) pos: vec4f, @location(0) uv: vec2f, };
131
+
132
+ @vertex fn vs(@builtin(vertex_index) i: u32) -> VOut {
133
+ let p = vec2f(f32((i << 1u) & 2u), f32(i & 2u));
134
+ var o: VOut;
135
+ o.pos = vec4f(p * 2.0 - 1.0, 0.0, 1.0);
136
+ o.uv = vec2f(p.x, 1.0 - p.y);
137
+ return o;
138
+ }
139
+
140
+ const SAMPLES: i32 = 16;
141
+
142
+ @fragment fn fs(in: VOut) -> @location(0) vec4f {
143
+ let size = u.params.zw;
144
+ let px = vec2i(in.pos.xy);
145
+ let vel = textureLoad(velocity, px, 0);
146
+ // The camera's share: where this pixel's world point was last frame.
147
+ let ndc = vec2f(in.uv.x * 2.0 - 1.0, 1.0 - in.uv.y * 2.0);
148
+ var d = textureLoad(depthTex, px, 0);
149
+ // A cleared pixel is the far plane, which an infinite projection cannot
150
+ // invert: nudged a hair inside it, it reprojects as a direction.
151
+ d = select(min(d, 0.999999), max(d, 0.000001), u.depth.x < 0.5);
152
+ let world = u.invViewProj * vec4f(ndc, d, 1.0);
153
+ let prevClip = u.prevViewProj * vec4f(world.xyz / world.w, 1.0);
154
+ let camVel = ndc - prevClip.xy / max(prevClip.w, 1e-5);
155
+ // Where models drew, theirs, by how much of the pixel they cover.
156
+ let v = vel.xy + (1.0 - clamp(vel.z, 0.0, 1.0)) * camVel;
157
+ // NDC to pixels (y down), times the shutter, clamped.
158
+ var streak = vec2f(v.x, -v.y) * 0.5 * size * u.params.x;
159
+ let len = length(streak);
160
+ if (len > u.params.y) { streak *= u.params.y / len; }
161
+ let centre = textureLoad(hdr, px, 0);
162
+ if (length(streak) < 0.5) { return centre; }
163
+ var sum = vec3f(0.0);
164
+ for (var i = 0; i < SAMPLES; i++) {
165
+ let t = (f32(i) + 0.5) / f32(SAMPLES) - 0.5;
166
+ let uv = in.uv + streak * t / size;
167
+ sum += textureSampleLevel(hdr, linearSampler, uv, 0.0).rgb;
168
+ }
169
+ return vec4f(sum / f32(SAMPLES), centre.a);
170
+ }
171
+ `
@@ -209,6 +209,13 @@ fn rzProject(p: vec3f) -> vec3f {
209
209
  fn rzCamPos() -> vec3f { return cam.camPos; }
210
210
  `
211
211
 
212
+ /** `fn particleStep(p, dt, id: u32)`: the step is told the particle's slot, as
213
+ * particleInit is, so it can read the slot's emitter. Two parameters is the
214
+ * usual step and is called as before. */
215
+ function stepTakesId(wgsl: string): boolean {
216
+ return /\bfn\s+particleStep\s*\([^)]*,[^)]*,[^)]*\)/.test(wgsl)
217
+ }
218
+
212
219
  /** Does the source define the particle contract? All three are required
213
220
  * together; `cover` is optional and only means anything to a cutout, and
214
221
  * `count` is optional and bounds the frame's work — see particleCount. */
@@ -302,7 +309,7 @@ fn main(@builtin(global_invocation_id) gid: vec3u) {
302
309
  // its life staggers the pool, which is the difference between snow and a
303
310
  // pulse of snow arriving all at once every few seconds.
304
311
  } else {
305
- p = particleStep(p, pu.dt);
312
+ p = particleStep(p, pu.dt${stepTakesId(src.wgsl) ? ", i" : ""});
306
313
  p.age = p.age + pu.dt;
307
314
  }
308
315
  particles[i] = p;
@@ -376,7 +383,12 @@ struct VSOut {
376
383
  fn vs(@builtin(vertex_index) vi: u32, @builtin(instance_index) ii: u32) -> VSOut {
377
384
  var out: VSOut;
378
385
  out.id = ii;
379
- let p = particles[ii];
386
+ ${/\bfn\s+particleWorld\s*\(/.test(src.wgsl) ? ` // the effect keeps the pool in its emitters' own frames (Unity's Local
387
+ // simulation space: a beam riding a moving head); particleWorld puts this
388
+ // one in the world as its emitter stands now, before the card is built
389
+ let p = particleWorld(particles[ii], ii);
390
+ ` : ` let p = particles[ii];
391
+ `}
380
392
  // Two triangles, corners in the order 0,1,2, 2,1,3.
381
393
  let quad = array<vec2f, 6>(
382
394
  vec2f(-1.0, -1.0), vec2f(1.0, -1.0), vec2f(-1.0, 1.0),