ugly-game 0.14.3 → 0.14.4
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 +30 -0
- package/dist/gpuShadow.js +72 -11
- package/package.json +10 -9
package/dist/gpuShadow.d.ts
CHANGED
|
@@ -11,6 +11,19 @@ export interface CubeInstance {
|
|
|
11
11
|
rot?: [number, number, number, number];
|
|
12
12
|
tile?: number;
|
|
13
13
|
up?: number;
|
|
14
|
+
/**
|
|
15
|
+
* CONTACT DECAL, packed. Both default to 0, which is exactly what fill() already wrote into these
|
|
16
|
+
* two slots, so an instance that omits them is byte-identical to one built before decals existed.
|
|
17
|
+
*
|
|
18
|
+
* decalPos = quantised centre of the disturbance in THIS block's own face-local frame
|
|
19
|
+
* decalKind = kind + per-prop style + radius
|
|
20
|
+
*
|
|
21
|
+
* The packing lives with the game that derives it (see the consumer's shared/decorDecal.ts); the
|
|
22
|
+
* renderer only unpacks. Keeping the format there rather than here is deliberate: it is a
|
|
23
|
+
* statement about props and soil, not about cubes.
|
|
24
|
+
*/
|
|
25
|
+
decalPos?: number;
|
|
26
|
+
decalKind?: number;
|
|
14
27
|
}
|
|
15
28
|
/** Atlas layout: which ARRAY LAYER a material's top/side/bottom faces sample.
|
|
16
29
|
*
|
|
@@ -60,6 +73,15 @@ export declare class GpuShadowRenderer {
|
|
|
60
73
|
private atlasSampler;
|
|
61
74
|
private tileLayerBuf;
|
|
62
75
|
private useAtlas;
|
|
76
|
+
/**
|
|
77
|
+
* How much of the per-voxel edge AO survives on ATLAS-textured blocks, 0..1.
|
|
78
|
+
*
|
|
79
|
+
* Zero by default, which is the behaviour every existing caller already has: the fragment does
|
|
80
|
+
* `mix(1.0, blockShade, 0.0)`, which is exactly 1.0. Textured terrain has therefore had no
|
|
81
|
+
* per-voxel AO at all — the full term reads as an inked grid, so it was dropped rather than
|
|
82
|
+
* softened, and nothing replaced it.
|
|
83
|
+
*/
|
|
84
|
+
private atlasAO;
|
|
63
85
|
private alphaPipe;
|
|
64
86
|
private alphaBGL;
|
|
65
87
|
private overlayBuf;
|
|
@@ -113,6 +135,14 @@ export declare class GpuShadowRenderer {
|
|
|
113
135
|
* distinct array layers; a `CubeInstance.tile` of that material id + its `up`-face code selects the
|
|
114
136
|
* right layer in-shader. `tex` must be a 2d texture with at least (max layer + 1) array layers.
|
|
115
137
|
* Call once after the texture is uploaded; instances with `tile < 0` still use the flat hue path. */
|
|
138
|
+
/**
|
|
139
|
+
* Soften the per-voxel edge AO back on for textured blocks. 0 (the default) is off entirely.
|
|
140
|
+
*
|
|
141
|
+
* Separate from `setAtlas` on purpose: the atlas is an ASSET and this is a LOOK, and a renderer
|
|
142
|
+
* that made you re-upload a 2816² texture to change a shading constant would be one nobody
|
|
143
|
+
* adjusted. Safe to call every frame — it writes one float into the camera uniform.
|
|
144
|
+
*/
|
|
145
|
+
setAtlasAO(strength: number): void;
|
|
116
146
|
setAtlas(tex: GPUTexture, layout: AtlasLayout): void;
|
|
117
147
|
/** Static scene: sizes the buffer to exactly these instances. */
|
|
118
148
|
setScene(instances: CubeInstance[]): void;
|
package/dist/gpuShadow.js
CHANGED
|
@@ -67,11 +67,11 @@ struct Cam {
|
|
|
67
67
|
sun: vec4<f32>, // xyz = direction light travels, w = ambient
|
|
68
68
|
sunCol: vec4<f32>, // xyz = sun colour, w = shadow map size (texels)
|
|
69
69
|
tint: vec4<f32>, // rgb = per-planet tint · w = tint strength (0 = none)
|
|
70
|
-
atlas: vec4<f32>, // x = useAtlas (1/0)
|
|
70
|
+
atlas: vec4<f32>, // x = useAtlas (1/0) · y = how much per-voxel AO survives on textured blocks (0 = none)
|
|
71
71
|
up: vec4<f32>, // xyz = local gravity up (for hemisphere face-shading readability); w = linear-HDR flag
|
|
72
72
|
csm: vec4<f32>, // x = active cascade count · y = crossfade band in uv units
|
|
73
73
|
};
|
|
74
|
-
struct Inst { pos: vec4<f32>, scl: vec4<f32>, rot: vec4<f32>, aux: vec4<f32> }; // pos.w = hue (<0 ⇒ ground) · scl.w = emissive/alpha · rot = quaternion · aux.x = atlas tile (<0 ⇒ hue) · aux.y = up-face code
|
|
74
|
+
struct Inst { pos: vec4<f32>, scl: vec4<f32>, rot: vec4<f32>, aux: vec4<f32> }; // pos.w = hue (<0 ⇒ ground) · scl.w = emissive/alpha · rot = quaternion · aux.x = atlas tile (<0 ⇒ hue) · aux.y = up-face code · aux.z/aux.w = CONTACT DECAL (0,0 = none; see setAtlasAO/CubeInstance.decal*)
|
|
75
75
|
@group(0) @binding(0) var<uniform> cam: Cam;
|
|
76
76
|
@group(0) @binding(1) var<storage, read> insts: array<Inst>;
|
|
77
77
|
|
|
@@ -229,7 +229,7 @@ struct GiGrid { org: vec4<f32>, dim: vec4<f32> };
|
|
|
229
229
|
@group(0) @binding(9) var<storage, read> probes: array<vec4<f32>>;
|
|
230
230
|
${GI_WGSL}
|
|
231
231
|
|
|
232
|
-
struct VOut { @builtin(position) clip: vec4<f32>, @location(0) world: vec3<f32>, @location(1) nrm: vec3<f32>, @location(2) hue: f32, @location(3) emis: f32, @location(4) blk: vec3<f32>, @location(5) objN: vec3<f32>, @location(6) tile: f32, @location(7) upc: f32 };
|
|
232
|
+
struct VOut { @builtin(position) clip: vec4<f32>, @location(0) world: vec3<f32>, @location(1) nrm: vec3<f32>, @location(2) hue: f32, @location(3) emis: f32, @location(4) blk: vec3<f32>, @location(5) objN: vec3<f32>, @location(6) tile: f32, @location(7) upc: f32, @location(8) @interpolate(flat) decal: vec2<f32> };
|
|
233
233
|
|
|
234
234
|
fn faceVec(code: f32) -> vec3<f32> {
|
|
235
235
|
let c = i32(code);
|
|
@@ -252,7 +252,7 @@ fn faceVec(code: f32) -> vec3<f32> {
|
|
|
252
252
|
// by inst.scl so a merged LOD cube (scl>1) still shows its sub-blocks. objN = pre-rotation face normal.
|
|
253
253
|
o.blk = (CUBE_POS[vi] + vec3(0.5, 0.5, 0.5)) * inst.scl.xyz;
|
|
254
254
|
o.objN = CUBE_NRM[vi];
|
|
255
|
-
o.tile = inst.aux.x; o.upc = inst.aux.y;
|
|
255
|
+
o.tile = inst.aux.x; o.upc = inst.aux.y; o.decal = inst.aux.zw;
|
|
256
256
|
return o;
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -344,10 +344,12 @@ fn fixedFill(N: vec3<f32>, up: vec3<f32>) -> f32 {
|
|
|
344
344
|
// pattern is anchored to the model's own block grid and translates/rotates with the instance.
|
|
345
345
|
let an = abs(i.objN);
|
|
346
346
|
var fx: f32; var fz: f32;
|
|
347
|
+
var bx: f32; var bz: f32; // the SAME pair unwrapped — fract() wraps at the far block edge, which
|
|
348
|
+
// a texture hides and a decal would show as a hard line through itself
|
|
347
349
|
var dfx: vec2<f32>; var dfz: vec2<f32>; // (ddx, ddy) of each in-face axis, selected alongside it
|
|
348
|
-
if (an.y >= an.x && an.y >= an.z) { fx = fract(i.blk.x); fz = fract(i.blk.z); dfx = vec2(dblkx.x, dblky.x); dfz = vec2(dblkx.z, dblky.z); }
|
|
349
|
-
else if (an.x >= an.z) { fx = fract(i.blk.y); fz = fract(i.blk.z); dfx = vec2(dblkx.y, dblky.y); dfz = vec2(dblkx.z, dblky.z); }
|
|
350
|
-
else { fx = fract(i.blk.x); fz = fract(i.blk.y); dfx = vec2(dblkx.x, dblky.x); dfz = vec2(dblkx.y, dblky.y); }
|
|
350
|
+
if (an.y >= an.x && an.y >= an.z) { fx = fract(i.blk.x); fz = fract(i.blk.z); bx = i.blk.x; bz = i.blk.z; dfx = vec2(dblkx.x, dblky.x); dfz = vec2(dblkx.z, dblky.z); }
|
|
351
|
+
else if (an.x >= an.z) { fx = fract(i.blk.y); fz = fract(i.blk.z); bx = i.blk.y; bz = i.blk.z; dfx = vec2(dblkx.y, dblky.y); dfz = vec2(dblkx.z, dblky.z); }
|
|
352
|
+
else { fx = fract(i.blk.x); fz = fract(i.blk.y); bx = i.blk.x; bz = i.blk.y; dfx = vec2(dblkx.x, dblky.x); dfz = vec2(dblkx.y, dblky.y); }
|
|
351
353
|
var base = select(mix(vec3(0.34), hsv(i.hue), 0.62), vec3(0.6, 0.62, 0.66), i.hue < 0.0);
|
|
352
354
|
if (cam.atlas.x > 0.5 && i.tile >= 0.0) { // ATLAS: pick top/side/bottom LAYER from the face vs the up axis
|
|
353
355
|
let d = dot(i.objN, faceVec(i.upc));
|
|
@@ -362,9 +364,48 @@ fn fixedFill(N: vec3<f32>, up: vec3<f32>) -> f32 {
|
|
|
362
364
|
let texc = textureSampleGrad(atlasTex, atlasSamp, uv, layer, vec2(dfx.x, dfz.x), vec2(dfx.y, dfz.y)).rgb;
|
|
363
365
|
base = mix(texc, texc * cam.tint.rgb, cam.tint.w); // per-planet tint
|
|
364
366
|
}
|
|
367
|
+
// ── PROP CONTACT DECAL ────────────────────────────────────────────────────────────────────────
|
|
368
|
+
// A plant on a 1 m cube reads as PASTED ON because the block under it is untouched: the same flat
|
|
369
|
+
// grass runs up to the trunk and stops. This stamps the ground the prop actually disturbed onto
|
|
370
|
+
// the block it stands on AND the blocks around it, and pools a little darkness where they meet.
|
|
371
|
+
//
|
|
372
|
+
// The pattern coordinate is p = (in-face position) - (decal centre), i.e. metres FROM THE PROP.
|
|
373
|
+
// That is what makes the bleed work with no shared state: every block the same prop splatted
|
|
374
|
+
// stores the centre in ITS OWN frame, so p is the same world vector in all of them and the falloff
|
|
375
|
+
// is continuous across block and chunk boundaries.
|
|
376
|
+
var soil = 0.0;
|
|
377
|
+
var contact = 1.0;
|
|
378
|
+
let dpos = u32(i.decal.x);
|
|
379
|
+
let dkind = u32(i.decal.y);
|
|
380
|
+
if (dkind != 0u) {
|
|
381
|
+
let du = f32(dpos >> 8u) * (1.0 / 32.0) - 4.0;
|
|
382
|
+
let dv = f32(dpos & 255u) * (1.0 / 32.0) - 4.0;
|
|
383
|
+
let rad = f32(dkind >> 10u) * (1.0 / 32.0);
|
|
384
|
+
let dtop = dot(i.objN, faceVec(i.upc));
|
|
385
|
+
if (dtop > 0.5 && rad > 0.0) { // TOP faces only: soil on a cliff wall is a stripe, not dirt
|
|
386
|
+
let t = clamp(length(vec2(bx, bz) - vec2(du, dv)) / rad, 0.0, 1.0);
|
|
387
|
+
soil = 1.0 - smoothstep(0.30, 1.0, t);
|
|
388
|
+
// CONTACT AO — the load-bearing half. The pasted-on read is largely the MISSING SHADOW where
|
|
389
|
+
// a prop meets the ground; SSAO gives a pixel or two, this gives the metre-scale pool a real
|
|
390
|
+
// root ball would.
|
|
391
|
+
contact = 1.0 - 0.42 * (1.0 - smoothstep(0.0, 0.85, t));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
// MULTIPLICATIVE, so the atlas's own grain and the planet tint survive underneath. A decal that
|
|
395
|
+
// REPLACED the colour would trade one pasted-on look for another and would need a per-biome
|
|
396
|
+
// palette to sit right on grass and sand and ash and snow; darkening and warming needs none.
|
|
397
|
+
base = base * mix(vec3(1.0), vec3(0.66, 0.55, 0.45), soil);
|
|
365
398
|
// per-block edge AO makes each voxel visible on FLAT-hue cubes, but reads as a hard GRID over textures — so the
|
|
366
|
-
// atlas path
|
|
367
|
-
|
|
399
|
+
// atlas path dropped it ENTIRELY, which left textured terrain with no per-voxel AO at all: only SSAO, which
|
|
400
|
+
// resolves a pixel or two of crease and nothing at the metre scale. The result is a surface that reads as a slab,
|
|
401
|
+
// and anything standing on it reads as pasted on.
|
|
402
|
+
//
|
|
403
|
+
// cam.atlas.y is how much of the term survives on textured blocks. 0 is the DEFAULT and reproduces the old
|
|
404
|
+
// behaviour exactly -- mix(1, bs, 0) is 1.0, bit for bit -- so a caller that never calls setAtlasAO is unchanged.
|
|
405
|
+
// Around 0.35, EDGE_DARK 0.6 yields a floor of 0.86: enough that a cube reads as a cube, far short of the inked
|
|
406
|
+
// grid the full term draws. (No backticks in here: this is inside a JS template literal.)
|
|
407
|
+
let bs = blockShade(fx, fz);
|
|
408
|
+
let ao = select(bs, mix(1.0, bs, cam.atlas.y), cam.atlas.x > 0.5 && i.tile >= 0.0) * contact;
|
|
368
409
|
// LIGHTING = fixed directional FILL (always on, reads 3D shape in the dark) + the sun KEY (primary, shadowed).
|
|
369
410
|
// cam.sun.w is the fill/ambient brightness knob; the fill's directional term (0.5..1.35) keeps every face's
|
|
370
411
|
// orientation legible day or night, while the sun adds bright, shadow-casting key light on top during the day.
|
|
@@ -428,6 +469,15 @@ export class GpuShadowRenderer {
|
|
|
428
469
|
atlasSampler;
|
|
429
470
|
tileLayerBuf;
|
|
430
471
|
useAtlas = 0;
|
|
472
|
+
/**
|
|
473
|
+
* How much of the per-voxel edge AO survives on ATLAS-textured blocks, 0..1.
|
|
474
|
+
*
|
|
475
|
+
* Zero by default, which is the behaviour every existing caller already has: the fragment does
|
|
476
|
+
* `mix(1.0, blockShade, 0.0)`, which is exactly 1.0. Textured terrain has therefore had no
|
|
477
|
+
* per-voxel AO at all — the full term reads as an inked grid, so it was dropped rather than
|
|
478
|
+
* softened, and nothing replaced it.
|
|
479
|
+
*/
|
|
480
|
+
atlasAO = 0;
|
|
431
481
|
alphaPipe;
|
|
432
482
|
alphaBGL; // kept so the overlay buffer can grow and rebind on demand
|
|
433
483
|
overlayBuf;
|
|
@@ -860,8 +910,8 @@ export class GpuShadowRenderer {
|
|
|
860
910
|
scratch[o + 11] = r ? r[3] : 1; // quaternion, default identity
|
|
861
911
|
scratch[o + 12] = c.tile ?? -1;
|
|
862
912
|
scratch[o + 13] = c.up ?? 1;
|
|
863
|
-
scratch[o + 14] = 0;
|
|
864
|
-
scratch[o + 15] = 0; // aux: atlas tile id
|
|
913
|
+
scratch[o + 14] = c.decalPos ?? 0;
|
|
914
|
+
scratch[o + 15] = c.decalKind ?? 0; // aux: atlas tile id, up-face code, contact decal (0 = none)
|
|
865
915
|
}
|
|
866
916
|
}
|
|
867
917
|
makeBindGroups() {
|
|
@@ -898,6 +948,16 @@ export class GpuShadowRenderer {
|
|
|
898
948
|
* distinct array layers; a `CubeInstance.tile` of that material id + its `up`-face code selects the
|
|
899
949
|
* right layer in-shader. `tex` must be a 2d texture with at least (max layer + 1) array layers.
|
|
900
950
|
* Call once after the texture is uploaded; instances with `tile < 0` still use the flat hue path. */
|
|
951
|
+
/**
|
|
952
|
+
* Soften the per-voxel edge AO back on for textured blocks. 0 (the default) is off entirely.
|
|
953
|
+
*
|
|
954
|
+
* Separate from `setAtlas` on purpose: the atlas is an ASSET and this is a LOOK, and a renderer
|
|
955
|
+
* that made you re-upload a 2816² texture to change a shading constant would be one nobody
|
|
956
|
+
* adjusted. Safe to call every frame — it writes one float into the camera uniform.
|
|
957
|
+
*/
|
|
958
|
+
setAtlasAO(strength) {
|
|
959
|
+
this.atlasAO = Math.max(0, Math.min(1, strength));
|
|
960
|
+
}
|
|
901
961
|
setAtlas(tex, layout) {
|
|
902
962
|
this.atlasView = tex.createView({ dimension: '2d-array' });
|
|
903
963
|
const ids = Object.keys(layout.tiles).map(Number);
|
|
@@ -1114,6 +1174,7 @@ export class GpuShadowRenderer {
|
|
|
1114
1174
|
this.cam[S + 10] = tint[2];
|
|
1115
1175
|
this.cam[S + 11] = tint[3];
|
|
1116
1176
|
this.cam[S + 12] = this.useAtlas;
|
|
1177
|
+
this.cam[S + 13] = this.atlasAO;
|
|
1117
1178
|
this.cam[S + 16] = up[0];
|
|
1118
1179
|
this.cam[S + 17] = up[1];
|
|
1119
1180
|
this.cam[S + 18] = up[2];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugly-game",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"preinstall": "npx only-allow pnpm",
|
|
20
|
+
"build": "tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
|
|
21
|
+
"lint": "ugly-app lint",
|
|
22
|
+
"lint:fix": "ugly-app lint --fix",
|
|
23
|
+
"pretty": "prettier --write .",
|
|
24
|
+
"prepublishOnly": "pnpm run pretty && ugly-app lint && tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/"
|
|
25
|
+
},
|
|
18
26
|
"dependencies": {
|
|
19
27
|
"meshoptimizer": "^1.2.0"
|
|
20
28
|
},
|
|
@@ -27,12 +35,5 @@
|
|
|
27
35
|
"@webgpu/types": "^0.1.40",
|
|
28
36
|
"prettier": "^3.9.5",
|
|
29
37
|
"ugly-app": "^0.1.841"
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"preinstall": "npx only-allow pnpm",
|
|
33
|
-
"build": "tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
|
|
34
|
-
"lint": "ugly-app lint",
|
|
35
|
-
"lint:fix": "ugly-app lint --fix",
|
|
36
|
-
"pretty": "prettier --write ."
|
|
37
38
|
}
|
|
38
|
-
}
|
|
39
|
+
}
|