ugly-game 0.15.59 → 0.15.60

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.
@@ -31,6 +31,10 @@ export declare class GpuTaaResolve {
31
31
  */
32
32
  frame(enc: GPUCommandEncoder, out: GPUTextureView, invCurrVP: Float32Array, prevVP: Float32Array, blend?: number, enabled?: boolean,
33
33
  /** Clip width in standard deviations. Lower = harsher rejection, less ghosting, more shimmer. */
34
- clipSigma?: number): void;
34
+ clipSigma?: number,
35
+ /** Reject history from a different perspective depth during camera motion.
36
+ * Requires rgba16float/rgba32float history; lower-range formats retain the
37
+ * previous color-only behavior rather than clipping the stored log depth. */
38
+ rejectDisocclusion?: boolean): void;
35
39
  destroy(): void;
36
40
  }
@@ -48,6 +48,7 @@ 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
52
  };
52
53
  @group(0) @binding(0) var<uniform> ru: RU;
53
54
  @group(0) @binding(1) var histSamp: sampler;
@@ -67,8 +68,19 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
67
68
  let px = clamp(vec2<i32>(floor(fc.xy)), vec2<i32>(0, 0), dim - vec2<i32>(1, 1));
68
69
  let cur = textureLoad(colorTex, px, 0).rgb;
69
70
  var o: ROut;
71
+ let d = textureLoad(depthTex, px, 0);
72
+ let uv = fc.xy * ru.texel.xy;
73
+ let ndc = vec3<f32>(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, d);
74
+ let wp4 = ru.invCurrVP * vec4(ndc, 1.0);
75
+ // History alpha stores log eye depth instead of unused opacity. This stays
76
+ // finite in rgba16float even for planetary far planes, with useful relative
77
+ // precision. Orthographic projections have no perspective w-depth; retain
78
+ // their previous color-only behavior. Screen alpha remains opaque.
79
+ let perspective = abs(ru.invCurrVP[2].w) > 0.000001;
80
+ let eyeDepth = 1.0 / max(abs(wp4.w), 0.00000001);
81
+ let historyDepth = log2(1.0 + eyeDepth);
70
82
  // Disabled, or the first frame after a cut: the current frame IS the answer and the history.
71
- if (ru.ctrl.y < 0.5 || ru.ctrl.z > 0.5) { o.screen = vec4(cur, 1.0); o.hist = vec4(cur, 1.0); return o; }
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; }
72
84
 
73
85
  // ANTI-GHOSTING CLAMP, by VARIANCE rather than by min/max. A raw 3x3 min/max box is enormous over
74
86
  // high-frequency detail -- a voxel world's textured terrain spans most of the range inside any
@@ -94,10 +106,6 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
94
106
 
95
107
  // Depth -> world -> previous clip. WebGPU depth is [0,1] and clip-space Y is up while the
96
108
  // 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
109
  let world = wp4.xyz / wp4.w;
102
110
  let pc = ru.prevVP * vec4(world, 1.0);
103
111
 
@@ -106,17 +114,29 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
106
114
  let pndc = pc.xyz / pc.w;
107
115
  let prevUV = vec2<f32>(pndc.x * 0.5 + 0.5, 0.5 - pndc.y * 0.5);
108
116
  if (prevUV.x >= 0.0 && prevUV.x <= 1.0 && prevUV.y >= 0.0 && prevUV.y <= 1.0) {
109
- let hist = clamp(textureSampleLevel(histTex, histSamp, prevUV, 0.0).rgb, mn, mx);
117
+ let history = textureSampleLevel(histTex, histSamp, prevUV, 0.0);
118
+ let hist = clamp(history.rgb, mn, mx);
110
119
  // TRUST LESS WHEN MOVING. The further a pixel travelled since last frame, the likelier its
111
120
  // history is disoccluded or belongs to different geometry -- and the more a wrong sample reads
112
121
  // as a trailing smear. Fade the history weight out with screen-space velocity instead of
113
122
  // holding 90% regardless of how fast the camera swings.
114
123
  let velPx = length((uv - prevUV) * vec2<f32>(ru.texel.z, ru.texel.w));
115
124
  let trust = clamp(1.0 - velPx * 0.045, 0.25, 1.0);
116
- outc = mix(cur, hist, ru.ctrl.x * trust);
125
+ // A color variance box alone cannot distinguish foreground history
126
+ // from newly revealed textured terrain. Compare the current surface's
127
+ // depth in the PREVIOUS camera with that camera's stored history depth.
128
+ // Read depth at the nearest history texel, not a fictitious interpolated
129
+ // depth across a silhouette. Keep stationary subpixel coverage averaging;
130
+ // jitter is deliberately absent from these motion matrices.
131
+ let historyPixel = clamp(vec2<i32>(floor(prevUV * ru.texel.zw)),vec2<i32>(0),dim-vec2<i32>(1));
132
+ let previousDepth = textureLoad(histTex,historyPixel,0).a;
133
+ let expectedDepth = log2(1.0 + max(pc.w,0.0));
134
+ let disoccluded = ru.depthControl.x > 0.5 && perspective && velPx > 0.25
135
+ && abs(previousDepth-expectedDepth) > 0.05;
136
+ outc = mix(cur, hist, select(ru.ctrl.x * trust,0.0,disoccluded));
117
137
  }
118
138
  }
119
- o.screen = vec4(outc, 1.0); o.hist = vec4(outc, 1.0);
139
+ o.screen = vec4(outc, 1.0); o.hist = vec4(outc, historyDepth);
120
140
  return o;
121
141
  }
122
142
  `;
@@ -125,7 +145,7 @@ export class GpuTaaResolve {
125
145
  format;
126
146
  pipe;
127
147
  uBuf;
128
- u = new Float32Array(40); // 2 x mat4 + 2 x vec4
148
+ u = new Float32Array(44); // 2 x mat4 + 3 x vec4
129
149
  samp;
130
150
  hist = [];
131
151
  histView = [];
@@ -204,7 +224,11 @@ export class GpuTaaResolve {
204
224
  */
205
225
  frame(enc, out, invCurrVP, prevVP, blend = 0.9, enabled = true,
206
226
  /** Clip width in standard deviations. Lower = harsher rejection, less ghosting, more shimmer. */
207
- clipSigma = 1.25) {
227
+ clipSigma = 1.25,
228
+ /** Reject history from a different perspective depth during camera motion.
229
+ * Requires rgba16float/rgba32float history; lower-range formats retain the
230
+ * previous color-only behavior rather than clipping the stored log depth. */
231
+ rejectDisocclusion = true) {
208
232
  if (this.histView.length !== 2)
209
233
  return;
210
234
  this.u.set(invCurrVP, 0);
@@ -217,6 +241,11 @@ export class GpuTaaResolve {
217
241
  this.u[37] = enabled ? 1 : 0;
218
242
  this.u[38] = this.primed ? 0 : 1; // first frame after a cut has no history to blend
219
243
  this.u[39] = clipSigma;
244
+ this.u[40] =
245
+ rejectDisocclusion &&
246
+ (this.format === 'rgba16float' || this.format === 'rgba32float')
247
+ ? 1
248
+ : 0;
220
249
  this.device.queue.writeBuffer(this.uBuf, 0, this.u);
221
250
  const pass = enc.beginRenderPass({
222
251
  colorAttachments: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.59",
3
+ "version": "0.15.60",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -15,22 +15,6 @@
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
- },
34
18
  "dependencies": {
35
19
  "@webgpu/types": "^0.1.40",
36
20
  "meshoptimizer": "^1.2.0"
@@ -46,5 +30,20 @@
46
30
  "typescript": "^5.6.0",
47
31
  "ugly-app": "^0.1.841",
48
32
  "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"
49
48
  }
50
- }
49
+ }