ugly-game 0.15.66 → 0.15.67

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.
@@ -1,4 +1,5 @@
1
1
  /// <reference types="@webgpu/types" preserve="true" />
2
+ import { type DepthConvention } from '../depthConvention.js';
2
3
  export declare const CROWD_MATERIAL_COUNT = 5;
3
4
  export declare const CROWD_RECORD_FLOATS = 24;
4
5
  export declare const CROWD_REC_LAYER = 20;
@@ -687,6 +688,8 @@ export declare class GpuCrowdRenderer {
687
688
  private device;
688
689
  /** Swap-chain format. Held for the render pipeline the draw pass builds. */
689
690
  readonly format: GPUTextureFormat;
691
+ /** The caller's scene depth: format, clear and which compare means nearer. */
692
+ readonly depth: DepthConvention;
690
693
  private morphPipe;
691
694
  private addPipe;
692
695
  private normalPipe;
@@ -795,7 +798,9 @@ export declare class GpuCrowdRenderer {
795
798
  private skin;
796
799
  constructor(device: GPUDevice,
797
800
  /** Swap-chain format. Held for the render pipeline the draw pass builds. */
798
- format: GPUTextureFormat);
801
+ format: GPUTextureFormat,
802
+ /** The caller's scene depth: format, clear and which compare means nearer. */
803
+ depth?: DepthConvention);
799
804
  /** The rung geometry and pool sizes, once the assets are in. Null before `setAssets`. */
800
805
  get assetPlan(): CrowdPlan | null;
801
806
  /** The four pools, for the skin pass and for a harness that reads a slot back to check it. */
@@ -25,6 +25,7 @@
25
25
  // "must match" comment, and a crowd that disagreed would light its characters out of a different
26
26
  // number of cascades than the ground they stand on.
27
27
  import { MAX_CASCADES } from './gpuSkin';
28
+ import { depthClearValue, FORWARD_DEPTH, nearerCompare, } from '../depthConvention.js';
28
29
  import { CROWD_MATERIAL_COUNT as CROWD_MATERIAL_COUNT_VALUE, CROWD_RECORD_FLOATS as CROWD_RECORD_FLOATS_VALUE, CROWD_REC_LAYER as CROWD_REC_LAYER_VALUE, CROWD_REC_MATERIAL as CROWD_REC_MATERIAL_VALUE, CROWD_REC_MODEL as CROWD_REC_MODEL_VALUE, CROWD_REC_PALETTE_SLOT as CROWD_REC_PALETTE_SLOT_VALUE, CROWD_REC_POOL_SLOT as CROWD_REC_POOL_SLOT_VALUE, CROWD_REC_TINT as CROWD_REC_TINT_VALUE, writeCrowdRecord as writeCrowdRecordValue, } from './crowdRecord.js';
29
30
  export const CROWD_MATERIAL_COUNT = CROWD_MATERIAL_COUNT_VALUE;
30
31
  export const CROWD_RECORD_FLOATS = CROWD_RECORD_FLOATS_VALUE;
@@ -1427,6 +1428,7 @@ const INITIAL_MERGE_ENTRIES = 4096;
1427
1428
  export class GpuCrowdRenderer {
1428
1429
  device;
1429
1430
  format;
1431
+ depth;
1430
1432
  morphPipe;
1431
1433
  addPipe;
1432
1434
  normalPipe;
@@ -1536,9 +1538,12 @@ export class GpuCrowdRenderer {
1536
1538
  skin = null;
1537
1539
  constructor(device,
1538
1540
  /** Swap-chain format. Held for the render pipeline the draw pass builds. */
1539
- format) {
1541
+ format,
1542
+ /** The caller's scene depth: format, clear and which compare means nearer. */
1543
+ depth = FORWARD_DEPTH) {
1540
1544
  this.device = device;
1541
1545
  this.format = format;
1546
+ this.depth = depth;
1542
1547
  const sm = device.createShaderModule({ code: MORPH });
1543
1548
  this.morphBGL = device.createBindGroupLayout({
1544
1549
  entries: CROWD_BINDINGS.morph,
@@ -1610,9 +1615,9 @@ export class GpuCrowdRenderer {
1610
1615
  targets: [{ format, ...(st.blend ? { blend: st.blend } : {}) }],
1611
1616
  },
1612
1617
  depthStencil: {
1613
- format: 'depth24plus',
1618
+ format: depth.format,
1614
1619
  depthWriteEnabled: st.depthWriteEnabled,
1615
- depthCompare: 'less',
1620
+ depthCompare: nearerCompare(depth),
1616
1621
  },
1617
1622
  });
1618
1623
  this.drawPipe = render(S.opaque);
@@ -2423,7 +2428,10 @@ export class GpuCrowdRenderer {
2423
2428
  view: depthView,
2424
2429
  ...(load
2425
2430
  ? { depthLoadOp: 'load' }
2426
- : { depthClearValue: 1, depthLoadOp: 'clear' }),
2431
+ : {
2432
+ depthClearValue: depthClearValue(this.depth),
2433
+ depthLoadOp: 'clear',
2434
+ }),
2427
2435
  depthStoreOp: 'store',
2428
2436
  },
2429
2437
  });
@@ -1,4 +1,5 @@
1
1
  /// <reference types="@webgpu/types" preserve="true" />
2
+ import { type DepthConvention } from '../depthConvention.js';
2
3
  export declare const MAX_CASCADES = 4;
3
4
  /**
4
5
  * Per-world surface + motion parameters.
@@ -81,6 +82,12 @@ export interface PropRendererOptions extends Partial<PropLook> {
81
82
  * occluder pass is unaffected (always single-sample).
82
83
  */
83
84
  sampleCount?: 1 | 4;
85
+ /**
86
+ * The caller's scene depth convention for every pipeline that targets its depth view. Default
87
+ * FORWARD_DEPTH (depth24plus, `less`). REVERSED_DEPTH needs a depth32float view and a projection
88
+ * that maps near to 1 and far to 0. The sun-shadow occluder keeps its own depth domain.
89
+ */
90
+ depth?: DepthConvention;
84
91
  }
85
92
  export interface PropMesh {
86
93
  /** Offline-cooked deformation bounds. Omit for procedural meshes. */
@@ -324,6 +331,8 @@ export declare class GpuPropsRenderer {
324
331
  private look;
325
332
  /** MSAA sample count the draw pipelines were built with. */
326
333
  readonly sampleCount: 1 | 4;
334
+ /** The caller's scene depth convention, fixed at construction. */
335
+ readonly depth: DepthConvention;
327
336
  /** Per-world look + motion. Defaults are inert: no sway, no grain, no grade. */
328
337
  private world;
329
338
  private phase;
@@ -7,6 +7,7 @@
7
7
  // The cull reuses the SAME plane extraction the rest of the engine uses. A second, local copy of
8
8
  // Gribb-Hartmann is exactly how a cull ends up disagreeing with the projection it is culling for.
9
9
  import { frustumPlanes } from '../mat4';
10
+ import { FORWARD_DEPTH, nearerCompare, } from '../depthConvention.js';
10
11
  export const MAX_CASCADES = 4; // must match gpuShadow's
11
12
  const SHADER = /* wgsl */ `
12
13
  // wind = (dirX, dirZ, amplitude, phase) — sway, amplitude scaled by the world's air density
@@ -668,6 +669,8 @@ export class GpuPropsRenderer {
668
669
  look = { ...DEFAULT_LOOK };
669
670
  /** MSAA sample count the draw pipelines were built with. */
670
671
  sampleCount;
672
+ /** The caller's scene depth convention, fixed at construction. */
673
+ depth;
671
674
  /** Per-world look + motion. Defaults are inert: no sway, no grain, no grade. */
672
675
  world = {
673
676
  windDir: [1, 0],
@@ -711,11 +714,12 @@ export class GpuPropsRenderer {
711
714
  }
712
715
  constructor(device, format, options = {}) {
713
716
  this.device = device;
714
- const { sampleCount = 1, ...look } = options;
717
+ const { sampleCount = 1, depth = FORWARD_DEPTH, ...look } = options;
715
718
  // Runtime guard for untyped callers: WebGPU only guarantees 1 and 4.
716
719
  if (![1, 4].includes(sampleCount))
717
720
  throw new RangeError(`Unsupported prop sampleCount ${String(sampleCount)}`);
718
721
  this.sampleCount = sampleCount;
722
+ this.depth = depth;
719
723
  this.setLook(look);
720
724
  const sm = device.createShaderModule({ code: SHADER });
721
725
  // The three groups the SHADER declares, written out so BOTH render pipelines share them. Under
@@ -816,9 +820,9 @@ export class GpuPropsRenderer {
816
820
  ...commonDraw,
817
821
  fragment: { module: sm, entryPoint: 'fs', targets: [{ format }] },
818
822
  depthStencil: {
819
- format: 'depth24plus',
823
+ format: depth.format,
820
824
  depthWriteEnabled: true,
821
- depthCompare: 'less',
825
+ depthCompare: nearerCompare(depth),
822
826
  },
823
827
  };
824
828
  this.pipe = device.createRenderPipeline(opaqueDescriptor);
@@ -848,9 +852,9 @@ export class GpuPropsRenderer {
848
852
  // in submission order — the nearer one clips the farther. For the glassy species (ice
849
853
  // crystals, tektite shards) that is the right trade.
850
854
  depthStencil: {
851
- format: 'depth24plus',
855
+ format: depth.format,
852
856
  depthWriteEnabled: true,
853
- depthCompare: 'less',
857
+ depthCompare: nearerCompare(depth),
854
858
  },
855
859
  };
856
860
  this.blendPipe = device.createRenderPipeline(blendDescriptor);
@@ -1,4 +1,5 @@
1
1
  /// <reference types="@webgpu/types" preserve="true" />
2
+ import { type DepthConvention } from '../depthConvention.js';
2
3
  export interface SkinCreature {
3
4
  rest: Float32Array;
4
5
  normals: Float32Array;
@@ -130,6 +131,8 @@ export interface SkinCreaturePose {
130
131
  export declare const MAX_CASCADES = 4;
131
132
  export declare class GpuSkinRenderer {
132
133
  private device;
134
+ /** The caller's scene depth: format, clear and which compare means nearer. */
135
+ readonly depth: DepthConvention;
133
136
  private skinPipe;
134
137
  private drawPipe;
135
138
  /**
@@ -168,7 +171,9 @@ export declare class GpuSkinRenderer {
168
171
  private texIds;
169
172
  private nextTexId;
170
173
  private texId;
171
- constructor(device: GPUDevice, format: GPUTextureFormat);
174
+ constructor(device: GPUDevice, format: GPUTextureFormat,
175
+ /** The caller's scene depth: format, clear and which compare means nearer. */
176
+ depth?: DepthConvention);
172
177
  setCreatures(list: SkinCreature[]): void;
173
178
  /**
174
179
  * Upload a new pose without reinstalling geometry. The list addresses the current
@@ -1,4 +1,11 @@
1
1
  /// <reference types="@webgpu/types" preserve="true" />
2
+ // ─────────────────────────────────────────────────────────────────────────────
3
+ // GPU SKIN — a reusable WebGPU renderer for skinned creatures (PLATFORM). A compute pass deforms the
4
+ // rest mesh (AND its normals) by each creature's bone palette; the render pass draws them with the SAME
5
+ // lighting model as the terrain/prop renderers — sun lambert on smooth per-vertex normals + ambient +
6
+ // distance fog — so creatures sit in the scene consistently instead of looking flat/mismatched.
7
+ // ─────────────────────────────────────────────────────────────────────────────
8
+ import { depthClearValue, FORWARD_DEPTH, nearerCompare, } from '../depthConvention.js';
2
9
  /**
3
10
  * Every GPUBuffer owned by one packed creature, stated exhaustively.
4
11
  *
@@ -172,6 +179,7 @@ const DRAW = drawWgsl(VS_ATTR);
172
179
  const DRAW_INST = drawWgsl(VS_INST);
173
180
  export class GpuSkinRenderer {
174
181
  device;
182
+ depth;
175
183
  skinPipe;
176
184
  drawPipe;
177
185
  /**
@@ -222,8 +230,11 @@ export class GpuSkinRenderer {
222
230
  }
223
231
  return id;
224
232
  }
225
- constructor(device, format) {
233
+ constructor(device, format,
234
+ /** The caller's scene depth: format, clear and which compare means nearer. */
235
+ depth = FORWARD_DEPTH) {
226
236
  this.device = device;
237
+ this.depth = depth;
227
238
  const sm = device.createShaderModule({ code: SKIN });
228
239
  this.skinPipe = device.createComputePipeline({
229
240
  layout: 'auto',
@@ -337,9 +348,9 @@ export class GpuSkinRenderer {
337
348
  ...common,
338
349
  fragment: { module: dm, entryPoint: 'fs', targets: [{ format }] },
339
350
  depthStencil: {
340
- format: 'depth24plus',
351
+ format: depth.format,
341
352
  depthWriteEnabled: true,
342
- depthCompare: 'less',
353
+ depthCompare: nearerCompare(depth),
343
354
  },
344
355
  });
345
356
  this.blendPipe = device.createRenderPipeline({
@@ -376,12 +387,12 @@ export class GpuSkinRenderer {
376
387
  ],
377
388
  },
378
389
  depthStencil: {
379
- format: 'depth24plus',
390
+ format: depth.format,
380
391
  // ⚠️ OFF. A translucent surface that writes depth hides what is behind it, which is exactly
381
392
  // what the caller asked to see through. It still TESTS against depth, so an opaque creature
382
393
  // in front still occludes it.
383
394
  depthWriteEnabled: false,
384
- depthCompare: 'less',
395
+ depthCompare: nearerCompare(depth),
385
396
  },
386
397
  });
387
398
  // ⚠️ ITS OWN LAYOUT WITH A FOURTH GROUP, and its own shader module. The instanced vertex stage
@@ -400,9 +411,9 @@ export class GpuSkinRenderer {
400
411
  ...instCommon,
401
412
  fragment: { module: im, entryPoint: 'fs', targets: [{ format }] },
402
413
  depthStencil: {
403
- format: 'depth24plus',
414
+ format: depth.format,
404
415
  depthWriteEnabled: true,
405
- depthCompare: 'less',
416
+ depthCompare: nearerCompare(depth),
406
417
  },
407
418
  });
408
419
  this.instBlendPipe = device.createRenderPipeline({
@@ -425,9 +436,9 @@ export class GpuSkinRenderer {
425
436
  ],
426
437
  },
427
438
  depthStencil: {
428
- format: 'depth24plus',
439
+ format: depth.format,
429
440
  depthWriteEnabled: false,
430
- depthCompare: 'less',
441
+ depthCompare: nearerCompare(depth),
431
442
  },
432
443
  });
433
444
  const dummy = device.createTexture({
@@ -773,7 +784,10 @@ export class GpuSkinRenderer {
773
784
  view: depthView,
774
785
  ...(load
775
786
  ? { depthLoadOp: 'load' }
776
- : { depthClearValue: 1, depthLoadOp: 'clear' }),
787
+ : {
788
+ depthClearValue: depthClearValue(this.depth),
789
+ depthLoadOp: 'clear',
790
+ }),
777
791
  depthStoreOp: 'store',
778
792
  },
779
793
  });
@@ -0,0 +1,10 @@
1
+ export interface DepthConvention {
2
+ readonly format: GPUTextureFormat;
3
+ readonly reversed: boolean;
4
+ }
5
+ export declare const FORWARD_DEPTH: DepthConvention;
6
+ export declare const REVERSED_DEPTH: DepthConvention;
7
+ /** The compare under which the NEARER fragment passes. */
8
+ export declare function nearerCompare(c: DepthConvention, orEqual?: boolean): GPUCompareFunction;
9
+ /** The depth a cleared buffer holds: the far plane, 1 forward and 0 reversed. */
10
+ export declare function depthClearValue(c: DepthConvention): number;
@@ -0,0 +1,28 @@
1
+ // SCENE DEPTH CONVENTION. Which way the caller's scene depth buffer points, so a renderer that draws
2
+ // into someone else's depth view builds pipelines that match it.
3
+ //
4
+ // FORWARD: depth24plus, cleared to 1, nearer wins with `less`. The default and the historical behaviour.
5
+ // REVERSED: depth32float, cleared to 0, nearer wins with `greater`. The caller's projection maps the
6
+ // near plane to 1 and the far plane to 0, which spends the float exponent on distance: a planet-scale
7
+ // far/near ratio keeps sub-block depth resolution at kilometres, where a 24-bit forward buffer resolves
8
+ // only blocks and distant surfaces z-fight.
9
+ //
10
+ // Shadow maps are their own depth domain and do not follow this; each renderer keeps its own.
11
+ export const FORWARD_DEPTH = {
12
+ format: 'depth24plus',
13
+ reversed: false,
14
+ };
15
+ export const REVERSED_DEPTH = {
16
+ format: 'depth32float',
17
+ reversed: true,
18
+ };
19
+ /** The compare under which the NEARER fragment passes. */
20
+ export function nearerCompare(c, orEqual = false) {
21
+ if (c.reversed)
22
+ return orEqual ? 'greater-equal' : 'greater';
23
+ return orEqual ? 'less-equal' : 'less';
24
+ }
25
+ /** The depth a cleared buffer holds: the far plane, 1 forward and 0 reversed. */
26
+ export function depthClearValue(c) {
27
+ return c.reversed ? 0 : 1;
28
+ }
@@ -1,7 +1,10 @@
1
1
  /// <reference types="@webgpu/types" preserve="true" />
2
+ import { type DepthConvention } from './depthConvention.js';
2
3
  /** Halton(2,3) sub-pixel jitter for frame `i`, in CLIP space. Multiply into the projection. */
3
4
  export declare function haltonJitter(i: number, w: number, h: number, samples?: number): [number, number];
4
5
  export declare class GpuTaaResolve {
6
+ /** The caller's scene depth. The resolve is convention-agnostic (see the header); recorded here. */
7
+ readonly depth: DepthConvention;
5
8
  private device;
6
9
  private format;
7
10
  private pipe;
@@ -18,7 +21,9 @@ export declare class GpuTaaResolve {
18
21
  private w;
19
22
  private h;
20
23
  private primed;
21
- constructor(device: GPUDevice, format: GPUTextureFormat);
24
+ constructor(device: GPUDevice, format: GPUTextureFormat,
25
+ /** The caller's scene depth. The resolve is convention-agnostic (see the header); recorded here. */
26
+ depth?: DepthConvention);
22
27
  /** (Re)allocate history at the render size. Also invalidates history — a resize is a cut. */
23
28
  resize(w: number, h: number, colorView: GPUTextureView, depthView: GPUTextureView): void;
24
29
  /** Bind group i READS history[i]; the same frame WRITES history[1-i]. */
@@ -23,10 +23,18 @@
23
23
  // (an MRT motion target on the geometry pass), and this pass gains a `motionView` input rather than
24
24
  // being replaced.
25
25
  //
26
- // Sky pixels sit at depth 1.0. Unprojecting them yields a point on the far plane, which reprojects
26
+ // DEPTH CONVENTION. The pass reads depth only to unproject it through `invCurrVP`, so it is agnostic
27
+ // to the direction of the caller's depth buffer as long as `invCurrVP`/`prevVP` are built from the
28
+ // SAME projection that rasterized it: a reversed projection (near 1, far 0) inverts to the same world
29
+ // point a forward one does, and `pc.w` (the history depth) is the eye depth either way. The
30
+ // orthographic test reads |invCurrVP[2].w|, whose sign is all a reversed projection changes. The
31
+ // constructor's `depth` records the convention for callers.
32
+ //
33
+ // Sky pixels sit at the far-plane clear (1.0 forward, 0.0 reversed). Unprojecting them yields a point on the far plane, which reprojects
27
34
  // correctly under camera ROTATION and slightly wrongly under camera TRANSLATION -- the parallax of
28
35
  // something infinitely far away is zero, and the far plane is not infinite. At normal draw
29
36
  // distances the error is far below a pixel.
37
+ import { FORWARD_DEPTH } from './depthConvention.js';
30
38
  /** Halton(2,3) sub-pixel jitter for frame `i`, in CLIP space. Multiply into the projection. */
31
39
  export function haltonJitter(i, w, h, samples = 8) {
32
40
  const radical = (n, base) => {
@@ -180,6 +188,7 @@ struct ROut { @location(0) screen: vec4<f32>, @location(1) hist: vec4<f32> };
180
188
  }
181
189
  `;
182
190
  export class GpuTaaResolve {
191
+ depth;
183
192
  device;
184
193
  format;
185
194
  pipe;
@@ -196,7 +205,10 @@ export class GpuTaaResolve {
196
205
  w = 0;
197
206
  h = 0;
198
207
  primed = false;
199
- constructor(device, format) {
208
+ constructor(device, format,
209
+ /** The caller's scene depth. The resolve is convention-agnostic (see the header); recorded here. */
210
+ depth = FORWARD_DEPTH) {
211
+ this.depth = depth;
200
212
  this.device = device;
201
213
  this.format = format;
202
214
  const mod = device.createShaderModule({ code: RESOLVE_WGSL });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './dmath';
2
2
  export * from './mat4';
3
+ export * from './depthConvention';
3
4
  export * from './noise';
4
5
  export * from './moat';
5
6
  export * from './stateIR';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // Games (all-mine-sky, the demo) depend on this package instead of copy-lifting these modules.
3
3
  export * from './dmath';
4
4
  export * from './mat4';
5
+ export * from './depthConvention';
5
6
  export * from './noise';
6
7
  export * from './moat';
7
8
  export * from './stateIR';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.66",
3
+ "version": "0.15.67",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -20,7 +20,7 @@
20
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
21
  "lint": "ugly-app lint",
22
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",
23
+ "test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin && pnpm run test:depth-convention",
24
24
  "test:flight": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/flight*.test.mts",
25
25
  "test:flight-browser": "playwright test -c playwright.flight.config.ts",
26
26
  "test:props-browser": "playwright test -c playwright.props.config.ts",
@@ -29,7 +29,8 @@
29
29
  "test:package-types": "node tools/packageTypesSmoke.mjs",
30
30
  "pretty": "prettier --write .",
31
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"
32
+ "test:gpu-skin": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/gpuSkin.test.mts",
33
+ "test:depth-convention": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/depthConvention.test.mts"
33
34
  },
34
35
  "dependencies": {
35
36
  "@webgpu/types": "^0.1.40",