ugly-game 0.15.7 → 0.15.9
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 +38 -9
- package/dist/gpuShadow.js +91 -37
- package/package.json +1 -1
package/dist/gpuShadow.d.ts
CHANGED
|
@@ -106,6 +106,27 @@ 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 TAPER — does this edge keep going in the next cell along it?
|
|
111
|
+
*
|
|
112
|
+
* A chamfer used to be all-or-nothing per cell, so where a chamfered edge met a block that does not
|
|
113
|
+
* chamfer (its own neighbour is solid) the rounding STOPPED DEAD in a step the height of the bevel.
|
|
114
|
+
* That is the "concave corners are not rendering correctly" report: at every inside junction a
|
|
115
|
+
* rounded edge ran into a square one and left a hard notch.
|
|
116
|
+
*
|
|
117
|
+
* `j` is the edge's own direction, signed toward the end this vertex sits at. Evaluating `edgeOpen`
|
|
118
|
+
* one cell further along it asks whether the neighbour chamfers the same edge; multiplying, the band
|
|
119
|
+
* fades to nothing across the last block instead of ending in a wall.
|
|
120
|
+
*
|
|
121
|
+
* ⚠️ AND THIS IS WHY IT CANNOT TEAR, which the previous attempt at the same symptom could not claim.
|
|
122
|
+
* Take the two cells sharing a vertex along the edge: one computes `edgeOpen(here) · edgeOpen(there)`
|
|
123
|
+
* and the other computes `edgeOpen(there) · edgeOpen(here)`. The product is SYMMETRIC, so they agree
|
|
124
|
+
* by construction rather than by luck — no block can cut a shared corner its neighbour keeps.
|
|
125
|
+
*
|
|
126
|
+
* Every cell it reads (a+j, b+j, a+b+j) has all components in {-1,0,1}, so it stays inside the
|
|
127
|
+
* 27-neighbourhood the mask carries.
|
|
128
|
+
*/
|
|
129
|
+
export declare function edgeOpenTapered(mask: number, a: readonly [number, number, number], b: readonly [number, number, number], j: readonly [number, number, number]): number;
|
|
109
130
|
/**
|
|
110
131
|
* THE NOTCH — the exact complement of `edgeOpen`: both faces SOLID, the diagonal between them AIR.
|
|
111
132
|
*
|
|
@@ -128,18 +149,26 @@ export declare const NOTCH_SCALE = 0.5;
|
|
|
128
149
|
* THE VERTEX RULE, in JS — the oracle `gpuShadow.bevel.test.mts` checks and the exact thing
|
|
129
150
|
* `bevelPos()` in COMMON_WGSL does. Kept in step with it by hand; the test is what notices.
|
|
130
151
|
*
|
|
131
|
-
* A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by
|
|
132
|
-
*
|
|
152
|
+
* A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by two conditions on
|
|
153
|
+
* that axis, which cannot both hold (one needs `home` AIR, the other needs it SOLID):
|
|
133
154
|
*
|
|
134
155
|
* CONVEX — `edgeOpen(home, e_k)`. The ordinary chamfer, at full size.
|
|
135
|
-
* NOTCH
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
156
|
+
* NOTCH — `notchOpen(home, e_k)`, at `NOTCH_SCALE`. Softens the inside corner of an L.
|
|
157
|
+
*
|
|
158
|
+
* ⚠️ NEITHER TERM MAY EVER MOVE A VERTEX ON AN EXPOSED FACE EXCEPT THE CONVEX ONE, and the oracle
|
|
159
|
+
* asserts it over 800 masks. An exposed face is part of the surface you can SEE, and its corners are
|
|
160
|
+
* shared with the neighbouring blocks that own the rest of that surface — each computing from its
|
|
161
|
+
* OWN neighbourhood. A term reading cells this block can see and its neighbour cannot will move a
|
|
162
|
+
* shared corner one-sidedly and tear the ground open.
|
|
163
|
+
*
|
|
164
|
+
* The convex term is safe because it requires the cell across the shared face to be AIR, and if it
|
|
165
|
+
* is air there is no neighbour to disagree with. `notchOpen` is safe because it requires `home`
|
|
166
|
+
* SOLID — a buried face, where the neighbour's own full face closes the wedge.
|
|
140
167
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
168
|
+
* A third "capping" term once cut an exposed face's corner wherever the in-plane diagonal was air,
|
|
169
|
+
* to stop the notch chamfer ending in a step. That is a plain diagonal step-down in any heightmap,
|
|
170
|
+
* the neighbour sharing the corner could not make the same cut, and it shipped as visibly torn
|
|
171
|
+
* ground — "concave corners are not rendering correctly". The step is the correct trade.
|
|
143
172
|
*/
|
|
144
173
|
export declare function bevelVertex(corner: readonly [number, number, number], home: readonly [number, number, number], mask: number, bevel: number): [number, number, number];
|
|
145
174
|
export declare class GpuShadowRenderer {
|
package/dist/gpuShadow.js
CHANGED
|
@@ -191,6 +191,42 @@ 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 TAPER — does this edge keep going in the next cell along it?
|
|
196
|
+
*
|
|
197
|
+
* A chamfer used to be all-or-nothing per cell, so where a chamfered edge met a block that does not
|
|
198
|
+
* chamfer (its own neighbour is solid) the rounding STOPPED DEAD in a step the height of the bevel.
|
|
199
|
+
* That is the "concave corners are not rendering correctly" report: at every inside junction a
|
|
200
|
+
* rounded edge ran into a square one and left a hard notch.
|
|
201
|
+
*
|
|
202
|
+
* `j` is the edge's own direction, signed toward the end this vertex sits at. Evaluating `edgeOpen`
|
|
203
|
+
* one cell further along it asks whether the neighbour chamfers the same edge; multiplying, the band
|
|
204
|
+
* fades to nothing across the last block instead of ending in a wall.
|
|
205
|
+
*
|
|
206
|
+
* ⚠️ AND THIS IS WHY IT CANNOT TEAR, which the previous attempt at the same symptom could not claim.
|
|
207
|
+
* Take the two cells sharing a vertex along the edge: one computes `edgeOpen(here) · edgeOpen(there)`
|
|
208
|
+
* and the other computes `edgeOpen(there) · edgeOpen(here)`. The product is SYMMETRIC, so they agree
|
|
209
|
+
* by construction rather than by luck — no block can cut a shared corner its neighbour keeps.
|
|
210
|
+
*
|
|
211
|
+
* Every cell it reads (a+j, b+j, a+b+j) has all components in {-1,0,1}, so it stays inside the
|
|
212
|
+
* 27-neighbourhood the mask carries.
|
|
213
|
+
*/
|
|
214
|
+
export function edgeOpenTapered(mask, a, b, j) {
|
|
215
|
+
const here = edgeOpen(mask, a, b);
|
|
216
|
+
if (here === 0)
|
|
217
|
+
return 0;
|
|
218
|
+
const sa = [a[0] + j[0], a[1] + j[1], a[2] + j[2]];
|
|
219
|
+
const sb = [b[0] + j[0], b[1] + j[1], b[2] + j[2]];
|
|
220
|
+
const sd = [
|
|
221
|
+
a[0] + b[0] + j[0],
|
|
222
|
+
a[1] + b[1] + j[1],
|
|
223
|
+
a[2] + b[2] + j[2],
|
|
224
|
+
];
|
|
225
|
+
return (here *
|
|
226
|
+
(1 - occSolid(mask, sa)) *
|
|
227
|
+
(1 - occSolid(mask, sb)) *
|
|
228
|
+
(1 - occSolid(mask, sd)));
|
|
229
|
+
}
|
|
194
230
|
/**
|
|
195
231
|
* THE NOTCH — the exact complement of `edgeOpen`: both faces SOLID, the diagonal between them AIR.
|
|
196
232
|
*
|
|
@@ -218,39 +254,47 @@ export const NOTCH_SCALE = 0.5;
|
|
|
218
254
|
* THE VERTEX RULE, in JS — the oracle `gpuShadow.bevel.test.mts` checks and the exact thing
|
|
219
255
|
* `bevelPos()` in COMMON_WGSL does. Kept in step with it by hand; the test is what notices.
|
|
220
256
|
*
|
|
221
|
-
* A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by
|
|
222
|
-
*
|
|
257
|
+
* A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by two conditions on
|
|
258
|
+
* that axis, which cannot both hold (one needs `home` AIR, the other needs it SOLID):
|
|
223
259
|
*
|
|
224
260
|
* CONVEX — `edgeOpen(home, e_k)`. The ordinary chamfer, at full size.
|
|
225
|
-
* NOTCH
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
261
|
+
* NOTCH — `notchOpen(home, e_k)`, at `NOTCH_SCALE`. Softens the inside corner of an L.
|
|
262
|
+
*
|
|
263
|
+
* ⚠️ NEITHER TERM MAY EVER MOVE A VERTEX ON AN EXPOSED FACE EXCEPT THE CONVEX ONE, and the oracle
|
|
264
|
+
* asserts it over 800 masks. An exposed face is part of the surface you can SEE, and its corners are
|
|
265
|
+
* shared with the neighbouring blocks that own the rest of that surface — each computing from its
|
|
266
|
+
* OWN neighbourhood. A term reading cells this block can see and its neighbour cannot will move a
|
|
267
|
+
* shared corner one-sidedly and tear the ground open.
|
|
268
|
+
*
|
|
269
|
+
* The convex term is safe because it requires the cell across the shared face to be AIR, and if it
|
|
270
|
+
* is air there is no neighbour to disagree with. `notchOpen` is safe because it requires `home`
|
|
271
|
+
* SOLID — a buried face, where the neighbour's own full face closes the wedge.
|
|
230
272
|
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
273
|
+
* A third "capping" term once cut an exposed face's corner wherever the in-plane diagonal was air,
|
|
274
|
+
* to stop the notch chamfer ending in a step. That is a plain diagonal step-down in any heightmap,
|
|
275
|
+
* the neighbour sharing the corner could not make the same cut, and it shipped as visibly torn
|
|
276
|
+
* ground — "concave corners are not rendering correctly". The step is the correct trade.
|
|
233
277
|
*/
|
|
234
278
|
export function bevelVertex(corner, home, mask, bevel) {
|
|
235
279
|
const out = [corner[0], corner[1], corner[2]];
|
|
236
280
|
if (bevel <= 0 || mask === 0)
|
|
237
281
|
return out;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
// agrees to — which is a crack.
|
|
250
|
-
const notch = Math.max(notchOpen(mask, home, bk), notchOpen(mask, bk, axis(j)));
|
|
282
|
+
for (let k = 0; k < 3; k++) {
|
|
283
|
+
if (home[k] !== 0)
|
|
284
|
+
continue; // the face axis itself is never pulled
|
|
285
|
+
const s = Math.sign(corner[k]);
|
|
286
|
+
const e = [0, 0, 0];
|
|
287
|
+
e[k] = s;
|
|
288
|
+
// The edge being cut runs along the THIRD axis — not this face's axis, not the pull axis — and
|
|
289
|
+
// this vertex sits at one end of it. `j` points at that end, which is what the taper needs.
|
|
290
|
+
const jAxis = [0, 1, 2].find((i) => i !== k && home[i] === 0) ?? k;
|
|
291
|
+
const j = [0, 0, 0];
|
|
292
|
+
j[jAxis] = Math.sign(corner[jAxis]);
|
|
251
293
|
out[k] -=
|
|
252
|
-
|
|
253
|
-
|
|
294
|
+
s *
|
|
295
|
+
bevel *
|
|
296
|
+
(edgeOpenTapered(mask, home, e, j) +
|
|
297
|
+
NOTCH_SCALE * notchOpen(mask, home, e));
|
|
254
298
|
}
|
|
255
299
|
return out;
|
|
256
300
|
}
|
|
@@ -324,12 +368,25 @@ fn notchOpen(mask: u32, a: vec3<f32>, b: vec3<f32>) -> f32 {
|
|
|
324
368
|
if (mask == 0u) { return 0.0; }
|
|
325
369
|
return occAt(mask, a) * occAt(mask, b) * (1.0 - occAt(mask, a + b));
|
|
326
370
|
}
|
|
327
|
-
// The vertex rule. A vertex's pull along a free axis is INWARD, gated by the
|
|
328
|
-
//
|
|
329
|
-
//
|
|
371
|
+
// The vertex rule. A vertex's pull along a free axis is INWARD, gated by the CONVEX chamfer (both
|
|
372
|
+
// cells air) or the NOTCH (both solid, diagonal air) — never both, since they disagree about the
|
|
373
|
+
// home face. See bevelVertex in TS for why nothing here may move a vertex on an EXPOSED face except
|
|
374
|
+
// the convex term: the visible surface is shared with neighbours computing from their own cells, and
|
|
375
|
+
// a one-sided cut tears it.
|
|
376
|
+
// 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, which is the
|
|
378
|
+
// "concave corners are not rendering correctly" report. j points along the edge toward the end this
|
|
379
|
+
// vertex sits at; asking edgeOpen one cell further fades the band out instead.
|
|
330
380
|
//
|
|
331
|
-
// ⚠️
|
|
332
|
-
//
|
|
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.
|
|
384
|
+
fn edgeOpenTapered(mask: u32, a: vec3<f32>, b: vec3<f32>, j: vec3<f32>) -> f32 {
|
|
385
|
+
let here = edgeOpen(mask, a, b);
|
|
386
|
+
if (here == 0.0) { return 0.0; }
|
|
387
|
+
return here * (1.0 - occAt(mask, a + j)) * (1.0 - occAt(mask, b + j))
|
|
388
|
+
* (1.0 - occAt(mask, a + b + j));
|
|
389
|
+
}
|
|
333
390
|
fn bevelPos(mask: u32, c: vec3<f32>, a: vec3<f32>, bevel: f32) -> vec3<f32> {
|
|
334
391
|
if (bevel <= 0.0 || mask == 0u) { return c; }
|
|
335
392
|
let free = vec3(1.0, 1.0, 1.0) - abs(a); // the two in-face axes; the face axis is never pulled
|
|
@@ -337,17 +394,14 @@ fn bevelPos(mask: u32, c: vec3<f32>, a: vec3<f32>, bevel: f32) -> vec3<f32> {
|
|
|
337
394
|
let ax = vec3(s.x, 0.0, 0.0);
|
|
338
395
|
let ay = vec3(0.0, s.y, 0.0);
|
|
339
396
|
let az = vec3(0.0, 0.0, s.z);
|
|
340
|
-
// The
|
|
341
|
-
//
|
|
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.
|
|
342
399
|
let fx = free.x * ax; let fy = free.y * ay; let fz = free.z * az;
|
|
343
400
|
let sum = fx + fy + fz;
|
|
344
401
|
var d = vec3(0.0, 0.0, 0.0);
|
|
345
|
-
d.x = free.x * s.x * bevel * (
|
|
346
|
-
|
|
347
|
-
d.
|
|
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)));
|
|
402
|
+
d.x = free.x * s.x * bevel * (edgeOpenTapered(mask, a, ax, sum - fx) + ${NOTCH_SCALE} * notchOpen(mask, a, ax));
|
|
403
|
+
d.y = free.y * s.y * bevel * (edgeOpenTapered(mask, a, ay, sum - fy) + ${NOTCH_SCALE} * notchOpen(mask, a, ay));
|
|
404
|
+
d.z = free.z * s.z * bevel * (edgeOpenTapered(mask, a, az, sum - fz) + ${NOTCH_SCALE} * notchOpen(mask, a, az));
|
|
351
405
|
return c - d;
|
|
352
406
|
}
|
|
353
407
|
// Vertex AO for cube vertex vi, in [AO_MIN, 1]. Every cube vertex sits at a CORNER, so CUBE_POS is
|