ugly-game 0.15.69 → 0.15.71

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.
@@ -104,6 +104,8 @@ export interface PropRendererOptions extends Partial<PropLook> {
104
104
  * that maps near to 1 and far to 0. The sun-shadow occluder keeps its own depth domain.
105
105
  */
106
106
  depth?: DepthConvention;
107
+ /** Format of the caller's sun-shadow depth attachment. Default depth32float. */
108
+ shadowDepthFormat?: 'depth16unorm' | 'depth32float';
107
109
  }
108
110
  export interface PropMesh {
109
111
  /** Offline-cooked deformation bounds. Omit for procedural meshes. */
@@ -345,8 +345,14 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
345
345
  if(mtl.maps.x>0.5) {
346
346
  let T=cross(py,N)*tx.x+cross(N,px)*ty.x;
347
347
  let B=cross(py,N)*tx.y+cross(N,px)*ty.y;
348
- let inv=inverseSqrt(max(max(dot(T,T),dot(B,B)),0.000001));
349
- N=normalize(N*mapN.z+(T*mapN.x+B*mapN.y)*inv*mtl.maps.z);
348
+ // Both derivatives shrink with the pixel footprint. A fixed floor on
349
+ // the frame length erases relief as the camera approaches the surface.
350
+ let frameLength2=max(dot(T,T),dot(B,B));
351
+ if (frameLength2 > 1e-28) {
352
+ let orientation=sign(dot(px,cross(py,N)));
353
+ let gradient=(T*mapN.x+B*mapN.y)*(orientation*inverseSqrt(frameLength2));
354
+ N=normalize(N*mapN.z+gradient*mtl.maps.z);
355
+ }
350
356
  }
351
357
  let ff = select(1.0, 0.5 + 0.85 * fixedFill(N, u.up.xyz), u.up.w > 0.5); // fixed fill (fall back to flat amb if no up)
352
358
  let d = clamp(dot(N, -normalize(u.sun.xyz)), 0.0, 1.0);
@@ -776,10 +782,12 @@ export class GpuPropsRenderer {
776
782
  }
777
783
  constructor(device, format, options = {}) {
778
784
  this.device = device;
779
- const { sampleCount = 1, depth = FORWARD_DEPTH, ...look } = options;
785
+ const { sampleCount = 1, depth = FORWARD_DEPTH, shadowDepthFormat = 'depth32float', ...look } = options;
780
786
  // Runtime guard for untyped callers: WebGPU only guarantees 1 and 4.
781
787
  if (![1, 4].includes(sampleCount))
782
788
  throw new RangeError(`Unsupported prop sampleCount ${String(sampleCount)}`);
789
+ if (!['depth16unorm', 'depth32float'].includes(shadowDepthFormat))
790
+ throw new RangeError(`Unsupported prop shadowDepthFormat ${shadowDepthFormat}`);
783
791
  this.sampleCount = sampleCount;
784
792
  this.depth = depth;
785
793
  this.setLook(look);
@@ -956,7 +964,7 @@ export class GpuPropsRenderer {
956
964
  },
957
965
  primitive: { topology: 'triangle-list', cullMode: 'none' },
958
966
  depthStencil: {
959
- format: 'depth32float',
967
+ format: shadowDepthFormat,
960
968
  depthWriteEnabled: true,
961
969
  depthCompare: 'less',
962
970
  // Offset the caster by its rasterized slope: a constant receiver bias
@@ -983,7 +991,7 @@ export class GpuPropsRenderer {
983
991
  });
984
992
  const dummy = device.createTexture({
985
993
  size: [1, 1],
986
- format: 'depth32float',
994
+ format: shadowDepthFormat,
987
995
  usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT,
988
996
  });
989
997
  this.dummyShadowView = dummy.createView({ dimension: '2d-array' }); // the binding is an array now
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.69",
3
+ "version": "0.15.71",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {