ugly-game 0.14.9 → 0.14.11
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/assets/gpuSkin.d.ts +26 -0
- package/dist/assets/gpuSkin.js +46 -7
- package/dist/gpuShadow.d.ts +0 -30
- package/dist/gpuShadow.js +11 -79
- package/package.json +1 -1
- package/dist/assets/basis/basis_transcoder.wasm +0 -0
package/dist/assets/gpuSkin.d.ts
CHANGED
|
@@ -53,6 +53,32 @@ export interface SkinCreature {
|
|
|
53
53
|
* state — byte-identical to before this existed.
|
|
54
54
|
*/
|
|
55
55
|
alpha?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Discard any fragment whose ALBEDO ALPHA is below this. 0, the default, is off.
|
|
58
|
+
*
|
|
59
|
+
* ⚠️ For cards-and-a-mask geometry — hair, foliage, chain-link — where the mesh is quads and the
|
|
60
|
+
* texture is what carves the shape out of them. Around 40% of a MakeHuman hair map is fully
|
|
61
|
+
* transparent; drawn without this it is a set of opaque rectangles.
|
|
62
|
+
*
|
|
63
|
+
* ⚠️ Stays on the OPAQUE pipeline, with depth writes ON. That is the difference between a cutout
|
|
64
|
+
* and `alpha` — a cutout surface still occludes, it just has holes. Routing it through the blend
|
|
65
|
+
* pipeline instead would stop it writing depth, and hair would fail to hide the scalp behind it.
|
|
66
|
+
*/
|
|
67
|
+
cutout?: number;
|
|
68
|
+
/**
|
|
69
|
+
* A THIRD texture, MULTIPLIED over the albedo — not lerped toward it the way `tex2` is.
|
|
70
|
+
*
|
|
71
|
+
* ⚠️ Sampled with `uvs2`, deliberately. An albedo's UVs are an atlas packing; a tint's are a
|
|
72
|
+
* projection. Sampling both with the same coordinates paints the tint onto the packing layout,
|
|
73
|
+
* which for hair is a patchwork of rotated islands rather than a head.
|
|
74
|
+
*
|
|
75
|
+
* ⚠️ Omitted ⇒ the same 1×1 white texture `tex` falls back to, so `albedo × white` is `albedo`
|
|
76
|
+
* and every existing caller renders byte-identically. Same contract `tex` and `tex2` shipped
|
|
77
|
+
* under; keep it.
|
|
78
|
+
*/
|
|
79
|
+
tint?: GPUTexture;
|
|
80
|
+
/** `n * 2` for `tint`. Omitted ⇒ `uvs`, which with the white fallback cannot matter. */
|
|
81
|
+
uvs2?: Float32Array;
|
|
56
82
|
indices: Uint32Array;
|
|
57
83
|
palette: Float32Array;
|
|
58
84
|
model: Float32Array;
|
package/dist/assets/gpuSkin.js
CHANGED
|
@@ -33,10 +33,13 @@ struct U { mvp: mat4x4<f32>, lightVP: mat4x4<f32>, sun: vec4<f32>, sunCol: vec4<
|
|
|
33
33
|
@group(2) @binding(0) var albedo: texture_2d<f32>;
|
|
34
34
|
@group(2) @binding(1) var albedoSamp: sampler;
|
|
35
35
|
@group(2) @binding(2) var albedo2: texture_2d<f32>;
|
|
36
|
-
|
|
36
|
+
// TINT — a third map, MULTIPLIED over the albedo and sampled with its OWN uv set. A 1x1 white is
|
|
37
|
+
// bound when a caller supplies none, so albedo x white = albedo and the untinted path is unchanged.
|
|
38
|
+
@group(2) @binding(3) var tintTex: texture_2d<f32>;
|
|
39
|
+
struct VOut { @builtin(position) pos: vec4<f32>, @location(0) world: vec3<f32>, @location(1) col: vec3<f32>, @location(2) n: vec3<f32>, @location(3) uv: vec2<f32>, @location(4) uv2: vec2<f32> };
|
|
37
40
|
// o.world must be the WORLD position (model·p), not the local deformed p — else the fog distance is computed
|
|
38
41
|
// against the world-space camera and blows up on a planet surface (huge coords), washing creatures into the fog.
|
|
39
|
-
@vertex fn vs(@location(0) p: vec3<f32>, @location(1) c: vec3<f32>, @location(2) nrm: vec3<f32>, @location(3) uv: vec2<f32>) -> VOut { var o: VOut; o.pos=u.mvp*vec4(p,1.0); o.world=(u.model*vec4(p,1.0)).xyz; o.col=c; o.n=nrm; o.uv=uv; return o; }
|
|
42
|
+
@vertex fn vs(@location(0) p: vec3<f32>, @location(1) c: vec3<f32>, @location(2) nrm: vec3<f32>, @location(3) uv: vec2<f32>, @location(4) uv2: vec2<f32>) -> VOut { var o: VOut; o.pos=u.mvp*vec4(p,1.0); o.world=(u.model*vec4(p,1.0)).xyz; o.col=c; o.n=nrm; o.uv=uv; o.uv2=uv2; return o; }
|
|
40
43
|
// PCF 3×3 sun shadow — mirrors gpuShadow.shadowFactor so creatures sit in the SAME shadow as the terrain. 1 = lit, 0 = shadowed.
|
|
41
44
|
fn pcfLayer(world: vec3<f32>, ndl: f32, layer: i32, inside: ptr<function, bool>) -> f32 {
|
|
42
45
|
let lp = u.cascades[layer] * vec4(world, 1.0);
|
|
@@ -74,9 +77,13 @@ fn shadowFactor(world: vec3<f32>, ndl: f32) -> f32 {
|
|
|
74
77
|
// stray backtick in a WGSL comment terminates the shader string and fails the build 100 lines
|
|
75
78
|
// away. With no second texture, albedo2 is the same 1x1 white as albedo and blend.x is 0, so this
|
|
76
79
|
// is exactly i.col * albedo — byte-identical to before 0.14.6.
|
|
77
|
-
let
|
|
80
|
+
let alb = textureSample(albedo, albedoSamp, i.uv);
|
|
78
81
|
let alb1 = textureSample(albedo2, albedoSamp, i.uv).rgb;
|
|
79
|
-
|
|
82
|
+
// blend.z is the cutout threshold, 0 for everyone who does not set one. A cards-and-mask surface
|
|
83
|
+
// is mostly holes; without this it draws as rectangles.
|
|
84
|
+
if (u.blend.z > 0.0 && alb.w < u.blend.z) { discard; }
|
|
85
|
+
let tint = textureSample(tintTex, albedoSamp, i.uv2).rgb;
|
|
86
|
+
let base = i.col * mix(alb.rgb, alb1, u.blend.x) * tint;
|
|
80
87
|
let lit = base * (u.amb.xyz + d * u.sunCol.xyz * sh);
|
|
81
88
|
let dist = length(i.world - u.cam.xyz);
|
|
82
89
|
let f = clamp(1.0 - exp(-dist * u.fog.w), 0.0, 1.0);
|
|
@@ -175,6 +182,11 @@ export class GpuSkinRenderer {
|
|
|
175
182
|
visibility: GPUShaderStage.FRAGMENT,
|
|
176
183
|
texture: { sampleType: 'float' },
|
|
177
184
|
},
|
|
185
|
+
{
|
|
186
|
+
binding: 3,
|
|
187
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
188
|
+
texture: { sampleType: 'float' },
|
|
189
|
+
},
|
|
178
190
|
],
|
|
179
191
|
});
|
|
180
192
|
this.drawBGL = [bgl0, bgl1, bgl2];
|
|
@@ -203,6 +215,10 @@ export class GpuSkinRenderer {
|
|
|
203
215
|
arrayStride: 8,
|
|
204
216
|
attributes: [{ shaderLocation: 3, offset: 0, format: 'float32x2' }],
|
|
205
217
|
},
|
|
218
|
+
{
|
|
219
|
+
arrayStride: 8,
|
|
220
|
+
attributes: [{ shaderLocation: 4, offset: 0, format: 'float32x2' }],
|
|
221
|
+
},
|
|
206
222
|
],
|
|
207
223
|
},
|
|
208
224
|
primitive: { topology: 'triangle-list', cullMode: 'none' },
|
|
@@ -286,6 +302,7 @@ export class GpuSkinRenderer {
|
|
|
286
302
|
p.defNB.destroy();
|
|
287
303
|
p.colB.destroy();
|
|
288
304
|
p.uvB.destroy();
|
|
305
|
+
p.uv2B?.destroy();
|
|
289
306
|
p.idxB.destroy();
|
|
290
307
|
p.uBuf.destroy();
|
|
291
308
|
p.palB.destroy();
|
|
@@ -316,11 +333,23 @@ export class GpuSkinRenderer {
|
|
|
316
333
|
// A zero-filled UV buffer when the caller has none: the white fallback samples to 1 at any
|
|
317
334
|
// coordinate, so the attribute still has to EXIST but its contents cannot matter.
|
|
318
335
|
const uvB = mk(c.uvs && c.uvs.length >= n * 2 ? c.uvs : new Float32Array(n * 2), U.VERTEX | U.COPY_DST);
|
|
336
|
+
// ⚠️ NULL when the caller has no `uvs2` — NOT a second buffer holding a copy of `uvs`.
|
|
337
|
+
//
|
|
338
|
+
// `setCreatures` tears down and rebuilds every buffer on each call and all-mine-sky calls it
|
|
339
|
+
// EVERY FRAME for EVERY creature. Allocating this unconditionally charged every caller in the
|
|
340
|
+
// game — none of which pass `uvs2` — an extra `createBuffer` plus a `writeBuffer` of the same
|
|
341
|
+
// n*2 floats, per creature, per frame, for a buffer whose contents cannot matter: with no
|
|
342
|
+
// tint the 1x1 white samples to 1 at any coordinate. The attribute still has to EXIST, so
|
|
343
|
+
// slot 4 binds `uvB` instead; WebGPU is happy to see the same GPUBuffer in two vertex slots.
|
|
344
|
+
const uv2B = c.uvs2 && c.uvs2.length >= n * 2
|
|
345
|
+
? mk(c.uvs2, U.VERTEX | U.COPY_DST)
|
|
346
|
+
: null;
|
|
319
347
|
const tex = c.tex ?? this.whiteTex;
|
|
320
348
|
const tex2 = c.tex2 ?? this.whiteTex;
|
|
321
|
-
|
|
322
|
-
//
|
|
323
|
-
|
|
349
|
+
const tint = c.tint ?? this.whiteTex;
|
|
350
|
+
// ⚠️ Keyed on the TRIPLE. Keyed on any subset, two creatures sharing those textures but
|
|
351
|
+
// differing in the others would silently share the first one's bind group.
|
|
352
|
+
const matKey = `${this.texId(tex)}:${this.texId(tex2)}:${this.texId(tint)}`;
|
|
324
353
|
let matBG = this.matBGs.get(matKey);
|
|
325
354
|
if (!matBG) {
|
|
326
355
|
matBG = dev.createBindGroup({
|
|
@@ -329,6 +358,7 @@ export class GpuSkinRenderer {
|
|
|
329
358
|
{ binding: 0, resource: tex.createView() },
|
|
330
359
|
{ binding: 1, resource: this.albedoSamp },
|
|
331
360
|
{ binding: 2, resource: tex2.createView() },
|
|
361
|
+
{ binding: 3, resource: tint.createView() },
|
|
332
362
|
],
|
|
333
363
|
});
|
|
334
364
|
this.matBGs.set(matKey, matBG);
|
|
@@ -370,6 +400,7 @@ export class GpuSkinRenderer {
|
|
|
370
400
|
defNB,
|
|
371
401
|
colB,
|
|
372
402
|
uvB,
|
|
403
|
+
uv2B,
|
|
373
404
|
matBG,
|
|
374
405
|
idxB,
|
|
375
406
|
idxCount: c.indices.length,
|
|
@@ -381,6 +412,7 @@ export class GpuSkinRenderer {
|
|
|
381
412
|
model: c.model,
|
|
382
413
|
mix: c.mix ?? 0,
|
|
383
414
|
alpha: c.alpha ?? 1,
|
|
415
|
+
cutout: c.cutout ?? 0,
|
|
384
416
|
};
|
|
385
417
|
});
|
|
386
418
|
}
|
|
@@ -420,6 +452,9 @@ export class GpuSkinRenderer {
|
|
|
420
452
|
// blend.y — opacity. 1 for every caller that does not set `alpha`, which is the constant the
|
|
421
453
|
// fragment shader used to return outright.
|
|
422
454
|
u[73 + 16 * MAX_CASCADES] = p.alpha;
|
|
455
|
+
// blend.z — the cutout threshold. 0 for every caller that does not set one, which is the
|
|
456
|
+
// constant the shader's guard compares against, so the untouched path is unchanged.
|
|
457
|
+
u[74 + 16 * MAX_CASCADES] = p.cutout;
|
|
423
458
|
this.device.queue.writeBuffer(p.uBuf, 0, u);
|
|
424
459
|
}
|
|
425
460
|
// group 1: the shadow map + comparison sampler (dummy when not receiving). Rebuild only when the view changes.
|
|
@@ -463,6 +498,10 @@ export class GpuSkinRenderer {
|
|
|
463
498
|
rp.setVertexBuffer(1, p.colB);
|
|
464
499
|
rp.setVertexBuffer(2, p.defNB);
|
|
465
500
|
rp.setVertexBuffer(3, p.uvB);
|
|
501
|
+
// Slot 4 falls back to the UV buffer when there is no second set — same buffer, two slots,
|
|
502
|
+
// which WebGPU permits. Without a tint texture the shader samples 1x1 white and the
|
|
503
|
+
// coordinates it reads cannot affect the result.
|
|
504
|
+
rp.setVertexBuffer(4, p.uv2B ?? p.uvB);
|
|
466
505
|
rp.setBindGroup(2, p.matBG);
|
|
467
506
|
rp.setIndexBuffer(p.idxB, 'uint32');
|
|
468
507
|
rp.drawIndexed(p.idxCount);
|
package/dist/gpuShadow.d.ts
CHANGED
|
@@ -11,19 +11,6 @@ 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;
|
|
27
14
|
}
|
|
28
15
|
/** Atlas layout: which ARRAY LAYER a material's top/side/bottom faces sample.
|
|
29
16
|
*
|
|
@@ -73,15 +60,6 @@ export declare class GpuShadowRenderer {
|
|
|
73
60
|
private atlasSampler;
|
|
74
61
|
private tileLayerBuf;
|
|
75
62
|
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;
|
|
85
63
|
private alphaPipe;
|
|
86
64
|
private alphaBGL;
|
|
87
65
|
private overlayBuf;
|
|
@@ -135,14 +113,6 @@ export declare class GpuShadowRenderer {
|
|
|
135
113
|
* distinct array layers; a `CubeInstance.tile` of that material id + its `up`-face code selects the
|
|
136
114
|
* right layer in-shader. `tex` must be a 2d texture with at least (max layer + 1) array layers.
|
|
137
115
|
* 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;
|
|
146
116
|
setAtlas(tex: GPUTexture, layout: AtlasLayout): void;
|
|
147
117
|
/** Static scene: sizes the buffer to exactly these instances. */
|
|
148
118
|
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)
|
|
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
|
|
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 };
|
|
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;
|
|
256
256
|
return o;
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -344,12 +344,10 @@ 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
|
|
349
347
|
var dfx: vec2<f32>; var dfz: vec2<f32>; // (ddx, ddy) of each in-face axis, selected alongside it
|
|
350
|
-
if (an.y >= an.x && an.y >= an.z) { fx = fract(i.blk.x); fz = fract(i.blk.z);
|
|
351
|
-
else if (an.x >= an.z) { fx = fract(i.blk.y); fz = fract(i.blk.z);
|
|
352
|
-
else { fx = fract(i.blk.x); fz = fract(i.blk.y);
|
|
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); }
|
|
353
351
|
var base = select(mix(vec3(0.34), hsv(i.hue), 0.62), vec3(0.6, 0.62, 0.66), i.hue < 0.0);
|
|
354
352
|
if (cam.atlas.x > 0.5 && i.tile >= 0.0) { // ATLAS: pick top/side/bottom LAYER from the face vs the up axis
|
|
355
353
|
let d = dot(i.objN, faceVec(i.upc));
|
|
@@ -364,55 +362,9 @@ fn fixedFill(N: vec3<f32>, up: vec3<f32>) -> f32 {
|
|
|
364
362
|
let texc = textureSampleGrad(atlasTex, atlasSamp, uv, layer, vec2(dfx.x, dfz.x), vec2(dfx.y, dfz.y)).rgb;
|
|
365
363
|
base = mix(texc, texc * cam.tint.rgb, cam.tint.w); // per-planet tint
|
|
366
364
|
}
|
|
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
|
-
// The plateau, not just the falloff. At 0.30 the soil was full only inside the inner third of
|
|
388
|
-
// the radius -- which is under the trunk, where nothing can see it -- so the decal read as pure
|
|
389
|
-
// contact shading and the DIRT never showed. Holding it out to 0.55 puts real soil in the
|
|
390
|
-
// visible ring around the stem, which is the thing this feature is named for.
|
|
391
|
-
soil = 1.0 - smoothstep(0.55, 1.0, t);
|
|
392
|
-
// CONTACT AO — the load-bearing half. The pasted-on read is largely the MISSING SHADOW where
|
|
393
|
-
// a prop meets the ground; SSAO gives a pixel or two, this gives the metre-scale pool a real
|
|
394
|
-
// root ball would.
|
|
395
|
-
contact = 1.0 - 0.42 * (1.0 - smoothstep(0.0, 0.85, t));
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
// MULTIPLICATIVE, so the atlas's own grain and the planet tint survive underneath. A decal that
|
|
399
|
-
// REPLACED the colour would trade one pasted-on look for another and would need a per-biome
|
|
400
|
-
// palette to sit right on grass and sand and ash and snow; darkening and warming needs none.
|
|
401
|
-
// Warm as well as dark. A near-neutral multiply just dims the ground, and dim grass still reads as
|
|
402
|
-
// grass; pulling blue down hardest is what makes the eye call it earth rather than shadow. Still a
|
|
403
|
-
// MULTIPLY, so the atlas grain and the planet tint survive and no per-biome palette is needed.
|
|
404
|
-
base = base * mix(vec3(1.0), vec3(0.72, 0.52, 0.34), soil);
|
|
405
365
|
// per-block edge AO makes each voxel visible on FLAT-hue cubes, but reads as a hard GRID over textures — so the
|
|
406
|
-
// atlas path
|
|
407
|
-
|
|
408
|
-
// and anything standing on it reads as pasted on.
|
|
409
|
-
//
|
|
410
|
-
// cam.atlas.y is how much of the term survives on textured blocks. 0 is the DEFAULT and reproduces the old
|
|
411
|
-
// behaviour exactly -- mix(1, bs, 0) is 1.0, bit for bit -- so a caller that never calls setAtlasAO is unchanged.
|
|
412
|
-
// 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
|
|
413
|
-
// grid the full term draws. (No backticks in here: this is inside a JS template literal.)
|
|
414
|
-
let bs = blockShade(fx, fz);
|
|
415
|
-
let ao = select(bs, mix(1.0, bs, cam.atlas.y), cam.atlas.x > 0.5 && i.tile >= 0.0) * contact;
|
|
366
|
+
// atlas path drops it entirely (the texture already supplies surface detail).
|
|
367
|
+
let ao = select(blockShade(fx, fz), 1.0, cam.atlas.x > 0.5 && i.tile >= 0.0);
|
|
416
368
|
// LIGHTING = fixed directional FILL (always on, reads 3D shape in the dark) + the sun KEY (primary, shadowed).
|
|
417
369
|
// cam.sun.w is the fill/ambient brightness knob; the fill's directional term (0.5..1.35) keeps every face's
|
|
418
370
|
// orientation legible day or night, while the sun adds bright, shadow-casting key light on top during the day.
|
|
@@ -476,15 +428,6 @@ export class GpuShadowRenderer {
|
|
|
476
428
|
atlasSampler;
|
|
477
429
|
tileLayerBuf;
|
|
478
430
|
useAtlas = 0;
|
|
479
|
-
/**
|
|
480
|
-
* How much of the per-voxel edge AO survives on ATLAS-textured blocks, 0..1.
|
|
481
|
-
*
|
|
482
|
-
* Zero by default, which is the behaviour every existing caller already has: the fragment does
|
|
483
|
-
* `mix(1.0, blockShade, 0.0)`, which is exactly 1.0. Textured terrain has therefore had no
|
|
484
|
-
* per-voxel AO at all — the full term reads as an inked grid, so it was dropped rather than
|
|
485
|
-
* softened, and nothing replaced it.
|
|
486
|
-
*/
|
|
487
|
-
atlasAO = 0;
|
|
488
431
|
alphaPipe;
|
|
489
432
|
alphaBGL; // kept so the overlay buffer can grow and rebind on demand
|
|
490
433
|
overlayBuf;
|
|
@@ -917,8 +860,8 @@ export class GpuShadowRenderer {
|
|
|
917
860
|
scratch[o + 11] = r ? r[3] : 1; // quaternion, default identity
|
|
918
861
|
scratch[o + 12] = c.tile ?? -1;
|
|
919
862
|
scratch[o + 13] = c.up ?? 1;
|
|
920
|
-
scratch[o + 14] =
|
|
921
|
-
scratch[o + 15] =
|
|
863
|
+
scratch[o + 14] = 0;
|
|
864
|
+
scratch[o + 15] = 0; // aux: atlas tile id + up-face code
|
|
922
865
|
}
|
|
923
866
|
}
|
|
924
867
|
makeBindGroups() {
|
|
@@ -955,16 +898,6 @@ export class GpuShadowRenderer {
|
|
|
955
898
|
* distinct array layers; a `CubeInstance.tile` of that material id + its `up`-face code selects the
|
|
956
899
|
* right layer in-shader. `tex` must be a 2d texture with at least (max layer + 1) array layers.
|
|
957
900
|
* Call once after the texture is uploaded; instances with `tile < 0` still use the flat hue path. */
|
|
958
|
-
/**
|
|
959
|
-
* Soften the per-voxel edge AO back on for textured blocks. 0 (the default) is off entirely.
|
|
960
|
-
*
|
|
961
|
-
* Separate from `setAtlas` on purpose: the atlas is an ASSET and this is a LOOK, and a renderer
|
|
962
|
-
* that made you re-upload a 2816² texture to change a shading constant would be one nobody
|
|
963
|
-
* adjusted. Safe to call every frame — it writes one float into the camera uniform.
|
|
964
|
-
*/
|
|
965
|
-
setAtlasAO(strength) {
|
|
966
|
-
this.atlasAO = Math.max(0, Math.min(1, strength));
|
|
967
|
-
}
|
|
968
901
|
setAtlas(tex, layout) {
|
|
969
902
|
this.atlasView = tex.createView({ dimension: '2d-array' });
|
|
970
903
|
const ids = Object.keys(layout.tiles).map(Number);
|
|
@@ -1181,7 +1114,6 @@ export class GpuShadowRenderer {
|
|
|
1181
1114
|
this.cam[S + 10] = tint[2];
|
|
1182
1115
|
this.cam[S + 11] = tint[3];
|
|
1183
1116
|
this.cam[S + 12] = this.useAtlas;
|
|
1184
|
-
this.cam[S + 13] = this.atlasAO;
|
|
1185
1117
|
this.cam[S + 16] = up[0];
|
|
1186
1118
|
this.cam[S + 17] = up[1];
|
|
1187
1119
|
this.cam[S + 18] = up[2];
|
package/package.json
CHANGED
|
Binary file
|