ugly-game 0.15.60 → 0.15.62

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.
@@ -7,6 +7,9 @@ export declare class GpuTaaResolve {
7
7
  private pipe;
8
8
  private uBuf;
9
9
  private u;
10
+ private dirtyRects;
11
+ private stableExclusions;
12
+ private excludeStableFrame;
10
13
  private samp;
11
14
  private hist;
12
15
  private histView;
@@ -24,6 +27,21 @@ export declare class GpuTaaResolve {
24
27
  setInputs(colorView: GPUTextureView, depthView: GPUTextureView): void;
25
28
  /** Throw the history away — camera cuts, teleports, origin rebases, pause→resume. */
26
29
  invalidate(): void;
30
+ /** Discard history in a normalized framebuffer rectangle on the next frame.
31
+ * Caller includes old/new projected bounds and its sampling guard band.
32
+ * Overflow falls back to a full reset, never to stale geometry history. */
33
+ invalidateRect(rect: readonly [number, number, number, number]): void;
34
+ /** Keep the existing variance-clamped TAA for a submitted animated footprint
35
+ * on the next frame. Supply current and previous positions projected into the
36
+ * current framebuffer (including every animated part); this method expands
37
+ * each rectangle by3physical pixels for the outer ring, jitter and filtering.
38
+ * Coalesces up to16regions. Overflow conservatively disables widening for the
39
+ * whole next frame; it never resets temporal history. Rectangles are consumed
40
+ * by frame(), so callers must resubmit coverage for every animated frame. */
41
+ excludeStableCoverageRect(rect: readonly [number, number, number, number]): void;
42
+ /** Unknown/unbounded dynamic coverage must not silently admit wider history.
43
+ * Fall back to the existing resolve for one frame without discarding history. */
44
+ excludeStableCoverageForFrame(): void;
27
45
  /**
28
46
  * Resolve one frame. `invCurrVP` inverts the UNJITTERED current view-projection; `prevVP` is the
29
47
  * previous frame's UNJITTERED view-projection. Jitter belongs in the geometry pass's projection
@@ -35,6 +53,14 @@ export declare class GpuTaaResolve {
35
53
  /** Reject history from a different perspective depth during camera motion.
36
54
  * Requires rgba16float/rgba32float history; lower-range formats retain the
37
55
  * previous color-only behavior rather than clipping the stored log depth. */
38
- rejectDisocclusion?: boolean): void;
56
+ rejectDisocclusion?: boolean,
57
+ /** Minimum perspective eye-depth (in camera world units) at which rejected
58
+ * stationary history may use an outer color neighborhood. Zero disables it.
59
+ * A distant-only threshold preserves the near-field rejection used by moving
60
+ * characters. Adds up to16texture reads at affected pixels. Distant moving
61
+ * objects need coverage exclusions or motion vectors; incomplete coverage
62
+ * must call excludeStableCoverageForFrame() instead of guessing bounds.
63
+ * Orthographic projections always retain the original variance box. */
64
+ stableCoverageMinDepth?: number): void;
39
65
  destroy(): void;
40
66
  }
@@ -48,7 +48,9 @@ struct RU {
48
48
  prevVP: mat4x4<f32>,
49
49
  texel: vec4<f32>, // xy = 1/size, zw = size
50
50
  ctrl: vec4<f32>, // x = history blend, y = enabled, z = reset, w = clip sigma
51
- depthControl: vec4<f32>, // x = disocclusion rejection enabled
51
+ depthControl: vec4<f32>, // x = disocclusion; y = dirty count; z = stable coverage minimum depth; w = exclusion count (-1 disables widening for this frame)
52
+ dirtyRects: array<vec4<f32>,16>, // normalized framebuffer UV, min.xy/max.zw
53
+ stableExclusions: array<vec4<f32>,16>, // animated coverage; retains ordinary TAA instead of resetting
52
54
  };
53
55
  @group(0) @binding(0) var<uniform> ru: RU;
54
56
  @group(0) @binding(1) var histSamp: sampler;
@@ -79,8 +81,15 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
79
81
  let perspective = abs(ru.invCurrVP[2].w) > 0.000001;
80
82
  let eyeDepth = 1.0 / max(abs(wp4.w), 0.00000001);
81
83
  let historyDepth = log2(1.0 + eyeDepth);
82
- // Disabled, or the first frame after a cut: the current frame IS the answer and the history.
83
- if (ru.ctrl.y < 0.5 || ru.ctrl.z > 0.5) { o.screen = vec4(cur, 1.0); o.hist = vec4(cur, historyDepth); return o; }
84
+ // Retire only the affected footprint when streamed geometry changes. The
85
+ // count is normally zero; this adds no texture reads or extra render pass.
86
+ var dirty = false;
87
+ for (var j = 0u; j < u32(ru.depthControl.y); j++) {
88
+ let rect = ru.dirtyRects[j];
89
+ dirty = dirty || (all(uv >= rect.xy) && all(uv <= rect.zw));
90
+ }
91
+ // Disabled, camera cut, or changed region: current color is authoritative.
92
+ if (ru.ctrl.y < 0.5 || ru.ctrl.z > 0.5 || dirty) { o.screen = vec4(cur, 1.0); o.hist = vec4(cur, historyDepth); return o; }
84
93
 
85
94
  // ANTI-GHOSTING CLAMP, by VARIANCE rather than by min/max. A raw 3x3 min/max box is enormous over
86
95
  // high-frequency detail -- a voxel world's textured terrain spans most of the range inside any
@@ -115,7 +124,6 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
115
124
  let prevUV = vec2<f32>(pndc.x * 0.5 + 0.5, 0.5 - pndc.y * 0.5);
116
125
  if (prevUV.x >= 0.0 && prevUV.x <= 1.0 && prevUV.y >= 0.0 && prevUV.y <= 1.0) {
117
126
  let history = textureSampleLevel(histTex, histSamp, prevUV, 0.0);
118
- let hist = clamp(history.rgb, mn, mx);
119
127
  // TRUST LESS WHEN MOVING. The further a pixel travelled since last frame, the likelier its
120
128
  // history is disoccluded or belongs to different geometry -- and the more a wrong sample reads
121
129
  // as a trailing smear. Fade the history weight out with screen-space velocity instead of
@@ -133,6 +141,37 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
133
141
  let expectedDepth = log2(1.0 + max(pc.w,0.0));
134
142
  let disoccluded = ru.depthControl.x > 0.5 && perspective && velPx > 0.25
135
143
  && abs(previousDepth-expectedDepth) > 0.05;
144
+ // A tiny opening can fall outside every sample in the 3x3 neighborhood
145
+ // for one jitter phase. Clipping its valid accumulated coverage to that
146
+ // phase's flat color produces a periodic flash. For an opt-in, nearly
147
+ // stationary distant pixel whose history was actually rejected, admit colors
148
+ // supported by the outer 5x5 ring. Ordinary motion keeps the tighter
149
+ // variance box, and real disocclusion still rejects history entirely.
150
+ // This costs16additional reads only on the rejected stationary branch.
151
+ // Camera-derived velocity cannot identify moving actors. Their submitted
152
+ // previous/current footprints exclude widening without throwing away TAA.
153
+ if (ru.depthControl.z > 0.0 && perspective && eyeDepth >= ru.depthControl.z
154
+ && velPx < 0.25 && !disoccluded
155
+ && (any(history.rgb < mn) || any(history.rgb > mx))) {
156
+ var excluded = ru.depthControl.w < 0.0;
157
+ if (ru.depthControl.w > 0.0) {
158
+ for (var j=0u;j<u32(ru.depthControl.w);j++) {
159
+ let rect=ru.stableExclusions[j];
160
+ excluded=excluded || (all(uv>=rect.xy) && all(uv<=rect.zw));
161
+ }
162
+ }
163
+ if (!excluded) {
164
+ for (var dy = -2; dy <= 2; dy = dy + 1) {
165
+ for (var dx = -2; dx <= 2; dx = dx + 1) {
166
+ if (abs(dx) != 2 && abs(dy) != 2) { continue; }
167
+ let q = clamp(px + vec2<i32>(dx,dy),vec2<i32>(0),dim-vec2<i32>(1));
168
+ let c = textureLoad(colorTex,q,0).rgb;
169
+ mn = min(mn,c); mx = max(mx,c);
170
+ }
171
+ }
172
+ }
173
+ }
174
+ let hist = clamp(history.rgb, mn, mx);
136
175
  outc = mix(cur, hist, select(ru.ctrl.x * trust,0.0,disoccluded));
137
176
  }
138
177
  }
@@ -145,7 +184,10 @@ export class GpuTaaResolve {
145
184
  format;
146
185
  pipe;
147
186
  uBuf;
148
- u = new Float32Array(44); // 2 x mat4 + 3 x vec4
187
+ u = new Float32Array(172); // matrices, controls,16dirty and16coverage-exclusion rectangles
188
+ dirtyRects = [];
189
+ stableExclusions = [];
190
+ excludeStableFrame = false;
149
191
  samp;
150
192
  hist = [];
151
193
  histView = [];
@@ -216,6 +258,97 @@ export class GpuTaaResolve {
216
258
  /** Throw the history away — camera cuts, teleports, origin rebases, pause→resume. */
217
259
  invalidate() {
218
260
  this.primed = false;
261
+ this.dirtyRects.length = 0;
262
+ }
263
+ /** Discard history in a normalized framebuffer rectangle on the next frame.
264
+ * Caller includes old/new projected bounds and its sampling guard band.
265
+ * Overflow falls back to a full reset, never to stale geometry history. */
266
+ invalidateRect(rect) {
267
+ if (!rect.every(Number.isFinite) || rect[0] > rect[2] || rect[1] > rect[3])
268
+ throw new Error('TAA invalidation requires finite ordered UV bounds');
269
+ if (!this.primed)
270
+ return;
271
+ const r = [
272
+ Math.max(0, rect[0]),
273
+ Math.max(0, rect[1]),
274
+ Math.min(1, rect[2]),
275
+ Math.min(1, rect[3]),
276
+ ];
277
+ if (r[0] >= r[2] || r[1] >= r[3])
278
+ return;
279
+ // Coalesce intersecting regions, retaining a conservative union. Restart
280
+ // after a merge because the enlarged rectangle may touch earlier ones.
281
+ for (let j = 0; j < this.dirtyRects.length;) {
282
+ const a = this.dirtyRects[j];
283
+ if (r[0] <= a[2] && r[2] >= a[0] && r[1] <= a[3] && r[3] >= a[1]) {
284
+ r[0] = Math.min(r[0], a[0]);
285
+ r[1] = Math.min(r[1], a[1]);
286
+ r[2] = Math.max(r[2], a[2]);
287
+ r[3] = Math.max(r[3], a[3]);
288
+ this.dirtyRects.splice(j, 1);
289
+ j = 0;
290
+ }
291
+ else
292
+ j++;
293
+ }
294
+ if (this.dirtyRects.length === 16) {
295
+ this.invalidate();
296
+ return;
297
+ }
298
+ this.dirtyRects.push(r);
299
+ }
300
+ /** Keep the existing variance-clamped TAA for a submitted animated footprint
301
+ * on the next frame. Supply current and previous positions projected into the
302
+ * current framebuffer (including every animated part); this method expands
303
+ * each rectangle by3physical pixels for the outer ring, jitter and filtering.
304
+ * Coalesces up to16regions. Overflow conservatively disables widening for the
305
+ * whole next frame; it never resets temporal history. Rectangles are consumed
306
+ * by frame(), so callers must resubmit coverage for every animated frame. */
307
+ excludeStableCoverageRect(rect) {
308
+ if (rect.length !== 4 ||
309
+ !rect.every(Number.isFinite) ||
310
+ rect[0] > rect[2] ||
311
+ rect[1] > rect[3])
312
+ throw new RangeError('Stable coverage exclusion requires finite ordered UV bounds');
313
+ if (this.excludeStableFrame)
314
+ return;
315
+ if (this.w <= 0 || this.h <= 0) {
316
+ this.excludeStableCoverageForFrame();
317
+ return;
318
+ }
319
+ const gx = 3 / this.w, gy = 3 / this.h;
320
+ const r = [
321
+ Math.max(0, rect[0] - gx),
322
+ Math.max(0, rect[1] - gy),
323
+ Math.min(1, rect[2] + gx),
324
+ Math.min(1, rect[3] + gy),
325
+ ];
326
+ if (r[0] >= r[2] || r[1] >= r[3])
327
+ return;
328
+ for (let j = 0; j < this.stableExclusions.length;) {
329
+ const a = this.stableExclusions[j];
330
+ if (r[0] <= a[2] && r[2] >= a[0] && r[1] <= a[3] && r[3] >= a[1]) {
331
+ r[0] = Math.min(r[0], a[0]);
332
+ r[1] = Math.min(r[1], a[1]);
333
+ r[2] = Math.max(r[2], a[2]);
334
+ r[3] = Math.max(r[3], a[3]);
335
+ this.stableExclusions.splice(j, 1);
336
+ j = 0;
337
+ }
338
+ else
339
+ j++;
340
+ }
341
+ if (this.stableExclusions.length === 16) {
342
+ this.excludeStableCoverageForFrame();
343
+ return;
344
+ }
345
+ this.stableExclusions.push(r);
346
+ }
347
+ /** Unknown/unbounded dynamic coverage must not silently admit wider history.
348
+ * Fall back to the existing resolve for one frame without discarding history. */
349
+ excludeStableCoverageForFrame() {
350
+ this.excludeStableFrame = true;
351
+ this.stableExclusions.length = 0;
219
352
  }
220
353
  /**
221
354
  * Resolve one frame. `invCurrVP` inverts the UNJITTERED current view-projection; `prevVP` is the
@@ -228,7 +361,18 @@ export class GpuTaaResolve {
228
361
  /** Reject history from a different perspective depth during camera motion.
229
362
  * Requires rgba16float/rgba32float history; lower-range formats retain the
230
363
  * previous color-only behavior rather than clipping the stored log depth. */
231
- rejectDisocclusion = true) {
364
+ rejectDisocclusion = true,
365
+ /** Minimum perspective eye-depth (in camera world units) at which rejected
366
+ * stationary history may use an outer color neighborhood. Zero disables it.
367
+ * A distant-only threshold preserves the near-field rejection used by moving
368
+ * characters. Adds up to16texture reads at affected pixels. Distant moving
369
+ * objects need coverage exclusions or motion vectors; incomplete coverage
370
+ * must call excludeStableCoverageForFrame() instead of guessing bounds.
371
+ * Orthographic projections always retain the original variance box. */
372
+ stableCoverageMinDepth = 0) {
373
+ if (stableCoverageMinDepth < 0 ||
374
+ !Number.isFinite(Math.fround(stableCoverageMinDepth)))
375
+ throw new RangeError('Stable coverage minimum depth must be a finite nonnegative f32');
232
376
  if (this.histView.length !== 2)
233
377
  return;
234
378
  this.u.set(invCurrVP, 0);
@@ -246,6 +390,16 @@ export class GpuTaaResolve {
246
390
  (this.format === 'rgba16float' || this.format === 'rgba32float')
247
391
  ? 1
248
392
  : 0;
393
+ this.u[41] = this.dirtyRects.length;
394
+ this.u[42] = stableCoverageMinDepth;
395
+ this.u[43] = this.excludeStableFrame ? -1 : this.stableExclusions.length;
396
+ for (let j = 0; j < this.dirtyRects.length; j++)
397
+ this.u.set(this.dirtyRects[j], 44 + j * 4);
398
+ for (let j = 0; j < this.stableExclusions.length; j++)
399
+ this.u.set(this.stableExclusions[j], 108 + j * 4);
400
+ this.dirtyRects.length = 0;
401
+ this.stableExclusions.length = 0;
402
+ this.excludeStableFrame = false;
249
403
  this.device.queue.writeBuffer(this.uBuf, 0, this.u);
250
404
  const pass = enc.beginRenderPass({
251
405
  colorAttachments: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.60",
3
+ "version": "0.15.62",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -15,6 +15,22 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
+ "scripts": {
19
+ "preinstall": "npx only-allow pnpm",
20
+ "build": "tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
21
+ "lint": "ugly-app lint",
22
+ "lint:fix": "ugly-app lint --fix",
23
+ "test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin",
24
+ "test:flight": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/flight*.test.mts",
25
+ "test:flight-browser": "playwright test -c playwright.flight.config.ts",
26
+ "test:props-browser": "playwright test -c playwright.props.config.ts",
27
+ "test:flight-perf": "playwright test -c playwright.flight.config.ts --grep 'CPU and retained-memory'",
28
+ "test:types": "tsc -p tsconfig.test.json",
29
+ "test:package-types": "node tools/packageTypesSmoke.mjs",
30
+ "pretty": "prettier --write .",
31
+ "prepublishOnly": "pnpm run pretty && ugly-app lint && tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
32
+ "test:gpu-skin": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/gpuSkin.test.mts"
33
+ },
18
34
  "dependencies": {
19
35
  "@webgpu/types": "^0.1.40",
20
36
  "meshoptimizer": "^1.2.0"
@@ -30,20 +46,5 @@
30
46
  "typescript": "^5.6.0",
31
47
  "ugly-app": "^0.1.841",
32
48
  "wesl": "0.7.28"
33
- },
34
- "scripts": {
35
- "preinstall": "npx only-allow pnpm",
36
- "build": "tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
37
- "lint": "ugly-app lint",
38
- "lint:fix": "ugly-app lint --fix",
39
- "test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin",
40
- "test:flight": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/flight*.test.mts",
41
- "test:flight-browser": "playwright test -c playwright.flight.config.ts",
42
- "test:props-browser": "playwright test -c playwright.props.config.ts",
43
- "test:flight-perf": "playwright test -c playwright.flight.config.ts --grep 'CPU and retained-memory'",
44
- "test:types": "tsc -p tsconfig.test.json",
45
- "test:package-types": "node tools/packageTypesSmoke.mjs",
46
- "pretty": "prettier --write .",
47
- "test:gpu-skin": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/gpuSkin.test.mts"
48
49
  }
49
- }
50
+ }