ugly-game 0.14.11 → 0.14.13

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.
@@ -0,0 +1,656 @@
1
+ /**
2
+ * One rung of the shared body mesh, as cooked into a .ugm.
3
+ *
4
+ * ⚠️ NO NORMALS, deliberately. The cook ships none (see `bodyVtxBytes` in cookCharUgm.mts) because
5
+ * a morphed rest mesh's normals are not the base mesh's normals, and morphing the base normals by
6
+ * the same deltas is an approximation that shows up as shading that lags the shape. They are
7
+ * recomputed exactly from `adjOffset`/`adjTri` after every morph instead — which is affordable
8
+ * precisely because morphing is rare.
9
+ */
10
+ export interface CrowdLod {
11
+ /** `3·t` LOD-local vertex indices. */
12
+ indices: Uint32Array;
13
+ vertCount: number;
14
+ /** `3·vertCount` rest positions, unmorphed. */
15
+ positions: Float32Array;
16
+ /** `2·vertCount`. */
17
+ uvs: Float32Array;
18
+ /** `4·vertCount` joint indices into the shared skeleton. */
19
+ joints: Uint16Array;
20
+ /** `4·vertCount` skin weights. */
21
+ weights: Float32Array;
22
+ /** `vertCount + 1` prefix offsets into `adjTri`. */
23
+ adjOffset: Uint32Array;
24
+ /** `adjOffset[vertCount]` TRIANGLE indices (not index-buffer offsets) — see vertexAdjacency.ts. */
25
+ adjTri: Uint32Array;
26
+ /**
27
+ * IGNORED. Accepted so a caller that has them does not have to strip them.
28
+ *
29
+ * `normals` is superseded by the adjacency pass (see the interface comment). `baseIndex` — the
30
+ * LOD vertex → original body vertex map from the CLUSTER chunk — is a COOK-TIME key: the cook has
31
+ * already gathered every morph target through it, so the MORPH chunks arrive in LOD-local
32
+ * numbering and the runtime never needs the map.
33
+ */
34
+ normals?: Float32Array;
35
+ baseIndex?: Int32Array;
36
+ }
37
+ /** One shipped morph target's gather at ONE rung. A target that misses a rung simply has no entry. */
38
+ export interface CrowdTarget {
39
+ lod: number;
40
+ /** `m` LOD-local vertex indices. */
41
+ index: Int32Array;
42
+ /** `3·m` position deltas, in the same order. */
43
+ delta: Float32Array;
44
+ }
45
+ export interface CrowdAssets {
46
+ lods: CrowdLod[];
47
+ /** `targets[targetId]` — that target's gathers, at most one per rung. */
48
+ targets: CrowdTarget[][];
49
+ boneCount: number;
50
+ /** Shared skin atlas. The CALLER owns and uploads it; this renderer never decodes anything. */
51
+ skin: GPUTexture;
52
+ /**
53
+ * Total vertices each pool holds. This is what BOUNDS VRAM: four pools × 16 bytes × this.
54
+ * Must be the same budget the slot allocator was constructed with.
55
+ */
56
+ vertexBudget: number;
57
+ /** Palette-slot count. `maxChars · boneCount · 16` floats of bone matrices. */
58
+ maxChars: number;
59
+ /**
60
+ * REQUIRED, one entry per rung: the vertices ONE character reserves in the pools there.
61
+ *
62
+ * ⚠️ THE SAME ARRAY THE SLOT ALLOCATOR WAS BUILT FROM, not a second copy of it. There is exactly
63
+ * one stride per rung in the whole system and it lives here, precisely so there is no second
64
+ * number for this one to drift from. It has NO DEFAULT for the same reason: a default would be a
65
+ * body-only stride that silently agrees with the allocator's own body-only default, and two
66
+ * defaults agreeing is how a dressed character ends up writing into its neighbour's slot. Compute
67
+ * it once with `poolStride` and feed it to both.
68
+ *
69
+ * Declare `garmentVerts` alongside it and this becomes CHECKABLE rather than merely explicit.
70
+ */
71
+ slotVerts: number[];
72
+ /**
73
+ * The wardrobe this crowd draws from: per-garment, per-rung vertex counts — exactly the shape of
74
+ * `char.kit.json`'s `garmentDetail[].lods[].verts`.
75
+ *
76
+ * Supplying it turns `slotVerts` from a promise into an assertion: `planCrowd` recomputes the
77
+ * worst-case demand and throws if a stride cannot hold it. At LOD3 the largest shipped garment
78
+ * (597 verts) is three times the body (195), so a body-only stride is short by nearly 4x — and
79
+ * without this it would be short SILENTLY, which is the failure this whole file exists to avoid.
80
+ *
81
+ * Omit it only for a genuinely naked crowd.
82
+ */
83
+ garmentVerts?: number[][];
84
+ /**
85
+ * How many garments one character may wear at once.
86
+ *
87
+ * ⚠️ Defaults to EVERY declared garment, which over-reserves. That direction is deliberate: a
88
+ * wrong default here makes `planCrowd` reject a stride that would have been fine, which is loud,
89
+ * rather than accept one that is too small, which is silent.
90
+ */
91
+ wear?: number;
92
+ }
93
+ /**
94
+ * Floats per instance record: mat4 (16) + tint (4) + layer/paletteSlot/poolSlot/pad (4).
95
+ *
96
+ * ⚠️ TWO slots, not one, and they are different KINDS of number. `paletteSlot` is a character
97
+ * ORDINAL — it multiplies by boneCount to reach that character's bone matrices. `poolSlot` is a
98
+ * VERTEX OFFSET into the four pools, straight from the allocator. Conflating them puts one
99
+ * character's vertices under another's skeleton, which animates but is the wrong body.
100
+ *
101
+ * Write records through `writeCrowdRecord` so this layout lives in exactly one place; the WGSL
102
+ * `Rec` struct below is its only other statement of the same thing.
103
+ */
104
+ export declare const CROWD_RECORD_FLOATS = 24;
105
+ /** Float offsets inside one record. `writeCrowdRecord` and the WGSL `Rec` struct must agree. */
106
+ export declare const CROWD_REC_MODEL = 0;
107
+ export declare const CROWD_REC_TINT = 16;
108
+ export declare const CROWD_REC_LAYER = 20;
109
+ export declare const CROWD_REC_PALETTE_SLOT = 21;
110
+ export declare const CROWD_REC_POOL_SLOT = 22;
111
+ /** Which LOD bucket a contiguous run of instance records belongs to. */
112
+ export interface CrowdBucket {
113
+ lod: number;
114
+ count: number;
115
+ /** First INSTANCE index (not a byte offset) — it goes straight to drawIndexed's firstInstance. */
116
+ first: number;
117
+ }
118
+ /** Bytes a vec4-padded pool of `verts` vertices occupies. */
119
+ export declare function poolBytes(verts: number): number;
120
+ /**
121
+ * gpuProps' growth rule, shared rather than re-typed so the two cannot drift: reuse the allocation
122
+ * while it fits, else 1.5× with a 16-entry floor.
123
+ */
124
+ export declare function growCapacity(need: number, cap: number): number;
125
+ /**
126
+ * What ONE character occupies at `lod`: the body rung plus every garment it is actually wearing.
127
+ *
128
+ * `worn` is per-garment per-LOD vertex counts, exactly the shape of `char.kit.json.garmentDetail`
129
+ * rows. A garment that has no entry at this rung contributes nothing.
130
+ */
131
+ export declare function charSlotVerts(lod: number, bodyVerts: number[], worn: number[][]): number;
132
+ /**
133
+ * The UNIFORM per-slot vertex stride a pool must reserve at each rung.
134
+ *
135
+ * ⚠️ A pool's free list only works if every slot at a tier is interchangeable, so the stride has to
136
+ * be the worst case a character can ask for — the body plus the `wear` LARGEST garments at that
137
+ * rung — and not the body alone. Sizing from the body alone is how a dressed character's garment
138
+ * vertices land in its neighbour's slot.
139
+ *
140
+ * Measured against the shipped kit with wear = 1: 23185 / 4229 / 1321 / 792 against body-only
141
+ * budgets of 14759 / 3000 / 800 / 200. The coarsest rung is undersized by very nearly 4×.
142
+ */
143
+ export declare function poolStride(bodyVerts: number[], garmentVerts: number[][], wear: number): number[];
144
+ /** vec3 run → vec4 run with a constant w. Throws rather than silently truncating a wrong length. */
145
+ export declare function padVec3(src: Float32Array, n: number, w: number): Float32Array;
146
+ /** u16 joint quads → the u32 quads WGSL's `array<vec4u>` expects. */
147
+ export declare function widenJoints(src: Uint16Array, n: number): Uint32Array;
148
+ /** Per-rung byte sizes, derived from the assets rather than recomputed at each createBuffer call. */
149
+ export interface CrowdLodPlan {
150
+ vertCount: number;
151
+ slotVerts: number;
152
+ posBytes: number;
153
+ uvBytes: number;
154
+ jointBytes: number;
155
+ weightBytes: number;
156
+ idxCount: number;
157
+ idxBytes: number;
158
+ adjOffsetBytes: number;
159
+ adjTriBytes: number;
160
+ /** Vertices a single morph can touch here — the ceiling on the merged-entry scratch buffer. */
161
+ maxMergeEntries: number;
162
+ }
163
+ export interface CrowdPlan {
164
+ lods: CrowdLodPlan[];
165
+ vertexBudget: number;
166
+ /** Bytes in EACH of the four pools (rest, restN, def, defN). */
167
+ poolBytes: number;
168
+ paletteBytes: number;
169
+ maxChars: number;
170
+ boneCount: number;
171
+ /** How many characters of the WORST rung fit the budget. 0 means the budget is unusable. */
172
+ worstCaseCapacity: number;
173
+ }
174
+ /**
175
+ * Validate the asset set and derive every buffer size from it.
176
+ *
177
+ * ⚠️ This checks every morph index against its rung's vertex count. That is ~1.9 M comparisons on
178
+ * the shipped kit and it happens ONCE, at load — cheap against the failure it catches, which is a
179
+ * target gathered for one rung being applied to another. That failure has no symptom except
180
+ * geometry exploding at whichever LOD the camera happens to reach, which is the worst possible
181
+ * place to start looking.
182
+ */
183
+ export declare function planCrowd(a: CrowdAssets): CrowdPlan;
184
+ /** Reusable accumulator for the CPU pre-merge. One per rung; `mergeTargets` leaves it clean. */
185
+ export interface MergeScratch {
186
+ vertCount: number;
187
+ /** `3·vertCount` weighted-delta accumulator. */
188
+ acc: Float32Array;
189
+ /** Vertices touched this merge, unsorted. */
190
+ touched: Uint32Array;
191
+ /** 1 where the vertex is already in `touched`. */
192
+ dirty: Uint8Array;
193
+ }
194
+ export declare function makeMergeScratch(vertCount: number): MergeScratch;
195
+ /** A character's whole morph, collapsed to one sparse list — see `mergeTargets`. */
196
+ export interface MergedMorph {
197
+ /** `count` LOD-local vertex indices, strictly ascending. */
198
+ index: Uint32Array;
199
+ /** `4·count` vec4-padded deltas, in the same order. */
200
+ delta: Float32Array;
201
+ count: number;
202
+ }
203
+ /**
204
+ * Collapse every weighted target at `lod` into ONE sparse (vertex, delta) list, on the CPU.
205
+ *
206
+ * ⚠️ THIS IS THE CORRECTNESS ARGUMENT FOR THE WHOLE MORPH PASS. The obvious GPU shape — one thread
207
+ * per (target, entry) doing `rest[v] += delta·w` — is a data race the moment two targets name the
208
+ * same vertex, which for a human is not an edge case: nose-width and nose-volume overlap almost
209
+ * entirely. The alternatives are an atomic add (f32 atomics are not in core WGSL), one dispatch per
210
+ * target (662 dispatches, and the ordering only works because each is a full barrier), or merging
211
+ * first. Merging first wins outright: the merged list names each vertex exactly ONCE, so a single
212
+ * dispatch has no ordering subtleties left to get wrong, and the cost lands on a path that runs at
213
+ * spawn and on a slider drag rather than sixty times a second.
214
+ *
215
+ * The weights are baked into the deltas here, so the GPU never sees a weight buffer or a target
216
+ * table at all — which also keeps ~30 MB of morph library out of VRAM.
217
+ *
218
+ * Output vertices are ASCENDING, so the same weights always produce a byte-identical upload.
219
+ */
220
+ export declare function mergeTargets(targets: CrowdTarget[][], weights: Float32Array, lod: number, scratch: MergeScratch): MergedMorph;
221
+ /** The morph pass's 16-byte uniform, written in one place so CPU and WGSL cannot disagree. */
222
+ export declare function morphParams(slot: number, vertCount: number, entryCount: number): Uint32Array;
223
+ /**
224
+ * Check a frame's instance buckets and return the total instance count.
225
+ *
226
+ * Overlapping buckets are the failure worth catching: two LODs pointing at the same records draw
227
+ * the same people twice with the wrong topology, which reads as flickering rather than as an error.
228
+ */
229
+ export declare function validateBuckets(records: Float32Array, byLod: CrowdBucket[], lodCount: number): number;
230
+ /**
231
+ * Write ONE instance record. The single CPU-side statement of the layout the WGSL `Rec` struct
232
+ * mirrors — a caller that packs 24 floats by hand has a second one, and the two drift.
233
+ *
234
+ * `model` is column-major, as everything else in this engine. `tint`'s W IS THE OPACITY: it is what
235
+ * `splitByAlpha` reads to route an instance to the blended pipeline, so an alpha below 1 needs
236
+ * nothing else set anywhere.
237
+ */
238
+ export declare function writeCrowdRecord(out: Float32Array, at: number, model: ArrayLike<number>, tint: ArrayLike<number>, layer: number, paletteSlot: number, poolSlot: number): void;
239
+ /** One `drawIndexed` — a maximal run of records at one LOD that are all opaque or all blended. */
240
+ export interface CrowdDraw {
241
+ lod: number;
242
+ /** First INSTANCE index — goes straight to drawIndexed's firstInstance. */
243
+ first: number;
244
+ count: number;
245
+ /** True ⇒ the source-alpha pipeline, drawn after every opaque run. */
246
+ blended: boolean;
247
+ }
248
+ /**
249
+ * Split each bucket into maximal runs of the same blend class, preserving order.
250
+ *
251
+ * ⚠️ RUNS, not a partition. `drawIndexed`'s firstInstance selects a CONTIGUOUS span of records, so
252
+ * an opaque record sitting between two translucent ones genuinely costs a third draw call — there
253
+ * is no way to express "these three, skipping the middle" in one call short of rewriting the buffer.
254
+ * A caller that cares therefore wants its translucent characters grouped at the end of their
255
+ * bucket, which is one comparison in whatever loop already writes the records. A caller that does
256
+ * not care still renders CORRECTLY, just with more draws, which is the right way round: the
257
+ * alternative — assuming one alpha per bucket — silently draws translucent people opaque.
258
+ */
259
+ export declare function splitByAlpha(records: Float32Array, byLod: readonly CrowdBucket[]): CrowdDraw[];
260
+ /**
261
+ * Bytes between consecutive skin-dispatch parameter blocks.
262
+ *
263
+ * 256 because that is WebGPU's DEFAULT `minUniformBufferOffsetAlignment` and an adapter may only
264
+ * report a SMALLER one (a smaller alignment is the better limit), so 256 is a legal dynamic offset
265
+ * everywhere. The block itself is 16 bytes; the rest is the alignment tax for being able to bind
266
+ * one buffer once and select a bucket's parameters with an offset instead of a bind group.
267
+ */
268
+ export declare const CROWD_SKIN_PARAM_STRIDE = 256;
269
+ /**
270
+ * The per-bucket uniform block for the skin dispatch: `vertCount, first, boneCount, pad`.
271
+ *
272
+ * ⚠️ `instCount` is NOT in here. The dispatch is 2-D — x covers the rung's vertices, y covers the
273
+ * bucket's instances — so the instance count is the y workgroup count and the shader reads
274
+ * `global_invocation_id.y` directly. A flat 1-D index over vertCount·instCount, which is the obvious
275
+ * shape, blows past the 65535 workgroups-per-dimension limit at a few hundred LOD0 characters.
276
+ */
277
+ export declare function skinParams(buckets: readonly CrowdBucket[], vertCountOf: readonly number[], boneCount: number): Uint32Array;
278
+ /** The three flags above, exported so a Node test can check them against the real WebGPU values. */
279
+ export declare const CROWD_STAGE_FLAGS: {
280
+ readonly VIS_VERTEX: 1;
281
+ readonly VIS_FRAGMENT: 2;
282
+ readonly VIS_COMPUTE: 4;
283
+ };
284
+ export declare const CROWD_BINDINGS: {
285
+ readonly morph: readonly [{
286
+ readonly binding: 0;
287
+ readonly visibility: 4;
288
+ readonly buffer: {
289
+ readonly type: "read-only-storage";
290
+ };
291
+ }, {
292
+ readonly binding: 1;
293
+ readonly visibility: 4;
294
+ readonly buffer: {
295
+ readonly type: "storage";
296
+ };
297
+ }, {
298
+ readonly binding: 2;
299
+ readonly visibility: 4;
300
+ readonly buffer: {
301
+ readonly type: "storage";
302
+ };
303
+ }, {
304
+ readonly binding: 3;
305
+ readonly visibility: 4;
306
+ readonly buffer: {
307
+ readonly type: "read-only-storage";
308
+ };
309
+ }, {
310
+ readonly binding: 4;
311
+ readonly visibility: 4;
312
+ readonly buffer: {
313
+ readonly type: "read-only-storage";
314
+ };
315
+ }, {
316
+ readonly binding: 5;
317
+ readonly visibility: 4;
318
+ readonly buffer: {
319
+ readonly type: "read-only-storage";
320
+ };
321
+ }, {
322
+ readonly binding: 6;
323
+ readonly visibility: 4;
324
+ readonly buffer: {
325
+ readonly type: "read-only-storage";
326
+ };
327
+ }, {
328
+ readonly binding: 7;
329
+ readonly visibility: 4;
330
+ readonly buffer: {
331
+ readonly type: "read-only-storage";
332
+ };
333
+ }, {
334
+ readonly binding: 8;
335
+ readonly visibility: 4;
336
+ readonly buffer: {
337
+ readonly type: "uniform";
338
+ };
339
+ }];
340
+ readonly skin: readonly [{
341
+ readonly binding: 0;
342
+ readonly visibility: 4;
343
+ readonly buffer: {
344
+ readonly type: "read-only-storage";
345
+ };
346
+ }, {
347
+ readonly binding: 1;
348
+ readonly visibility: 4;
349
+ readonly buffer: {
350
+ readonly type: "read-only-storage";
351
+ };
352
+ }, {
353
+ readonly binding: 2;
354
+ readonly visibility: 4;
355
+ readonly buffer: {
356
+ readonly type: "storage";
357
+ };
358
+ }, {
359
+ readonly binding: 3;
360
+ readonly visibility: 4;
361
+ readonly buffer: {
362
+ readonly type: "storage";
363
+ };
364
+ }, {
365
+ readonly binding: 4;
366
+ readonly visibility: 4;
367
+ readonly buffer: {
368
+ readonly type: "read-only-storage";
369
+ };
370
+ }, {
371
+ readonly binding: 5;
372
+ readonly visibility: 4;
373
+ readonly buffer: {
374
+ readonly type: "read-only-storage";
375
+ };
376
+ }, {
377
+ readonly binding: 6;
378
+ readonly visibility: 4;
379
+ readonly buffer: {
380
+ readonly type: "read-only-storage";
381
+ };
382
+ }, {
383
+ readonly binding: 7;
384
+ readonly visibility: 4;
385
+ readonly buffer: {
386
+ readonly type: "read-only-storage";
387
+ };
388
+ }, {
389
+ readonly binding: 8;
390
+ readonly visibility: 4;
391
+ readonly buffer: {
392
+ readonly type: "uniform";
393
+ readonly hasDynamicOffset: true;
394
+ readonly minBindingSize: 16;
395
+ };
396
+ }];
397
+ /** group 0 — the scene uniform, identical in shape to gpuSkin's so the two composite alike. */
398
+ readonly draw0: readonly [{
399
+ readonly binding: 0;
400
+ readonly visibility: number;
401
+ readonly buffer: {
402
+ readonly type: "uniform";
403
+ };
404
+ }];
405
+ /** group 1 — the SHARED cascaded sun shadow map, so a character and its ground agree. */
406
+ readonly draw1: readonly [{
407
+ readonly binding: 0;
408
+ readonly visibility: 2;
409
+ readonly texture: {
410
+ readonly sampleType: "depth";
411
+ readonly viewDimension: "2d-array";
412
+ };
413
+ }, {
414
+ readonly binding: 1;
415
+ readonly visibility: 2;
416
+ readonly sampler: {
417
+ readonly type: "comparison";
418
+ };
419
+ }];
420
+ /** group 2 — the shared skin atlas. ARRAY-dimensioned: the per-instance layer picks a tone. */
421
+ readonly draw2: readonly [{
422
+ readonly binding: 0;
423
+ readonly visibility: 2;
424
+ readonly texture: {
425
+ readonly sampleType: "float";
426
+ readonly viewDimension: "2d-array";
427
+ };
428
+ }, {
429
+ readonly binding: 1;
430
+ readonly visibility: 2;
431
+ readonly sampler: {
432
+ readonly type: "filtering";
433
+ };
434
+ }];
435
+ /**
436
+ * group 3 — the pooled geometry and the instance records, per rung.
437
+ *
438
+ * ⚠️ VERTEX-visible STORAGE buffers, and there is no vertex buffer at all. Positions cannot be an
439
+ * attribute here: the pool offset varies PER INSTANCE, and a vertex buffer is stepped by the
440
+ * vertex index alone. UVs could have been an attribute, but binding them here keeps every
441
+ * per-rung resource in one bind group and the pipeline free of a vertex layout to get wrong.
442
+ */
443
+ readonly draw3: readonly [{
444
+ readonly binding: 0;
445
+ readonly visibility: 1;
446
+ readonly buffer: {
447
+ readonly type: "read-only-storage";
448
+ };
449
+ }, {
450
+ readonly binding: 1;
451
+ readonly visibility: 1;
452
+ readonly buffer: {
453
+ readonly type: "read-only-storage";
454
+ };
455
+ }, {
456
+ readonly binding: 2;
457
+ readonly visibility: 1;
458
+ readonly buffer: {
459
+ readonly type: "read-only-storage";
460
+ };
461
+ }, {
462
+ readonly binding: 3;
463
+ readonly visibility: 1;
464
+ readonly buffer: {
465
+ readonly type: "read-only-storage";
466
+ };
467
+ }];
468
+ };
469
+ /**
470
+ * The two render pipelines' differing state, as data.
471
+ *
472
+ * ⚠️ `blended.cullMode` is 'back' and that is NOT cosmetic — it is the fix gpuSkin shipped in
473
+ * 0.14.9. With 'none' and no depth write, every triangle of a closed body blends: the far side of
474
+ * the torso, then the near side. How many layers survive at a pixel depends on what opaque geometry
475
+ * happens to sit BETWEEN them, so an opaque marker inside the body masks the far side there and
476
+ * nowhere else — which stamps the marker's silhouette into the skin as a hard-edged rectangle of
477
+ * different accumulated opacity. One front-facing layer per pixel is the fix. Overlapping SEPARATE
478
+ * surfaces (an arm across the torso) still blend twice, which is correct: two things to see through.
479
+ *
480
+ * ⚠️ `blended.depthWriteEnabled` is false. A translucent surface that writes depth occludes what is
481
+ * behind it, which is the one thing an opacity control exists to prevent. It still TESTS depth, so
482
+ * an opaque character in front still hides it.
483
+ *
484
+ * The OPAQUE pipeline keeps cullMode 'none' — a garment is often a single-sided shell and culling it
485
+ * would punch holes in a fully opaque crowd.
486
+ */
487
+ export declare const CROWD_PIPELINE_STATE: {
488
+ readonly opaque: {
489
+ readonly cullMode: "none";
490
+ readonly depthWriteEnabled: true;
491
+ readonly blend: null;
492
+ };
493
+ readonly blended: {
494
+ readonly cullMode: "back";
495
+ readonly depthWriteEnabled: false;
496
+ readonly blend: {
497
+ readonly color: {
498
+ readonly srcFactor: "src-alpha";
499
+ readonly dstFactor: "one-minus-src-alpha";
500
+ };
501
+ readonly alpha: {
502
+ readonly srcFactor: "zero";
503
+ readonly dstFactor: "one";
504
+ };
505
+ };
506
+ };
507
+ };
508
+ /** Floats in the draw pass's scene uniform. See `frame` for the field-by-field layout. */
509
+ export declare const CROWD_U_FLOATS: number;
510
+ /** The four vertex pools. rest/restN are morph output; def/defN are the per-frame skin output. */
511
+ export interface CrowdPools {
512
+ rest: GPUBuffer;
513
+ restN: GPUBuffer;
514
+ def: GPUBuffer;
515
+ defN: GPUBuffer;
516
+ }
517
+ export declare class GpuCrowdRenderer {
518
+ private device;
519
+ /** Swap-chain format. Held for the render pipeline the draw pass builds. */
520
+ readonly format: GPUTextureFormat;
521
+ private morphPipe;
522
+ private addPipe;
523
+ private normalPipe;
524
+ /**
525
+ * ⚠️ ONE EXPLICIT layout shared by all three compute pipelines, not `layout: 'auto'`. An auto
526
+ * layout is derived per PIPELINE from the bindings that entry point statically uses, so the three
527
+ * entry points here — which use overlapping but different subsets — would get three incompatible
528
+ * layouts, and the single per-LOD bind group below could only ever be used by one of them.
529
+ */
530
+ private morphBGL;
531
+ private morphLayout;
532
+ /** The per-frame skin pass. One dispatch per BUCKET, selected by a dynamic uniform offset. */
533
+ private skinPipe;
534
+ private skinBGL;
535
+ /**
536
+ * The instanced draw, and the same pipeline with source-alpha blending for `tint.w < 1`.
537
+ *
538
+ * ⚠️ ONE explicit pipeline layout for both, for the same reason the compute passes share theirs:
539
+ * two `layout: 'auto'` pipelines mint two distinct bind-group layouts even from identical shader
540
+ * code, and every bind group here is built once and reused by whichever pipeline draws it.
541
+ */
542
+ private drawPipe;
543
+ private blendPipe;
544
+ private drawBGL;
545
+ private uBuf;
546
+ private uBG;
547
+ /** Dummy 1x1 depth array + comparison sampler for the no-shadow path. Mirrors gpuSkin's. */
548
+ private dummyShadowView;
549
+ private dummyShadowSamp;
550
+ private shadowBG;
551
+ private lastSV;
552
+ private lastSS;
553
+ private skinSamp;
554
+ /** group 2, rebuilt only when the kit's atlas changes. */
555
+ private matBG;
556
+ private plan;
557
+ /** The CPU-side morph library. It never reaches the GPU — see `mergeTargets`. */
558
+ private targets;
559
+ private lodGpu;
560
+ private pools;
561
+ private paletteBuf;
562
+ private paramBuf;
563
+ /** Shared merged-morph upload target. Grown 1.5×; every LOD bind group is rebuilt when it moves. */
564
+ private mIdxBuf;
565
+ private mDeltaBuf;
566
+ private mergeCap;
567
+ private instBuf;
568
+ private instCap;
569
+ private buckets;
570
+ /** This frame's draw runs, opaque and blended interleaved in bucket order. See `splitByAlpha`. */
571
+ private draws;
572
+ /** Per-bucket skin uniforms, one CROWD_SKIN_PARAM_STRIDE block each. */
573
+ private skinParamBuf;
574
+ private skinParamCap;
575
+ /**
576
+ * Set whenever a buffer the per-rung bind groups point at is REPLACED (pools on a kit swap, the
577
+ * record buffer or the skin-param buffer on growth). Cleared by `ensureFrameBindGroups`, which
578
+ * runs at the top of `frame` — deferring the rebuild to there means a caller that grows the
579
+ * record buffer three times before drawing pays for one rebuild, not three.
580
+ */
581
+ private frameBGDirty;
582
+ private skin;
583
+ constructor(device: GPUDevice,
584
+ /** Swap-chain format. Held for the render pipeline the draw pass builds. */
585
+ format: GPUTextureFormat);
586
+ /** The rung geometry and pool sizes, once the assets are in. Null before `setAssets`. */
587
+ get assetPlan(): CrowdPlan | null;
588
+ /** The four pools, for the skin pass and for a harness that reads a slot back to check it. */
589
+ get vertexPools(): CrowdPools | null;
590
+ get palettes(): GPUBuffer | null;
591
+ get instances(): GPUBuffer | null;
592
+ get lodBuckets(): readonly CrowdBucket[];
593
+ /** This frame's draw runs, in submission order within each blend class. See `splitByAlpha`. */
594
+ get drawRuns(): readonly CrowdDraw[];
595
+ get skinTexture(): GPUTexture | null;
596
+ get lodCount(): number;
597
+ /** Index count and buffer for one rung — the instanced draw's two arguments. */
598
+ lodIndices(lod: number): {
599
+ buffer: GPUBuffer;
600
+ count: number;
601
+ } | null;
602
+ /**
603
+ * Upload the shared, immutable asset set: every rung's geometry, the pools, the palette buffer.
604
+ *
605
+ * Runs ONCE per kit — at load, and again only if a coarser kit replaces it. Nothing here is
606
+ * per-character or per-frame; a character is a slot plus a record, and that is the whole point.
607
+ */
608
+ setAssets(a: CrowdAssets): void;
609
+ private allocMergeBuffers;
610
+ private rebuildLodBindGroups;
611
+ /**
612
+ * Build the skin pass's group 0 and the draw pass's group 3 for every rung.
613
+ *
614
+ * Deferred to the first `frame` after anything they point at is replaced, because the record
615
+ * buffer only exists once `setInstances` has run and both groups hold it. Returns false — and
616
+ * leaves the dirty flag set — while any of the four resources is still missing, so a `frame`
617
+ * before `setAssets`/`setInstances` draws nothing rather than throwing on a null buffer.
618
+ */
619
+ private ensureFrameBindGroups;
620
+ private releaseAssets;
621
+ /**
622
+ * Shape one character into its pool slot. Called at spawn, on a LOD change, and on a slider drag
623
+ * — never per frame.
624
+ *
625
+ * `slot` is the VERTEX OFFSET the allocator handed back. `weights` is indexed by target id and
626
+ * may be shorter than the target library; missing entries read as 0.
627
+ *
628
+ * ⚠️ ONE SUBMIT PER CALL, deliberately. The merged list goes to a single shared scratch buffer, so
629
+ * two morphs recorded into one encoder would have the second overwrite the first's data before it
630
+ * ran. Batching a spawn storm therefore needs a scratch ring, not a shared encoder — which is
631
+ * worth building when spawning a thousand people in one frame is actually the shape of the
632
+ * problem, and is a silent corruption if faked before then.
633
+ */
634
+ morph(slot: number, lod: number, weights: Float32Array): void;
635
+ /**
636
+ * Upload this frame's instance records and their per-LOD buckets.
637
+ *
638
+ * Safe every frame: the buffer is REUSED whenever the count fits, and grows with headroom, the
639
+ * same rule gpuProps uses — a crowd re-buckets constantly as the camera moves, so reallocating
640
+ * per frame would cost more than the LOD saves.
641
+ */
642
+ setInstances(records: Float32Array, byLod: CrowdBucket[]): void;
643
+ /** `maxChars · boneCount` column-major bone matrices, flat. Uploaded whole, once per frame. */
644
+ setPalettes(p: Float32Array): void;
645
+ /**
646
+ * Skin every character in every bucket, then draw them — one dispatch per bucket, one
647
+ * `drawIndexed` per run of same-blend records at a rung.
648
+ *
649
+ * ⚠️ THE PARAMETER LIST IS `GpuSkinRenderer.frame`'s, exactly. The game composites both renderers
650
+ * into the same colour buffer, the same depth buffer and the same cascaded shadow map, and a
651
+ * crowd that took its sun or its fog in a different order would sit in a different scene from the
652
+ * fauna standing next to it. `load = true` composites over whatever is already there; `false`
653
+ * clears to `clear`.
654
+ */
655
+ 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;
656
+ }