ugly-game 0.15.2 → 0.15.4
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/gpuCrowd.d.ts +11 -0
- package/dist/assets/gpuCrowd.js +29 -4
- package/dist/gpuShadow.d.ts +9 -0
- package/dist/gpuShadow.js +8 -6
- package/package.json +1 -1
|
@@ -899,6 +899,17 @@ export declare class GpuCrowdRenderer {
|
|
|
899
899
|
* character's current rung each frame without branching.
|
|
900
900
|
*/
|
|
901
901
|
enableFaceRig(slot: number, lod: number, dstSlot: number): void;
|
|
902
|
+
/**
|
|
903
|
+
* Copy `slot` (positions AND normals) into `dstSlot` — the seed the face pass then rewrites
|
|
904
|
+
* face vertices on top of. Called by `enableFaceRig`, and by `morph` whenever the slot is
|
|
905
|
+
* rigged (see the re-seed note there).
|
|
906
|
+
*
|
|
907
|
+
* ⚠️ VIA A STAGING BUFFER, because WebGPU REFUSES copyBufferToBuffer when the source and the
|
|
908
|
+
* destination are the SAME buffer — even for ranges that provably do not overlap. ("Source and
|
|
909
|
+
* destination are the same buffer.") Both slots live in the one rest pool, so the copy has to
|
|
910
|
+
* hop out and back.
|
|
911
|
+
*/
|
|
912
|
+
private seedFaceSlot;
|
|
902
913
|
/** Stop dispatching for this slot — it costs exactly what it cost before the rig existed. */
|
|
903
914
|
disableFaceRig(slot: number): void;
|
|
904
915
|
/**
|
package/dist/assets/gpuCrowd.js
CHANGED
|
@@ -2082,6 +2082,18 @@ export class GpuCrowdRenderer {
|
|
|
2082
2082
|
cp.dispatchWorkgroups(Math.ceil(l.plan.vertCount / 64));
|
|
2083
2083
|
cp.end();
|
|
2084
2084
|
dev.queue.submit([enc.finish()]);
|
|
2085
|
+
// ⚠️ A RIGGED FACE IS A SECOND COPY OF THIS SLOT, and it does not follow the morph on its
|
|
2086
|
+
// own. The face pass rewrites only face vertices per frame; every other vertex of the
|
|
2087
|
+
// animated slot keeps whatever the seed copy held, so a re-morph that skips the re-seed
|
|
2088
|
+
// draws the OLD body with the NEW face — stretched between the two morphs across the scalp,
|
|
2089
|
+
// a second head floating above the first. Any slider that moves the skull shows it (age is
|
|
2090
|
+
// simply the biggest); no caller remembered, because nothing in `morph`'s signature says a
|
|
2091
|
+
// copy exists. Owned HERE, not by the caller, so the rule cannot be forgotten a second time.
|
|
2092
|
+
// The rung must match: a LOD change re-rigs through `enableFaceRig`, and a copy sized for
|
|
2093
|
+
// the new rung aimed at the old rung's slot would overrun its stride.
|
|
2094
|
+
const rig = this.rigged.get(slot);
|
|
2095
|
+
if (rig?.lod === lod)
|
|
2096
|
+
this.seedFaceSlot(slot, lod, rig.dst);
|
|
2085
2097
|
}
|
|
2086
2098
|
// ── the per-frame face rig ───────────────────────────────────────────────────────────────────
|
|
2087
2099
|
/** Grow the weight and face-table buffers to hold `rows`, and rebuild the bind groups on them. */
|
|
@@ -2169,11 +2181,24 @@ export class GpuCrowdRenderer {
|
|
|
2169
2181
|
this.rigged.set(slot, { row, lod, dst: dstSlot });
|
|
2170
2182
|
if ((row + 1) * FACE_ROW_FLOATS > this.wCpu.length)
|
|
2171
2183
|
this.allocFaceBuffers(growCapacity(row + 1, this.wCpu.length / FACE_ROW_FLOATS));
|
|
2184
|
+
this.seedFaceSlot(slot, lod, dstSlot);
|
|
2185
|
+
}
|
|
2186
|
+
/**
|
|
2187
|
+
* Copy `slot` (positions AND normals) into `dstSlot` — the seed the face pass then rewrites
|
|
2188
|
+
* face vertices on top of. Called by `enableFaceRig`, and by `morph` whenever the slot is
|
|
2189
|
+
* rigged (see the re-seed note there).
|
|
2190
|
+
*
|
|
2191
|
+
* ⚠️ VIA A STAGING BUFFER, because WebGPU REFUSES copyBufferToBuffer when the source and the
|
|
2192
|
+
* destination are the SAME buffer — even for ranges that provably do not overlap. ("Source and
|
|
2193
|
+
* destination are the same buffer.") Both slots live in the one rest pool, so the copy has to
|
|
2194
|
+
* hop out and back.
|
|
2195
|
+
*/
|
|
2196
|
+
seedFaceSlot(slot, lod, dstSlot) {
|
|
2197
|
+
const l = maybe(this.lodGpu, lod);
|
|
2198
|
+
const pools = this.pools;
|
|
2199
|
+
if (!l || !pools)
|
|
2200
|
+
return;
|
|
2172
2201
|
const bytes = l.plan.slotVerts * 16; // the pools are arrays of vec4
|
|
2173
|
-
// ⚠️ VIA A STAGING BUFFER, because WebGPU REFUSES copyBufferToBuffer when the source and the
|
|
2174
|
-
// destination are the SAME buffer — even for ranges that provably do not overlap. ("Source and
|
|
2175
|
-
// destination are the same buffer.") Both slots live in the one rest pool, so the copy has to
|
|
2176
|
-
// hop out and back. One-time, at enable, so it costs nothing per frame.
|
|
2177
2202
|
const staging = this.device.createBuffer({
|
|
2178
2203
|
size: bytes,
|
|
2179
2204
|
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
|
package/dist/gpuShadow.d.ts
CHANGED
|
@@ -53,6 +53,15 @@ export interface CubeInstance {
|
|
|
53
53
|
* visibly re-patterning as you walk. The caller knows the stable coordinate; the shader does not.
|
|
54
54
|
*/
|
|
55
55
|
jitter?: number;
|
|
56
|
+
/**
|
|
57
|
+
* TEXTURE FIT, 0 or 1 (default 0). The in-block texture coordinate is multiplied by the instance
|
|
58
|
+
* scale so a MERGED LOD cube — one big cube standing in for scl³ sub-blocks — still shows its
|
|
59
|
+
* sub-blocks. An instance that IS a single block drawn at a registered scale ≠ 1 (a ship's hull
|
|
60
|
+
* voxel in the system frame, where the scale is frame registration, not a sub-block count) gets
|
|
61
|
+
* its atlas tile repeated scale× per face instead, which reads as a completely different material.
|
|
62
|
+
* Set this to 1 to keep exactly one tile per face however large the instance is drawn.
|
|
63
|
+
*/
|
|
64
|
+
texFit?: number;
|
|
56
65
|
}
|
|
57
66
|
/** Atlas layout: which ARRAY LAYER a material's top/side/bottom faces sample.
|
|
58
67
|
*
|
package/dist/gpuShadow.js
CHANGED
|
@@ -28,7 +28,7 @@ const MAX_CASCADES = 4;
|
|
|
28
28
|
const AO_MIN = 0.55;
|
|
29
29
|
const CULL_WG = 64; // compute-cull workgroup size
|
|
30
30
|
// Floats per instance: pos.xyz+hue, scl.xyz+emissive, rot quat, aux (tile, up, decalPos, decalKind),
|
|
31
|
-
// aux2 (occLo, occHi, jitter,
|
|
31
|
+
// aux2 (occLo, occHi, jitter, texFit).
|
|
32
32
|
//
|
|
33
33
|
// ⚠️ 20, NOT 17, AND THE PADDING IS NOT WASTE. `Inst` is read as a `array<Inst>` of vec4s, so WGSL
|
|
34
34
|
// rounds the struct's stride up to a multiple of 16 bytes: one more float would cost a whole vec4
|
|
@@ -82,7 +82,7 @@ struct Cam {
|
|
|
82
82
|
csm: vec4<f32>, // x = active cascade count · y = crossfade band in uv units
|
|
83
83
|
eye: vec4<f32>, // xyz = camera position in world space (material relief + specular); w unused
|
|
84
84
|
};
|
|
85
|
-
struct Inst { pos: vec4<f32>, scl: vec4<f32>, rot: vec4<f32>, aux: vec4<f32>, aux2: vec4<f32> }; // pos.w = hue (<0 ⇒ ground) · scl.w = emissive/alpha · rot = quaternion · aux.x = atlas tile (<0 ⇒ hue) · aux.y = up-face code · aux.z/aux.w = CONTACT DECAL (0,0 = none) · aux2.xy = 27-bit NEIGHBOUR OCCUPANCY split 14/13 (0,0 = unknown ⇒ no corner AO) · aux2.z = per-block albedo jitter · aux2.w
|
|
85
|
+
struct Inst { pos: vec4<f32>, scl: vec4<f32>, rot: vec4<f32>, aux: vec4<f32>, aux2: vec4<f32> }; // pos.w = hue (<0 ⇒ ground) · scl.w = emissive/alpha · rot = quaternion · aux.x = atlas tile (<0 ⇒ hue) · aux.y = up-face code · aux.z/aux.w = CONTACT DECAL (0,0 = none) · aux2.xy = 27-bit NEIGHBOUR OCCUPANCY split 14/13 (0,0 = unknown ⇒ no corner AO) · aux2.z = per-block albedo jitter · aux2.w = texFit (≠0 ⇒ one atlas tile per face, texture coords NOT scaled by inst.scl)
|
|
86
86
|
@group(0) @binding(0) var<uniform> cam: Cam;
|
|
87
87
|
@group(0) @binding(1) var<storage, read> insts: array<Inst>;
|
|
88
88
|
|
|
@@ -313,9 +313,11 @@ fn faceVec(code: f32) -> vec3<f32> {
|
|
|
313
313
|
o.emis = inst.scl.w;
|
|
314
314
|
// OBJECT-space block coord (per-sub-block units, anchored to the model, NOT world) so per-block AO moves +
|
|
315
315
|
// rotates with the instance (ships/creatures/plants) instead of sliding over a world-anchored grid; scale
|
|
316
|
-
// by inst.scl so a merged LOD cube (scl>1) still shows its sub-blocks
|
|
317
|
-
|
|
318
|
-
|
|
316
|
+
// by inst.scl so a merged LOD cube (scl>1) still shows its sub-blocks — UNLESS aux2.w (texFit) says the
|
|
317
|
+
// instance is ONE block drawn at a registered scale, where the multiply would just repeat its tile scale×.
|
|
318
|
+
let tscl = select(inst.scl.xyz, vec3<f32>(1.0, 1.0, 1.0), vec3<bool>(inst.aux2.w != 0.0));
|
|
319
|
+
o.blk = (CUBE_POS[vi] + vec3(0.5, 0.5, 0.5)) * tscl;
|
|
320
|
+
o.objN = CUBE_NRM[vi]; // objN = pre-rotation face normal
|
|
319
321
|
o.tile = inst.aux.x; o.upc = inst.aux.y; o.decal = inst.aux.zw;
|
|
320
322
|
// The 27-bit occupancy mask, reassembled from the 14/13 split fill() had to make because an f32
|
|
321
323
|
// is exact only to 2^24.
|
|
@@ -1121,7 +1123,7 @@ export class GpuShadowRenderer {
|
|
|
1121
1123
|
scratch[o + 16] = occ & 0x3fff;
|
|
1122
1124
|
scratch[o + 17] = (occ / 0x4000) | 0;
|
|
1123
1125
|
scratch[o + 18] = c.jitter ?? 0;
|
|
1124
|
-
scratch[o + 19] = 0; //
|
|
1126
|
+
scratch[o + 19] = c.texFit ?? 0; // texFit: one atlas tile per face at any draw scale (see CubeInstance.texFit)
|
|
1125
1127
|
}
|
|
1126
1128
|
}
|
|
1127
1129
|
makeBindGroups() {
|