ugly-game 0.14.9 → 0.14.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/assets/gpuSkin.d.ts +26 -0
- package/dist/assets/gpuSkin.js +40 -7
- package/package.json +1 -1
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,20 @@ 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
|
+
// Falls back to `uvs`, then to zeros. The white tint samples to 1 at any coordinate, so the
|
|
337
|
+
// attribute must EXIST but its contents cannot matter.
|
|
338
|
+
const uv2Src = c.uvs2 && c.uvs2.length >= n * 2
|
|
339
|
+
? c.uvs2
|
|
340
|
+
: c.uvs && c.uvs.length >= n * 2
|
|
341
|
+
? c.uvs
|
|
342
|
+
: new Float32Array(n * 2);
|
|
343
|
+
const uv2B = mk(uv2Src, U.VERTEX | U.COPY_DST);
|
|
319
344
|
const tex = c.tex ?? this.whiteTex;
|
|
320
345
|
const tex2 = c.tex2 ?? this.whiteTex;
|
|
321
|
-
|
|
322
|
-
//
|
|
323
|
-
|
|
346
|
+
const tint = c.tint ?? this.whiteTex;
|
|
347
|
+
// ⚠️ Keyed on the TRIPLE. Keyed on any subset, two creatures sharing those textures but
|
|
348
|
+
// differing in the others would silently share the first one's bind group.
|
|
349
|
+
const matKey = `${this.texId(tex)}:${this.texId(tex2)}:${this.texId(tint)}`;
|
|
324
350
|
let matBG = this.matBGs.get(matKey);
|
|
325
351
|
if (!matBG) {
|
|
326
352
|
matBG = dev.createBindGroup({
|
|
@@ -329,6 +355,7 @@ export class GpuSkinRenderer {
|
|
|
329
355
|
{ binding: 0, resource: tex.createView() },
|
|
330
356
|
{ binding: 1, resource: this.albedoSamp },
|
|
331
357
|
{ binding: 2, resource: tex2.createView() },
|
|
358
|
+
{ binding: 3, resource: tint.createView() },
|
|
332
359
|
],
|
|
333
360
|
});
|
|
334
361
|
this.matBGs.set(matKey, matBG);
|
|
@@ -370,6 +397,7 @@ export class GpuSkinRenderer {
|
|
|
370
397
|
defNB,
|
|
371
398
|
colB,
|
|
372
399
|
uvB,
|
|
400
|
+
uv2B,
|
|
373
401
|
matBG,
|
|
374
402
|
idxB,
|
|
375
403
|
idxCount: c.indices.length,
|
|
@@ -381,6 +409,7 @@ export class GpuSkinRenderer {
|
|
|
381
409
|
model: c.model,
|
|
382
410
|
mix: c.mix ?? 0,
|
|
383
411
|
alpha: c.alpha ?? 1,
|
|
412
|
+
cutout: c.cutout ?? 0,
|
|
384
413
|
};
|
|
385
414
|
});
|
|
386
415
|
}
|
|
@@ -420,6 +449,9 @@ export class GpuSkinRenderer {
|
|
|
420
449
|
// blend.y — opacity. 1 for every caller that does not set `alpha`, which is the constant the
|
|
421
450
|
// fragment shader used to return outright.
|
|
422
451
|
u[73 + 16 * MAX_CASCADES] = p.alpha;
|
|
452
|
+
// blend.z — the cutout threshold. 0 for every caller that does not set one, which is the
|
|
453
|
+
// constant the shader's guard compares against, so the untouched path is unchanged.
|
|
454
|
+
u[74 + 16 * MAX_CASCADES] = p.cutout;
|
|
423
455
|
this.device.queue.writeBuffer(p.uBuf, 0, u);
|
|
424
456
|
}
|
|
425
457
|
// group 1: the shadow map + comparison sampler (dummy when not receiving). Rebuild only when the view changes.
|
|
@@ -463,6 +495,7 @@ export class GpuSkinRenderer {
|
|
|
463
495
|
rp.setVertexBuffer(1, p.colB);
|
|
464
496
|
rp.setVertexBuffer(2, p.defNB);
|
|
465
497
|
rp.setVertexBuffer(3, p.uvB);
|
|
498
|
+
rp.setVertexBuffer(4, p.uv2B);
|
|
466
499
|
rp.setBindGroup(2, p.matBG);
|
|
467
500
|
rp.setIndexBuffer(p.idxB, 'uint32');
|
|
468
501
|
rp.drawIndexed(p.idxCount);
|