ugly-game 0.14.16 → 0.14.17
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/gpuProps.d.ts +32 -0
- package/dist/assets/gpuProps.js +42 -8
- package/package.json +1 -1
|
@@ -66,6 +66,24 @@ export interface PropMesh {
|
|
|
66
66
|
* map is a single depth buffer with nowhere to put a partial occluder.
|
|
67
67
|
*/
|
|
68
68
|
alpha?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Alpha-test cutoff: a fragment whose ALBEDO alpha is below this is discarded. 0 (the default)
|
|
71
|
+
* tests nothing.
|
|
72
|
+
*
|
|
73
|
+
* This is for cut-out sheets — hair cards, leaf planes, grass blades — where the mesh is a handful
|
|
74
|
+
* of rectangles and the shape lives entirely in the texture's alpha. Without it the texture's RGB
|
|
75
|
+
* is drawn over the whole rectangle and a hairstyle renders as a stack of opaque boxes.
|
|
76
|
+
*
|
|
77
|
+
* ⚠️ NOT `alpha`, and not a substitute for it. `alpha < 1` is a translucent MATERIAL: it moves the
|
|
78
|
+
* model to the blended pipeline with depth writes off, which for a cut-out sheet is wrong twice
|
|
79
|
+
* over — the opaque parts stop writing depth, so sheets composite in submission order and a
|
|
80
|
+
* character's fringe draws through the back of their own head.
|
|
81
|
+
*
|
|
82
|
+
* ⚠️ A cut-out model casts NO SUN SHADOW, exactly like a translucent one: `shadowPass` is depth-only
|
|
83
|
+
* and has no albedo bound, so it can only cast the rectangles. A missing shadow is a much smaller
|
|
84
|
+
* lie than a box-shaped one across the face.
|
|
85
|
+
*/
|
|
86
|
+
cutout?: number;
|
|
69
87
|
}
|
|
70
88
|
/**
|
|
71
89
|
* Per-instance deformation. Every field is neutral at its default, so an instance that supplies none
|
|
@@ -105,6 +123,20 @@ export interface PropDeform {
|
|
|
105
123
|
* sway at all either way.
|
|
106
124
|
*/
|
|
107
125
|
sway?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Per-instance colour multiply, `[1,1,1]` being the mesh as authored.
|
|
128
|
+
*
|
|
129
|
+
* ⚠️ PER INSTANCE, unlike `PropMesh.alpha`, and that is the whole point: `valueJitter` next to it
|
|
130
|
+
* multiplies vertex colour by a SCALAR, so it can make a plant lighter or darker and can never
|
|
131
|
+
* make it a different colour. A crowd of characters whose hair is black, brown, blonde, auburn and
|
|
132
|
+
* grey is one greyscale mesh and five hues — expressible here, and expressible as five extra
|
|
133
|
+
* MODELS otherwise, which is five more copies of the geometry and five more draw calls per style.
|
|
134
|
+
*
|
|
135
|
+
* ⚠️ Defaults to white rather than to zero. A zero-filled instance record would multiply every
|
|
136
|
+
* existing prop to black, which is why `writeDeform` writes the ones explicitly instead of
|
|
137
|
+
* relying on the buffer's initial contents.
|
|
138
|
+
*/
|
|
139
|
+
tint?: readonly [number, number, number];
|
|
108
140
|
}
|
|
109
141
|
export interface PropInstance {
|
|
110
142
|
model: number;
|
package/dist/assets/gpuProps.js
CHANGED
|
@@ -20,12 +20,14 @@ struct U { mvp: mat4x4<f32>, lightVP: mat4x4<f32>, sun: vec4<f32>, sunCol: vec4<
|
|
|
20
20
|
// d0 = (heightScale, girth, taper, 1/sourceHeight)
|
|
21
21
|
// d1 = (bend, bendDir, twist, droop)
|
|
22
22
|
// d2 = (yaw, valueJitter, 1/halfWidth, swayScale)
|
|
23
|
-
|
|
23
|
+
// d3 = (tintR, tintG, tintB, -)
|
|
24
|
+
struct Inst { m: mat4x4<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32>, d3: vec4<f32> };
|
|
24
25
|
@group(0) @binding(1) var<storage,read> models: array<Inst>;
|
|
25
26
|
@group(2) @binding(0) var albedoTex: texture_2d<f32>;
|
|
26
27
|
@group(2) @binding(1) var albedoSamp: sampler;
|
|
27
28
|
// PER-MODEL material. Group 2 is already the per-model group (the albedo lives here), so opacity
|
|
28
|
-
// rides along rather than needing a fourth group or a dynamic offset. mat.x is alpha.
|
|
29
|
+
// rides along rather than needing a fourth group or a dynamic offset. mat.x is alpha, mat.y is the
|
|
30
|
+
// alpha-test cutoff (0 ⇒ no test, which is every model that predates it).
|
|
29
31
|
struct Mat { mat: vec4<f32> };
|
|
30
32
|
@group(2) @binding(2) var<uniform> mtl: Mat;
|
|
31
33
|
@group(1) @binding(0) var shadowMap: texture_depth_2d_array; // the SAME cascaded sun shadow map the terrain cubes sample
|
|
@@ -102,7 +104,7 @@ fn deformNormal(n: vec3<f32>, py: f32, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f3
|
|
|
102
104
|
let sc = length(m[0].xyz);
|
|
103
105
|
world = sway(lp, world, upv, sc * inst.d2.w);
|
|
104
106
|
var o: VO; o.pos = u.mvp * vec4(world, 1.0); o.world = world; o.n = (m * vec4(ln, 0.0)).xyz;
|
|
105
|
-
o.c = col * inst.d2.y; o.l = lp; o.uv = uv; return o;
|
|
107
|
+
o.c = col * inst.d2.y * inst.d3.rgb; o.l = lp; o.uv = uv; return o;
|
|
106
108
|
}
|
|
107
109
|
// same fixed directional FILL as the terrain cubes (gpuShadow.fixedFill) so plants/rocks read the same 3D shape,
|
|
108
110
|
// day or night, under one shared light. up.w > 0.5 signals a valid local-up was supplied (else fall back to flat).
|
|
@@ -190,7 +192,11 @@ fn hsvShift(c: vec3<f32>, hue: f32, sat: f32, val: f32) -> vec3<f32> {
|
|
|
190
192
|
// Albedo modulates the vertex colour rather than replacing it, so the StyleGuide role tint and the
|
|
191
193
|
// per-instance hue jitter still act on a textured prop — and an untextured one samples the 1x1
|
|
192
194
|
// white fallback and is unchanged.
|
|
193
|
-
|
|
195
|
+
let tex = textureSample(albedoTex, albedoSamp, i.uv);
|
|
196
|
+
// ALPHA TEST, before any shading is paid for. mtl.mat.y is 0 for every model that does not ask for
|
|
197
|
+
// one, and tex.a is 1 on the white fallback, so an untextured or opaque model never discards.
|
|
198
|
+
if (tex.a < mtl.mat.y) { discard; }
|
|
199
|
+
var base = i.c * tex.rgb;
|
|
194
200
|
if (u.surf.x > 0.0) {
|
|
195
201
|
let grain = triplanar(i.l, N, u.surf.x);
|
|
196
202
|
base = base * (1.0 - u.surf.y * 0.5 + u.surf.y * grain);
|
|
@@ -211,7 +217,10 @@ fn hsvShift(c: vec3<f32>, hue: f32, sat: f32, val: f32) -> vec3<f32> {
|
|
|
211
217
|
const OCCLUDER = /* wgsl */ `
|
|
212
218
|
struct OU { lightVP: mat4x4<f32>, wind: vec4<f32> };
|
|
213
219
|
@group(0) @binding(0) var<uniform> o: OU;
|
|
214
|
-
|
|
220
|
+
// ⚠️ The SAME layout as the draw pass's Inst, d3 included. Both shaders index the same storage
|
|
221
|
+
// buffer, so a struct that is one vec4 shorter here does not read a shorter instance — it reads the
|
|
222
|
+
// NEXT one's matrix, and every shadow in the scene lands under the wrong prop.
|
|
223
|
+
struct Inst { m: mat4x4<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32>, d3: vec4<f32> };
|
|
215
224
|
@group(0) @binding(1) var<storage,read> models: array<Inst>;
|
|
216
225
|
// The occluder must apply the identical DEFORM as well as the identical sway. A deformed plant whose
|
|
217
226
|
// shadow is cast from its undeformed silhouette is the same detachment bug as swaying leaves over a
|
|
@@ -254,8 +263,15 @@ fn deformLocal(p: vec3<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32>) -> vec
|
|
|
254
263
|
}
|
|
255
264
|
return o.lightVP * vec4(world, 1.0);
|
|
256
265
|
}`;
|
|
257
|
-
/**
|
|
258
|
-
|
|
266
|
+
/**
|
|
267
|
+
* Floats per instance in the storage buffer: mat4 + d0 + d1 + d2 + d3.
|
|
268
|
+
*
|
|
269
|
+
* ⚠️ Stated in THREE places — here, `Inst` in the draw shader and `Inst` in the occluder. All three
|
|
270
|
+
* describe the same bytes and there is no mechanism that keeps them agreeing, so a field added to
|
|
271
|
+
* one must be added to all three in the same edit. A short struct does not read a truncated
|
|
272
|
+
* instance; it reads into the next one.
|
|
273
|
+
*/
|
|
274
|
+
const INST_FLOATS = 32;
|
|
259
275
|
export class GpuPropsRenderer {
|
|
260
276
|
device;
|
|
261
277
|
pipe;
|
|
@@ -581,13 +597,15 @@ export class GpuPropsRenderer {
|
|
|
581
597
|
: this.uploadAlbedo(m.albedo)
|
|
582
598
|
: null;
|
|
583
599
|
const alpha = m.alpha ?? 1;
|
|
600
|
+
const cutout = m.cutout ?? 0;
|
|
584
601
|
const matBuf = dev.createBuffer({
|
|
585
602
|
size: 16,
|
|
586
603
|
usage: U.UNIFORM | U.COPY_DST,
|
|
587
604
|
});
|
|
588
|
-
dev.queue.writeBuffer(matBuf, 0, new Float32Array([alpha,
|
|
605
|
+
dev.queue.writeBuffer(matBuf, 0, new Float32Array([alpha, cutout, 0, 0]));
|
|
589
606
|
return {
|
|
590
607
|
alpha,
|
|
608
|
+
cutout,
|
|
591
609
|
matBuf,
|
|
592
610
|
ownsTex,
|
|
593
611
|
posB: mk(m.positions, U.VERTEX | U.COPY_DST),
|
|
@@ -700,6 +718,14 @@ export class GpuPropsRenderer {
|
|
|
700
718
|
// none at all — and the opaque one is the more obviously wrong picture.
|
|
701
719
|
if (mdl.alpha < 1)
|
|
702
720
|
continue;
|
|
721
|
+
// ...and neither does a CUT-OUT model, for a different reason: this pass is depth-only and has
|
|
722
|
+
// no albedo bound, so it cannot run the alpha test the draw pass runs. What it would cast is
|
|
723
|
+
// the un-tested rectangles — a hairstyle's shadow as a stack of boxes across the face, which is
|
|
724
|
+
// far more obviously wrong than no shadow at all. Binding the texture here would fix it and is
|
|
725
|
+
// a bigger change than this one: the occluder would need a per-model bind group and a second
|
|
726
|
+
// pipeline for the tested case.
|
|
727
|
+
if (mdl.cutout > 0)
|
|
728
|
+
continue;
|
|
703
729
|
pass.setBindGroup(0, bg);
|
|
704
730
|
pass.setVertexBuffer(0, mdl.posB);
|
|
705
731
|
pass.setIndexBuffer(mdl.idxB, 'uint32');
|
|
@@ -832,6 +858,14 @@ function writeDeform(out, o, d, e) {
|
|
|
832
858
|
out[o + 9] = d?.valueJitter ?? 1;
|
|
833
859
|
out[o + 10] = e.invHalfW;
|
|
834
860
|
out[o + 11] = d?.sway ?? 1;
|
|
861
|
+
// ⚠️ Written unconditionally, ones and all. `arrays[m]` is a fresh zero-filled Float32Array every
|
|
862
|
+
// frame, so an absent tint left unwritten is BLACK, not neutral — and it would be black for every
|
|
863
|
+
// prop in the world, none of which has ever heard of a tint.
|
|
864
|
+
const t = d?.tint;
|
|
865
|
+
out[o + 12] = t ? t[0] : 1;
|
|
866
|
+
out[o + 13] = t ? t[1] : 1;
|
|
867
|
+
out[o + 14] = t ? t[2] : 1;
|
|
868
|
+
out[o + 15] = 0;
|
|
835
869
|
}
|
|
836
870
|
// column-major identity mat4, used for lightVP when shadow-receive is off
|
|
837
871
|
const IDENTITY4 = new Float32Array([
|