ugly-game 0.15.6 → 0.15.7

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.
@@ -106,13 +106,40 @@ export declare function occSolid(mask: number, o: readonly [number, number, numb
106
106
  * one that knows the other block is there.
107
107
  */
108
108
  export declare function edgeOpen(mask: number, a: readonly [number, number, number], b: readonly [number, number, number]): number;
109
+ /**
110
+ * THE NOTCH — the exact complement of `edgeOpen`: both faces SOLID, the diagonal between them AIR.
111
+ *
112
+ * Three blocks in an L around an empty cell. The two with a FACE on that cell chamfer it normally.
113
+ * The third touches it only along one corner edge, so `edgeOpen` refuses — both its face-neighbours
114
+ * are solid — and it keeps a hard 90° arris running down the inside of the notch while everything
115
+ * around it is rounded. It is the one edge in a rounded world that still looks stamped out of a grid.
116
+ *
117
+ * ⚠️ CUTTING IT CANNOT OPEN A HOLE, which is worth stating because the diagonal test everywhere else
118
+ * in this file exists to PREVENT holes. The wedge removed lies inside this block's own cell, and the
119
+ * two neighbours' buried faces close the gap behind it — every instance draws all six faces, so they
120
+ * are already there. Neither neighbour cuts at that edge: each has one OPEN face there, so
121
+ * `edgeOpen` (needs both open) and `notchOpen` (needs both solid) are false for both of them.
122
+ */
123
+ export declare function notchOpen(mask: number, a: readonly [number, number, number], b: readonly [number, number, number]): number;
124
+ /** How much of the main bevel a notch edge gets. Half — it softens an INSIDE corner rather than
125
+ * rounding an outside one, and at the full amount it reads as a gouge instead of a relief. */
126
+ export declare const NOTCH_SCALE = 0.5;
109
127
  /**
110
128
  * THE VERTEX RULE, in JS — the oracle `gpuShadow.bevel.test.mts` checks and the exact thing
111
129
  * `bevelPos()` in COMMON_WGSL does. Kept in step with it by hand; the test is what notices.
112
130
  *
113
- * A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by the edge between
114
- * its home face and the face whose normal is `sign(corner[k]) * e_k`. Both primitives sharing a
115
- * vertex resolve the same face/axis pair, which is where watertightness comes from.
131
+ * A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by one of three
132
+ * conditions on that axis:
133
+ *
134
+ * CONVEX — `edgeOpen(home, e_k)`. The ordinary chamfer, at full size.
135
+ * NOTCH, FLANKING — `notchOpen(home, e_k)`. This vertex is on one of the two faces meeting at a
136
+ * notch edge; this cuts that edge itself.
137
+ * NOTCH, CAPPING — `notchOpen(e_k, e_j)`, `j` being the OTHER free axis. This vertex is on the
138
+ * face PERPENDICULAR to a notch edge — the ground above it, say. Both its free axes pull, which
139
+ * cuts that face's corner diagonally so the notch chamfer does not stop dead in a step.
140
+ *
141
+ * The convex term cannot collide with either notch term: it requires both cells AIR, they require
142
+ * one SOLID.
116
143
  */
117
144
  export declare function bevelVertex(corner: readonly [number, number, number], home: readonly [number, number, number], mask: number, bevel: number): [number, number, number];
118
145
  export declare class GpuShadowRenderer {
package/dist/gpuShadow.js CHANGED
@@ -191,25 +191,66 @@ export function edgeOpen(mask, a, b) {
191
191
  const d = [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
192
192
  return ((1 - occSolid(mask, a)) * (1 - occSolid(mask, b)) * (1 - occSolid(mask, d)));
193
193
  }
194
+ /**
195
+ * THE NOTCH — the exact complement of `edgeOpen`: both faces SOLID, the diagonal between them AIR.
196
+ *
197
+ * Three blocks in an L around an empty cell. The two with a FACE on that cell chamfer it normally.
198
+ * The third touches it only along one corner edge, so `edgeOpen` refuses — both its face-neighbours
199
+ * are solid — and it keeps a hard 90° arris running down the inside of the notch while everything
200
+ * around it is rounded. It is the one edge in a rounded world that still looks stamped out of a grid.
201
+ *
202
+ * ⚠️ CUTTING IT CANNOT OPEN A HOLE, which is worth stating because the diagonal test everywhere else
203
+ * in this file exists to PREVENT holes. The wedge removed lies inside this block's own cell, and the
204
+ * two neighbours' buried faces close the gap behind it — every instance draws all six faces, so they
205
+ * are already there. Neither neighbour cuts at that edge: each has one OPEN face there, so
206
+ * `edgeOpen` (needs both open) and `notchOpen` (needs both solid) are false for both of them.
207
+ */
208
+ export function notchOpen(mask, a, b) {
209
+ if (mask === 0)
210
+ return 0; // unknown ⇒ no bevel, see CubeInstance.occ
211
+ const d = [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
212
+ return occSolid(mask, a) * occSolid(mask, b) * (1 - occSolid(mask, d));
213
+ }
214
+ /** How much of the main bevel a notch edge gets. Half — it softens an INSIDE corner rather than
215
+ * rounding an outside one, and at the full amount it reads as a gouge instead of a relief. */
216
+ export const NOTCH_SCALE = 0.5;
194
217
  /**
195
218
  * THE VERTEX RULE, in JS — the oracle `gpuShadow.bevel.test.mts` checks and the exact thing
196
219
  * `bevelPos()` in COMMON_WGSL does. Kept in step with it by hand; the test is what notices.
197
220
  *
198
- * A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by the edge between
199
- * its home face and the face whose normal is `sign(corner[k]) * e_k`. Both primitives sharing a
200
- * vertex resolve the same face/axis pair, which is where watertightness comes from.
221
+ * A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by one of three
222
+ * conditions on that axis:
223
+ *
224
+ * CONVEX — `edgeOpen(home, e_k)`. The ordinary chamfer, at full size.
225
+ * NOTCH, FLANKING — `notchOpen(home, e_k)`. This vertex is on one of the two faces meeting at a
226
+ * notch edge; this cuts that edge itself.
227
+ * NOTCH, CAPPING — `notchOpen(e_k, e_j)`, `j` being the OTHER free axis. This vertex is on the
228
+ * face PERPENDICULAR to a notch edge — the ground above it, say. Both its free axes pull, which
229
+ * cuts that face's corner diagonally so the notch chamfer does not stop dead in a step.
230
+ *
231
+ * The convex term cannot collide with either notch term: it requires both cells AIR, they require
232
+ * one SOLID.
201
233
  */
202
234
  export function bevelVertex(corner, home, mask, bevel) {
203
235
  const out = [corner[0], corner[1], corner[2]];
204
236
  if (bevel <= 0 || mask === 0)
205
237
  return out;
206
- for (let k = 0; k < 3; k++) {
207
- if (home[k] !== 0)
208
- continue; // the face axis itself is never pulled
209
- const s = Math.sign(corner[k]);
210
- const b = [0, 0, 0];
211
- b[k] = s;
212
- out[k] -= s * bevel * edgeOpen(mask, home, b);
238
+ const free = [0, 1, 2].filter((i) => home[i] === 0); // the two in-face axes
239
+ const axis = (i) => {
240
+ const v = [0, 0, 0];
241
+ v[i] = Math.sign(corner[i]);
242
+ return v;
243
+ };
244
+ for (const k of free) {
245
+ const j = free.find((f) => f !== k) ?? k;
246
+ const bk = axis(k);
247
+ // ⚠️ max, NOT +. See the note above: both notch terms hold at once on a face flanking two
248
+ // notches at right angles, and summing there pulls the corner twice as far as any neighbour
249
+ // agrees to — which is a crack.
250
+ const notch = Math.max(notchOpen(mask, home, bk), notchOpen(mask, bk, axis(j)));
251
+ out[k] -=
252
+ Math.sign(corner[k]) *
253
+ (bevel * edgeOpen(mask, home, bk) + bevel * NOTCH_SCALE * notch);
213
254
  }
214
255
  return out;
215
256
  }
@@ -273,14 +314,40 @@ fn edgeOpen(mask: u32, a: vec3<f32>, b: vec3<f32>) -> f32 {
273
314
  // face and the face on that side. Both primitives that share a vertex resolve the same face/axis
274
315
  // pair, so they cannot land in different places — that is where watertightness comes from, and it
275
316
  // is why this takes (corner, home) rather than a vertex index.
317
+ // THE NOTCH — the exact complement of edgeOpen: both faces SOLID, the diagonal between them AIR.
318
+ // Three blocks in an L around an empty cell: the two with a FACE on it chamfer normally, the third
319
+ // touches it only along one corner edge and keeps a hard arris down the inside of the notch. This is
320
+ // what softens that. Cutting it cannot open a hole — the wedge is inside this block's own cell and
321
+ // the neighbours' buried faces (drawn, like every face of every instance) close it. Mirrors
322
+ // notchOpen() in TS.
323
+ fn notchOpen(mask: u32, a: vec3<f32>, b: vec3<f32>) -> f32 {
324
+ if (mask == 0u) { return 0.0; }
325
+ return occAt(mask, a) * occAt(mask, b) * (1.0 - occAt(mask, a + b));
326
+ }
327
+ // The vertex rule. A vertex's pull along a free axis is INWARD, gated by the edge between its home
328
+ // face and the face on that side (CONVEX, full size), or by a notch it flanks, or by a notch it caps
329
+ // from the perpendicular face — see bevelVertex in TS for the full statement.
330
+ //
331
+ // ⚠️ max, NOT +, ON THE TWO NOTCH TERMS. Both hold at once on a face flanking two notches at right
332
+ // angles, and summing there pulls that corner twice as far as any neighbour agrees to — a crack.
276
333
  fn bevelPos(mask: u32, c: vec3<f32>, a: vec3<f32>, bevel: f32) -> vec3<f32> {
277
334
  if (bevel <= 0.0 || mask == 0u) { return c; }
278
335
  let free = vec3(1.0, 1.0, 1.0) - abs(a); // the two in-face axes; the face axis is never pulled
279
336
  let s = sign(c);
337
+ let ax = vec3(s.x, 0.0, 0.0);
338
+ let ay = vec3(0.0, s.y, 0.0);
339
+ let az = vec3(0.0, 0.0, s.z);
340
+ // The OTHER free axis for each axis: one of the three is masked off by "free", so the remaining
341
+ // two are each other's partner — the partner direction is the sum of the free ones minus this one.
342
+ let fx = free.x * ax; let fy = free.y * ay; let fz = free.z * az;
343
+ let sum = fx + fy + fz;
280
344
  var d = vec3(0.0, 0.0, 0.0);
281
- d.x = free.x * s.x * bevel * edgeOpen(mask, a, vec3(s.x, 0.0, 0.0));
282
- d.y = free.y * s.y * bevel * edgeOpen(mask, a, vec3(0.0, s.y, 0.0));
283
- d.z = free.z * s.z * bevel * edgeOpen(mask, a, vec3(0.0, 0.0, s.z));
345
+ d.x = free.x * s.x * bevel * (edgeOpen(mask, a, ax)
346
+ + ${NOTCH_SCALE} * max(notchOpen(mask, a, ax), notchOpen(mask, ax, sum - fx)));
347
+ d.y = free.y * s.y * bevel * (edgeOpen(mask, a, ay)
348
+ + ${NOTCH_SCALE} * max(notchOpen(mask, a, ay), notchOpen(mask, ay, sum - fy)));
349
+ d.z = free.z * s.z * bevel * (edgeOpen(mask, a, az)
350
+ + ${NOTCH_SCALE} * max(notchOpen(mask, a, az), notchOpen(mask, az, sum - fz)));
284
351
  return c - d;
285
352
  }
286
353
  // Vertex AO for cube vertex vi, in [AO_MIN, 1]. Every cube vertex sits at a CORNER, so CUBE_POS is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.6",
3
+ "version": "0.15.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {