ugly-game 0.14.6 → 0.14.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.
@@ -43,6 +43,29 @@ export interface PropMesh {
43
43
  * the offline encoder's.
44
44
  */
45
45
  albedo?: ImageBitmap | GPUTexture;
46
+ /**
47
+ * Opacity, 1 (the default) being fully opaque.
48
+ *
49
+ * Per MODEL rather than per instance, because this is a property of the material: glass is glass
50
+ * in every stand of it. A cryogenic ice crystal, a tektite glass shard and a gasbag membrane are
51
+ * the cases — all three currently render as solid rock, which is not a subtle wrongness when one
52
+ * of them is 54% of all the flora placed in all-mine-sky.
53
+ *
54
+ * ⚠️ Below 1 the model moves to a SECOND pipeline — source-alpha blended, depth writes OFF — drawn
55
+ * after every opaque one. Depth writes have to go: a translucent surface that writes depth
56
+ * occludes what is behind it, which is the one thing this exists to prevent. The cost is that a
57
+ * closed mesh blends against its own far side, so a crystal reads as glass rather than as a
58
+ * tinted solid — which for ice and glass is the desired picture.
59
+ *
60
+ * ⚠️ There is NO depth sort, between models or between instances of one model. Overlapping
61
+ * translucent props composite in submission order. Sorting tens of thousands of instances per
62
+ * frame would cost more than the artifact it removes.
63
+ *
64
+ * ⚠️ A translucent model casts NO sun shadow — it is skipped in `shadowPass`. An opaque
65
+ * silhouette cast by a pane of glass is more obviously wrong than a missing one, and the shadow
66
+ * map is a single depth buffer with nowhere to put a partial occluder.
67
+ */
68
+ alpha?: number;
46
69
  }
47
70
  /**
48
71
  * Per-instance deformation. Every field is neutral at its default, so an instance that supplies none
@@ -92,6 +115,17 @@ export interface PropInstance {
92
115
  export declare class GpuPropsRenderer {
93
116
  private device;
94
117
  private pipe;
118
+ /**
119
+ * The same pipeline with source-alpha blending and depth writes off, for models with `alpha < 1`.
120
+ *
121
+ * ⚠️ Both are built from ONE EXPLICIT pipeline layout rather than `layout: 'auto'`. Two `auto`
122
+ * pipelines get two distinct bind-group layouts even from identical shader code, so a bind group
123
+ * made for one is rejected by the other — and every bind group here is built once, in `setModels`
124
+ * or `setInstances`, and reused by whichever pipeline draws it.
125
+ */
126
+ private blendPipe;
127
+ /** The explicit group 0/1/2 layouts, shared by both render pipelines. */
128
+ private drawBGL;
95
129
  private occPipe;
96
130
  private uBuf;
97
131
  private lightBuf;
@@ -24,6 +24,10 @@ struct Inst { m: mat4x4<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32> };
24
24
  @group(0) @binding(1) var<storage,read> models: array<Inst>;
25
25
  @group(2) @binding(0) var albedoTex: texture_2d<f32>;
26
26
  @group(2) @binding(1) var albedoSamp: sampler;
27
+ // 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
+ struct Mat { mat: vec4<f32> };
30
+ @group(2) @binding(2) var<uniform> mtl: Mat;
27
31
  @group(1) @binding(0) var shadowMap: texture_depth_2d_array; // the SAME cascaded sun shadow map the terrain cubes sample
28
32
  @group(1) @binding(1) var shadowSamp: sampler_comparison;
29
33
  struct VO { @builtin(position) pos: vec4<f32>, @location(0) world: vec3<f32>, @location(1) n: vec3<f32>, @location(2) c: vec3<f32>, @location(3) l: vec3<f32>, @location(4) uv: vec2<f32> };
@@ -197,7 +201,9 @@ fn hsvShift(c: vec3<f32>, hue: f32, sat: f32, val: f32) -> vec3<f32> {
197
201
  + base * u.surf.w; // emissive — bioluminescence on dark worlds
198
202
  let dist = length(i.world - u.cam.xyz);
199
203
  let f = clamp(1.0 - exp(-dist * u.fog.w), 0.0, 1.0);
200
- return vec4(mix(lit, u.fog.xyz, f), 1.0);
204
+ // mtl.mat.x is the model's opacity, 1 for every model that does not set it — the same constant
205
+ // this returned before, so the opaque pipeline draws exactly what it always did.
206
+ return vec4(mix(lit, u.fog.xyz, f), mtl.mat.x);
201
207
  }`;
202
208
  // Depth-only occluder pass: instanced prop depth from the sun's ortho view (so trees/rocks cast shadows).
203
209
  // Depth-only occluder. It MUST apply the identical sway, or the shadows stay put while the leaves
@@ -253,6 +259,17 @@ const INST_FLOATS = 28;
253
259
  export class GpuPropsRenderer {
254
260
  device;
255
261
  pipe;
262
+ /**
263
+ * The same pipeline with source-alpha blending and depth writes off, for models with `alpha < 1`.
264
+ *
265
+ * ⚠️ Both are built from ONE EXPLICIT pipeline layout rather than `layout: 'auto'`. Two `auto`
266
+ * pipelines get two distinct bind-group layouts even from identical shader code, so a bind group
267
+ * made for one is rejected by the other — and every bind group here is built once, in `setModels`
268
+ * or `setInstances`, and reused by whichever pipeline draws it.
269
+ */
270
+ blendPipe;
271
+ /** The explicit group 0/1/2 layouts, shared by both render pipelines. */
272
+ drawBGL;
256
273
  occPipe;
257
274
  uBuf;
258
275
  lightBuf;
@@ -303,8 +320,62 @@ export class GpuPropsRenderer {
303
320
  constructor(device, format) {
304
321
  this.device = device;
305
322
  const sm = device.createShaderModule({ code: SHADER });
306
- this.pipe = device.createRenderPipeline({
307
- layout: 'auto',
323
+ // The three groups the SHADER declares, written out so BOTH render pipelines share them. Under
324
+ // `layout: 'auto'` each pipeline would mint its own and the bind groups built elsewhere in this
325
+ // class could only ever be used by one of them.
326
+ const bgl0 = device.createBindGroupLayout({
327
+ entries: [
328
+ {
329
+ binding: 0,
330
+ visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
331
+ buffer: { type: 'uniform' },
332
+ },
333
+ {
334
+ binding: 1,
335
+ visibility: GPUShaderStage.VERTEX,
336
+ buffer: { type: 'read-only-storage' },
337
+ },
338
+ ],
339
+ });
340
+ const bgl1 = device.createBindGroupLayout({
341
+ entries: [
342
+ {
343
+ binding: 0,
344
+ visibility: GPUShaderStage.FRAGMENT,
345
+ texture: { sampleType: 'depth', viewDimension: '2d-array' },
346
+ },
347
+ {
348
+ binding: 1,
349
+ visibility: GPUShaderStage.FRAGMENT,
350
+ sampler: { type: 'comparison' },
351
+ },
352
+ ],
353
+ });
354
+ const bgl2 = device.createBindGroupLayout({
355
+ entries: [
356
+ {
357
+ binding: 0,
358
+ visibility: GPUShaderStage.FRAGMENT,
359
+ texture: { sampleType: 'float' },
360
+ },
361
+ {
362
+ binding: 1,
363
+ visibility: GPUShaderStage.FRAGMENT,
364
+ sampler: { type: 'filtering' },
365
+ },
366
+ {
367
+ binding: 2,
368
+ visibility: GPUShaderStage.FRAGMENT,
369
+ buffer: { type: 'uniform' },
370
+ },
371
+ ],
372
+ });
373
+ this.drawBGL = [bgl0, bgl1, bgl2];
374
+ const drawLayout = device.createPipelineLayout({
375
+ bindGroupLayouts: this.drawBGL,
376
+ });
377
+ const commonDraw = {
378
+ layout: drawLayout,
308
379
  vertex: {
309
380
  module: sm,
310
381
  entryPoint: 'vs',
@@ -329,14 +400,44 @@ export class GpuPropsRenderer {
329
400
  },
330
401
  ],
331
402
  },
332
- fragment: { module: sm, entryPoint: 'fs', targets: [{ format }] },
333
403
  primitive: { topology: 'triangle-list', cullMode: 'none' },
404
+ };
405
+ this.pipe = device.createRenderPipeline({
406
+ ...commonDraw,
407
+ fragment: { module: sm, entryPoint: 'fs', targets: [{ format }] },
334
408
  depthStencil: {
335
409
  format: 'depth24plus',
336
410
  depthWriteEnabled: true,
337
411
  depthCompare: 'less',
338
412
  },
339
413
  });
414
+ this.blendPipe = device.createRenderPipeline({
415
+ ...commonDraw,
416
+ fragment: {
417
+ module: sm,
418
+ entryPoint: 'fs',
419
+ targets: [
420
+ {
421
+ format,
422
+ blend: {
423
+ color: {
424
+ srcFactor: 'src-alpha',
425
+ dstFactor: 'one-minus-src-alpha',
426
+ },
427
+ alpha: { srcFactor: 'one', dstFactor: 'one-minus-src-alpha' },
428
+ },
429
+ },
430
+ ],
431
+ },
432
+ // Depth TEST stays on — a crystal behind a hill is still behind the hill. Depth WRITE goes:
433
+ // otherwise the translucent surface occludes whatever is drawn after it, which is the whole
434
+ // thing this exists to prevent.
435
+ depthStencil: {
436
+ format: 'depth24plus',
437
+ depthWriteEnabled: false,
438
+ depthCompare: 'less',
439
+ },
440
+ });
340
441
  const om = device.createShaderModule({ code: OCCLUDER });
341
442
  this.occPipe = device.createRenderPipeline({
342
443
  layout: 'auto',
@@ -439,6 +540,7 @@ export class GpuPropsRenderer {
439
540
  // a repeated setModels bind dead resources.
440
541
  if (p.ownsTex)
441
542
  p.tex?.destroy();
543
+ p.matBuf.destroy();
442
544
  }
443
545
  const mk = (d, u) => {
444
546
  const b = dev.createBuffer({ size: d.byteLength, usage: u });
@@ -478,7 +580,15 @@ export class GpuPropsRenderer {
478
580
  ? m.albedo
479
581
  : this.uploadAlbedo(m.albedo)
480
582
  : null;
583
+ const alpha = m.alpha ?? 1;
584
+ const matBuf = dev.createBuffer({
585
+ size: 16,
586
+ usage: U.UNIFORM | U.COPY_DST,
587
+ });
588
+ dev.queue.writeBuffer(matBuf, 0, new Float32Array([alpha, 0, 0, 0]));
481
589
  return {
590
+ alpha,
591
+ matBuf,
482
592
  ownsTex,
483
593
  posB: mk(m.positions, U.VERTEX | U.COPY_DST),
484
594
  nrmB: mk(m.normals, U.VERTEX | U.COPY_DST),
@@ -490,10 +600,11 @@ export class GpuPropsRenderer {
490
600
  extent: measureExtent(m.positions),
491
601
  tex,
492
602
  matBG: dev.createBindGroup({
493
- layout: this.pipe.getBindGroupLayout(2),
603
+ layout: this.drawBGL[2],
494
604
  entries: [
495
605
  { binding: 0, resource: (tex ?? this.white).createView() },
496
606
  { binding: 1, resource: this.sampler },
607
+ { binding: 2, resource: { buffer: matBuf } },
497
608
  ],
498
609
  }),
499
610
  };
@@ -551,7 +662,7 @@ export class GpuPropsRenderer {
551
662
  });
552
663
  this.caps[m] = cap;
553
664
  this.bgs[m] = dev.createBindGroup({
554
- layout: this.pipe.getBindGroupLayout(0),
665
+ layout: this.drawBGL[0],
555
666
  entries: [
556
667
  { binding: 0, resource: { buffer: this.uBuf } },
557
668
  { binding: 1, resource: { buffer: this.instBufs[m] } },
@@ -584,6 +695,11 @@ export class GpuPropsRenderer {
584
695
  const bg = this.occBGs[m], mdl = this.models[m];
585
696
  if (!bg || this.counts[m] === 0)
586
697
  continue;
698
+ // A translucent model casts no shadow. The shadow map is one depth buffer and has nowhere to
699
+ // record a partial occluder, so the choice is an OPAQUE silhouette cast by a pane of glass or
700
+ // none at all — and the opaque one is the more obviously wrong picture.
701
+ if (mdl.alpha < 1)
702
+ continue;
587
703
  pass.setBindGroup(0, bg);
588
704
  pass.setVertexBuffer(0, mdl.posB);
589
705
  pass.setIndexBuffer(mdl.idxB, 'uint32');
@@ -622,7 +738,7 @@ export class GpuPropsRenderer {
622
738
  const sv = shadowView ?? this.dummyShadowView, ss = shadowSamp ?? this.dummyShadowSamp;
623
739
  if (!this.shadowBG || sv !== this.lastSV || ss !== this.lastSS) {
624
740
  this.shadowBG = this.device.createBindGroup({
625
- layout: this.pipe.getBindGroupLayout(1),
741
+ layout: this.drawBGL[1],
626
742
  entries: [
627
743
  { binding: 0, resource: sv },
628
744
  { binding: 1, resource: ss },
@@ -639,12 +755,11 @@ export class GpuPropsRenderer {
639
755
  depthStoreOp: 'store',
640
756
  },
641
757
  });
642
- rp.setPipeline(this.pipe);
643
758
  rp.setBindGroup(1, this.shadowBG);
644
- for (let m = 0; m < this.models.length; m++) {
759
+ const drawModel = (m) => {
645
760
  const bg = this.bgs[m], mdl = this.models[m];
646
761
  if (!bg || this.counts[m] === 0)
647
- continue;
762
+ return;
648
763
  rp.setBindGroup(0, bg);
649
764
  rp.setVertexBuffer(0, mdl.posB);
650
765
  rp.setVertexBuffer(1, mdl.nrmB);
@@ -653,7 +768,30 @@ export class GpuPropsRenderer {
653
768
  rp.setBindGroup(2, mdl.matBG);
654
769
  rp.setIndexBuffer(mdl.idxB, 'uint32');
655
770
  rp.drawIndexed(mdl.idxCount, this.counts[m]);
656
- }
771
+ };
772
+ // OPAQUE FIRST, then the blended models — the whole point of the second pass. A translucent
773
+ // crystal drawn before an opaque rock composites against whatever the sky left in the target and
774
+ // the rock then paints over it; drawn after, it composites against the rock. Two loops over the
775
+ // model list rather than a sort: the split is by MODEL and the list is tens of entries long, so
776
+ // it costs nothing measurable, and both loops skip the pipeline switch when one side is empty.
777
+ let anyOpaque = false;
778
+ for (let m = 0; m < this.models.length; m++)
779
+ if (this.models[m].alpha >= 1) {
780
+ if (!anyOpaque) {
781
+ rp.setPipeline(this.pipe);
782
+ anyOpaque = true;
783
+ }
784
+ drawModel(m);
785
+ }
786
+ let anyBlend = false;
787
+ for (let m = 0; m < this.models.length; m++)
788
+ if (this.models[m].alpha < 1) {
789
+ if (!anyBlend) {
790
+ rp.setPipeline(this.blendPipe);
791
+ anyBlend = true;
792
+ }
793
+ drawModel(m);
794
+ }
657
795
  rp.end();
658
796
  }
659
797
  }
@@ -36,6 +36,23 @@ export interface SkinCreature {
36
36
  */
37
37
  tex2?: GPUTexture;
38
38
  mix?: number;
39
+ /**
40
+ * Opacity, 1 (the default) being fully opaque.
41
+ *
42
+ * ⚠️ Below 1 the creature moves to a SECOND pipeline — source-alpha blended, and with DEPTH
43
+ * WRITES OFF — drawn after every opaque one. Depth writes have to go: a translucent surface that
44
+ * writes depth occludes whatever is behind it, which is the one thing an opacity control exists
45
+ * to prevent. The cost is that a closed mesh blends against its own far side, so a body at 0.4
46
+ * reads as an x-ray rather than as tinted glass. For the character builder that wants to see a
47
+ * skeleton through the skin, that is the desired picture, not a defect to sort around.
48
+ *
49
+ * ⚠️ There is NO depth sort between translucent creatures. Two overlapping ones composite in
50
+ * submission order. Adding a sort would be a per-frame CPU cost on a path that today draws one.
51
+ *
52
+ * `alpha` of 1, or omitted, keeps the creature on the original pipeline with the original depth
53
+ * state — byte-identical to before this existed.
54
+ */
55
+ alpha?: number;
39
56
  indices: Uint32Array;
40
57
  palette: Float32Array;
41
58
  model: Float32Array;
@@ -45,6 +62,17 @@ export declare class GpuSkinRenderer {
45
62
  private device;
46
63
  private skinPipe;
47
64
  private drawPipe;
65
+ /**
66
+ * The same pipeline with source-alpha blending and depth writes off, for `alpha < 1`.
67
+ *
68
+ * ⚠️ Both are built from ONE EXPLICIT pipeline layout rather than `layout: 'auto'`. Two `auto`
69
+ * pipelines get two distinct bind-group layouts even from identical shader code, so a bind group
70
+ * made for one is rejected by the other — and every bind group here is built once in
71
+ * `setCreatures` and reused by whichever pipeline draws it.
72
+ */
73
+ private blendPipe;
74
+ /** The explicit group 0/1/2 layouts, shared by both render pipelines. */
75
+ private drawBGL;
48
76
  private packed;
49
77
  private dummyShadowView;
50
78
  private dummyShadowSamp;
@@ -80,12 +80,25 @@ fn shadowFactor(world: vec3<f32>, ndl: f32) -> f32 {
80
80
  let lit = base * (u.amb.xyz + d * u.sunCol.xyz * sh);
81
81
  let dist = length(i.world - u.cam.xyz);
82
82
  let f = clamp(1.0 - exp(-dist * u.fog.w), 0.0, 1.0);
83
- return vec4(mix(lit, u.fog.xyz, f), 1.0);
83
+ // blend.y is the creature's opacity, 1 for everyone who does not set it — the same constant this
84
+ // returned before, so the opaque pipeline is unchanged.
85
+ return vec4(mix(lit, u.fog.xyz, f), u.blend.y);
84
86
  }`;
85
87
  export class GpuSkinRenderer {
86
88
  device;
87
89
  skinPipe;
88
90
  drawPipe;
91
+ /**
92
+ * The same pipeline with source-alpha blending and depth writes off, for `alpha < 1`.
93
+ *
94
+ * ⚠️ Both are built from ONE EXPLICIT pipeline layout rather than `layout: 'auto'`. Two `auto`
95
+ * pipelines get two distinct bind-group layouts even from identical shader code, so a bind group
96
+ * made for one is rejected by the other — and every bind group here is built once in
97
+ * `setCreatures` and reused by whichever pipeline draws it.
98
+ */
99
+ blendPipe;
100
+ /** The explicit group 0/1/2 layouts, shared by both render pipelines. */
101
+ drawBGL;
89
102
  packed = [];
90
103
  // shadow-receive (group 1): dummy 1×1 depth map when no sun shadow is supplied (demo path), else the terrain's
91
104
  // shared shadow map. The bind group is cached and rebuilt only when the supplied view/sampler identity changes.
@@ -119,8 +132,57 @@ export class GpuSkinRenderer {
119
132
  compute: { module: sm, entryPoint: 'main' },
120
133
  });
121
134
  const dm = device.createShaderModule({ code: DRAW });
122
- this.drawPipe = device.createRenderPipeline({
123
- layout: 'auto',
135
+ // The three groups the DRAW shader declares, written out so BOTH render pipelines share them.
136
+ // Under `layout: 'auto'` each pipeline would mint its own, and the bind groups `setCreatures`
137
+ // builds could only ever be used by one of them.
138
+ const bgl0 = device.createBindGroupLayout({
139
+ entries: [
140
+ {
141
+ binding: 0,
142
+ visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
143
+ buffer: { type: 'uniform' },
144
+ },
145
+ ],
146
+ });
147
+ const bgl1 = device.createBindGroupLayout({
148
+ entries: [
149
+ {
150
+ binding: 0,
151
+ visibility: GPUShaderStage.FRAGMENT,
152
+ texture: { sampleType: 'depth', viewDimension: '2d-array' },
153
+ },
154
+ {
155
+ binding: 1,
156
+ visibility: GPUShaderStage.FRAGMENT,
157
+ sampler: { type: 'comparison' },
158
+ },
159
+ ],
160
+ });
161
+ const bgl2 = device.createBindGroupLayout({
162
+ entries: [
163
+ {
164
+ binding: 0,
165
+ visibility: GPUShaderStage.FRAGMENT,
166
+ texture: { sampleType: 'float' },
167
+ },
168
+ {
169
+ binding: 1,
170
+ visibility: GPUShaderStage.FRAGMENT,
171
+ sampler: { type: 'filtering' },
172
+ },
173
+ {
174
+ binding: 2,
175
+ visibility: GPUShaderStage.FRAGMENT,
176
+ texture: { sampleType: 'float' },
177
+ },
178
+ ],
179
+ });
180
+ this.drawBGL = [bgl0, bgl1, bgl2];
181
+ const layout = device.createPipelineLayout({
182
+ bindGroupLayouts: this.drawBGL,
183
+ });
184
+ const common = {
185
+ layout,
124
186
  vertex: {
125
187
  module: dm,
126
188
  entryPoint: 'vs',
@@ -143,14 +205,46 @@ export class GpuSkinRenderer {
143
205
  },
144
206
  ],
145
207
  },
146
- fragment: { module: dm, entryPoint: 'fs', targets: [{ format }] },
147
208
  primitive: { topology: 'triangle-list', cullMode: 'none' },
209
+ };
210
+ this.drawPipe = device.createRenderPipeline({
211
+ ...common,
212
+ fragment: { module: dm, entryPoint: 'fs', targets: [{ format }] },
148
213
  depthStencil: {
149
214
  format: 'depth24plus',
150
215
  depthWriteEnabled: true,
151
216
  depthCompare: 'less',
152
217
  },
153
218
  });
219
+ this.blendPipe = device.createRenderPipeline({
220
+ ...common,
221
+ fragment: {
222
+ module: dm,
223
+ entryPoint: 'fs',
224
+ targets: [
225
+ {
226
+ format,
227
+ blend: {
228
+ color: {
229
+ srcFactor: 'src-alpha',
230
+ dstFactor: 'one-minus-src-alpha',
231
+ },
232
+ // The destination alpha is left alone — an opaque canvas has nothing to accumulate,
233
+ // and `one` on a target that is already 1 is a no-op either way.
234
+ alpha: { srcFactor: 'zero', dstFactor: 'one' },
235
+ },
236
+ },
237
+ ],
238
+ },
239
+ depthStencil: {
240
+ format: 'depth24plus',
241
+ // ⚠️ OFF. A translucent surface that writes depth hides what is behind it, which is exactly
242
+ // what the caller asked to see through. It still TESTS against depth, so an opaque creature
243
+ // in front still occludes it.
244
+ depthWriteEnabled: false,
245
+ depthCompare: 'less',
246
+ },
247
+ });
154
248
  const dummy = device.createTexture({
155
249
  size: [1, 1],
156
250
  format: 'depth32float',
@@ -217,7 +311,7 @@ export class GpuSkinRenderer {
217
311
  let matBG = this.matBGs.get(matKey);
218
312
  if (!matBG) {
219
313
  matBG = dev.createBindGroup({
220
- layout: this.drawPipe.getBindGroupLayout(2),
314
+ layout: this.drawBGL[2],
221
315
  entries: [
222
316
  { binding: 0, resource: tex.createView() },
223
317
  { binding: 1, resource: this.albedoSamp },
@@ -255,7 +349,7 @@ export class GpuSkinRenderer {
255
349
  usage: U.UNIFORM | U.COPY_DST,
256
350
  });
257
351
  const uBG = dev.createBindGroup({
258
- layout: this.drawPipe.getBindGroupLayout(0),
352
+ layout: this.drawBGL[0],
259
353
  entries: [{ binding: 0, resource: { buffer: uBuf } }],
260
354
  });
261
355
  return {
@@ -273,6 +367,7 @@ export class GpuSkinRenderer {
273
367
  n,
274
368
  model: c.model,
275
369
  mix: c.mix ?? 0,
370
+ alpha: c.alpha ?? 1,
276
371
  };
277
372
  });
278
373
  }
@@ -309,13 +404,16 @@ export class GpuSkinRenderer {
309
404
  // blend.x — the second albedo's share. 0 for every caller that does not set `mix`, and
310
405
  // `mix(a, white, 0)` is `a`, so the default path is byte-identical to the pre-0.14.6 output.
311
406
  u[72 + 16 * MAX_CASCADES] = p.mix;
407
+ // blend.y — opacity. 1 for every caller that does not set `alpha`, which is the constant the
408
+ // fragment shader used to return outright.
409
+ u[73 + 16 * MAX_CASCADES] = p.alpha;
312
410
  this.device.queue.writeBuffer(p.uBuf, 0, u);
313
411
  }
314
412
  // group 1: the shadow map + comparison sampler (dummy when not receiving). Rebuild only when the view changes.
315
413
  const sv = shadowView ?? this.dummyShadowView, ss = shadowSamp ?? this.dummyShadowSamp;
316
414
  if (!this.shadowBG || sv !== this.lastSV || ss !== this.lastSS) {
317
415
  this.shadowBG = this.device.createBindGroup({
318
- layout: this.drawPipe.getBindGroupLayout(1),
416
+ layout: this.drawBGL[1],
319
417
  entries: [
320
418
  { binding: 0, resource: sv },
321
419
  { binding: 1, resource: ss },
@@ -345,9 +443,8 @@ export class GpuSkinRenderer {
345
443
  depthStoreOp: 'store',
346
444
  },
347
445
  });
348
- rp.setPipeline(this.drawPipe);
349
446
  rp.setBindGroup(1, this.shadowBG);
350
- for (const p of this.packed) {
447
+ const drawOne = (p) => {
351
448
  rp.setBindGroup(0, p.uBG);
352
449
  rp.setVertexBuffer(0, p.defB);
353
450
  rp.setVertexBuffer(1, p.colB);
@@ -356,6 +453,21 @@ export class GpuSkinRenderer {
356
453
  rp.setBindGroup(2, p.matBG);
357
454
  rp.setIndexBuffer(p.idxB, 'uint32');
358
455
  rp.drawIndexed(p.idxCount);
456
+ };
457
+ // ⚠️ OPAQUE FIRST, in two passes over the list rather than one. The translucent creatures do not
458
+ // write depth, so anything opaque drawn after them would still appear — but they must blend
459
+ // against a colour buffer that already HAS the opaque scene in it, or they composite over the
460
+ // background and the thing behind them is simply missing. With no `alpha` set anywhere the
461
+ // second loop is empty and this is the original single loop.
462
+ rp.setPipeline(this.drawPipe);
463
+ for (const p of this.packed)
464
+ if (p.alpha >= 1)
465
+ drawOne(p);
466
+ const translucent = this.packed.filter((p) => p.alpha < 1);
467
+ if (translucent.length) {
468
+ rp.setPipeline(this.blendPipe);
469
+ for (const p of translucent)
470
+ drawOne(p);
359
471
  }
360
472
  rp.end();
361
473
  }
package/dist/gpuShadow.js CHANGED
@@ -384,7 +384,11 @@ fn fixedFill(N: vec3<f32>, up: vec3<f32>) -> f32 {
384
384
  let dtop = dot(i.objN, faceVec(i.upc));
385
385
  if (dtop > 0.5 && rad > 0.0) { // TOP faces only: soil on a cliff wall is a stripe, not dirt
386
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);
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);
388
392
  // CONTACT AO — the load-bearing half. The pasted-on read is largely the MISSING SHADOW where
389
393
  // a prop meets the ground; SSAO gives a pixel or two, this gives the metre-scale pool a real
390
394
  // root ball would.
@@ -394,7 +398,10 @@ fn fixedFill(N: vec3<f32>, up: vec3<f32>) -> f32 {
394
398
  // MULTIPLICATIVE, so the atlas's own grain and the planet tint survive underneath. A decal that
395
399
  // REPLACED the colour would trade one pasted-on look for another and would need a per-biome
396
400
  // 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);
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);
398
405
  // per-block edge AO makes each voxel visible on FLAT-hue cubes, but reads as a hard GRID over textures — so the
399
406
  // atlas path dropped it ENTIRELY, which left textured terrain with no per-voxel AO at all: only SSAO, which
400
407
  // resolves a pixel or two of crease and nothing at the metre scale. The result is a surface that reads as a slab,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.14.6",
3
+ "version": "0.14.8",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -15,14 +15,6 @@
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
- },
26
18
  "dependencies": {
27
19
  "meshoptimizer": "^1.2.0"
28
20
  },
@@ -35,5 +27,12 @@
35
27
  "@webgpu/types": "^0.1.40",
36
28
  "prettier": "^3.9.5",
37
29
  "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 ."
38
37
  }
39
- }
38
+ }