ugly-game 0.15.9 → 0.15.10
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/gpuShadow.d.ts +22 -3
- package/dist/gpuShadow.js +277 -57
- package/package.json +1 -1
package/dist/gpuShadow.d.ts
CHANGED
|
@@ -84,15 +84,33 @@ export declare const CUBE: {
|
|
|
84
84
|
};
|
|
85
85
|
/** Vertex counts for the two cube geometries the camera pass can draw. */
|
|
86
86
|
export declare const SHARP_VERTS = 36;
|
|
87
|
-
export declare const BEVEL_VERTS =
|
|
87
|
+
export declare const BEVEL_VERTS = 276;
|
|
88
|
+
/** What a vertex is, which decides how it is allowed to move. */
|
|
89
|
+
export declare const ROLE_SHARP = 0;
|
|
90
|
+
export declare const ROLE_CENTER = 1;
|
|
91
|
+
export declare const ROLE_RIM = 2;
|
|
92
|
+
export declare const ROLE_BAND = 3;
|
|
93
|
+
export declare const ROLE_FACET = 4;
|
|
88
94
|
export interface BevelCube {
|
|
89
|
-
/** Which of the 8 sharp corners each vertex sits on — always (±0.5, ±0.5, ±0.5)
|
|
95
|
+
/** Which of the 8 sharp corners each vertex sits on — always (±0.5, ±0.5, ±0.5), except a fan
|
|
96
|
+
* hub, which sits at its face centre. */
|
|
90
97
|
corner: [number, number, number][];
|
|
91
98
|
/** The face normal each vertex belongs to. Doubles as its shading normal AND the anchor
|
|
92
99
|
* every one of its bevel gates is measured from. */
|
|
93
100
|
home: [number, number, number][];
|
|
101
|
+
/** ROLE_* — see above. */
|
|
102
|
+
role: number[];
|
|
103
|
+
/** Role-dependent axis, as a signed unit direction:
|
|
104
|
+
* ROLE_RIM — the axis this rim point takes the CORNER-CLIP pull along (the other of the
|
|
105
|
+
* face's two in-plane axes stays put), which is what splits one corner into two
|
|
106
|
+
* points and turns the quad into a pentagon.
|
|
107
|
+
* ROLE_FACET — the cube edge this facet vertex belongs to.
|
|
108
|
+
* Zero for every other role. */
|
|
109
|
+
axis: [number, number, number][];
|
|
94
110
|
cornerWgsl: string;
|
|
95
111
|
homeWgsl: string;
|
|
112
|
+
roleWgsl: string;
|
|
113
|
+
axisWgsl: string;
|
|
96
114
|
}
|
|
97
115
|
export declare const BEVEL: BevelCube;
|
|
98
116
|
/** Is the neighbour at offset `o` solid, per the 27-bit mask? 1 = solid. Mirrors `occAt` in WGSL. */
|
|
@@ -170,7 +188,8 @@ export declare const NOTCH_SCALE = 0.5;
|
|
|
170
188
|
* the neighbour sharing the corner could not make the same cut, and it shipped as visibly torn
|
|
171
189
|
* ground — "concave corners are not rendering correctly". The step is the correct trade.
|
|
172
190
|
*/
|
|
173
|
-
export declare function
|
|
191
|
+
export declare function case3(mask: number, a: readonly [number, number, number], corner: readonly [number, number, number]): number;
|
|
192
|
+
export declare function bevelVertex(corner: readonly [number, number, number], home: readonly [number, number, number], mask: number, bevel: number, role?: number, axis?: readonly [number, number, number]): [number, number, number];
|
|
174
193
|
export declare class GpuShadowRenderer {
|
|
175
194
|
private device;
|
|
176
195
|
private instBuf;
|
package/dist/gpuShadow.js
CHANGED
|
@@ -71,7 +71,15 @@ function buildCube() {
|
|
|
71
71
|
export const CUBE = buildCube();
|
|
72
72
|
/** Vertex counts for the two cube geometries the camera pass can draw. */
|
|
73
73
|
export const SHARP_VERTS = 36;
|
|
74
|
-
|
|
74
|
+
// 36 sharp quads (drawn only when the bevel is OFF, collapsed when it is on)
|
|
75
|
+
// + 6 face FANS (6 x 24) + 12 bevel bands (72) + 8 corner facets (24)
|
|
76
|
+
export const BEVEL_VERTS = 276;
|
|
77
|
+
/** What a vertex is, which decides how it is allowed to move. */
|
|
78
|
+
export const ROLE_SHARP = 0; // one of the 36 plain quad vertices — only alive when bevel == 0
|
|
79
|
+
export const ROLE_CENTER = 1; // a face fan's hub; never moves
|
|
80
|
+
export const ROLE_RIM = 2; // a face fan's boundary point — this is what can clip a corner
|
|
81
|
+
export const ROLE_BAND = 3; // an edge chamfer's vertex
|
|
82
|
+
export const ROLE_FACET = 4; // a corner facet's vertex
|
|
75
83
|
// THE CHAMFERED CUBE — a cube with all twelve edges cut back, where each cut COLLAPSES to a sharp
|
|
76
84
|
// corner unless that edge is actually exposed to air or water.
|
|
77
85
|
//
|
|
@@ -94,7 +102,6 @@ export const BEVEL_VERTS = 132; // 6 face quads (36) + 12 bevel bands (72) + 8 c
|
|
|
94
102
|
// bevel is off — so turning the feature off costs exactly what it cost before the feature existed,
|
|
95
103
|
// rather than merely looking the same while paying for 96 degenerate vertices per instance.
|
|
96
104
|
function buildBevelCube() {
|
|
97
|
-
// The same six faces, in the same order, as buildCube().
|
|
98
105
|
const faces = [
|
|
99
106
|
{ n: [1, 0, 0], u: [0, 0, 1], v: [0, 1, 0] },
|
|
100
107
|
{ n: [-1, 0, 0], u: [0, 0, 1], v: [0, 1, 0] },
|
|
@@ -113,42 +120,80 @@ function buildBevelCube() {
|
|
|
113
120
|
];
|
|
114
121
|
const corner = [];
|
|
115
122
|
const home = [];
|
|
116
|
-
const
|
|
123
|
+
const role = [];
|
|
124
|
+
const axis = [];
|
|
125
|
+
const push = (c, h, r, a) => {
|
|
117
126
|
corner.push(c);
|
|
118
127
|
home.push(h);
|
|
128
|
+
role.push(r);
|
|
129
|
+
axis.push(a);
|
|
119
130
|
};
|
|
131
|
+
const Z = [0, 0, 0];
|
|
120
132
|
const axisOf = (n) => (n[0] !== 0 ? 0 : n[1] !== 0 ? 1 : 2);
|
|
121
|
-
|
|
133
|
+
const mul = (a, k) => [a[0] * k, a[1] * k, a[2] * k];
|
|
134
|
+
const add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
135
|
+
// ── 1. THE SHARP QUADS (0..35) — byte-for-byte buildCube(). Alive only while the bevel is OFF;
|
|
136
|
+
// with a bevel set they collapse to the cube centre and the fans below take over. That is what
|
|
137
|
+
// keeps "bevel off" costing a 36-vertex draw rather than the full beveled cube.
|
|
122
138
|
for (const f of faces)
|
|
123
139
|
for (const [cu, cv] of quad)
|
|
124
140
|
push([
|
|
125
141
|
f.n[0] * 0.5 + f.u[0] * cu + f.v[0] * cv,
|
|
126
142
|
f.n[1] * 0.5 + f.u[1] * cu + f.v[1] * cv,
|
|
127
143
|
f.n[2] * 0.5 + f.u[2] * cu + f.v[2] * cv,
|
|
128
|
-
], [...f.n]);
|
|
129
|
-
// ── 2.
|
|
130
|
-
// Each band spans two faces, so its two long sides carry DIFFERENT home normals; interpolating
|
|
131
|
-
// between them across the band is what makes a 45° cut read as a curve instead of a facet.
|
|
144
|
+
], [...f.n], ROLE_SHARP, Z);
|
|
145
|
+
// ── 2. FACE FANS (36..179) — hub + 8 rim points, 8 triangles each.
|
|
132
146
|
//
|
|
133
|
-
// ⚠️
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
147
|
+
// ⚠️ A FAN, NOT A QUAD, AND THAT IS THE WHOLE POINT OF THIS REWRITE. A two-triangle quad has one
|
|
148
|
+
// vertex per corner, so it cannot CLIP a corner — moving that vertex shears the entire face
|
|
149
|
+
// instead of cutting the corner off. The rim carries TWO points per corner: normally coincident
|
|
150
|
+
// (the face is its old rectangle and four of the eight triangles are degenerate), separating only
|
|
151
|
+
// where a corner has to be clipped, which turns the face into a pentagon exactly there.
|
|
152
|
+
for (const f of faces) {
|
|
153
|
+
const centre = mul(f.n, 0.5);
|
|
154
|
+
const rim = [];
|
|
155
|
+
// The boundary cycle: along the v=-1 edge, round the +u corner, along u=+1, and so on. At each
|
|
156
|
+
// corner the two points are "pulled along u" and "pulled along v"; the segment between them is
|
|
157
|
+
// the corner clip.
|
|
158
|
+
const at = (su, sv) => add(centre, add(mul(f.u, su * 0.5), mul(f.v, sv * 0.5)));
|
|
159
|
+
const seq = [
|
|
160
|
+
[-1, -1, f.u],
|
|
161
|
+
[1, -1, f.u],
|
|
162
|
+
[1, -1, f.v],
|
|
163
|
+
[1, 1, f.v],
|
|
164
|
+
[1, 1, f.u],
|
|
165
|
+
[-1, 1, f.u],
|
|
166
|
+
[-1, 1, f.v],
|
|
167
|
+
[-1, -1, f.v],
|
|
168
|
+
];
|
|
169
|
+
for (const [su, sv, ax] of seq)
|
|
170
|
+
rim.push({
|
|
171
|
+
c: at(su, sv),
|
|
172
|
+
a: mul(ax, axisOf(ax) === axisOf(f.u) ? su : sv),
|
|
173
|
+
});
|
|
174
|
+
for (let i = 0; i < 8; i++) {
|
|
175
|
+
const a = rim[i], b = rim[(i + 1) % 8];
|
|
176
|
+
push(centre, [...f.n], ROLE_CENTER, Z);
|
|
177
|
+
push(a.c, [...f.n], ROLE_RIM, a.a);
|
|
178
|
+
push(b.c, [...f.n], ROLE_RIM, b.a);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// ── 3. BEVEL BANDS (180..251) — one quad per edge, unchanged in spirit: the owning face's vertex
|
|
182
|
+
// goes FIRST in every triangle because objN is flat-interpolated off the provoking vertex.
|
|
137
183
|
for (let ai = 0; ai < faces.length; ai++)
|
|
138
184
|
for (let bi = ai + 1; bi < faces.length; bi++) {
|
|
139
185
|
const a = faces[ai].n, b = faces[bi].n;
|
|
140
186
|
const axA = axisOf(a), axB = axisOf(b);
|
|
141
187
|
if (axA === axB)
|
|
142
|
-
continue;
|
|
143
|
-
const axE = 3 - axA - axB;
|
|
188
|
+
continue;
|
|
189
|
+
const axE = 3 - axA - axB;
|
|
144
190
|
const at = (t, h) => {
|
|
145
191
|
const c = [0, 0, 0];
|
|
146
192
|
c[axA] = a[axA] * 0.5;
|
|
147
193
|
c[axB] = b[axB] * 0.5;
|
|
148
194
|
c[axE] = t;
|
|
149
|
-
push(c, h);
|
|
195
|
+
push(c, h, ROLE_BAND, Z);
|
|
150
196
|
};
|
|
151
|
-
// two triangles, A-side vertex first in each
|
|
152
197
|
at(-0.5, [...a]);
|
|
153
198
|
at(-0.5, [...b]);
|
|
154
199
|
at(0.5, [...b]);
|
|
@@ -156,20 +201,40 @@ function buildBevelCube() {
|
|
|
156
201
|
at(0.5, [...b]);
|
|
157
202
|
at(0.5, [...a]);
|
|
158
203
|
}
|
|
159
|
-
// ──
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
// produces both, which is why the mixed cases need no special handling.
|
|
204
|
+
// ── 4. CORNER FACETS (252..275) — one triangle per corner, one vertex per cube EDGE meeting there.
|
|
205
|
+
// Convex, it is the usual chamfer corner. At a rim turn it is the one-axis triangle that closes
|
|
206
|
+
// the pentagon the fan just cut.
|
|
163
207
|
for (const sx of [-0.5, 0.5])
|
|
164
208
|
for (const sy of [-0.5, 0.5])
|
|
165
209
|
for (const sz of [-0.5, 0.5]) {
|
|
166
210
|
const c = [sx, sy, sz];
|
|
167
|
-
push([...c], [Math.sign(sx), 0, 0]
|
|
168
|
-
|
|
169
|
-
|
|
211
|
+
push([...c], [Math.sign(sx), 0, 0], ROLE_FACET, [
|
|
212
|
+
Math.sign(sx),
|
|
213
|
+
0,
|
|
214
|
+
0,
|
|
215
|
+
]);
|
|
216
|
+
push([...c], [0, Math.sign(sy), 0], ROLE_FACET, [
|
|
217
|
+
0,
|
|
218
|
+
Math.sign(sy),
|
|
219
|
+
0,
|
|
220
|
+
]);
|
|
221
|
+
push([...c], [0, 0, Math.sign(sz)], ROLE_FACET, [
|
|
222
|
+
0,
|
|
223
|
+
0,
|
|
224
|
+
Math.sign(sz),
|
|
225
|
+
]);
|
|
170
226
|
}
|
|
171
|
-
const
|
|
172
|
-
return {
|
|
227
|
+
const wv = (a) => a.map((p) => `vec3<f32>(${p[0]},${p[1]},${p[2]})`).join(', ');
|
|
228
|
+
return {
|
|
229
|
+
corner,
|
|
230
|
+
home,
|
|
231
|
+
role,
|
|
232
|
+
axis,
|
|
233
|
+
cornerWgsl: wv(corner),
|
|
234
|
+
homeWgsl: wv(home),
|
|
235
|
+
roleWgsl: role.join(', '),
|
|
236
|
+
axisWgsl: wv(axis),
|
|
237
|
+
};
|
|
173
238
|
}
|
|
174
239
|
export const BEVEL = buildBevelCube();
|
|
175
240
|
/** Is the neighbour at offset `o` solid, per the 27-bit mask? 1 = solid. Mirrors `occAt` in WGSL. */
|
|
@@ -275,26 +340,128 @@ export const NOTCH_SCALE = 0.5;
|
|
|
275
340
|
* the neighbour sharing the corner could not make the same cut, and it shipped as visibly torn
|
|
276
341
|
* ground — "concave corners are not rendering correctly". The step is the correct trade.
|
|
277
342
|
*/
|
|
278
|
-
export function
|
|
343
|
+
export function case3(mask, a, corner) {
|
|
344
|
+
if (mask === 0)
|
|
345
|
+
return 0;
|
|
346
|
+
if (occSolid(mask, a) === 1)
|
|
347
|
+
return 0; // only an EXPOSED face has a rim to turn
|
|
348
|
+
const ax = a[0] !== 0 ? 0 : a[1] !== 0 ? 1 : 2;
|
|
349
|
+
const f = [0, 1, 2].filter((i) => i !== ax);
|
|
350
|
+
const d1 = [0, 0, 0];
|
|
351
|
+
const d2 = [0, 0, 0];
|
|
352
|
+
d1[f[0]] = Math.sign(corner[f[0]]);
|
|
353
|
+
d2[f[1]] = Math.sign(corner[f[1]]);
|
|
354
|
+
const diag = [
|
|
355
|
+
d1[0] + d2[0],
|
|
356
|
+
d1[1] + d2[1],
|
|
357
|
+
d1[2] + d2[2],
|
|
358
|
+
];
|
|
359
|
+
// Both in-plane neighbours SOLID, the cell diagonally between them AIR: the surface runs on in
|
|
360
|
+
// both directions but a hole sits off the corner, so the hole's rim turns right here.
|
|
361
|
+
return occSolid(mask, d1) * occSolid(mask, d2) * (1 - occSolid(mask, diag));
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* THE EIGHT CELLS MEETING AT A CORNER, and who — if anyone — owns the rim turn there.
|
|
365
|
+
*
|
|
366
|
+
* ⚠️ ASKED OF THE CORNER, NOT OF THIS CELL, and that is the whole point. Every earlier attempt let
|
|
367
|
+
* each cell decide from its own position, so at a rim turn the diagonal cell clipped its corner
|
|
368
|
+
* while the two cells beside it went on emitting facets built around the corner that had just been
|
|
369
|
+
* cut away — two unpaired edges per corner, every time. A corner is SHARED, so the decision has to
|
|
370
|
+
* be a property of the corner: all eight cells see the same eight-cell configuration (relabelled),
|
|
371
|
+
* so they all reach the same answer and exactly one of them acts on it.
|
|
372
|
+
*
|
|
373
|
+
* The configuration that is a rim turn: along some axis the four cells on the far side are all air
|
|
374
|
+
* and three of the four on this side are solid — a surface with an L-shaped bite out of it. The
|
|
375
|
+
* owner is the solid cell DIAGONAL to the bite, the one whose corner pokes into the rim.
|
|
376
|
+
*/
|
|
377
|
+
function rimTurn(mask, corner) {
|
|
378
|
+
const sg = [Math.sign(corner[0]), Math.sign(corner[1]), Math.sign(corner[2])];
|
|
379
|
+
const cell = (a, b, c) => {
|
|
380
|
+
const o = [a * sg[0], b * sg[1], c * sg[2]];
|
|
381
|
+
if (o[0] === 0 && o[1] === 0 && o[2] === 0)
|
|
382
|
+
return 1; // this cell, always solid
|
|
383
|
+
return occSolid(mask, o);
|
|
384
|
+
};
|
|
385
|
+
for (let k = 0; k < 3; k++) {
|
|
386
|
+
const rest = [0, 1, 2].filter((i) => i !== k);
|
|
387
|
+
const at = (near, p, q) => {
|
|
388
|
+
const b = [0, 0, 0];
|
|
389
|
+
b[k] = near;
|
|
390
|
+
b[rest[0]] = p;
|
|
391
|
+
b[rest[1]] = q;
|
|
392
|
+
return cell(b[0], b[1], b[2]);
|
|
393
|
+
};
|
|
394
|
+
if (at(1, 0, 0) + at(1, 1, 0) + at(1, 0, 1) + at(1, 1, 1) !== 0)
|
|
395
|
+
continue;
|
|
396
|
+
const near = [at(0, 0, 0), at(0, 1, 0), at(0, 0, 1), at(0, 1, 1)];
|
|
397
|
+
if (near[0] + near[1] + near[2] + near[3] !== 3)
|
|
398
|
+
continue;
|
|
399
|
+
// The exposed face is the one pointing at the empty side.
|
|
400
|
+
const face = [0, 0, 0];
|
|
401
|
+
face[k] = sg[k];
|
|
402
|
+
return { here: true, mine: near[3] === 0, face };
|
|
403
|
+
}
|
|
404
|
+
return { here: false, mine: false, face: [0, 0, 0] };
|
|
405
|
+
}
|
|
406
|
+
export function bevelVertex(corner, home, mask, bevel, role = ROLE_RIM, axis = [0, 0, 0]) {
|
|
279
407
|
const out = [corner[0], corner[1], corner[2]];
|
|
280
|
-
|
|
408
|
+
// The plain quads exist only for the bevel-off draw; with a bevel set the fans replace them, so
|
|
409
|
+
// they collapse rather than z-fight against the geometry that supersedes them.
|
|
410
|
+
if (role === ROLE_SHARP)
|
|
411
|
+
return bevel > 0 ? [0, 0, 0] : out;
|
|
412
|
+
if (role === ROLE_CENTER || bevel <= 0 || mask === 0)
|
|
281
413
|
return out;
|
|
414
|
+
// ONE FACET PER RIM TURN. The cells beside the owner stand down: their corner facet is built
|
|
415
|
+
// around a corner the owner has just cut away, and emitting it leaves that cut unpaired.
|
|
416
|
+
const rt = rimTurn(mask, corner);
|
|
417
|
+
// ONE FACET PER RIM TURN. The cells beside the owner stand down: their corner facet is built
|
|
418
|
+
// around a corner the owner has just cut away, and emitting it leaves that cut unpaired.
|
|
419
|
+
if (role === ROLE_FACET && rt.here && !rt.mine)
|
|
420
|
+
return out; // zero area, never drawn
|
|
282
421
|
for (let k = 0; k < 3; k++) {
|
|
283
|
-
if (home[k] !== 0)
|
|
284
|
-
continue; // the face axis itself is never pulled
|
|
285
422
|
const s = Math.sign(corner[k]);
|
|
286
423
|
const e = [0, 0, 0];
|
|
287
424
|
e[k] = s;
|
|
288
|
-
|
|
289
|
-
|
|
425
|
+
if (home[k] !== 0) {
|
|
426
|
+
// The face's own axis. Only a corner facet may move along it, and only to reach the low
|
|
427
|
+
// point of a rim turn — the vertex where both neighbours' chamfer bands bottom out.
|
|
428
|
+
if (role === ROLE_FACET && axis[k] !== 0 && rt.mine)
|
|
429
|
+
out[k] -= s * bevel;
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
290
432
|
const jAxis = [0, 1, 2].find((i) => i !== k && home[i] === 0) ?? k;
|
|
291
433
|
const j = [0, 0, 0];
|
|
292
434
|
j[jAxis] = Math.sign(corner[jAxis]);
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
435
|
+
// ⚠️ NO NOTCH TERM. 0.15.7 cut the edge between two BURIED faces whose diagonal is air; it is
|
|
436
|
+
// invisible (the neighbours' own faces occlude it completely) and it fires on exactly the
|
|
437
|
+
// configuration case3 handles, so it dragged facet vertices off the rim they have to meet.
|
|
438
|
+
// ⚠️ A RIM TURN SUSPENDS THE TAPER. The taper fades a chamfer out where the next cell does not
|
|
439
|
+
// continue it — but at a rim turn the next cell does something else entirely: it hands the
|
|
440
|
+
// chamfer to this corner's facet. Fading here would retract the neighbour's band to the sharp
|
|
441
|
+
// corner and leave the facet reaching for an edge that is no longer there.
|
|
442
|
+
// ⚠️ A RIM TURN SUSPENDS THE TAPER: at such a corner the next cell hands the chamfer to the
|
|
443
|
+
// facet rather than dropping it, so fading here would retract a band the facet has to meet.
|
|
444
|
+
// ⚠️ A RIM TURN SUSPENDS THE TAPER, AND FOR EVERY CELL AT THE CORNER — not just the owner.
|
|
445
|
+
// The taper fades a chamfer where the next cell does not continue it, but here the next cell
|
|
446
|
+
// hands it to the owner's facet instead. Fading retracts the very band the facet has to meet,
|
|
447
|
+
// which is what left it hanging with two unpaired edges per corner.
|
|
448
|
+
let pull = rt.here
|
|
449
|
+
? edgeOpen(mask, home, e)
|
|
450
|
+
: edgeOpenTapered(mask, home, e, j);
|
|
451
|
+
// THE CORNER CLIP — taken by exactly ONE of a corner's two rim points, which is what separates
|
|
452
|
+
// them and turns the face into a pentagon there. A facet vertex never takes it on a free axis:
|
|
453
|
+
// it moves along its OWN cube edge and nowhere else, or it will not land on the rim.
|
|
454
|
+
// ⚠️ THE CLIP AND THE FACET MUST BE THE SAME DECISION. Gating the clip on case3 and the facet
|
|
455
|
+
// on rimTurn let them disagree in tangled geometry — the face clipped its corner and no facet
|
|
456
|
+
// came to close it, 15 open edges on a noise field. One predicate, one owner, one exposed face.
|
|
457
|
+
if (role === ROLE_RIM &&
|
|
458
|
+
axis[k] !== 0 &&
|
|
459
|
+
rt.mine &&
|
|
460
|
+
home[0] === rt.face[0] &&
|
|
461
|
+
home[1] === rt.face[1] &&
|
|
462
|
+
home[2] === rt.face[2])
|
|
463
|
+
pull += 1;
|
|
464
|
+
out[k] -= s * bevel * pull;
|
|
298
465
|
}
|
|
299
466
|
return out;
|
|
300
467
|
}
|
|
@@ -319,6 +486,8 @@ const CUBE_POS = array<vec3<f32>, 36>(${CUBE.pos});
|
|
|
319
486
|
const CUBE_NRM = array<vec3<f32>, 36>(${CUBE.nrm});
|
|
320
487
|
const BEV_CORNER = array<vec3<f32>, ${BEVEL_VERTS}>(${BEVEL.cornerWgsl});
|
|
321
488
|
const BEV_HOME = array<vec3<f32>, ${BEVEL_VERTS}>(${BEVEL.homeWgsl});
|
|
489
|
+
const BEV_ROLE = array<f32, ${BEVEL_VERTS}>(${BEVEL.role.map((r) => `${r}.0`).join(', ')});
|
|
490
|
+
const BEV_AXIS = array<vec3<f32>, ${BEVEL_VERTS}>(${BEVEL.axisWgsl});
|
|
322
491
|
|
|
323
492
|
fn qrot(q: vec4<f32>, v: vec3<f32>) -> vec3<f32> { let t = 2.0 * cross(q.xyz, v); return v + q.w * t + cross(q.xyz, t); }
|
|
324
493
|
fn worldOf(inst: Inst, vi: u32) -> vec3<f32> { return inst.pos.xyz + qrot(inst.rot, CUBE_POS[vi] * inst.scl.xyz); }
|
|
@@ -374,34 +543,85 @@ fn notchOpen(mask: u32, a: vec3<f32>, b: vec3<f32>) -> f32 {
|
|
|
374
543
|
// the convex term: the visible surface is shared with neighbours computing from their own cells, and
|
|
375
544
|
// a one-sided cut tears it.
|
|
376
545
|
// THE TAPER — does this edge keep going in the next cell along it? A chamfer that was all-or-nothing
|
|
377
|
-
// per cell STOPPED DEAD in a step wherever it met a block that does not chamfer
|
|
378
|
-
//
|
|
379
|
-
//
|
|
380
|
-
//
|
|
381
|
-
// ⚠️ AND IT CANNOT TEAR: the two cells sharing a vertex along the edge compute edgeOpen(here) *
|
|
382
|
-
// edgeOpen(there) and edgeOpen(there) * edgeOpen(here). The product is SYMMETRIC, so they agree by
|
|
383
|
-
// construction. Mirrors edgeOpenTapered() in TS.
|
|
546
|
+
// per cell STOPPED DEAD in a step wherever it met a block that does not chamfer. j points along the
|
|
547
|
+
// edge toward the end this vertex sits at; asking edgeOpen one cell further fades the band out.
|
|
548
|
+
// Symmetric in the two cells sharing the vertex, so they agree by construction. Mirrors TS.
|
|
384
549
|
fn edgeOpenTapered(mask: u32, a: vec3<f32>, b: vec3<f32>, j: vec3<f32>) -> f32 {
|
|
385
550
|
let here = edgeOpen(mask, a, b);
|
|
386
551
|
if (here == 0.0) { return 0.0; }
|
|
387
552
|
return here * (1.0 - occAt(mask, a + j)) * (1.0 - occAt(mask, b + j))
|
|
388
553
|
* (1.0 - occAt(mask, a + b + j));
|
|
389
554
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
555
|
+
// THE EIGHT CELLS AT A CORNER, and who owns the rim turn there. Asked of the CORNER, not of this
|
|
556
|
+
// cell: all eight see the same configuration relabelled, so exactly one of them acts. Returns
|
|
557
|
+
// (here, mine, faceAxisIndex+1) packed — 0 in .z means "not a rim turn". Mirrors rimTurn() in TS.
|
|
558
|
+
fn rimTurn(mask: u32, c: vec3<f32>) -> vec3<f32> {
|
|
559
|
+
let sg = sign(c);
|
|
560
|
+
for (var k = 0; k < 3; k = k + 1) {
|
|
561
|
+
var far = 0.0;
|
|
562
|
+
var near = 0.0;
|
|
563
|
+
var diagAir = 0.0;
|
|
564
|
+
for (var m = 0u; m < 4u; m = m + 1u) {
|
|
565
|
+
let p = f32(m & 1u);
|
|
566
|
+
let q = f32((m >> 1u) & 1u);
|
|
567
|
+
var o1 = vec3<f32>(0.0, 0.0, 0.0);
|
|
568
|
+
var o0 = vec3<f32>(0.0, 0.0, 0.0);
|
|
569
|
+
if (k == 0) { o1 = vec3(1.0, p, q); o0 = vec3(0.0, p, q); }
|
|
570
|
+
else if (k == 1) { o1 = vec3(p, 1.0, q); o0 = vec3(p, 0.0, q); }
|
|
571
|
+
else { o1 = vec3(p, q, 1.0); o0 = vec3(p, q, 0.0); }
|
|
572
|
+
far = far + occAt(mask, o1 * sg);
|
|
573
|
+
let isSelf = o0.x + o0.y + o0.z;
|
|
574
|
+
let solid0 = select(occAt(mask, o0 * sg), 1.0, isSelf == 0.0);
|
|
575
|
+
near = near + solid0;
|
|
576
|
+
if (p == 1.0 && q == 1.0) { diagAir = 1.0 - solid0; }
|
|
577
|
+
}
|
|
578
|
+
if (far == 0.0 && near == 3.0) {
|
|
579
|
+
return vec3(1.0, diagAir, f32(k) + 1.0);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return vec3(0.0, 0.0, 0.0);
|
|
583
|
+
}
|
|
584
|
+
// The vertex rule — see bevelVertex in TS for the full statement of each term.
|
|
585
|
+
fn bevelPos(mask: u32, c: vec3<f32>, a: vec3<f32>, bevel: f32, role: f32, ax: vec3<f32>) -> vec3<f32> {
|
|
586
|
+
if (role == ${ROLE_SHARP}.0) { return select(c, vec3(0.0, 0.0, 0.0), bevel > 0.0); }
|
|
587
|
+
if (role == ${ROLE_CENTER}.0 || bevel <= 0.0 || mask == 0u) { return c; }
|
|
588
|
+
let rt = rimTurn(mask, c);
|
|
589
|
+
let rtHere = rt.x;
|
|
590
|
+
let rtMine = rt.x * rt.y;
|
|
591
|
+
var rtFace = vec3(0.0, 0.0, 0.0);
|
|
592
|
+
if (rt.z == 1.0) { rtFace = vec3(sign(c.x), 0.0, 0.0); }
|
|
593
|
+
else if (rt.z == 2.0) { rtFace = vec3(0.0, sign(c.y), 0.0); }
|
|
594
|
+
else if (rt.z == 3.0) { rtFace = vec3(0.0, 0.0, sign(c.z)); }
|
|
595
|
+
// One facet per rim turn: the cells beside the owner stand down.
|
|
596
|
+
if (role == ${ROLE_FACET}.0 && rtHere == 1.0 && rtMine == 0.0) { return c; }
|
|
597
|
+
|
|
598
|
+
let free = vec3(1.0, 1.0, 1.0) - abs(a);
|
|
393
599
|
let s = sign(c);
|
|
394
|
-
let
|
|
395
|
-
let ay = vec3(0.0, s.y, 0.0);
|
|
396
|
-
let az = vec3(0.0, 0.0, s.z);
|
|
397
|
-
// The edge cut along axis k runs along the OTHER free axis; free masks the face axis off, so the
|
|
398
|
-
// partner direction is the sum of the free ones minus this one.
|
|
399
|
-
let fx = free.x * ax; let fy = free.y * ay; let fz = free.z * az;
|
|
400
|
-
let sum = fx + fy + fz;
|
|
600
|
+
let onFace = f32(rtMine == 1.0 && all(a == rtFace));
|
|
401
601
|
var d = vec3(0.0, 0.0, 0.0);
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
602
|
+
for (var k = 0; k < 3; k = k + 1) {
|
|
603
|
+
var e = vec3(0.0, 0.0, 0.0);
|
|
604
|
+
var jj = vec3(0.0, 0.0, 0.0);
|
|
605
|
+
var sk = 0.0;
|
|
606
|
+
var axk = 0.0;
|
|
607
|
+
var freek = 0.0;
|
|
608
|
+
if (k == 0) { e = vec3(s.x, 0.0, 0.0); sk = s.x; axk = ax.x; freek = free.x; }
|
|
609
|
+
else if (k == 1) { e = vec3(0.0, s.y, 0.0); sk = s.y; axk = ax.y; freek = free.y; }
|
|
610
|
+
else { e = vec3(0.0, 0.0, s.z); sk = s.z; axk = ax.z; freek = free.z; }
|
|
611
|
+
if (freek < 0.5) {
|
|
612
|
+
// the face's own axis — only the owning facet moves along it, to the rim's low point
|
|
613
|
+
if (role == ${ROLE_FACET}.0 && abs(axk) > 0.5 && rtMine == 1.0) {
|
|
614
|
+
d = d + e * bevel;
|
|
615
|
+
}
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
// the OTHER free axis is the edge this cut runs along
|
|
619
|
+
let partner = (free * s) - e;
|
|
620
|
+
jj = partner;
|
|
621
|
+
var pull = select(edgeOpenTapered(mask, a, e, jj), edgeOpen(mask, a, e), rtHere == 1.0);
|
|
622
|
+
if (role == ${ROLE_RIM}.0 && abs(axk) > 0.5 && onFace == 1.0) { pull = pull + 1.0; }
|
|
623
|
+
d = d + e * bevel * pull;
|
|
624
|
+
}
|
|
405
625
|
return c - d;
|
|
406
626
|
}
|
|
407
627
|
// Vertex AO for cube vertex vi, in [AO_MIN, 1]. Every cube vertex sits at a CORNER, so CUBE_POS is
|
|
@@ -618,7 +838,7 @@ fn faceVec(code: f32) -> vec3<f32> {
|
|
|
618
838
|
// 36 vertices long in that case anyway (see the indirect args), so the tail is never even reached.
|
|
619
839
|
let sharp = BEV_CORNER[vi];
|
|
620
840
|
let home = BEV_HOME[vi];
|
|
621
|
-
let local = bevelPos(mask, sharp, home, cam.eye.w);
|
|
841
|
+
let local = bevelPos(mask, sharp, home, cam.eye.w, BEV_ROLE[vi], BEV_AXIS[vi]);
|
|
622
842
|
let world = inst.pos.xyz + qrot(inst.rot, local * inst.scl.xyz);
|
|
623
843
|
var o: VOut;
|
|
624
844
|
o.clip = cam.camVP * vec4(world, 1.0);
|