ugly-game 0.15.6 → 0.15.8
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 -3
- package/dist/gpuShadow.js +70 -9
- package/package.json +1 -1
package/dist/gpuShadow.d.ts
CHANGED
|
@@ -106,13 +106,48 @@ 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
|
|
114
|
-
*
|
|
115
|
-
*
|
|
131
|
+
* A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by two conditions on
|
|
132
|
+
* that axis, which cannot both hold (one needs `home` AIR, the other needs it SOLID):
|
|
133
|
+
*
|
|
134
|
+
* CONVEX — `edgeOpen(home, e_k)`. The ordinary chamfer, at full size.
|
|
135
|
+
* NOTCH — `notchOpen(home, e_k)`, at `NOTCH_SCALE`. Softens the inside corner of an L.
|
|
136
|
+
*
|
|
137
|
+
* ⚠️ NEITHER TERM MAY EVER MOVE A VERTEX ON AN EXPOSED FACE EXCEPT THE CONVEX ONE, and the oracle
|
|
138
|
+
* asserts it over 800 masks. An exposed face is part of the surface you can SEE, and its corners are
|
|
139
|
+
* shared with the neighbouring blocks that own the rest of that surface — each computing from its
|
|
140
|
+
* OWN neighbourhood. A term reading cells this block can see and its neighbour cannot will move a
|
|
141
|
+
* shared corner one-sidedly and tear the ground open.
|
|
142
|
+
*
|
|
143
|
+
* The convex term is safe because it requires the cell across the shared face to be AIR, and if it
|
|
144
|
+
* is air there is no neighbour to disagree with. `notchOpen` is safe because it requires `home`
|
|
145
|
+
* SOLID — a buried face, where the neighbour's own full face closes the wedge.
|
|
146
|
+
*
|
|
147
|
+
* A third "capping" term once cut an exposed face's corner wherever the in-plane diagonal was air,
|
|
148
|
+
* to stop the notch chamfer ending in a step. That is a plain diagonal step-down in any heightmap,
|
|
149
|
+
* the neighbour sharing the corner could not make the same cut, and it shipped as visibly torn
|
|
150
|
+
* ground — "concave corners are not rendering correctly". The step is the correct trade.
|
|
116
151
|
*/
|
|
117
152
|
export declare function bevelVertex(corner: readonly [number, number, number], home: readonly [number, number, number], mask: number, bevel: number): [number, number, number];
|
|
118
153
|
export declare class GpuShadowRenderer {
|
package/dist/gpuShadow.js
CHANGED
|
@@ -191,13 +191,53 @@ 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
|
|
199
|
-
*
|
|
200
|
-
*
|
|
221
|
+
* A vertex's pull along a free axis `k` is inward (`-sign(corner[k])`), gated by two conditions on
|
|
222
|
+
* that axis, which cannot both hold (one needs `home` AIR, the other needs it SOLID):
|
|
223
|
+
*
|
|
224
|
+
* CONVEX — `edgeOpen(home, e_k)`. The ordinary chamfer, at full size.
|
|
225
|
+
* NOTCH — `notchOpen(home, e_k)`, at `NOTCH_SCALE`. Softens the inside corner of an L.
|
|
226
|
+
*
|
|
227
|
+
* ⚠️ NEITHER TERM MAY EVER MOVE A VERTEX ON AN EXPOSED FACE EXCEPT THE CONVEX ONE, and the oracle
|
|
228
|
+
* asserts it over 800 masks. An exposed face is part of the surface you can SEE, and its corners are
|
|
229
|
+
* shared with the neighbouring blocks that own the rest of that surface — each computing from its
|
|
230
|
+
* OWN neighbourhood. A term reading cells this block can see and its neighbour cannot will move a
|
|
231
|
+
* shared corner one-sidedly and tear the ground open.
|
|
232
|
+
*
|
|
233
|
+
* The convex term is safe because it requires the cell across the shared face to be AIR, and if it
|
|
234
|
+
* is air there is no neighbour to disagree with. `notchOpen` is safe because it requires `home`
|
|
235
|
+
* SOLID — a buried face, where the neighbour's own full face closes the wedge.
|
|
236
|
+
*
|
|
237
|
+
* A third "capping" term once cut an exposed face's corner wherever the in-plane diagonal was air,
|
|
238
|
+
* to stop the notch chamfer ending in a step. That is a plain diagonal step-down in any heightmap,
|
|
239
|
+
* the neighbour sharing the corner could not make the same cut, and it shipped as visibly torn
|
|
240
|
+
* ground — "concave corners are not rendering correctly". The step is the correct trade.
|
|
201
241
|
*/
|
|
202
242
|
export function bevelVertex(corner, home, mask, bevel) {
|
|
203
243
|
const out = [corner[0], corner[1], corner[2]];
|
|
@@ -207,9 +247,12 @@ export function bevelVertex(corner, home, mask, bevel) {
|
|
|
207
247
|
if (home[k] !== 0)
|
|
208
248
|
continue; // the face axis itself is never pulled
|
|
209
249
|
const s = Math.sign(corner[k]);
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
out[k] -=
|
|
250
|
+
const e = [0, 0, 0];
|
|
251
|
+
e[k] = s;
|
|
252
|
+
out[k] -=
|
|
253
|
+
s *
|
|
254
|
+
bevel *
|
|
255
|
+
(edgeOpen(mask, home, e) + NOTCH_SCALE * notchOpen(mask, home, e));
|
|
213
256
|
}
|
|
214
257
|
return out;
|
|
215
258
|
}
|
|
@@ -273,14 +316,32 @@ fn edgeOpen(mask: u32, a: vec3<f32>, b: vec3<f32>) -> f32 {
|
|
|
273
316
|
// face and the face on that side. Both primitives that share a vertex resolve the same face/axis
|
|
274
317
|
// pair, so they cannot land in different places — that is where watertightness comes from, and it
|
|
275
318
|
// is why this takes (corner, home) rather than a vertex index.
|
|
319
|
+
// THE NOTCH — the exact complement of edgeOpen: both faces SOLID, the diagonal between them AIR.
|
|
320
|
+
// Three blocks in an L around an empty cell: the two with a FACE on it chamfer normally, the third
|
|
321
|
+
// touches it only along one corner edge and keeps a hard arris down the inside of the notch. This is
|
|
322
|
+
// what softens that. Cutting it cannot open a hole — the wedge is inside this block's own cell and
|
|
323
|
+
// the neighbours' buried faces (drawn, like every face of every instance) close it. Mirrors
|
|
324
|
+
// notchOpen() in TS.
|
|
325
|
+
fn notchOpen(mask: u32, a: vec3<f32>, b: vec3<f32>) -> f32 {
|
|
326
|
+
if (mask == 0u) { return 0.0; }
|
|
327
|
+
return occAt(mask, a) * occAt(mask, b) * (1.0 - occAt(mask, a + b));
|
|
328
|
+
}
|
|
329
|
+
// The vertex rule. A vertex's pull along a free axis is INWARD, gated by the CONVEX chamfer (both
|
|
330
|
+
// cells air) or the NOTCH (both solid, diagonal air) — never both, since they disagree about the
|
|
331
|
+
// home face. See bevelVertex in TS for why nothing here may move a vertex on an EXPOSED face except
|
|
332
|
+
// the convex term: the visible surface is shared with neighbours computing from their own cells, and
|
|
333
|
+
// a one-sided cut tears it.
|
|
276
334
|
fn bevelPos(mask: u32, c: vec3<f32>, a: vec3<f32>, bevel: f32) -> vec3<f32> {
|
|
277
335
|
if (bevel <= 0.0 || mask == 0u) { return c; }
|
|
278
336
|
let free = vec3(1.0, 1.0, 1.0) - abs(a); // the two in-face axes; the face axis is never pulled
|
|
279
337
|
let s = sign(c);
|
|
338
|
+
let ax = vec3(s.x, 0.0, 0.0);
|
|
339
|
+
let ay = vec3(0.0, s.y, 0.0);
|
|
340
|
+
let az = vec3(0.0, 0.0, s.z);
|
|
280
341
|
var d = vec3(0.0, 0.0, 0.0);
|
|
281
|
-
d.x = free.x * s.x * bevel * edgeOpen(mask, a,
|
|
282
|
-
d.y = free.y * s.y * bevel * edgeOpen(mask, a,
|
|
283
|
-
d.z = free.z * s.z * bevel * edgeOpen(mask, a,
|
|
342
|
+
d.x = free.x * s.x * bevel * (edgeOpen(mask, a, ax) + ${NOTCH_SCALE} * notchOpen(mask, a, ax));
|
|
343
|
+
d.y = free.y * s.y * bevel * (edgeOpen(mask, a, ay) + ${NOTCH_SCALE} * notchOpen(mask, a, ay));
|
|
344
|
+
d.z = free.z * s.z * bevel * (edgeOpen(mask, a, az) + ${NOTCH_SCALE} * notchOpen(mask, a, az));
|
|
284
345
|
return c - d;
|
|
285
346
|
}
|
|
286
347
|
// Vertex AO for cube vertex vi, in [AO_MIN, 1]. Every cube vertex sits at a CORNER, so CUBE_POS is
|