ugly-game 0.15.12 → 0.15.14

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.
@@ -109,6 +109,7 @@ export declare const ROLE_FACET = 4;
109
109
  export declare const ROLE_FRIM = 5;
110
110
  export declare const ROLE_FMID = 6;
111
111
  export declare const ROLE_CARVE = 7;
112
+ export declare const ROLE_BASE = 8;
112
113
  export interface BevelCube {
113
114
  /** Which of the 8 sharp corners each vertex sits on — always (±0.5, ±0.5, ±0.5), except a fan
114
115
  * hub, which sits at its face centre. */
@@ -237,6 +238,30 @@ export declare function case3(mask: number, a: readonly [number, number, number]
237
238
  * neighbour retreats its own rim by the same b, which is the same condition. See bevelVertex.
238
239
  */
239
240
  export declare function carveOpen(mask: number, home: readonly [number, number, number], corner: readonly [number, number, number]): number;
241
+ /**
242
+ * THE BASE CORNER — one convex edge meeting two concave ones, asked by any of the eight cells.
243
+ * Returns the direction of the ALL-SOLID layer, or null.
244
+ *
245
+ * A block standing on a plane, at its base: the block's vertical edge is convex and chamfered, and
246
+ * its two junctions with the plane are concave and filleted. Reported from production as "all convex
247
+ * edges that merge with two concave edges in a corner look broken" — the fillets run along each wall
248
+ * and stop dead at the block's vertical edge instead of wrapping it, leaving a notch you can see
249
+ * through. 83% of every corner in a real terrain sample that does not close.
250
+ */
251
+ export declare function baseAt(mask: number, corner: readonly [number, number, number]): [number, number, number] | null;
252
+ /**
253
+ * …and whether THIS cube is the one that emits the patch: the cell of the flat surface that sits on
254
+ * the 3D diagonal from the block.
255
+ *
256
+ * ⚠️ THE FLAT SURFACE OWNS IT, NOT THE BLOCK, and that is not arbitrary. The patch is a piece of
257
+ * FILLET wrapping the block's corner, and the design's rule for fillets is that each half is emitted
258
+ * by the cube whose face it grows out of. Emitting the whole thing from the block put its shading
259
+ * normal on a face the geometry does not lie on — it hangs BELOW the block — and it shipped as black
260
+ * wedges. From the surface cell the normal is that cell's own top face, which is where the patch
261
+ * actually sits, and bevelConsistent's shading check passes by construction rather than by choice.
262
+ * The diagonal cell is the one neither wall's fillet already covers.
263
+ */
264
+ export declare function baseOwner(mask: number, corner: readonly [number, number, number]): [number, number, number] | null;
240
265
  /**
241
266
  * THE SAME INSIDE CORNER, ASKED BY ANY OF THE EIGHT CELLS — the direction of the all-air layer, or
242
267
  * null. `carveOpen` can only be asked by the ONE cube whose exposed face turns the corner; this is
package/dist/gpuShadow.js CHANGED
@@ -97,7 +97,8 @@ export const BEVEL_VERTS = 36 +
97
97
  12 * 6 * BEVEL_SEG +
98
98
  8 * 3 * BEVEL_SEG * BEVEL_SEG +
99
99
  144 +
100
- 8 * 3 * (2 * BEVEL_SEG + 1);
100
+ 8 * 3 * (2 * BEVEL_SEG + 1) +
101
+ 8 * 12;
101
102
  /** What a vertex is, which decides how it is allowed to move. */
102
103
  export const ROLE_SHARP = 0; // one of the 36 plain quad vertices — only alive when bevel == 0
103
104
  export const ROLE_CENTER = 1; // a face fan's hub; never moves
@@ -107,6 +108,7 @@ export const ROLE_FACET = 4; // a corner facet's vertex
107
108
  export const ROLE_FRIM = 5; // a fillet half-band's foot, on the face it grows out of
108
109
  export const ROLE_FMID = 6; // a fillet half-band's crest, at the 45° line OUTSIDE the cube
109
110
  export const ROLE_CARVE = 7; // the patch that radiuses an INSIDE corner where two chamfers meet
111
+ export const ROLE_BASE = 8; // where ONE convex edge lands among TWO concave ones — see section 7
110
112
  // THE CHAMFERED CUBE — a cube with all twelve edges cut back, where each cut COLLAPSES to a sharp
111
113
  // corner unless that edge is actually exposed to air or water.
112
114
  //
@@ -403,6 +405,37 @@ function buildBevelCube() {
403
405
  for (const v of [Q[0], Q[i], Q[i + 1]])
404
406
  push([...c], h, ROLE_CARVE, [...v]);
405
407
  }
408
+ // ── 7. BASE CORNERS — one convex edge landing among two concave ones: a block's foot on a plane.
409
+ //
410
+ // Reported from production: "all convex edges that merge with two concave edges in a corner look
411
+ // broken." The two wall fillets run along each face and stop dead at the block's vertical edge
412
+ // instead of wrapping it, and the notch between them is a hole.
413
+ //
414
+ // Six points, every one already emitted by something else, and ONE new side — the diagonal across
415
+ // the flat surface that carries the fillet's foot around the chamfered corner. With the corner at
416
+ // c, h pointing away from the solid layer (up, out of the surface) and fa, fb the two horizontal
417
+ // directions away from the block:
418
+ //
419
+ // 0 c + conc·fb this cell's own fillet foot, coming in along fb
420
+ // 1 c - bevel·fa + (conc/2)(fb + h) the crest, where the two halves must meet
421
+ // 2 c - bevel·fa + conc·h the block's fillet foot, on its chamfered face
422
+ // 3 c - bevel·fb + conc·h the same on the other face
423
+ // 4 c + (conc/2)(fa + h) - bevel·fb the crest on that side
424
+ // 5 c + conc·fa the other fillet foot
425
+ //
426
+ // ⚠️ IT COLLAPSES ENTIRELY WITHOUT A FILLET. This patch carries the FILLET around the chamfer, so
427
+ // with conc = 0 there is nothing to carry, and its degenerate form is a triangle lying in the flat
428
+ // surface's own plane — coplanar with the buried face under the block, 76 overlaps on a random
429
+ // field. See bevelVertex.
430
+ for (const sx of [-0.5, 0.5])
431
+ for (const sy of [-0.5, 0.5])
432
+ for (const sz of [-0.5, 0.5]) {
433
+ const c = [sx, sy, sz];
434
+ const hp = [Math.sign(sx), 0, 0]; // placeholder; the shader resolves it from the mask
435
+ for (let i = 1; i <= 4; i++)
436
+ for (const q of [0, i, i + 1])
437
+ push([...c], hp, ROLE_BASE, [q, 0, 0]);
438
+ }
406
439
  const wv = (a) => a.map((p) => `vec3<f32>(${p[0]},${p[1]},${p[2]})`).join(', ');
407
440
  return {
408
441
  corner,
@@ -588,6 +621,73 @@ export function carveOpen(mask, home, corner) {
588
621
  }
589
622
  /** Which axis a signed unit vector lies on. */
590
623
  const cAx = (v) => v[0] !== 0 ? 0 : v[1] !== 0 ? 1 : 2;
624
+ /**
625
+ * THE BASE CORNER — one convex edge meeting two concave ones, asked by any of the eight cells.
626
+ * Returns the direction of the ALL-SOLID layer, or null.
627
+ *
628
+ * A block standing on a plane, at its base: the block's vertical edge is convex and chamfered, and
629
+ * its two junctions with the plane are concave and filleted. Reported from production as "all convex
630
+ * edges that merge with two concave edges in a corner look broken" — the fillets run along each wall
631
+ * and stop dead at the block's vertical edge instead of wrapping it, leaving a notch you can see
632
+ * through. 83% of every corner in a real terrain sample that does not close.
633
+ */
634
+ export function baseAt(mask, corner) {
635
+ if (mask === 0)
636
+ return null;
637
+ const s = [Math.sign(corner[0]), Math.sign(corner[1]), Math.sign(corner[2])];
638
+ for (let k = 0; k < 3; k++) {
639
+ const j = [0, 1, 2].filter((i) => i !== k);
640
+ let far = 0;
641
+ let near = 0;
642
+ for (const a of [0, 1])
643
+ for (const b of [0, 1]) {
644
+ const off = [0, 0, 0];
645
+ off[j[0]] = a ? s[j[0]] : 0;
646
+ off[j[1]] = b ? s[j[1]] : 0;
647
+ const fo = [off[0], off[1], off[2]];
648
+ fo[k] = s[k];
649
+ far += occSolid(mask, fo);
650
+ near += a === 0 && b === 0 ? 1 : occSolid(mask, off);
651
+ }
652
+ const g = [0, 0, 0];
653
+ if (far === 4 && near === 1) {
654
+ g[k] = s[k];
655
+ return g;
656
+ } // this cube stands alone: the block
657
+ if (near === 4 && far === 1) {
658
+ g[k] = -s[k];
659
+ return g;
660
+ } // this cube is part of the surface
661
+ }
662
+ return null;
663
+ }
664
+ /**
665
+ * …and whether THIS cube is the one that emits the patch: the cell of the flat surface that sits on
666
+ * the 3D diagonal from the block.
667
+ *
668
+ * ⚠️ THE FLAT SURFACE OWNS IT, NOT THE BLOCK, and that is not arbitrary. The patch is a piece of
669
+ * FILLET wrapping the block's corner, and the design's rule for fillets is that each half is emitted
670
+ * by the cube whose face it grows out of. Emitting the whole thing from the block put its shading
671
+ * normal on a face the geometry does not lie on — it hangs BELOW the block — and it shipped as black
672
+ * wedges. From the surface cell the normal is that cell's own top face, which is where the patch
673
+ * actually sits, and bevelConsistent's shading check passes by construction rather than by choice.
674
+ * The diagonal cell is the one neither wall's fillet already covers.
675
+ */
676
+ export function baseOwner(mask, corner) {
677
+ const g = baseAt(mask, corner);
678
+ if (g === null)
679
+ return null;
680
+ const s = [
681
+ Math.sign(corner[0]),
682
+ Math.sign(corner[1]),
683
+ Math.sign(corner[2]),
684
+ ];
685
+ if (g[0] * s[0] + g[1] * s[1] + g[2] * s[2] > 0)
686
+ return null; // that is the block, not the surface
687
+ if (occSolid(mask, s) !== 1)
688
+ return null; // …and only the cell diagonally under the block
689
+ return g;
690
+ }
591
691
  /**
592
692
  * THE SAME INSIDE CORNER, ASKED BY ANY OF THE EIGHT CELLS — the direction of the all-air layer, or
593
693
  * null. `carveOpen` can only be asked by the ONE cube whose exposed face turns the corner; this is
@@ -772,6 +872,40 @@ concave = bevel) {
772
872
  // THE FACET'S SPHERE — `axis` is the barycentric (i, j, k) over the three base points, one per
773
873
  // cube edge. The patch is the sphere of radius b about the corner pulled in on all three axes,
774
874
  // which is the same circle the bands arrive on, so they meet arc for arc.
875
+ // THE BASE CORNER — see section 7. axis[0] names which of the six points this vertex is.
876
+ if (role === ROLE_BASE) {
877
+ const g = concave > 0 ? baseOwner(mask, corner) : null;
878
+ if (g === null)
879
+ return out;
880
+ const k = g[0] !== 0 ? 0 : g[1] !== 0 ? 1 : 2;
881
+ const h = [-g[0], -g[1], -g[2]]; // up, out of the flat surface
882
+ const f = [0, 1, 2].filter((i) => i !== k);
883
+ // the two horizontal directions AWAY from the block, which sits on this cell's 3D diagonal
884
+ let fa = [0, 0, 0];
885
+ let fb = [0, 0, 0];
886
+ fa[f[0]] = -Math.sign(corner[f[0]]);
887
+ fb[f[1]] = -Math.sign(corner[f[1]]);
888
+ const cr = [
889
+ fa[1] * fb[2] - fa[2] * fb[1],
890
+ fa[2] * fb[0] - fa[0] * fb[2],
891
+ fa[0] * fb[1] - fa[1] * fb[0],
892
+ ];
893
+ if (cr[0] * h[0] + cr[1] * h[1] + cr[2] * h[2] < 0)
894
+ [fa, fb] = [fb, fa];
895
+ // (along fa, along fb, along h) per point — see section 7
896
+ const T = [
897
+ [0, concave, 0],
898
+ [-bevel, concave / 2, concave / 2],
899
+ [-bevel, 0, concave],
900
+ [0, -bevel, concave],
901
+ [concave / 2, -bevel, concave / 2],
902
+ [concave, 0, 0],
903
+ ];
904
+ const t = T[Math.round(axis[0])];
905
+ for (let i = 0; i < 3; i++)
906
+ out[i] += fa[i] * t[0] + fb[i] * t[1] + h[i] * t[2];
907
+ return out;
908
+ }
775
909
  if (role === ROLE_FACET) {
776
910
  const f = [0, 1, 2].map((k) => {
777
911
  const v = [0, 0, 0];
@@ -919,7 +1053,31 @@ concave = bevel) {
919
1053
  // ONCE. A corner can be clipped by a chamfer and filled by a fillet on the same axis, and adding
920
1054
  // those retreats pulls the rim twice as far as either operation asked for. Each term keeps its
921
1055
  // own radius so the halves can still be judged apart, but they do not stack.
922
- const filPull = fil * concave * (role === ROLE_FMID ? 0.5 : 1);
1056
+ // ⚠️ A FILLET CREST RETREATS AT A BASE CORNER AND ITS FOOT DOES NOT. The crest is the one line
1057
+ // the fillet's two halves SHARE, and at such a corner they disagree about where it ends: the
1058
+ // block's half stops where the chamfer ate its face, this one runs on to the corner. Ending at
1059
+ // different places along a shared line is not a gap that can be patched — the band T-junctions
1060
+ // against itself. The foot keeps going, because it follows the offset of the block's footprint,
1061
+ // which does. What is left is a slanted end edge, foot to crest, and that is side 0→1 of the
1062
+ // patch in section 7.
1063
+ if (role === ROLE_FMID && axis[k] === 0) {
1064
+ const gb = baseAt(mask, corner);
1065
+ if (gb !== null && gb[k] === 0)
1066
+ pull = Math.max(pull, 1);
1067
+ }
1068
+ let filPull = fil * concave * (role === ROLE_FMID ? 0.5 : 1);
1069
+ // ⚠️ AND THE FLAT SURFACE GIVES UP ITS CORNER — by the CONCAVE radius, on the cell diagonally
1070
+ // under the block, which is the one neither wall's fillet already covers. That diagonal is the
1071
+ // patch's one new side; without this the surface still reaches past it. One axis per rim point,
1072
+ // or the two collapse onto a single point instead of cutting the corner between them.
1073
+ if (role === ROLE_RIM && axis[k] !== 0 && occSolid(mask, home) === 0) {
1074
+ const gb = baseOwner(mask, corner);
1075
+ if (gb !== null) {
1076
+ const gk = gb[0] !== 0 ? 0 : gb[1] !== 0 ? 1 : 2;
1077
+ if (home[gk] === -gb[gk])
1078
+ filPull = Math.max(filPull, concave);
1079
+ }
1080
+ }
923
1081
  out[k] -= s * Math.max(pull * bevel, filPull);
924
1082
  }
925
1083
  return out;
@@ -1056,6 +1214,34 @@ fn carveCorner(mask: u32, c: vec3<f32>) -> vec3<f32> {
1056
1214
  }
1057
1215
  return vec3(0.0, 0.0, 0.0);
1058
1216
  }
1217
+ // THE BASE CORNER — one convex edge among two concave ones, asked by any of the eight cells.
1218
+ // Returns the direction of the ALL-SOLID layer, or (0,0,0). Mirrors baseAt() in TS.
1219
+ fn baseAt(mask: u32, c: vec3<f32>) -> vec3<f32> {
1220
+ if (mask == 0u) { return vec3(0.0, 0.0, 0.0); }
1221
+ let s = sign(c);
1222
+ for (var k = 0; k < 3; k = k + 1) {
1223
+ var u1 = vec3(0.0, 0.0, 0.0);
1224
+ var u2 = vec3(0.0, 0.0, 0.0);
1225
+ var hk = vec3(0.0, 0.0, 0.0);
1226
+ if (k == 0) { u1 = vec3(0.0, s.y, 0.0); u2 = vec3(0.0, 0.0, s.z); hk = vec3(s.x, 0.0, 0.0); }
1227
+ else if (k == 1) { u1 = vec3(s.x, 0.0, 0.0); u2 = vec3(0.0, 0.0, s.z); hk = vec3(0.0, s.y, 0.0); }
1228
+ else { u1 = vec3(s.x, 0.0, 0.0); u2 = vec3(0.0, s.y, 0.0); hk = vec3(0.0, 0.0, s.z); }
1229
+ let far = occAt(mask, hk) + occAt(mask, hk + u1) + occAt(mask, hk + u2) + occAt(mask, hk + u1 + u2);
1230
+ let near = 1.0 + occAt(mask, u1) + occAt(mask, u2) + occAt(mask, u1 + u2);
1231
+ if (far > 3.5 && near < 1.5) { return hk; }
1232
+ if (near > 3.5 && far < 1.5) { return -hk; }
1233
+ }
1234
+ return vec3(0.0, 0.0, 0.0);
1235
+ }
1236
+ // …and only the surface cell on the 3D diagonal from the block emits the patch. The flat surface
1237
+ // owns it, not the block — see baseOwner() in TS for why the shading depends on that.
1238
+ fn baseOwner(mask: u32, c: vec3<f32>) -> vec3<f32> {
1239
+ let g = baseAt(mask, c);
1240
+ if (length(g) < 0.5) { return g; }
1241
+ if (dot(g, sign(c)) > 0.0) { return vec3(0.0, 0.0, 0.0); }
1242
+ if (occAt(mask, sign(c)) < 0.5) { return vec3(0.0, 0.0, 0.0); }
1243
+ return g;
1244
+ }
1059
1245
  // WHICH of the three faces at this corner is the exposed one the carve fires on — (0,0,0) if none.
1060
1246
  // At most one can answer (see carveFace() in TS), so this is the corner's whole verdict, and the
1061
1247
  // patch takes its home from it rather than from the table: which face is exposed is something only
@@ -1108,6 +1294,32 @@ fn bevelPos(mask: u32, c: vec3<f32>, a: vec3<f32>, bevel: f32, role: f32, ax: ve
1108
1294
  }
1109
1295
  // A CORNER FACET IS THE JOIN BETWEEN THREE CHAMFERS — without all three it is not a join, it is a
1110
1296
  // flat triangle lying in a buried face's plane, z-fighting against it. See bevelVertex in TS.
1297
+ // THE BASE CORNER — see section 7. ax.x names which of the six points this vertex is. It carries
1298
+ // the FILLET around the chamfer, so with no fillet it collapses. Mirrors bevelVertex in TS.
1299
+ if (role == ${ROLE_BASE}.0) {
1300
+ var g = vec3(0.0, 0.0, 0.0);
1301
+ if (conc > 0.0) { g = baseOwner(mask, c); }
1302
+ if (length(g) < 0.5) { return c; }
1303
+ let hb = -g;
1304
+ let ip = -sign(c) * (vec3(1.0, 1.0, 1.0) - abs(g)); // horizontals AWAY from the block
1305
+ var e1 = vec3(0.0, 0.0, 0.0);
1306
+ var e2 = vec3(0.0, 0.0, 0.0);
1307
+ if (abs(g.x) > 0.5) { e1 = vec3(0.0, ip.y, 0.0); e2 = vec3(0.0, 0.0, ip.z); }
1308
+ else if (abs(g.y) > 0.5) { e1 = vec3(ip.x, 0.0, 0.0); e2 = vec3(0.0, 0.0, ip.z); }
1309
+ else { e1 = vec3(ip.x, 0.0, 0.0); e2 = vec3(0.0, ip.y, 0.0); }
1310
+ var fa = e1;
1311
+ var fb = e2;
1312
+ if (dot(cross(e1, e2), hb) < 0.0) { fa = e2; fb = e1; }
1313
+ var t = vec3(0.0, 0.0, 0.0);
1314
+ let i = i32(ax.x + 0.5);
1315
+ if (i == 0) { t = vec3(0.0, conc, 0.0); }
1316
+ else if (i == 1) { t = vec3(-bevel, conc * 0.5, conc * 0.5); }
1317
+ else if (i == 2) { t = vec3(-bevel, 0.0, conc); }
1318
+ else if (i == 3) { t = vec3(0.0, -bevel, conc); }
1319
+ else if (i == 4) { t = vec3(conc * 0.5, -bevel, conc * 0.5); }
1320
+ else { t = vec3(conc, 0.0, 0.0); }
1321
+ return c + fa * t.x + fb * t.y + hb * t.z;
1322
+ }
1111
1323
  // A CHAMFER BAND EXISTS ONLY WHERE THERE IS A CHAMFER. Until fillets existed a band on any other
1112
1324
  // edge collapsed on its own, because neither of its sides moved; a fillet moves one side and not
1113
1325
  // the other, and the band then draws a quad of width b lying inside the solid. ax carries the
@@ -1201,10 +1413,23 @@ fn bevelPos(mask: u32, c: vec3<f32>, a: vec3<f32>, bevel: f32, role: f32, ax: ve
1201
1413
  pull = max(pull, p2);
1202
1414
  }
1203
1415
  }
1416
+ // A FILLET CREST RETREATS AT A BASE CORNER AND ITS FOOT DOES NOT — the crest is the one line the
1417
+ // fillet's two halves share, and they otherwise end at different places along it. See TS.
1418
+ if (role == ${ROLE_FMID}.0 && abs(dot(e, ax)) < 0.5) {
1419
+ let gb = baseAt(mask, c);
1420
+ if (length(gb) > 0.5 && abs(dot(e, gb)) < 0.5) { pull = max(pull, 1.0); }
1421
+ }
1204
1422
  // Max across the radii too: a face gives up its ground ONCE — see bevelVertex in TS.
1205
1423
  var half = 1.0;
1206
1424
  if (role == ${ROLE_FMID}.0) { half = 0.5; }
1207
- d = d + e * max(pull * bevel, fil * conc * half);
1425
+ var fp = fil * conc * half;
1426
+ // AND THE FLAT SURFACE GIVES UP ITS CORNER, by the CONCAVE radius, on the cell diagonally under
1427
+ // the block — the patch's one new side. One axis each. See bevelVertex in TS.
1428
+ if (role == ${ROLE_RIM}.0 && abs(axk) > 0.5 && occAt(mask, a) < 0.5) {
1429
+ let gb = baseOwner(mask, c);
1430
+ if (length(gb) > 0.5 && dot(a, gb) < -0.5) { fp = max(fp, conc); }
1431
+ }
1432
+ d = d + e * max(pull * bevel, fp);
1208
1433
  }
1209
1434
  return c - d;
1210
1435
  }
@@ -1432,6 +1657,34 @@ fn faceVec(code: f32) -> vec3<f32> {
1432
1657
  let cf = carveFace(mask, sharp);
1433
1658
  if (length(cf) > 0.5) { home = cf; }
1434
1659
  }
1660
+ // ⚠️ AND THE BASE PATCH TOO. It belongs to the FLAT SURFACE it grows out of, whose outward normal
1661
+ // is -g, and the table cannot know which axis that is. Left as the placeholder it shipped as black
1662
+ // wedges once already.
1663
+ if (BEV_ROLE[vi] == ${ROLE_BASE}.0) {
1664
+ let gb = baseOwner(mask, sharp);
1665
+ if (length(gb) > 0.5) {
1666
+ home = -gb; // the TEXTURE is the flat surface's, which is what the patch is mostly made of
1667
+ // …but the NORMAL has to wrap with the geometry: it runs from the surface, over the fillet's
1668
+ // crest, onto the block's two walls. One flat normal across all of it is the same mistake the
1669
+ // band just made, on a patch that turns through 90°.
1670
+ let hb = -gb;
1671
+ let ipb = -sign(sharp) * (vec3(1.0, 1.0, 1.0) - abs(gb));
1672
+ var b1 = vec3(0.0, 0.0, 0.0);
1673
+ var b2 = vec3(0.0, 0.0, 0.0);
1674
+ if (abs(gb.x) > 0.5) { b1 = vec3(0.0, ipb.y, 0.0); b2 = vec3(0.0, 0.0, ipb.z); }
1675
+ else if (abs(gb.y) > 0.5) { b1 = vec3(ipb.x, 0.0, 0.0); b2 = vec3(0.0, 0.0, ipb.z); }
1676
+ else { b1 = vec3(ipb.x, 0.0, 0.0); b2 = vec3(0.0, ipb.y, 0.0); }
1677
+ var fa2 = b1;
1678
+ var fb2 = b2;
1679
+ if (dot(cross(b1, b2), hb) < 0.0) { fa2 = b2; fb2 = b1; }
1680
+ let ib = i32(BEV_AXIS[vi].x + 0.5);
1681
+ if (ib == 1) { shade = normalize(hb + fb2); } // the crest, fb side
1682
+ else if (ib == 2) { shade = fb2; } // on the block's wall
1683
+ else if (ib == 3) { shade = fa2; } // …and the other wall
1684
+ else if (ib == 4) { shade = normalize(hb + fa2); } // the crest, fa side
1685
+ else { shade = hb; } // the two feet, flat on the surface
1686
+ }
1687
+ }
1435
1688
  let local = bevelPos(mask, sharp, home, cam.eye.w, BEV_ROLE[vi], BEV_AXIS[vi], cam.csm.z);
1436
1689
  let world = inst.pos.xyz + qrot(inst.rot, local * inst.scl.xyz);
1437
1690
  var o: VOut;
@@ -1448,6 +1701,20 @@ fn faceVec(code: f32) -> vec3<f32> {
1448
1701
  // curve through the groove. objN stays home, so the texture still belongs to the face it grew from.
1449
1702
  var shade = home;
1450
1703
  if (BEV_ROLE[vi] == ${ROLE_FMID}.0) { shade = normalize(home - BEV_AXIS[vi]); }
1704
+ // ⚠️ A BAND'S NORMAL SWEEPS ACROSS THE STRIP. That sweep is the only reason a flat 45° chamfer
1705
+ // reads as a cylinder — the geometry is a plane and the shading is a curve. It used to happen for
1706
+ // free, because the quad's two long edges carried different home faces; subdividing the band
1707
+ // gave every vertex the OWNING face so the texture would stay put, and with it every rounded edge
1708
+ // in the world went flat. Reported as "the shading is way off", and it was.
1709
+ //
1710
+ // Rotate from the owning face to the partner across the arc. At step 0 and BEVEL_SEG this is
1711
+ // exactly the two normals the old quad carried, so at one segment nothing changes.
1712
+ if (BEV_ROLE[vi] == ${ROLE_BAND}.0) {
1713
+ let pb = sign(BEV_AXIS[vi]);
1714
+ let stb = round(max(max(abs(BEV_AXIS[vi].x), abs(BEV_AXIS[vi].y)), abs(BEV_AXIS[vi].z))) - 1.0;
1715
+ let thb = (stb / ${BEVEL_SEG}.0) * 1.5707963267948966;
1716
+ shade = normalize(home * cos(thb) + pb * sin(thb));
1717
+ }
1451
1718
  // ⚠️ A SUBDIVIDED FACET SHADES AS THE SPHERE IT IS. Its vertices carry a face normal for the
1452
1719
  // TEXTURE, and at one segment those three normals sweeping across one triangle is what made a flat
1453
1720
  // chamfer corner read round. Once the patch is a real octant, the honest normal is the sphere's —
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.12",
3
+ "version": "0.15.14",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {