ugly-game 0.15.61 → 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.
@@ -8,6 +8,8 @@ export declare class GpuTaaResolve {
8
8
  private uBuf;
9
9
  private u;
10
10
  private dirtyRects;
11
+ private stableExclusions;
12
+ private excludeStableFrame;
11
13
  private samp;
12
14
  private hist;
13
15
  private histView;
@@ -29,6 +31,17 @@ export declare class GpuTaaResolve {
29
31
  * Caller includes old/new projected bounds and its sampling guard band.
30
32
  * Overflow falls back to a full reset, never to stale geometry history. */
31
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;
32
45
  /**
33
46
  * Resolve one frame. `invCurrVP` inverts the UNJITTERED current view-projection; `prevVP` is the
34
47
  * previous frame's UNJITTERED view-projection. Jitter belongs in the geometry pass's projection
@@ -40,6 +53,14 @@ export declare class GpuTaaResolve {
40
53
  /** Reject history from a different perspective depth during camera motion.
41
54
  * Requires rgba16float/rgba32float history; lower-range formats retain the
42
55
  * previous color-only behavior rather than clipping the stored log depth. */
43
- 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;
44
65
  destroy(): void;
45
66
  }
@@ -48,8 +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; y = dirty rectangle count
51
+ depthControl: vec4<f32>, // x = disocclusion; y = dirty count; z = stable coverage minimum depth; w = exclusion count (-1 disables widening for this frame)
52
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
53
54
  };
54
55
  @group(0) @binding(0) var<uniform> ru: RU;
55
56
  @group(0) @binding(1) var histSamp: sampler;
@@ -123,7 +124,6 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
123
124
  let prevUV = vec2<f32>(pndc.x * 0.5 + 0.5, 0.5 - pndc.y * 0.5);
124
125
  if (prevUV.x >= 0.0 && prevUV.x <= 1.0 && prevUV.y >= 0.0 && prevUV.y <= 1.0) {
125
126
  let history = textureSampleLevel(histTex, histSamp, prevUV, 0.0);
126
- let hist = clamp(history.rgb, mn, mx);
127
127
  // TRUST LESS WHEN MOVING. The further a pixel travelled since last frame, the likelier its
128
128
  // history is disoccluded or belongs to different geometry -- and the more a wrong sample reads
129
129
  // as a trailing smear. Fade the history weight out with screen-space velocity instead of
@@ -141,6 +141,37 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
141
141
  let expectedDepth = log2(1.0 + max(pc.w,0.0));
142
142
  let disoccluded = ru.depthControl.x > 0.5 && perspective && velPx > 0.25
143
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);
144
175
  outc = mix(cur, hist, select(ru.ctrl.x * trust,0.0,disoccluded));
145
176
  }
146
177
  }
@@ -153,8 +184,10 @@ export class GpuTaaResolve {
153
184
  format;
154
185
  pipe;
155
186
  uBuf;
156
- u = new Float32Array(108); // matrices, controls and16dirty rectangles
187
+ u = new Float32Array(172); // matrices, controls,16dirty and16coverage-exclusion rectangles
157
188
  dirtyRects = [];
189
+ stableExclusions = [];
190
+ excludeStableFrame = false;
158
191
  samp;
159
192
  hist = [];
160
193
  histView = [];
@@ -264,6 +297,59 @@ export class GpuTaaResolve {
264
297
  }
265
298
  this.dirtyRects.push(r);
266
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;
352
+ }
267
353
  /**
268
354
  * Resolve one frame. `invCurrVP` inverts the UNJITTERED current view-projection; `prevVP` is the
269
355
  * previous frame's UNJITTERED view-projection. Jitter belongs in the geometry pass's projection
@@ -275,7 +361,18 @@ export class GpuTaaResolve {
275
361
  /** Reject history from a different perspective depth during camera motion.
276
362
  * Requires rgba16float/rgba32float history; lower-range formats retain the
277
363
  * previous color-only behavior rather than clipping the stored log depth. */
278
- 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');
279
376
  if (this.histView.length !== 2)
280
377
  return;
281
378
  this.u.set(invCurrVP, 0);
@@ -294,9 +391,15 @@ export class GpuTaaResolve {
294
391
  ? 1
295
392
  : 0;
296
393
  this.u[41] = this.dirtyRects.length;
394
+ this.u[42] = stableCoverageMinDepth;
395
+ this.u[43] = this.excludeStableFrame ? -1 : this.stableExclusions.length;
297
396
  for (let j = 0; j < this.dirtyRects.length; j++)
298
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);
299
400
  this.dirtyRects.length = 0;
401
+ this.stableExclusions.length = 0;
402
+ this.excludeStableFrame = false;
300
403
  this.device.queue.writeBuffer(this.uBuf, 0, this.u);
301
404
  const pass = enc.beginRenderPass({
302
405
  colorAttachments: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.61",
3
+ "version": "0.15.62",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {