ugly-game 0.15.53 → 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;
@@ -211,7 +211,17 @@ fn studioEnv(r: vec3<f32>, rough: f32) -> vec3<f32> {
211
211
  fn environment(r: vec3<f32>, rough: f32) -> vec3<f32> {
212
212
  if (mtl.coat.z < 0.5) { return studioEnv(r,rough); }
213
213
  let uv=vec2(atan2(r.z,r.x)/6.2831853+0.5,acos(clamp(r.y,-1.0,1.0))/3.14159265);
214
- return textureSampleLevel(environmentTex,albedoSamp,uv,rough*mtl.coat.w).rgb;
214
+ // Roughness alone under-filters glossy curved surfaces: one screen pixel can
215
+ // span many environment texels, making chrome/clearcoat flash while orbiting.
216
+ // Respect that footprint as well as the material's prefiltered reflection.
217
+ // Longitude wraps at the panorama seam; unwrap its derivatives so crossing
218
+ // that seam does not introduce a spurious blurry stripe.
219
+ let dx=dpdx(uv); let dy=dpdy(uv);
220
+ let dimensions=vec2<f32>(textureDimensions(environmentTex));
221
+ let sx=vec2(dx.x-round(dx.x),dx.y)*dimensions;
222
+ let sy=vec2(dy.x-round(dy.x),dy.y)*dimensions;
223
+ let pixelLod=log2(max(1.0,max(length(sx),length(sy))));
224
+ return textureSampleLevel(environmentTex,albedoSamp,uv,max(rough*mtl.coat.w,pixelLod)).rgb;
215
225
  }
216
226
  fn fresnel(f0: vec3<f32>, cosTheta: f32) -> vec3<f32> {
217
227
  return f0 + (vec3(1.0) - f0) * pow(1.0 - clamp(cosTheta, 0.0, 1.0), 5.0);
@@ -471,6 +481,7 @@ export class GpuPropsRenderer {
471
481
  * or `setInstances`, and reused by whichever pipeline draws it.
472
482
  */
473
483
  blendPipe;
484
+ drawPipeline;
474
485
  /** The explicit group 0/1/2 layouts, shared by both render pipelines. */
475
486
  drawBGL;
476
487
  occPipe;
@@ -646,7 +657,7 @@ export class GpuPropsRenderer {
646
657
  },
647
658
  primitive: { topology: 'triangle-list', cullMode: 'none' },
648
659
  };
649
- this.pipe = device.createRenderPipeline({
660
+ const opaqueDescriptor = {
650
661
  ...commonDraw,
651
662
  fragment: { module: sm, entryPoint: 'fs', targets: [{ format }] },
652
663
  depthStencil: {
@@ -654,8 +665,9 @@ export class GpuPropsRenderer {
654
665
  depthWriteEnabled: true,
655
666
  depthCompare: 'less',
656
667
  },
657
- });
658
- this.blendPipe = device.createRenderPipeline({
668
+ };
669
+ this.pipe = device.createRenderPipeline(opaqueDescriptor);
670
+ const blendDescriptor = {
659
671
  ...commonDraw,
660
672
  fragment: {
661
673
  module: sm,
@@ -685,7 +697,29 @@ export class GpuPropsRenderer {
685
697
  depthWriteEnabled: true,
686
698
  depthCompare: 'less',
687
699
  },
688
- });
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
+ };
689
723
  const om = device.createShaderModule({ code: OCCLUDER });
690
724
  this.occPipe = device.createRenderPipeline({
691
725
  layout: 'auto',
@@ -934,6 +968,8 @@ export class GpuPropsRenderer {
934
968
  dev.queue.writeBuffer(matBuf, 0, materialValues);
935
969
  return {
936
970
  alpha,
971
+ cullMode: m.cullMode ?? 'none',
972
+ depthWrite: m.depthWrite ?? true,
937
973
  cutout,
938
974
  matBuf,
939
975
  materialValues,
@@ -1326,24 +1362,20 @@ export class GpuPropsRenderer {
1326
1362
  // the rock then paints over it; drawn after, it composites against the rock. Two loops over the
1327
1363
  // model list rather than a sort: the split is by MODEL and the list is tens of entries long, so
1328
1364
  // it costs nothing measurable, and both loops skip the pipeline switch when one side is empty.
1329
- let anyOpaque = false;
1330
- for (let m = 0; m < this.models.length; m++)
1331
- if (this.models[m].alpha >= 1) {
1332
- if (!anyOpaque) {
1333
- rp.setPipeline(this.pipe);
1334
- anyOpaque = true;
1335
- }
1336
- drawModel(m);
1337
- }
1338
- let anyBlend = false;
1339
- for (let m = 0; m < this.models.length; m++)
1340
- if (this.models[m].alpha < 1) {
1341
- if (!anyBlend) {
1342
- rp.setPipeline(this.blendPipe);
1343
- 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;
1344
1375
  }
1345
1376
  drawModel(m);
1346
1377
  }
1378
+ }
1347
1379
  rp.end();
1348
1380
  }
1349
1381
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.53",
3
+ "version": "0.15.55",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -23,6 +23,7 @@
23
23
  "test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin",
24
24
  "test:flight": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/flight*.test.mts",
25
25
  "test:flight-browser": "playwright test -c playwright.flight.config.ts",
26
+ "test:props-browser": "playwright test -c playwright.props.config.ts",
26
27
  "test:flight-perf": "playwright test -c playwright.flight.config.ts --grep 'CPU and retained-memory'",
27
28
  "test:types": "tsc -p tsconfig.test.json",
28
29
  "test:package-types": "node tools/packageTypesSmoke.mjs",