ugly-game 0.15.54 → 0.15.55

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.
@@ -82,11 +82,9 @@ export interface PropMesh {
82
82
  * the cases — all three currently render as solid rock, which is not a subtle wrongness when one
83
83
  * of them is 54% of all the flora placed in all-mine-sky.
84
84
  *
85
- * ⚠️ Below 1 the model moves to a SECOND pipeline — source-alpha blended, depth writes OFF — drawn
86
- * after every opaque one. Depth writes have to go: a translucent surface that writes depth
87
- * occludes what is behind it, which is the one thing this exists to prevent. The cost is that a
88
- * closed mesh blends against its own far side, so a crystal reads as glass rather than as a
89
- * tinted solid — which for ice and glass is the desired picture.
85
+ * Below 1 the model uses source-alpha blending after every opaque model.
86
+ * Depth writes remain enabled by default for compatibility with later world passes.
87
+ * Window glass should set depthWrite:false so near panes cannot reject far panes.
90
88
  *
91
89
  * ⚠️ There is NO depth sort, between models or between instances of one model. Overlapping
92
90
  * translucent props composite in submission order. Sorting tens of thousands of instances per
@@ -97,6 +95,10 @@ export interface PropMesh {
97
95
  * map is a single depth buffer with nowhere to put a partial occluder.
98
96
  */
99
97
  alpha?: number;
98
+ /** Face rejection; existing thin-sheet assets default to none. */
99
+ cullMode?: GPUCullMode;
100
+ /** Disable writes for layered glass while retaining depth testing. Defaults to true. */
101
+ depthWrite?: boolean;
100
102
  /**
101
103
  * Alpha-test cutoff: a fragment whose ALBEDO alpha is below this is discarded. 0 (the default)
102
104
  * tests nothing.
@@ -187,6 +189,7 @@ export declare class GpuPropsRenderer {
187
189
  * or `setInstances`, and reused by whichever pipeline draws it.
188
190
  */
189
191
  private blendPipe;
192
+ private drawPipeline;
190
193
  /** The explicit group 0/1/2 layouts, shared by both render pipelines. */
191
194
  private drawBGL;
192
195
  private occPipe;
@@ -481,6 +481,7 @@ export class GpuPropsRenderer {
481
481
  * or `setInstances`, and reused by whichever pipeline draws it.
482
482
  */
483
483
  blendPipe;
484
+ drawPipeline;
484
485
  /** The explicit group 0/1/2 layouts, shared by both render pipelines. */
485
486
  drawBGL;
486
487
  occPipe;
@@ -656,7 +657,7 @@ export class GpuPropsRenderer {
656
657
  },
657
658
  primitive: { topology: 'triangle-list', cullMode: 'none' },
658
659
  };
659
- this.pipe = device.createRenderPipeline({
660
+ const opaqueDescriptor = {
660
661
  ...commonDraw,
661
662
  fragment: { module: sm, entryPoint: 'fs', targets: [{ format }] },
662
663
  depthStencil: {
@@ -664,8 +665,9 @@ export class GpuPropsRenderer {
664
665
  depthWriteEnabled: true,
665
666
  depthCompare: 'less',
666
667
  },
667
- });
668
- this.blendPipe = device.createRenderPipeline({
668
+ };
669
+ this.pipe = device.createRenderPipeline(opaqueDescriptor);
670
+ const blendDescriptor = {
669
671
  ...commonDraw,
670
672
  fragment: {
671
673
  module: sm,
@@ -695,7 +697,29 @@ export class GpuPropsRenderer {
695
697
  depthWriteEnabled: true,
696
698
  depthCompare: 'less',
697
699
  },
698
- });
700
+ };
701
+ this.blendPipe = device.createRenderPipeline(blendDescriptor);
702
+ const variants = new Map([
703
+ ['false:none:true', this.pipe],
704
+ ['true:none:true', this.blendPipe],
705
+ ]);
706
+ this.drawPipeline = (blend, cull, depthWrite) => {
707
+ const key = `${blend}:${cull}:${depthWrite}`;
708
+ let pipeline = variants.get(key);
709
+ if (!pipeline) {
710
+ const base = blend ? blendDescriptor : opaqueDescriptor;
711
+ pipeline = device.createRenderPipeline({
712
+ ...base,
713
+ primitive: { ...base.primitive, cullMode: cull },
714
+ depthStencil: {
715
+ ...base.depthStencil,
716
+ depthWriteEnabled: depthWrite,
717
+ },
718
+ });
719
+ variants.set(key, pipeline);
720
+ }
721
+ return pipeline;
722
+ };
699
723
  const om = device.createShaderModule({ code: OCCLUDER });
700
724
  this.occPipe = device.createRenderPipeline({
701
725
  layout: 'auto',
@@ -944,6 +968,8 @@ export class GpuPropsRenderer {
944
968
  dev.queue.writeBuffer(matBuf, 0, materialValues);
945
969
  return {
946
970
  alpha,
971
+ cullMode: m.cullMode ?? 'none',
972
+ depthWrite: m.depthWrite ?? true,
947
973
  cutout,
948
974
  matBuf,
949
975
  materialValues,
@@ -1336,24 +1362,20 @@ export class GpuPropsRenderer {
1336
1362
  // the rock then paints over it; drawn after, it composites against the rock. Two loops over the
1337
1363
  // model list rather than a sort: the split is by MODEL and the list is tens of entries long, so
1338
1364
  // it costs nothing measurable, and both loops skip the pipeline switch when one side is empty.
1339
- let anyOpaque = false;
1340
- for (let m = 0; m < this.models.length; m++)
1341
- if (this.models[m].alpha >= 1) {
1342
- if (!anyOpaque) {
1343
- rp.setPipeline(this.pipe);
1344
- anyOpaque = true;
1345
- }
1346
- drawModel(m);
1347
- }
1348
- let anyBlend = false;
1349
- for (let m = 0; m < this.models.length; m++)
1350
- if (this.models[m].alpha < 1) {
1351
- if (!anyBlend) {
1352
- rp.setPipeline(this.blendPipe);
1353
- anyBlend = true;
1365
+ let activePipeline;
1366
+ for (const blended of [false, true]) {
1367
+ for (let m = 0; m < this.models.length; m++) {
1368
+ const model = this.models[m];
1369
+ if (model.alpha < 1 !== blended || this.counts[m] === 0)
1370
+ continue;
1371
+ const pipeline = this.drawPipeline(blended, model.cullMode, model.depthWrite);
1372
+ if (pipeline !== activePipeline) {
1373
+ rp.setPipeline(pipeline);
1374
+ activePipeline = pipeline;
1354
1375
  }
1355
1376
  drawModel(m);
1356
1377
  }
1378
+ }
1357
1379
  rp.end();
1358
1380
  }
1359
1381
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.54",
3
+ "version": "0.15.55",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {