ugly-game 0.15.45 → 0.15.47
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/assets/gpuSkin.d.ts +22 -0
- package/dist/assets/gpuSkin.js +260 -160
- package/package.json +4 -3
- package/dist/flightTestFixture.d.mts +0 -2
- package/dist/flightTestFixture.mjs +0 -57
- package/dist/gpuShadow.d.ts +0 -1133
- package/dist/gpuShadow.js +0 -4463
package/dist/assets/gpuSkin.d.ts
CHANGED
|
@@ -118,6 +118,15 @@ export interface SkinCreature {
|
|
|
118
118
|
models: Float32Array;
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
+
/** Dynamic data for an already installed creature; geometry and textures remain unchanged. */
|
|
122
|
+
export interface SkinCreaturePose {
|
|
123
|
+
palette: Float32Array;
|
|
124
|
+
model: Float32Array;
|
|
125
|
+
mix?: number;
|
|
126
|
+
alpha?: number;
|
|
127
|
+
cutout?: number;
|
|
128
|
+
instances?: SkinCreature['instances'];
|
|
129
|
+
}
|
|
121
130
|
export declare const MAX_CASCADES = 4;
|
|
122
131
|
export declare class GpuSkinRenderer {
|
|
123
132
|
private device;
|
|
@@ -145,6 +154,8 @@ export declare class GpuSkinRenderer {
|
|
|
145
154
|
/** The explicit group 0/1/2 layouts, shared by both render pipelines. */
|
|
146
155
|
private drawBGL;
|
|
147
156
|
private packed;
|
|
157
|
+
private disposed;
|
|
158
|
+
private dummyShadow;
|
|
148
159
|
private dummyShadowView;
|
|
149
160
|
private dummyShadowSamp;
|
|
150
161
|
private shadowBG;
|
|
@@ -159,6 +170,17 @@ export declare class GpuSkinRenderer {
|
|
|
159
170
|
private texId;
|
|
160
171
|
constructor(device: GPUDevice, format: GPUTextureFormat);
|
|
161
172
|
setCreatures(list: SkinCreature[]): void;
|
|
173
|
+
/**
|
|
174
|
+
* Upload a new pose without reinstalling geometry. The list addresses the current
|
|
175
|
+
* installed slots in order. Validate every slot before any GPU write; topology,
|
|
176
|
+
* textures or instance-count changes require setCreatures instead. Existing
|
|
177
|
+
* setCreatures callers retain their full replacement semantics, including arrays
|
|
178
|
+
* whose contents were modified in place.
|
|
179
|
+
*/
|
|
180
|
+
updatePoses(list: readonly SkinCreaturePose[]): void;
|
|
181
|
+
/** Release only renderer-owned resources. Caller-supplied textures remain owned by the caller. */
|
|
182
|
+
dispose(): void;
|
|
183
|
+
private assertLive;
|
|
162
184
|
/** Deform + draw every creature with the shared scene lighting. load=true composites over the world;
|
|
163
185
|
* otherwise clears to `clear`. sun/sunCol/amb/cam/fog/fogDensity match the terrain & prop renderers. */
|
|
164
186
|
frame(enc: GPUCommandEncoder, colorView: GPUTextureView, depthView: GPUTextureView, camVP: Float32Array, sunDir: [number, number, number], sunCol: [number, number, number], amb: [number, number, number], camPos: [number, number, number], fog: [number, number, number], fogDensity: number, clear: [number, number, number], load?: boolean, lightVP?: Float32Array | Float32Array[], shadowView?: GPUTextureView, shadowSamp?: GPUSampler): void;
|
package/dist/assets/gpuSkin.js
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
/// <reference types="@webgpu/types" preserve="true" />
|
|
2
|
+
/**
|
|
3
|
+
* Every GPUBuffer owned by one packed creature, stated exhaustively.
|
|
4
|
+
*
|
|
5
|
+
* `setCreatures` replaces the complete packed list. Keeping teardown as a typed
|
|
6
|
+
* record means adding a buffer to `Packed` without adding it here is a compile
|
|
7
|
+
* error instead of a per-frame leak that only appears under a clothed actor.
|
|
8
|
+
*/
|
|
9
|
+
const PACKED_BUFFER_KEYS = {
|
|
10
|
+
restB: true,
|
|
11
|
+
restNB: true,
|
|
12
|
+
jointsB: true,
|
|
13
|
+
weightsB: true,
|
|
14
|
+
defB: true,
|
|
15
|
+
defNB: true,
|
|
16
|
+
colB: true,
|
|
17
|
+
uvB: true,
|
|
18
|
+
uv2B: true,
|
|
19
|
+
idxB: true,
|
|
20
|
+
uBuf: true,
|
|
21
|
+
palB: true,
|
|
22
|
+
pB: true,
|
|
23
|
+
instModelB: true,
|
|
24
|
+
instParamB: true,
|
|
25
|
+
};
|
|
26
|
+
function destroyPackedBuffers(packed) {
|
|
27
|
+
for (const key of Object.keys(PACKED_BUFFER_KEYS))
|
|
28
|
+
packed[key]?.destroy();
|
|
29
|
+
}
|
|
2
30
|
export const MAX_CASCADES = 4; // must match gpuShadow's
|
|
3
31
|
const SKIN = /* wgsl */ `
|
|
4
32
|
@group(0) @binding(0) var<storage,read> rest: array<vec4f>;
|
|
@@ -168,6 +196,8 @@ export class GpuSkinRenderer {
|
|
|
168
196
|
/** The explicit group 0/1/2 layouts, shared by both render pipelines. */
|
|
169
197
|
drawBGL;
|
|
170
198
|
packed = [];
|
|
199
|
+
disposed = false;
|
|
200
|
+
dummyShadow;
|
|
171
201
|
// shadow-receive (group 1): dummy 1×1 depth map when no sun shadow is supplied (demo path), else the terrain's
|
|
172
202
|
// shared shadow map. The bind group is cached and rebuilt only when the supplied view/sampler identity changes.
|
|
173
203
|
dummyShadowView;
|
|
@@ -405,6 +435,7 @@ export class GpuSkinRenderer {
|
|
|
405
435
|
format: 'depth32float',
|
|
406
436
|
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT,
|
|
407
437
|
});
|
|
438
|
+
this.dummyShadow = dummy;
|
|
408
439
|
this.dummyShadowView = dummy.createView({ dimension: '2d-array' }); // the binding is an array now
|
|
409
440
|
this.dummyShadowSamp = device.createSampler({ compare: 'less' });
|
|
410
441
|
this.whiteTex = device.createTexture({
|
|
@@ -422,67 +453,66 @@ export class GpuSkinRenderer {
|
|
|
422
453
|
});
|
|
423
454
|
}
|
|
424
455
|
setCreatures(list) {
|
|
456
|
+
this.assertLive();
|
|
425
457
|
const dev = this.device, U = GPUBufferUsage;
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
if (!matBG) {
|
|
485
|
-
matBG = dev.createBindGroup({
|
|
458
|
+
// Build a complete replacement before releasing the previous generation. A failed
|
|
459
|
+
// allocation/validation must not leak a partial mesh or invalidate a still drawable one.
|
|
460
|
+
const allocated = [];
|
|
461
|
+
const materialGroups = new Map();
|
|
462
|
+
const createBuffer = (descriptor) => {
|
|
463
|
+
const buffer = dev.createBuffer(descriptor);
|
|
464
|
+
allocated.push(buffer);
|
|
465
|
+
return buffer;
|
|
466
|
+
};
|
|
467
|
+
let next;
|
|
468
|
+
try {
|
|
469
|
+
next = list.map((c) => {
|
|
470
|
+
const n = c.rest.length / 3;
|
|
471
|
+
const rest = new Float32Array(n * 4), restN = new Float32Array(n * 4), joints = new Uint32Array(n * 4), weights = new Float32Array(n * 4);
|
|
472
|
+
for (let i = 0; i < n; i++) {
|
|
473
|
+
rest[i * 4] = c.rest[i * 3];
|
|
474
|
+
rest[i * 4 + 1] = c.rest[i * 3 + 1];
|
|
475
|
+
rest[i * 4 + 2] = c.rest[i * 3 + 2];
|
|
476
|
+
rest[i * 4 + 3] = 1;
|
|
477
|
+
restN[i * 4] = c.normals[i * 3];
|
|
478
|
+
restN[i * 4 + 1] = c.normals[i * 3 + 1];
|
|
479
|
+
restN[i * 4 + 2] = c.normals[i * 3 + 2];
|
|
480
|
+
}
|
|
481
|
+
for (let i = 0; i < n * 4; i++) {
|
|
482
|
+
joints[i] = c.joints[i];
|
|
483
|
+
weights[i] = c.weights[i];
|
|
484
|
+
}
|
|
485
|
+
const mk = (d, u) => {
|
|
486
|
+
const b = createBuffer({ size: d.byteLength, usage: u });
|
|
487
|
+
dev.queue.writeBuffer(b, 0, d);
|
|
488
|
+
return b;
|
|
489
|
+
};
|
|
490
|
+
const restB = mk(rest, U.STORAGE | U.COPY_DST), restNB = mk(restN, U.STORAGE | U.COPY_DST), jointsB = mk(joints, U.STORAGE | U.COPY_DST), weightsB = mk(weights, U.STORAGE | U.COPY_DST);
|
|
491
|
+
// ⚠️ `| U.STORAGE` so the instanced vertex stage can read them as arrays. Adding a usage to a
|
|
492
|
+
// buffer that is still bound the same way on the original path changes nothing about it.
|
|
493
|
+
const colB = mk(c.colors, U.VERTEX | U.STORAGE | U.COPY_DST), idxB = mk(c.indices, U.INDEX | U.COPY_DST);
|
|
494
|
+
// A zero-filled UV buffer when the caller has none: the white fallback samples to 1 at any
|
|
495
|
+
// coordinate, so the attribute still has to EXIST but its contents cannot matter.
|
|
496
|
+
const uvB = mk(c.uvs && c.uvs.length >= n * 2 ? c.uvs : new Float32Array(n * 2), U.VERTEX | U.STORAGE | U.COPY_DST);
|
|
497
|
+
// ⚠️ NULL when the caller has no `uvs2` — NOT a second buffer holding a copy of `uvs`.
|
|
498
|
+
//
|
|
499
|
+
// `setCreatures` tears down and rebuilds every buffer on each call and all-mine-sky calls it
|
|
500
|
+
// EVERY FRAME for EVERY creature. Allocating this unconditionally charged every caller in the
|
|
501
|
+
// game — none of which pass `uvs2` — an extra `createBuffer` plus a `writeBuffer` of the same
|
|
502
|
+
// n*2 floats, per creature, per frame, for a buffer whose contents cannot matter: with no
|
|
503
|
+
// tint the 1x1 white samples to 1 at any coordinate. The attribute still has to EXIST, so
|
|
504
|
+
// slot 4 binds `uvB` instead; WebGPU is happy to see the same GPUBuffer in two vertex slots.
|
|
505
|
+
const uv2B = c.uvs2 && c.uvs2.length >= n * 2
|
|
506
|
+
? mk(c.uvs2, U.VERTEX | U.STORAGE | U.COPY_DST)
|
|
507
|
+
: null;
|
|
508
|
+
const tex = c.tex ?? this.whiteTex;
|
|
509
|
+
const tex2 = c.tex2 ?? this.whiteTex;
|
|
510
|
+
const tint = c.tint ?? this.whiteTex;
|
|
511
|
+
// ⚠️ Keyed on the TRIPLE. Keyed on any subset, two creatures sharing those textures but
|
|
512
|
+
// differing in the others would silently share the first one's bind group.
|
|
513
|
+
const matKey = `${this.texId(tex)}:${this.texId(tex2)}:${this.texId(tint)}`;
|
|
514
|
+
let matBG = materialGroups.get(matKey) ?? this.matBGs.get(matKey);
|
|
515
|
+
matBG ??= dev.createBindGroup({
|
|
486
516
|
layout: this.drawBGL[2],
|
|
487
517
|
entries: [
|
|
488
518
|
{ binding: 0, resource: tex.createView() },
|
|
@@ -491,112 +521,181 @@ export class GpuSkinRenderer {
|
|
|
491
521
|
{ binding: 3, resource: tint.createView() },
|
|
492
522
|
],
|
|
493
523
|
});
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
size: palSrc.length * 4,
|
|
511
|
-
usage: U.STORAGE | U.COPY_DST,
|
|
512
|
-
});
|
|
513
|
-
dev.queue.writeBuffer(palB, 0, palSrc);
|
|
514
|
-
// ⚠️ STORAGE **and** VERTEX on both paths. The instanced vertex stage reads these as arrays
|
|
515
|
-
// while the original binds them as vertex buffers, and declaring both usages on one buffer
|
|
516
|
-
// costs nothing — it is the same memory, read two ways.
|
|
517
|
-
const defB = dev.createBuffer({
|
|
518
|
-
size: n * 16 * count,
|
|
519
|
-
usage: U.STORAGE | U.VERTEX,
|
|
520
|
-
}), defNB = dev.createBuffer({
|
|
521
|
-
size: n * 16 * count,
|
|
522
|
-
usage: U.STORAGE | U.VERTEX,
|
|
523
|
-
});
|
|
524
|
-
const pB = dev.createBuffer({ size: 16, usage: U.UNIFORM | U.COPY_DST });
|
|
525
|
-
// P.x total invocations, P.y verts per instance, P.z the palette stride.
|
|
526
|
-
dev.queue.writeBuffer(pB, 0, new Uint32Array([n * count, n, jointCount, 0]));
|
|
527
|
-
const skinBG = dev.createBindGroup({
|
|
528
|
-
layout: this.skinPipe.getBindGroupLayout(0),
|
|
529
|
-
entries: [
|
|
530
|
-
{ binding: 0, resource: { buffer: restB } },
|
|
531
|
-
{ binding: 1, resource: { buffer: jointsB } },
|
|
532
|
-
{ binding: 2, resource: { buffer: weightsB } },
|
|
533
|
-
{ binding: 3, resource: { buffer: palB } },
|
|
534
|
-
{ binding: 4, resource: { buffer: defB } },
|
|
535
|
-
{ binding: 5, resource: { buffer: pB } },
|
|
536
|
-
{ binding: 6, resource: { buffer: restNB } },
|
|
537
|
-
{ binding: 7, resource: { buffer: defNB } },
|
|
538
|
-
],
|
|
539
|
-
});
|
|
540
|
-
const uBuf = dev.createBuffer({
|
|
541
|
-
size: 96 + 16 * 7 + 64 + 16 + 64 * MAX_CASCADES + 16, // + csm vec4 + cascades + blend vec4
|
|
542
|
-
usage: U.UNIFORM | U.COPY_DST,
|
|
543
|
-
});
|
|
544
|
-
const uBG = dev.createBindGroup({
|
|
545
|
-
layout: this.drawBGL[0],
|
|
546
|
-
entries: [{ binding: 0, resource: { buffer: uBuf } }],
|
|
547
|
-
});
|
|
548
|
-
// Group 3 exists only for an instanced creature — the single-instance pipeline never binds it.
|
|
549
|
-
let instBG = null;
|
|
550
|
-
let instModelB = null;
|
|
551
|
-
let instParamB = null;
|
|
552
|
-
if (inst) {
|
|
553
|
-
instModelB = dev.createBuffer({
|
|
554
|
-
size: count * 64,
|
|
524
|
+
// ── INSTANCING ────────────────────────────────────────────────────────────────────────────
|
|
525
|
+
// `count` of 1 with no `instances` is the original path exactly: one palette, one deformed
|
|
526
|
+
// copy, P = [n, n, jointCount], which makes the compute shader's inst and po both zero.
|
|
527
|
+
materialGroups.set(matKey, matBG);
|
|
528
|
+
const inst = c.instances;
|
|
529
|
+
const count = Math.max(1, inst?.count ?? 1);
|
|
530
|
+
const palSrc = inst ? inst.palettes : c.palette;
|
|
531
|
+
// ⚠️ DERIVED, NOT ASSUMED. jointCount strides the palette per instance, and getting it wrong
|
|
532
|
+
// does not throw — it indexes one character's bones through another's offset, so everybody
|
|
533
|
+
// after the first wears somebody else's skeleton. Checked against the array length so a
|
|
534
|
+
// caller whose palettes do not divide by count is told, rather than rendered wrongly.
|
|
535
|
+
const jointCount = Math.floor(palSrc.length / count / 16);
|
|
536
|
+
if (inst && jointCount * count * 16 !== palSrc.length)
|
|
537
|
+
throw new Error(`gpuSkin: palettes is ${palSrc.length} floats, which is not count(${count}) x jointCount x 16`);
|
|
538
|
+
const palB = createBuffer({
|
|
539
|
+
size: palSrc.length * 4,
|
|
555
540
|
usage: U.STORAGE | U.COPY_DST,
|
|
556
541
|
});
|
|
557
|
-
dev.queue.writeBuffer(
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
542
|
+
dev.queue.writeBuffer(palB, 0, palSrc);
|
|
543
|
+
// ⚠️ STORAGE **and** VERTEX on both paths. The instanced vertex stage reads these as arrays
|
|
544
|
+
// while the original binds them as vertex buffers, and declaring both usages on one buffer
|
|
545
|
+
// costs nothing — it is the same memory, read two ways.
|
|
546
|
+
const defB = createBuffer({
|
|
547
|
+
size: n * 16 * count,
|
|
548
|
+
usage: U.STORAGE | U.VERTEX,
|
|
549
|
+
}), defNB = createBuffer({
|
|
550
|
+
size: n * 16 * count,
|
|
551
|
+
usage: U.STORAGE | U.VERTEX,
|
|
561
552
|
});
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
553
|
+
const pB = createBuffer({ size: 16, usage: U.UNIFORM | U.COPY_DST });
|
|
554
|
+
// P.x total invocations, P.y verts per instance, P.z the palette stride.
|
|
555
|
+
dev.queue.writeBuffer(pB, 0, new Uint32Array([n * count, n, jointCount, 0]));
|
|
556
|
+
const skinBG = dev.createBindGroup({
|
|
557
|
+
layout: this.skinPipe.getBindGroupLayout(0),
|
|
565
558
|
entries: [
|
|
566
|
-
{ binding: 0, resource: { buffer:
|
|
567
|
-
{ binding: 1, resource: { buffer:
|
|
568
|
-
{ binding: 2, resource: { buffer:
|
|
569
|
-
{ binding: 3, resource: { buffer:
|
|
570
|
-
{ binding: 4, resource: { buffer:
|
|
571
|
-
{ binding: 5, resource: { buffer:
|
|
572
|
-
{ binding: 6, resource: { buffer:
|
|
559
|
+
{ binding: 0, resource: { buffer: restB } },
|
|
560
|
+
{ binding: 1, resource: { buffer: jointsB } },
|
|
561
|
+
{ binding: 2, resource: { buffer: weightsB } },
|
|
562
|
+
{ binding: 3, resource: { buffer: palB } },
|
|
563
|
+
{ binding: 4, resource: { buffer: defB } },
|
|
564
|
+
{ binding: 5, resource: { buffer: pB } },
|
|
565
|
+
{ binding: 6, resource: { buffer: restNB } },
|
|
566
|
+
{ binding: 7, resource: { buffer: defNB } },
|
|
573
567
|
],
|
|
574
568
|
});
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
569
|
+
const uBuf = createBuffer({
|
|
570
|
+
size: 96 + 16 * 7 + 64 + 16 + 64 * MAX_CASCADES + 16, // + csm vec4 + cascades + blend vec4
|
|
571
|
+
usage: U.UNIFORM | U.COPY_DST,
|
|
572
|
+
});
|
|
573
|
+
const uBG = dev.createBindGroup({
|
|
574
|
+
layout: this.drawBGL[0],
|
|
575
|
+
entries: [{ binding: 0, resource: { buffer: uBuf } }],
|
|
576
|
+
});
|
|
577
|
+
// Group 3 exists only for an instanced creature — the single-instance pipeline never binds it.
|
|
578
|
+
let instBG = null;
|
|
579
|
+
let instModelB = null;
|
|
580
|
+
let instParamB = null;
|
|
581
|
+
if (inst) {
|
|
582
|
+
instModelB = createBuffer({
|
|
583
|
+
size: count * 64,
|
|
584
|
+
usage: U.STORAGE | U.COPY_DST,
|
|
585
|
+
});
|
|
586
|
+
dev.queue.writeBuffer(instModelB, 0, inst.models);
|
|
587
|
+
instParamB = createBuffer({
|
|
588
|
+
size: 16,
|
|
589
|
+
usage: U.UNIFORM | U.COPY_DST,
|
|
590
|
+
});
|
|
591
|
+
dev.queue.writeBuffer(instParamB, 0, new Uint32Array([n, 0, 0, 0]));
|
|
592
|
+
instBG = dev.createBindGroup({
|
|
593
|
+
layout: this.instBGL,
|
|
594
|
+
entries: [
|
|
595
|
+
{ binding: 0, resource: { buffer: defB } },
|
|
596
|
+
{ binding: 1, resource: { buffer: defNB } },
|
|
597
|
+
{ binding: 2, resource: { buffer: colB } },
|
|
598
|
+
{ binding: 3, resource: { buffer: uvB } },
|
|
599
|
+
{ binding: 4, resource: { buffer: uv2B ?? uvB } },
|
|
600
|
+
{ binding: 5, resource: { buffer: instModelB } },
|
|
601
|
+
{ binding: 6, resource: { buffer: instParamB } },
|
|
602
|
+
],
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
return {
|
|
606
|
+
count,
|
|
607
|
+
instBG,
|
|
608
|
+
instModelB,
|
|
609
|
+
instParamB,
|
|
610
|
+
restB,
|
|
611
|
+
restNB,
|
|
612
|
+
jointsB,
|
|
613
|
+
weightsB,
|
|
614
|
+
defB,
|
|
615
|
+
defNB,
|
|
616
|
+
colB,
|
|
617
|
+
uvB,
|
|
618
|
+
uv2B,
|
|
619
|
+
matBG,
|
|
620
|
+
idxB,
|
|
621
|
+
idxCount: c.indices.length,
|
|
622
|
+
skinBG,
|
|
623
|
+
uBuf,
|
|
624
|
+
uBG,
|
|
625
|
+
palB,
|
|
626
|
+
pB,
|
|
627
|
+
n,
|
|
628
|
+
paletteFloats: palSrc.length,
|
|
629
|
+
model: c.model,
|
|
630
|
+
mix: c.mix ?? 0,
|
|
631
|
+
alpha: c.alpha ?? 1,
|
|
632
|
+
cutout: c.cutout ?? 0,
|
|
633
|
+
};
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
for (const buffer of allocated)
|
|
638
|
+
buffer.destroy();
|
|
639
|
+
throw error;
|
|
640
|
+
}
|
|
641
|
+
for (const packed of this.packed)
|
|
642
|
+
destroyPackedBuffers(packed);
|
|
643
|
+
this.packed = next;
|
|
644
|
+
this.matBGs = materialGroups;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Upload a new pose without reinstalling geometry. The list addresses the current
|
|
648
|
+
* installed slots in order. Validate every slot before any GPU write; topology,
|
|
649
|
+
* textures or instance-count changes require setCreatures instead. Existing
|
|
650
|
+
* setCreatures callers retain their full replacement semantics, including arrays
|
|
651
|
+
* whose contents were modified in place.
|
|
652
|
+
*/
|
|
653
|
+
updatePoses(list) {
|
|
654
|
+
this.assertLive();
|
|
655
|
+
if (list.length !== this.packed.length)
|
|
656
|
+
throw new Error('gpuSkin: pose count differs from installed creatures');
|
|
657
|
+
for (let i = 0; i < list.length; i++) {
|
|
658
|
+
const pose = list[i], packed = this.packed[i];
|
|
659
|
+
const instances = pose.instances;
|
|
660
|
+
if (Boolean(instances) !== Boolean(packed.instBG) ||
|
|
661
|
+
(instances && instances.count !== packed.count))
|
|
662
|
+
throw new Error('gpuSkin: pose instance count differs from installed creature');
|
|
663
|
+
if (pose.model.length !== 16 ||
|
|
664
|
+
(instances && instances.models.length !== packed.count * 16))
|
|
665
|
+
throw new Error('gpuSkin: pose model must contain 16 floats per instance');
|
|
666
|
+
if ((instances?.palettes ?? pose.palette).length !== packed.paletteFloats)
|
|
667
|
+
throw new Error('gpuSkin: pose palette differs from installed skeleton');
|
|
668
|
+
}
|
|
669
|
+
for (let i = 0; i < list.length; i++) {
|
|
670
|
+
const pose = list[i], packed = this.packed[i];
|
|
671
|
+
this.device.queue.writeBuffer(packed.palB, 0, (pose.instances?.palettes ??
|
|
672
|
+
pose.palette));
|
|
673
|
+
if (pose.instances && packed.instModelB)
|
|
674
|
+
this.device.queue.writeBuffer(packed.instModelB, 0, pose.instances.models);
|
|
675
|
+
packed.model = pose.model;
|
|
676
|
+
packed.mix = pose.mix ?? 0;
|
|
677
|
+
packed.alpha = pose.alpha ?? 1;
|
|
678
|
+
packed.cutout = pose.cutout ?? 0;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/** Release only renderer-owned resources. Caller-supplied textures remain owned by the caller. */
|
|
682
|
+
dispose() {
|
|
683
|
+
if (this.disposed)
|
|
684
|
+
return;
|
|
685
|
+
this.disposed = true;
|
|
686
|
+
for (const packed of this.packed)
|
|
687
|
+
destroyPackedBuffers(packed);
|
|
688
|
+
this.packed = [];
|
|
689
|
+
this.matBGs.clear();
|
|
690
|
+
this.shadowBG = null;
|
|
691
|
+
this.lastSV = null;
|
|
692
|
+
this.lastSS = null;
|
|
693
|
+
this.whiteTex.destroy();
|
|
694
|
+
this.dummyShadow.destroy();
|
|
695
|
+
}
|
|
696
|
+
assertLive() {
|
|
697
|
+
if (this.disposed)
|
|
698
|
+
throw new Error('gpuSkin: renderer is disposed');
|
|
600
699
|
}
|
|
601
700
|
/** Deform + draw every creature with the shared scene lighting. load=true composites over the world;
|
|
602
701
|
* otherwise clears to `clear`. sun/sunCol/amb/cam/fog/fogDensity match the terrain & prop renderers. */
|
|
@@ -604,6 +703,7 @@ export class GpuSkinRenderer {
|
|
|
604
703
|
// Optional sun shadow-receive: pass the terrain's lightVP + shadow-map view + comparison sampler and creatures
|
|
605
704
|
// sit in the same shadow. Omit all three (the demo path) → no shadowing, byte-identical to before.
|
|
606
705
|
lightVP, shadowView, shadowSamp) {
|
|
706
|
+
this.assertLive();
|
|
607
707
|
const receive = !!(lightVP && shadowView && shadowSamp);
|
|
608
708
|
const mats = lightVP ? (Array.isArray(lightVP) ? lightVP : [lightVP]) : [];
|
|
609
709
|
const cp = enc.beginComputePass();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugly-game",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.47",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -20,14 +20,15 @@
|
|
|
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",
|
|
23
|
+
"test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin",
|
|
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:flight-perf": "playwright test -c playwright.flight.config.ts --grep 'CPU and retained-memory'",
|
|
27
27
|
"test:types": "tsc -p tsconfig.test.json",
|
|
28
28
|
"test:package-types": "node tools/packageTypesSmoke.mjs",
|
|
29
29
|
"pretty": "prettier --write .",
|
|
30
|
-
"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/"
|
|
30
|
+
"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/",
|
|
31
|
+
"test:gpu-skin": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/gpuSkin.test.mts"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"@webgpu/types": "^0.1.40",
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { FLIGHT_CHANNELS } from './flightTypes';
|
|
2
|
-
const emptyCounts = () => Object.fromEntries(FLIGHT_CHANNELS.map((channel) => [channel, 0]));
|
|
3
|
-
export function fixtureCapture() {
|
|
4
|
-
const channels = Object.fromEntries(FLIGHT_CHANNELS.map((channel) => [channel, []]));
|
|
5
|
-
channels.inputs = [
|
|
6
|
-
{ sequence: 2, monotonicMs: 2, tick: 0, kind: 0, flags: 0, payload: new Uint8Array([7]) },
|
|
7
|
-
];
|
|
8
|
-
channels.lifecycle = [
|
|
9
|
-
{ sequence: 1, monotonicMs: 1, tick: null, kind: 2, flags: 0, payload: new Uint8Array([8]) },
|
|
10
|
-
];
|
|
11
|
-
return {
|
|
12
|
-
header: {
|
|
13
|
-
recorderSchema: 1,
|
|
14
|
-
gameSchema: 2,
|
|
15
|
-
checkpointSchema: 3,
|
|
16
|
-
inputSchema: 4,
|
|
17
|
-
app: 'test',
|
|
18
|
-
buildId: 'build',
|
|
19
|
-
sessionId: 'session',
|
|
20
|
-
startedAtMs: 1,
|
|
21
|
-
capturedAtMs: 2,
|
|
22
|
-
capturedAtMonotonicMs: 2,
|
|
23
|
-
capturedAtTick: 0,
|
|
24
|
-
tickRate: 60,
|
|
25
|
-
environment: { runtime: 'node' },
|
|
26
|
-
reason: ['manual'],
|
|
27
|
-
},
|
|
28
|
-
anchor: {
|
|
29
|
-
requestId: 1,
|
|
30
|
-
tick: 0,
|
|
31
|
-
monotonicMs: 0,
|
|
32
|
-
schema: 3,
|
|
33
|
-
checkpoint: new Uint8Array([1, 2, 3]),
|
|
34
|
-
rng: new Uint32Array([4, 5]),
|
|
35
|
-
encodedBytes: 3,
|
|
36
|
-
transferBytes: 3,
|
|
37
|
-
},
|
|
38
|
-
channels,
|
|
39
|
-
truncation: {
|
|
40
|
-
dropped: emptyCounts(),
|
|
41
|
-
droppedBytes: emptyCounts(),
|
|
42
|
-
rejectedOversize: emptyCounts(),
|
|
43
|
-
},
|
|
44
|
-
replay: { status: 'unverified' },
|
|
45
|
-
selfTelemetry: {
|
|
46
|
-
calls: 1,
|
|
47
|
-
averageMs: 0.01,
|
|
48
|
-
p95Ms: 0.02,
|
|
49
|
-
p99Ms: 0.02,
|
|
50
|
-
maxMs: 0.02,
|
|
51
|
-
retainedBytes: 100,
|
|
52
|
-
checkpointRequests: 1,
|
|
53
|
-
checkpointFailures: 0,
|
|
54
|
-
checkpointMs: 1,
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
}
|