ugly-game 0.15.2 → 0.15.3

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.
@@ -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 spare
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. objN = pre-rotation face normal.
317
- o.blk = (CUBE_POS[vi] + vec3(0.5, 0.5, 0.5)) * inst.scl.xyz;
318
- o.objN = CUBE_NRM[vi];
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; // spare
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() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.2",
3
+ "version": "0.15.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {