ugly-game 0.14.10 → 0.14.11

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.
@@ -302,7 +302,7 @@ export class GpuSkinRenderer {
302
302
  p.defNB.destroy();
303
303
  p.colB.destroy();
304
304
  p.uvB.destroy();
305
- p.uv2B.destroy();
305
+ p.uv2B?.destroy();
306
306
  p.idxB.destroy();
307
307
  p.uBuf.destroy();
308
308
  p.palB.destroy();
@@ -333,14 +333,17 @@ export class GpuSkinRenderer {
333
333
  // A zero-filled UV buffer when the caller has none: the white fallback samples to 1 at any
334
334
  // coordinate, so the attribute still has to EXIST but its contents cannot matter.
335
335
  const uvB = mk(c.uvs && c.uvs.length >= n * 2 ? c.uvs : new Float32Array(n * 2), U.VERTEX | U.COPY_DST);
336
- // Falls back to `uvs`, then to zeros. The white tint samples to 1 at any coordinate, so the
337
- // attribute must EXIST but its contents cannot matter.
338
- const uv2Src = c.uvs2 && c.uvs2.length >= n * 2
339
- ? c.uvs2
340
- : c.uvs && c.uvs.length >= n * 2
341
- ? c.uvs
342
- : new Float32Array(n * 2);
343
- const uv2B = mk(uv2Src, U.VERTEX | U.COPY_DST);
336
+ // ⚠️ NULL when the caller has no `uvs2` — NOT a second buffer holding a copy of `uvs`.
337
+ //
338
+ // `setCreatures` tears down and rebuilds every buffer on each call and all-mine-sky calls it
339
+ // EVERY FRAME for EVERY creature. Allocating this unconditionally charged every caller in the
340
+ // game — none of which pass `uvs2` — an extra `createBuffer` plus a `writeBuffer` of the same
341
+ // n*2 floats, per creature, per frame, for a buffer whose contents cannot matter: with no
342
+ // tint the 1x1 white samples to 1 at any coordinate. The attribute still has to EXIST, so
343
+ // slot 4 binds `uvB` instead; WebGPU is happy to see the same GPUBuffer in two vertex slots.
344
+ const uv2B = c.uvs2 && c.uvs2.length >= n * 2
345
+ ? mk(c.uvs2, U.VERTEX | U.COPY_DST)
346
+ : null;
344
347
  const tex = c.tex ?? this.whiteTex;
345
348
  const tex2 = c.tex2 ?? this.whiteTex;
346
349
  const tint = c.tint ?? this.whiteTex;
@@ -495,7 +498,10 @@ export class GpuSkinRenderer {
495
498
  rp.setVertexBuffer(1, p.colB);
496
499
  rp.setVertexBuffer(2, p.defNB);
497
500
  rp.setVertexBuffer(3, p.uvB);
498
- rp.setVertexBuffer(4, p.uv2B);
501
+ // Slot 4 falls back to the UV buffer when there is no second set — same buffer, two slots,
502
+ // which WebGPU permits. Without a tint texture the shader samples 1x1 white and the
503
+ // coordinates it reads cannot affect the result.
504
+ rp.setVertexBuffer(4, p.uv2B ?? p.uvB);
499
505
  rp.setBindGroup(2, p.matBG);
500
506
  rp.setIndexBuffer(p.idxB, 'uint32');
501
507
  rp.drawIndexed(p.idxCount);
@@ -11,19 +11,6 @@ export interface CubeInstance {
11
11
  rot?: [number, number, number, number];
12
12
  tile?: number;
13
13
  up?: number;
14
- /**
15
- * CONTACT DECAL, packed. Both default to 0, which is exactly what fill() already wrote into these
16
- * two slots, so an instance that omits them is byte-identical to one built before decals existed.
17
- *
18
- * decalPos = quantised centre of the disturbance in THIS block's own face-local frame
19
- * decalKind = kind + per-prop style + radius
20
- *
21
- * The packing lives with the game that derives it (see the consumer's shared/decorDecal.ts); the
22
- * renderer only unpacks. Keeping the format there rather than here is deliberate: it is a
23
- * statement about props and soil, not about cubes.
24
- */
25
- decalPos?: number;
26
- decalKind?: number;
27
14
  }
28
15
  /** Atlas layout: which ARRAY LAYER a material's top/side/bottom faces sample.
29
16
  *
@@ -73,15 +60,6 @@ export declare class GpuShadowRenderer {
73
60
  private atlasSampler;
74
61
  private tileLayerBuf;
75
62
  private useAtlas;
76
- /**
77
- * How much of the per-voxel edge AO survives on ATLAS-textured blocks, 0..1.
78
- *
79
- * Zero by default, which is the behaviour every existing caller already has: the fragment does
80
- * `mix(1.0, blockShade, 0.0)`, which is exactly 1.0. Textured terrain has therefore had no
81
- * per-voxel AO at all — the full term reads as an inked grid, so it was dropped rather than
82
- * softened, and nothing replaced it.
83
- */
84
- private atlasAO;
85
63
  private alphaPipe;
86
64
  private alphaBGL;
87
65
  private overlayBuf;
@@ -135,14 +113,6 @@ export declare class GpuShadowRenderer {
135
113
  * distinct array layers; a `CubeInstance.tile` of that material id + its `up`-face code selects the
136
114
  * right layer in-shader. `tex` must be a 2d texture with at least (max layer + 1) array layers.
137
115
  * Call once after the texture is uploaded; instances with `tile < 0` still use the flat hue path. */
138
- /**
139
- * Soften the per-voxel edge AO back on for textured blocks. 0 (the default) is off entirely.
140
- *
141
- * Separate from `setAtlas` on purpose: the atlas is an ASSET and this is a LOOK, and a renderer
142
- * that made you re-upload a 2816² texture to change a shading constant would be one nobody
143
- * adjusted. Safe to call every frame — it writes one float into the camera uniform.
144
- */
145
- setAtlasAO(strength: number): void;
146
116
  setAtlas(tex: GPUTexture, layout: AtlasLayout): void;
147
117
  /** Static scene: sizes the buffer to exactly these instances. */
148
118
  setScene(instances: CubeInstance[]): void;
package/dist/gpuShadow.js CHANGED
@@ -67,11 +67,11 @@ struct Cam {
67
67
  sun: vec4<f32>, // xyz = direction light travels, w = ambient
68
68
  sunCol: vec4<f32>, // xyz = sun colour, w = shadow map size (texels)
69
69
  tint: vec4<f32>, // rgb = per-planet tint · w = tint strength (0 = none)
70
- atlas: vec4<f32>, // x = useAtlas (1/0) · y = how much per-voxel AO survives on textured blocks (0 = none)
70
+ atlas: vec4<f32>, // x = useAtlas (1/0)
71
71
  up: vec4<f32>, // xyz = local gravity up (for hemisphere face-shading readability); w = linear-HDR flag
72
72
  csm: vec4<f32>, // x = active cascade count · y = crossfade band in uv units
73
73
  };
74
- struct Inst { pos: vec4<f32>, scl: vec4<f32>, rot: vec4<f32>, aux: 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; see setAtlasAO/CubeInstance.decal*)
74
+ struct Inst { pos: vec4<f32>, scl: vec4<f32>, rot: vec4<f32>, aux: vec4<f32> }; // pos.w = hue (<0 ⇒ ground) · scl.w = emissive/alpha · rot = quaternion · aux.x = atlas tile (<0 ⇒ hue) · aux.y = up-face code
75
75
  @group(0) @binding(0) var<uniform> cam: Cam;
76
76
  @group(0) @binding(1) var<storage, read> insts: array<Inst>;
77
77
 
@@ -229,7 +229,7 @@ struct GiGrid { org: vec4<f32>, dim: vec4<f32> };
229
229
  @group(0) @binding(9) var<storage, read> probes: array<vec4<f32>>;
230
230
  ${GI_WGSL}
231
231
 
232
- struct VOut { @builtin(position) clip: vec4<f32>, @location(0) world: vec3<f32>, @location(1) nrm: vec3<f32>, @location(2) hue: f32, @location(3) emis: f32, @location(4) blk: vec3<f32>, @location(5) objN: vec3<f32>, @location(6) tile: f32, @location(7) upc: f32, @location(8) @interpolate(flat) decal: vec2<f32> };
232
+ struct VOut { @builtin(position) clip: vec4<f32>, @location(0) world: vec3<f32>, @location(1) nrm: vec3<f32>, @location(2) hue: f32, @location(3) emis: f32, @location(4) blk: vec3<f32>, @location(5) objN: vec3<f32>, @location(6) tile: f32, @location(7) upc: f32 };
233
233
 
234
234
  fn faceVec(code: f32) -> vec3<f32> {
235
235
  let c = i32(code);
@@ -252,7 +252,7 @@ fn faceVec(code: f32) -> vec3<f32> {
252
252
  // by inst.scl so a merged LOD cube (scl>1) still shows its sub-blocks. objN = pre-rotation face normal.
253
253
  o.blk = (CUBE_POS[vi] + vec3(0.5, 0.5, 0.5)) * inst.scl.xyz;
254
254
  o.objN = CUBE_NRM[vi];
255
- o.tile = inst.aux.x; o.upc = inst.aux.y; o.decal = inst.aux.zw;
255
+ o.tile = inst.aux.x; o.upc = inst.aux.y;
256
256
  return o;
257
257
  }
258
258
 
@@ -344,12 +344,10 @@ fn fixedFill(N: vec3<f32>, up: vec3<f32>) -> f32 {
344
344
  // pattern is anchored to the model's own block grid and translates/rotates with the instance.
345
345
  let an = abs(i.objN);
346
346
  var fx: f32; var fz: f32;
347
- var bx: f32; var bz: f32; // the SAME pair unwrapped — fract() wraps at the far block edge, which
348
- // a texture hides and a decal would show as a hard line through itself
349
347
  var dfx: vec2<f32>; var dfz: vec2<f32>; // (ddx, ddy) of each in-face axis, selected alongside it
350
- if (an.y >= an.x && an.y >= an.z) { fx = fract(i.blk.x); fz = fract(i.blk.z); bx = i.blk.x; bz = i.blk.z; dfx = vec2(dblkx.x, dblky.x); dfz = vec2(dblkx.z, dblky.z); }
351
- else if (an.x >= an.z) { fx = fract(i.blk.y); fz = fract(i.blk.z); bx = i.blk.y; bz = i.blk.z; dfx = vec2(dblkx.y, dblky.y); dfz = vec2(dblkx.z, dblky.z); }
352
- else { fx = fract(i.blk.x); fz = fract(i.blk.y); bx = i.blk.x; bz = i.blk.y; dfx = vec2(dblkx.x, dblky.x); dfz = vec2(dblkx.y, dblky.y); }
348
+ if (an.y >= an.x && an.y >= an.z) { fx = fract(i.blk.x); fz = fract(i.blk.z); dfx = vec2(dblkx.x, dblky.x); dfz = vec2(dblkx.z, dblky.z); }
349
+ else if (an.x >= an.z) { fx = fract(i.blk.y); fz = fract(i.blk.z); dfx = vec2(dblkx.y, dblky.y); dfz = vec2(dblkx.z, dblky.z); }
350
+ else { fx = fract(i.blk.x); fz = fract(i.blk.y); dfx = vec2(dblkx.x, dblky.x); dfz = vec2(dblkx.y, dblky.y); }
353
351
  var base = select(mix(vec3(0.34), hsv(i.hue), 0.62), vec3(0.6, 0.62, 0.66), i.hue < 0.0);
354
352
  if (cam.atlas.x > 0.5 && i.tile >= 0.0) { // ATLAS: pick top/side/bottom LAYER from the face vs the up axis
355
353
  let d = dot(i.objN, faceVec(i.upc));
@@ -364,55 +362,9 @@ fn fixedFill(N: vec3<f32>, up: vec3<f32>) -> f32 {
364
362
  let texc = textureSampleGrad(atlasTex, atlasSamp, uv, layer, vec2(dfx.x, dfz.x), vec2(dfx.y, dfz.y)).rgb;
365
363
  base = mix(texc, texc * cam.tint.rgb, cam.tint.w); // per-planet tint
366
364
  }
367
- // ── PROP CONTACT DECAL ────────────────────────────────────────────────────────────────────────
368
- // A plant on a 1 m cube reads as PASTED ON because the block under it is untouched: the same flat
369
- // grass runs up to the trunk and stops. This stamps the ground the prop actually disturbed onto
370
- // the block it stands on AND the blocks around it, and pools a little darkness where they meet.
371
- //
372
- // The pattern coordinate is p = (in-face position) - (decal centre), i.e. metres FROM THE PROP.
373
- // That is what makes the bleed work with no shared state: every block the same prop splatted
374
- // stores the centre in ITS OWN frame, so p is the same world vector in all of them and the falloff
375
- // is continuous across block and chunk boundaries.
376
- var soil = 0.0;
377
- var contact = 1.0;
378
- let dpos = u32(i.decal.x);
379
- let dkind = u32(i.decal.y);
380
- if (dkind != 0u) {
381
- let du = f32(dpos >> 8u) * (1.0 / 32.0) - 4.0;
382
- let dv = f32(dpos & 255u) * (1.0 / 32.0) - 4.0;
383
- let rad = f32(dkind >> 10u) * (1.0 / 32.0);
384
- let dtop = dot(i.objN, faceVec(i.upc));
385
- if (dtop > 0.5 && rad > 0.0) { // TOP faces only: soil on a cliff wall is a stripe, not dirt
386
- let t = clamp(length(vec2(bx, bz) - vec2(du, dv)) / rad, 0.0, 1.0);
387
- // The plateau, not just the falloff. At 0.30 the soil was full only inside the inner third of
388
- // the radius -- which is under the trunk, where nothing can see it -- so the decal read as pure
389
- // contact shading and the DIRT never showed. Holding it out to 0.55 puts real soil in the
390
- // visible ring around the stem, which is the thing this feature is named for.
391
- soil = 1.0 - smoothstep(0.55, 1.0, t);
392
- // CONTACT AO — the load-bearing half. The pasted-on read is largely the MISSING SHADOW where
393
- // a prop meets the ground; SSAO gives a pixel or two, this gives the metre-scale pool a real
394
- // root ball would.
395
- contact = 1.0 - 0.42 * (1.0 - smoothstep(0.0, 0.85, t));
396
- }
397
- }
398
- // MULTIPLICATIVE, so the atlas's own grain and the planet tint survive underneath. A decal that
399
- // REPLACED the colour would trade one pasted-on look for another and would need a per-biome
400
- // palette to sit right on grass and sand and ash and snow; darkening and warming needs none.
401
- // Warm as well as dark. A near-neutral multiply just dims the ground, and dim grass still reads as
402
- // grass; pulling blue down hardest is what makes the eye call it earth rather than shadow. Still a
403
- // MULTIPLY, so the atlas grain and the planet tint survive and no per-biome palette is needed.
404
- base = base * mix(vec3(1.0), vec3(0.72, 0.52, 0.34), soil);
405
365
  // per-block edge AO makes each voxel visible on FLAT-hue cubes, but reads as a hard GRID over textures — so the
406
- // atlas path dropped it ENTIRELY, which left textured terrain with no per-voxel AO at all: only SSAO, which
407
- // resolves a pixel or two of crease and nothing at the metre scale. The result is a surface that reads as a slab,
408
- // and anything standing on it reads as pasted on.
409
- //
410
- // cam.atlas.y is how much of the term survives on textured blocks. 0 is the DEFAULT and reproduces the old
411
- // behaviour exactly -- mix(1, bs, 0) is 1.0, bit for bit -- so a caller that never calls setAtlasAO is unchanged.
412
- // Around 0.35, EDGE_DARK 0.6 yields a floor of 0.86: enough that a cube reads as a cube, far short of the inked
413
- // grid the full term draws. (No backticks in here: this is inside a JS template literal.)
414
- let bs = blockShade(fx, fz);
415
- let ao = select(bs, mix(1.0, bs, cam.atlas.y), cam.atlas.x > 0.5 && i.tile >= 0.0) * contact;
366
+ // atlas path drops it entirely (the texture already supplies surface detail).
367
+ let ao = select(blockShade(fx, fz), 1.0, cam.atlas.x > 0.5 && i.tile >= 0.0);
416
368
  // LIGHTING = fixed directional FILL (always on, reads 3D shape in the dark) + the sun KEY (primary, shadowed).
417
369
  // cam.sun.w is the fill/ambient brightness knob; the fill's directional term (0.5..1.35) keeps every face's
418
370
  // orientation legible day or night, while the sun adds bright, shadow-casting key light on top during the day.
@@ -476,15 +428,6 @@ export class GpuShadowRenderer {
476
428
  atlasSampler;
477
429
  tileLayerBuf;
478
430
  useAtlas = 0;
479
- /**
480
- * How much of the per-voxel edge AO survives on ATLAS-textured blocks, 0..1.
481
- *
482
- * Zero by default, which is the behaviour every existing caller already has: the fragment does
483
- * `mix(1.0, blockShade, 0.0)`, which is exactly 1.0. Textured terrain has therefore had no
484
- * per-voxel AO at all — the full term reads as an inked grid, so it was dropped rather than
485
- * softened, and nothing replaced it.
486
- */
487
- atlasAO = 0;
488
431
  alphaPipe;
489
432
  alphaBGL; // kept so the overlay buffer can grow and rebind on demand
490
433
  overlayBuf;
@@ -917,8 +860,8 @@ export class GpuShadowRenderer {
917
860
  scratch[o + 11] = r ? r[3] : 1; // quaternion, default identity
918
861
  scratch[o + 12] = c.tile ?? -1;
919
862
  scratch[o + 13] = c.up ?? 1;
920
- scratch[o + 14] = c.decalPos ?? 0;
921
- scratch[o + 15] = c.decalKind ?? 0; // aux: atlas tile id, up-face code, contact decal (0 = none)
863
+ scratch[o + 14] = 0;
864
+ scratch[o + 15] = 0; // aux: atlas tile id + up-face code
922
865
  }
923
866
  }
924
867
  makeBindGroups() {
@@ -955,16 +898,6 @@ export class GpuShadowRenderer {
955
898
  * distinct array layers; a `CubeInstance.tile` of that material id + its `up`-face code selects the
956
899
  * right layer in-shader. `tex` must be a 2d texture with at least (max layer + 1) array layers.
957
900
  * Call once after the texture is uploaded; instances with `tile < 0` still use the flat hue path. */
958
- /**
959
- * Soften the per-voxel edge AO back on for textured blocks. 0 (the default) is off entirely.
960
- *
961
- * Separate from `setAtlas` on purpose: the atlas is an ASSET and this is a LOOK, and a renderer
962
- * that made you re-upload a 2816² texture to change a shading constant would be one nobody
963
- * adjusted. Safe to call every frame — it writes one float into the camera uniform.
964
- */
965
- setAtlasAO(strength) {
966
- this.atlasAO = Math.max(0, Math.min(1, strength));
967
- }
968
901
  setAtlas(tex, layout) {
969
902
  this.atlasView = tex.createView({ dimension: '2d-array' });
970
903
  const ids = Object.keys(layout.tiles).map(Number);
@@ -1181,7 +1114,6 @@ export class GpuShadowRenderer {
1181
1114
  this.cam[S + 10] = tint[2];
1182
1115
  this.cam[S + 11] = tint[3];
1183
1116
  this.cam[S + 12] = this.useAtlas;
1184
- this.cam[S + 13] = this.atlasAO;
1185
1117
  this.cam[S + 16] = up[0];
1186
1118
  this.cam[S + 17] = up[1];
1187
1119
  this.cam[S + 18] = up[2];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.14.10",
3
+ "version": "0.14.11",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {