ugly-game 0.15.59 → 0.15.61
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/gpuTaaResolve.d.ts +10 -1
- package/dist/gpuTaaResolve.js +91 -11
- package/package.json +1 -1
package/dist/gpuTaaResolve.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class GpuTaaResolve {
|
|
|
7
7
|
private pipe;
|
|
8
8
|
private uBuf;
|
|
9
9
|
private u;
|
|
10
|
+
private dirtyRects;
|
|
10
11
|
private samp;
|
|
11
12
|
private hist;
|
|
12
13
|
private histView;
|
|
@@ -24,6 +25,10 @@ export declare class GpuTaaResolve {
|
|
|
24
25
|
setInputs(colorView: GPUTextureView, depthView: GPUTextureView): void;
|
|
25
26
|
/** Throw the history away — camera cuts, teleports, origin rebases, pause→resume. */
|
|
26
27
|
invalidate(): void;
|
|
28
|
+
/** Discard history in a normalized framebuffer rectangle on the next frame.
|
|
29
|
+
* Caller includes old/new projected bounds and its sampling guard band.
|
|
30
|
+
* Overflow falls back to a full reset, never to stale geometry history. */
|
|
31
|
+
invalidateRect(rect: readonly [number, number, number, number]): void;
|
|
27
32
|
/**
|
|
28
33
|
* Resolve one frame. `invCurrVP` inverts the UNJITTERED current view-projection; `prevVP` is the
|
|
29
34
|
* previous frame's UNJITTERED view-projection. Jitter belongs in the geometry pass's projection
|
|
@@ -31,6 +36,10 @@ export declare class GpuTaaResolve {
|
|
|
31
36
|
*/
|
|
32
37
|
frame(enc: GPUCommandEncoder, out: GPUTextureView, invCurrVP: Float32Array, prevVP: Float32Array, blend?: number, enabled?: boolean,
|
|
33
38
|
/** Clip width in standard deviations. Lower = harsher rejection, less ghosting, more shimmer. */
|
|
34
|
-
clipSigma?: number
|
|
39
|
+
clipSigma?: number,
|
|
40
|
+
/** Reject history from a different perspective depth during camera motion.
|
|
41
|
+
* Requires rgba16float/rgba32float history; lower-range formats retain the
|
|
42
|
+
* previous color-only behavior rather than clipping the stored log depth. */
|
|
43
|
+
rejectDisocclusion?: boolean): void;
|
|
35
44
|
destroy(): void;
|
|
36
45
|
}
|
package/dist/gpuTaaResolve.js
CHANGED
|
@@ -48,6 +48,8 @@ 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
|
|
52
|
+
dirtyRects: array<vec4<f32>,16>, // normalized framebuffer UV, min.xy/max.zw
|
|
51
53
|
};
|
|
52
54
|
@group(0) @binding(0) var<uniform> ru: RU;
|
|
53
55
|
@group(0) @binding(1) var histSamp: sampler;
|
|
@@ -67,8 +69,26 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
|
|
|
67
69
|
let px = clamp(vec2<i32>(floor(fc.xy)), vec2<i32>(0, 0), dim - vec2<i32>(1, 1));
|
|
68
70
|
let cur = textureLoad(colorTex, px, 0).rgb;
|
|
69
71
|
var o: ROut;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
let d = textureLoad(depthTex, px, 0);
|
|
73
|
+
let uv = fc.xy * ru.texel.xy;
|
|
74
|
+
let ndc = vec3<f32>(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, d);
|
|
75
|
+
let wp4 = ru.invCurrVP * vec4(ndc, 1.0);
|
|
76
|
+
// History alpha stores log eye depth instead of unused opacity. This stays
|
|
77
|
+
// finite in rgba16float even for planetary far planes, with useful relative
|
|
78
|
+
// precision. Orthographic projections have no perspective w-depth; retain
|
|
79
|
+
// their previous color-only behavior. Screen alpha remains opaque.
|
|
80
|
+
let perspective = abs(ru.invCurrVP[2].w) > 0.000001;
|
|
81
|
+
let eyeDepth = 1.0 / max(abs(wp4.w), 0.00000001);
|
|
82
|
+
let historyDepth = log2(1.0 + eyeDepth);
|
|
83
|
+
// Retire only the affected footprint when streamed geometry changes. The
|
|
84
|
+
// count is normally zero; this adds no texture reads or extra render pass.
|
|
85
|
+
var dirty = false;
|
|
86
|
+
for (var j = 0u; j < u32(ru.depthControl.y); j++) {
|
|
87
|
+
let rect = ru.dirtyRects[j];
|
|
88
|
+
dirty = dirty || (all(uv >= rect.xy) && all(uv <= rect.zw));
|
|
89
|
+
}
|
|
90
|
+
// Disabled, camera cut, or changed region: current color is authoritative.
|
|
91
|
+
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; }
|
|
72
92
|
|
|
73
93
|
// ANTI-GHOSTING CLAMP, by VARIANCE rather than by min/max. A raw 3x3 min/max box is enormous over
|
|
74
94
|
// high-frequency detail -- a voxel world's textured terrain spans most of the range inside any
|
|
@@ -94,10 +114,6 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
|
|
|
94
114
|
|
|
95
115
|
// Depth -> world -> previous clip. WebGPU depth is [0,1] and clip-space Y is up while the
|
|
96
116
|
// framebuffer's Y is down, hence the flip in both directions.
|
|
97
|
-
let d = textureLoad(depthTex, px, 0);
|
|
98
|
-
let uv = fc.xy * ru.texel.xy;
|
|
99
|
-
let ndc = vec3<f32>(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, d);
|
|
100
|
-
let wp4 = ru.invCurrVP * vec4(ndc, 1.0);
|
|
101
117
|
let world = wp4.xyz / wp4.w;
|
|
102
118
|
let pc = ru.prevVP * vec4(world, 1.0);
|
|
103
119
|
|
|
@@ -106,17 +122,29 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
|
|
|
106
122
|
let pndc = pc.xyz / pc.w;
|
|
107
123
|
let prevUV = vec2<f32>(pndc.x * 0.5 + 0.5, 0.5 - pndc.y * 0.5);
|
|
108
124
|
if (prevUV.x >= 0.0 && prevUV.x <= 1.0 && prevUV.y >= 0.0 && prevUV.y <= 1.0) {
|
|
109
|
-
let
|
|
125
|
+
let history = textureSampleLevel(histTex, histSamp, prevUV, 0.0);
|
|
126
|
+
let hist = clamp(history.rgb, mn, mx);
|
|
110
127
|
// TRUST LESS WHEN MOVING. The further a pixel travelled since last frame, the likelier its
|
|
111
128
|
// history is disoccluded or belongs to different geometry -- and the more a wrong sample reads
|
|
112
129
|
// as a trailing smear. Fade the history weight out with screen-space velocity instead of
|
|
113
130
|
// holding 90% regardless of how fast the camera swings.
|
|
114
131
|
let velPx = length((uv - prevUV) * vec2<f32>(ru.texel.z, ru.texel.w));
|
|
115
132
|
let trust = clamp(1.0 - velPx * 0.045, 0.25, 1.0);
|
|
116
|
-
|
|
133
|
+
// A color variance box alone cannot distinguish foreground history
|
|
134
|
+
// from newly revealed textured terrain. Compare the current surface's
|
|
135
|
+
// depth in the PREVIOUS camera with that camera's stored history depth.
|
|
136
|
+
// Read depth at the nearest history texel, not a fictitious interpolated
|
|
137
|
+
// depth across a silhouette. Keep stationary subpixel coverage averaging;
|
|
138
|
+
// jitter is deliberately absent from these motion matrices.
|
|
139
|
+
let historyPixel = clamp(vec2<i32>(floor(prevUV * ru.texel.zw)),vec2<i32>(0),dim-vec2<i32>(1));
|
|
140
|
+
let previousDepth = textureLoad(histTex,historyPixel,0).a;
|
|
141
|
+
let expectedDepth = log2(1.0 + max(pc.w,0.0));
|
|
142
|
+
let disoccluded = ru.depthControl.x > 0.5 && perspective && velPx > 0.25
|
|
143
|
+
&& abs(previousDepth-expectedDepth) > 0.05;
|
|
144
|
+
outc = mix(cur, hist, select(ru.ctrl.x * trust,0.0,disoccluded));
|
|
117
145
|
}
|
|
118
146
|
}
|
|
119
|
-
o.screen = vec4(outc, 1.0); o.hist = vec4(outc,
|
|
147
|
+
o.screen = vec4(outc, 1.0); o.hist = vec4(outc, historyDepth);
|
|
120
148
|
return o;
|
|
121
149
|
}
|
|
122
150
|
`;
|
|
@@ -125,7 +153,8 @@ export class GpuTaaResolve {
|
|
|
125
153
|
format;
|
|
126
154
|
pipe;
|
|
127
155
|
uBuf;
|
|
128
|
-
u = new Float32Array(
|
|
156
|
+
u = new Float32Array(108); // matrices, controls and16dirty rectangles
|
|
157
|
+
dirtyRects = [];
|
|
129
158
|
samp;
|
|
130
159
|
hist = [];
|
|
131
160
|
histView = [];
|
|
@@ -196,6 +225,44 @@ export class GpuTaaResolve {
|
|
|
196
225
|
/** Throw the history away — camera cuts, teleports, origin rebases, pause→resume. */
|
|
197
226
|
invalidate() {
|
|
198
227
|
this.primed = false;
|
|
228
|
+
this.dirtyRects.length = 0;
|
|
229
|
+
}
|
|
230
|
+
/** Discard history in a normalized framebuffer rectangle on the next frame.
|
|
231
|
+
* Caller includes old/new projected bounds and its sampling guard band.
|
|
232
|
+
* Overflow falls back to a full reset, never to stale geometry history. */
|
|
233
|
+
invalidateRect(rect) {
|
|
234
|
+
if (!rect.every(Number.isFinite) || rect[0] > rect[2] || rect[1] > rect[3])
|
|
235
|
+
throw new Error('TAA invalidation requires finite ordered UV bounds');
|
|
236
|
+
if (!this.primed)
|
|
237
|
+
return;
|
|
238
|
+
const r = [
|
|
239
|
+
Math.max(0, rect[0]),
|
|
240
|
+
Math.max(0, rect[1]),
|
|
241
|
+
Math.min(1, rect[2]),
|
|
242
|
+
Math.min(1, rect[3]),
|
|
243
|
+
];
|
|
244
|
+
if (r[0] >= r[2] || r[1] >= r[3])
|
|
245
|
+
return;
|
|
246
|
+
// Coalesce intersecting regions, retaining a conservative union. Restart
|
|
247
|
+
// after a merge because the enlarged rectangle may touch earlier ones.
|
|
248
|
+
for (let j = 0; j < this.dirtyRects.length;) {
|
|
249
|
+
const a = this.dirtyRects[j];
|
|
250
|
+
if (r[0] <= a[2] && r[2] >= a[0] && r[1] <= a[3] && r[3] >= a[1]) {
|
|
251
|
+
r[0] = Math.min(r[0], a[0]);
|
|
252
|
+
r[1] = Math.min(r[1], a[1]);
|
|
253
|
+
r[2] = Math.max(r[2], a[2]);
|
|
254
|
+
r[3] = Math.max(r[3], a[3]);
|
|
255
|
+
this.dirtyRects.splice(j, 1);
|
|
256
|
+
j = 0;
|
|
257
|
+
}
|
|
258
|
+
else
|
|
259
|
+
j++;
|
|
260
|
+
}
|
|
261
|
+
if (this.dirtyRects.length === 16) {
|
|
262
|
+
this.invalidate();
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
this.dirtyRects.push(r);
|
|
199
266
|
}
|
|
200
267
|
/**
|
|
201
268
|
* Resolve one frame. `invCurrVP` inverts the UNJITTERED current view-projection; `prevVP` is the
|
|
@@ -204,7 +271,11 @@ export class GpuTaaResolve {
|
|
|
204
271
|
*/
|
|
205
272
|
frame(enc, out, invCurrVP, prevVP, blend = 0.9, enabled = true,
|
|
206
273
|
/** Clip width in standard deviations. Lower = harsher rejection, less ghosting, more shimmer. */
|
|
207
|
-
clipSigma = 1.25
|
|
274
|
+
clipSigma = 1.25,
|
|
275
|
+
/** Reject history from a different perspective depth during camera motion.
|
|
276
|
+
* Requires rgba16float/rgba32float history; lower-range formats retain the
|
|
277
|
+
* previous color-only behavior rather than clipping the stored log depth. */
|
|
278
|
+
rejectDisocclusion = true) {
|
|
208
279
|
if (this.histView.length !== 2)
|
|
209
280
|
return;
|
|
210
281
|
this.u.set(invCurrVP, 0);
|
|
@@ -217,6 +288,15 @@ export class GpuTaaResolve {
|
|
|
217
288
|
this.u[37] = enabled ? 1 : 0;
|
|
218
289
|
this.u[38] = this.primed ? 0 : 1; // first frame after a cut has no history to blend
|
|
219
290
|
this.u[39] = clipSigma;
|
|
291
|
+
this.u[40] =
|
|
292
|
+
rejectDisocclusion &&
|
|
293
|
+
(this.format === 'rgba16float' || this.format === 'rgba32float')
|
|
294
|
+
? 1
|
|
295
|
+
: 0;
|
|
296
|
+
this.u[41] = this.dirtyRects.length;
|
|
297
|
+
for (let j = 0; j < this.dirtyRects.length; j++)
|
|
298
|
+
this.u.set(this.dirtyRects[j], 44 + j * 4);
|
|
299
|
+
this.dirtyRects.length = 0;
|
|
220
300
|
this.device.queue.writeBuffer(this.uBuf, 0, this.u);
|
|
221
301
|
const pass = enc.beginRenderPass({
|
|
222
302
|
colorAttachments: [
|