ugly-game 0.10.0 → 0.11.0

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.
@@ -1,3 +1,4 @@
1
+ export declare const MAX_CASCADES = 4;
1
2
  /**
2
3
  * Per-world surface + motion parameters.
3
4
  *
@@ -130,5 +131,5 @@ export declare class GpuPropsRenderer {
130
131
  setInstances(instances: PropInstance[]): void;
131
132
  /** Occluder pass: draw all instanced props' depth into the shared shadow map from the sun's ortho view. */
132
133
  shadowPass(pass: GPURenderPassEncoder, lightVP: Float32Array): void;
133
- frame(enc: GPUCommandEncoder, colorView: GPUTextureView, depthView: GPUTextureView, camVP: Float32Array, sunDir: [number, number, number], sunCol: [number, number, number], amb: [number, number, number], camPos: [number, number, number], fog: [number, number, number], fogDensity: number, up?: [number, number, number], lightVP?: Float32Array, shadowView?: GPUTextureView, shadowSamp?: GPUSampler): void;
134
+ frame(enc: GPUCommandEncoder, colorView: GPUTextureView, depthView: GPUTextureView, camVP: Float32Array, sunDir: [number, number, number], sunCol: [number, number, number], amb: [number, number, number], camPos: [number, number, number], fog: [number, number, number], fogDensity: number, up?: [number, number, number], lightVP?: Float32Array | Float32Array[], shadowView?: GPUTextureView, shadowSamp?: GPUSampler): void;
134
135
  }
@@ -3,11 +3,15 @@
3
3
  // model (tree/rock/bush/…) many times at per-instance world transforms, lit + fogged to match the
4
4
  // terrain. Runs in a load pass after the terrain so props depth-test against the surface.
5
5
  // ─────────────────────────────────────────────────────────────────────────────
6
+ export const MAX_CASCADES = 4; // must match gpuShadow's
6
7
  const SHADER = /* wgsl */ `
7
8
  // wind = (dirX, dirZ, amplitude, phase) — sway, amplitude scaled by the world's air density
8
9
  // surf = (grainScale, grainDepth, roughness, emissive)
9
10
  // grade = (hueShift, saturation, valueLift, unused)
10
- struct U { mvp: mat4x4<f32>, lightVP: mat4x4<f32>, sun: vec4<f32>, sunCol: vec4<f32>, amb: vec4<f32>, cam: vec4<f32>, fog: vec4<f32>, up: vec4<f32>, wind: vec4<f32>, surf: vec4<f32>, grade: vec4<f32> };
11
+ // csm + cascades are APPENDED, not woven in: every field above keeps the byte offset it had, so the
12
+ // existing writes in frame() are untouched and a caller that knows nothing about cascades stays
13
+ // byte-identical. lightVP remains the legacy cascade-0 slot; shading reads cascades instead.
14
+ struct U { mvp: mat4x4<f32>, lightVP: mat4x4<f32>, sun: vec4<f32>, sunCol: vec4<f32>, amb: vec4<f32>, cam: vec4<f32>, fog: vec4<f32>, up: vec4<f32>, wind: vec4<f32>, surf: vec4<f32>, grade: vec4<f32>, csm: vec4<f32>, cascades: array<mat4x4<f32>, ${MAX_CASCADES}> };
11
15
  @group(0) @binding(0) var<uniform> u: U;
12
16
  // One instance. 'm' is the placement; d0/d1/d2 are the per-instance DEFORM, which is what lets
13
17
  // thousands of visibly different plants share a single mesh and a single draw call. Baking each
@@ -20,7 +24,7 @@ struct Inst { m: mat4x4<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32> };
20
24
  @group(0) @binding(1) var<storage,read> models: array<Inst>;
21
25
  @group(2) @binding(0) var albedoTex: texture_2d<f32>;
22
26
  @group(2) @binding(1) var albedoSamp: sampler;
23
- @group(1) @binding(0) var shadowMap: texture_depth_2d; // the SAME sun shadow map the terrain cubes sample
27
+ @group(1) @binding(0) var shadowMap: texture_depth_2d_array; // the SAME cascaded sun shadow map the terrain cubes sample
24
28
  @group(1) @binding(1) var shadowSamp: sampler_comparison;
25
29
  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> };
26
30
  // WIND SWAY. Displacement is weighted by height above the instance's own anchor, so a trunk stays
@@ -106,21 +110,35 @@ fn fixedFill(N: vec3<f32>, up: vec3<f32>) -> f32 {
106
110
  return max(dot(N, L), 0.0);
107
111
  }
108
112
  // PCF 3×3 sun shadow — mirrors gpuShadow.shadowFactor so props sit in the SAME shadow as the terrain. 1 = lit, 0 = shadowed.
109
- fn shadowFactor(world: vec3<f32>, ndl: f32) -> f32 {
110
- let lp = u.lightVP * vec4(world, 1.0);
113
+ fn pcfLayer(world: vec3<f32>, ndl: f32, layer: i32, inside: ptr<function, bool>) -> f32 {
114
+ let lp = u.cascades[layer] * vec4(world, 1.0);
111
115
  let proj = lp.xyz / lp.w;
112
116
  let uv = proj.xy * vec2(0.5, -0.5) + vec2(0.5, 0.5);
113
- if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 || proj.z > 1.0 || proj.z < 0.0) { return 1.0; }
114
- let bias = max(0.0006 * (1.0 - ndl), 0.0004);
117
+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 || proj.z > 1.0 || proj.z < 0.0) {
118
+ *inside = false; return 1.0;
119
+ }
120
+ *inside = true;
121
+ let bias = max(0.0006 * (1.0 - ndl), 0.0004) * (1.0 + f32(layer) * 1.5);
115
122
  let texel = 1.0 / 2048.0;
116
123
  var s = 0.0;
117
124
  for (var dy = -1; dy <= 1; dy = dy + 1) {
118
125
  for (var dx = -1; dx <= 1; dx = dx + 1) {
119
- s = s + textureSampleCompareLevel(shadowMap, shadowSamp, uv + vec2(f32(dx), f32(dy)) * texel, proj.z - bias);
126
+ s = s + textureSampleCompareLevel(shadowMap, shadowSamp, uv + vec2(f32(dx), f32(dy)) * texel, layer, proj.z - bias);
120
127
  }
121
128
  }
122
129
  return s / 9.0;
123
130
  }
131
+ // Tightest cascade that CONTAINS the point wins — the same rule gpuShadow uses, so a prop and the
132
+ // terrain under it always resolve against the same map and cannot disagree about being in shadow.
133
+ fn shadowFactor(world: vec3<f32>, ndl: f32) -> f32 {
134
+ let n = i32(u.csm.x);
135
+ var inside = false;
136
+ for (var c = 0; c < n; c = c + 1) {
137
+ let f = pcfLayer(world, ndl, c, &inside);
138
+ if (inside) { return f; }
139
+ }
140
+ return 1.0;
141
+ }
124
142
  // ── PROCEDURAL SURFACE ───────────────────────────────────────────────────────
125
143
  // Detail is generated in the shader rather than sampled from a texture. Three reasons, all of them
126
144
  // load-bearing for a procedurally-populated universe: generated meshes have unreliable UVs (so
@@ -340,7 +358,7 @@ export class GpuPropsRenderer {
340
358
  },
341
359
  });
342
360
  this.uBuf = device.createBuffer({
343
- size: 128 + 16 * 9, // 2× mat4 (mvp + lightVP) + 9× vec4 (…, wind, surf, grade)
361
+ size: 128 + 16 * 9 + 16 + 64 * MAX_CASCADES, // + csm vec4 + the cascade matrices
344
362
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
345
363
  });
346
364
  this.lightBuf = device.createBuffer({
@@ -352,7 +370,7 @@ export class GpuPropsRenderer {
352
370
  format: 'depth32float',
353
371
  usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT,
354
372
  });
355
- this.dummyShadowView = dummy.createView();
373
+ this.dummyShadowView = dummy.createView({ dimension: '2d-array' }); // the binding is an array now
356
374
  this.dummyShadowSamp = device.createSampler({ compare: 'less' });
357
375
  }
358
376
  /**
@@ -566,9 +584,10 @@ export class GpuPropsRenderer {
566
584
  // in the same shadow. Omit all three (the demo path) → no shadowing, byte-identical to before.
567
585
  lightVP, shadowView, shadowSamp) {
568
586
  const receive = !!(lightVP && shadowView && shadowSamp);
569
- const u = new Float32Array(68);
587
+ const mats = lightVP ? (Array.isArray(lightVP) ? lightVP : [lightVP]) : [];
588
+ const u = new Float32Array(68 + 4 + 16 * MAX_CASCADES);
570
589
  u.set(camVP, 0);
571
- u.set(lightVP ?? IDENTITY4, 16); // lightVP (identity when not receiving — result is gated off by sun.w)
590
+ u.set(mats[0] ?? IDENTITY4, 16); // legacy cascade-0 slot, kept so the offsets above never move
572
591
  u.set([sunDir[0], sunDir[1], sunDir[2], receive ? 1 : 0], 32); // sun.w = shadow-receive enable
573
592
  u.set([sunCol[0], sunCol[1], sunCol[2], 0], 36);
574
593
  u.set([amb[0], amb[1], amb[2], 0], 40);
@@ -582,6 +601,11 @@ export class GpuPropsRenderer {
582
601
  u.set([w.windDir[0], w.windDir[1], w.windAmp, this.phase], 56);
583
602
  u.set([w.grainScale, w.grainDepth, w.roughness, w.emissive], 60);
584
603
  u.set([w.hueShift, w.saturation, w.valueLift, 0], 64);
604
+ // csm.x = how many cascades are live; the matrices follow. Zero when not receiving, so the
605
+ // selection loop exits at once and returns fully lit — the old no-shadow path exactly.
606
+ u[68] = receive ? Math.min(MAX_CASCADES, mats.length) : 0;
607
+ for (let i = 0; i < Math.min(MAX_CASCADES, mats.length); i++)
608
+ u.set(mats[i], 72 + i * 16);
585
609
  this.device.queue.writeBuffer(this.uBuf, 0, u);
586
610
  // group 1: the shadow map + comparison sampler (dummy when not receiving). Rebuild only when the view changes.
587
611
  const sv = shadowView ?? this.dummyShadowView, ss = shadowSamp ?? this.dummyShadowSamp;
@@ -8,6 +8,7 @@ export interface SkinCreature {
8
8
  palette: Float32Array;
9
9
  model: Float32Array;
10
10
  }
11
+ export declare const MAX_CASCADES = 4;
11
12
  export declare class GpuSkinRenderer {
12
13
  private device;
13
14
  private skinPipe;
@@ -22,5 +23,5 @@ export declare class GpuSkinRenderer {
22
23
  setCreatures(list: SkinCreature[]): void;
23
24
  /** Deform + draw every creature with the shared scene lighting. load=true composites over the world;
24
25
  * otherwise clears to `clear`. sun/sunCol/amb/cam/fog/fogDensity match the terrain & prop renderers. */
25
- frame(enc: GPUCommandEncoder, colorView: GPUTextureView, depthView: GPUTextureView, camVP: Float32Array, sunDir: [number, number, number], sunCol: [number, number, number], amb: [number, number, number], camPos: [number, number, number], fog: [number, number, number], fogDensity: number, clear: [number, number, number], load?: boolean, lightVP?: Float32Array, shadowView?: GPUTextureView, shadowSamp?: GPUSampler): void;
26
+ frame(enc: GPUCommandEncoder, colorView: GPUTextureView, depthView: GPUTextureView, camVP: Float32Array, sunDir: [number, number, number], sunCol: [number, number, number], amb: [number, number, number], camPos: [number, number, number], fog: [number, number, number], fogDensity: number, clear: [number, number, number], load?: boolean, lightVP?: Float32Array | Float32Array[], shadowView?: GPUTextureView, shadowSamp?: GPUSampler): void;
26
27
  }
@@ -4,6 +4,7 @@
4
4
  // lighting model as the terrain/prop renderers — sun lambert on smooth per-vertex normals + ambient +
5
5
  // distance fog — so creatures sit in the scene consistently instead of looking flat/mismatched.
6
6
  // ─────────────────────────────────────────────────────────────────────────────
7
+ export const MAX_CASCADES = 4; // must match gpuShadow's
7
8
  const SKIN = /* wgsl */ `
8
9
  @group(0) @binding(0) var<storage,read> rest: array<vec4f>;
9
10
  @group(0) @binding(1) var<storage,read> joints: array<vec4u>;
@@ -21,30 +22,46 @@ fn rot(m: mat4x4f, v: vec3f) -> vec3f { return mat3x3f(m[0].xyz, m[1].xyz, m[2].
21
22
  deformed[i]=vec4f(a.xyz,1.0); defN[i]=vec4f(normalize(b),0.0);
22
23
  }`;
23
24
  const DRAW = /* wgsl */ `
24
- struct U { mvp: mat4x4<f32>, lightVP: mat4x4<f32>, sun: vec4<f32>, sunCol: vec4<f32>, amb: vec4<f32>, cam: vec4<f32>, fog: vec4<f32>, model: mat4x4<f32> };
25
+ // csm + cascades are APPENDED so every field above keeps its byte offset — a caller that knows
26
+ // nothing about cascades writes exactly the bytes it always did. lightVP stays as the legacy slot.
27
+ struct U { mvp: mat4x4<f32>, lightVP: mat4x4<f32>, sun: vec4<f32>, sunCol: vec4<f32>, amb: vec4<f32>, cam: vec4<f32>, fog: vec4<f32>, model: mat4x4<f32>, csm: vec4<f32>, cascades: array<mat4x4<f32>, ${MAX_CASCADES}> };
25
28
  @group(0) @binding(0) var<uniform> u: U;
26
- @group(1) @binding(0) var shadowMap: texture_depth_2d; // the SAME sun shadow map the terrain cubes sample
29
+ @group(1) @binding(0) var shadowMap: texture_depth_2d_array; // the SAME cascaded sun shadow map the terrain cubes sample
27
30
  @group(1) @binding(1) var shadowSamp: sampler_comparison;
28
31
  struct VOut { @builtin(position) pos: vec4<f32>, @location(0) world: vec3<f32>, @location(1) col: vec3<f32>, @location(2) n: vec3<f32> };
29
32
  // o.world must be the WORLD position (model·p), not the local deformed p — else the fog distance is computed
30
33
  // against the world-space camera and blows up on a planet surface (huge coords), washing creatures into the fog.
31
34
  @vertex fn vs(@location(0) p: vec3<f32>, @location(1) c: vec3<f32>, @location(2) nrm: vec3<f32>) -> VOut { var o: VOut; o.pos=u.mvp*vec4(p,1.0); o.world=(u.model*vec4(p,1.0)).xyz; o.col=c; o.n=nrm; return o; }
32
35
  // PCF 3×3 sun shadow — mirrors gpuShadow.shadowFactor so creatures sit in the SAME shadow as the terrain. 1 = lit, 0 = shadowed.
33
- fn shadowFactor(world: vec3<f32>, ndl: f32) -> f32 {
34
- let lp = u.lightVP * vec4(world, 1.0);
36
+ fn pcfLayer(world: vec3<f32>, ndl: f32, layer: i32, inside: ptr<function, bool>) -> f32 {
37
+ let lp = u.cascades[layer] * vec4(world, 1.0);
35
38
  let proj = lp.xyz / lp.w;
36
39
  let uv = proj.xy * vec2(0.5, -0.5) + vec2(0.5, 0.5);
37
- if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 || proj.z > 1.0 || proj.z < 0.0) { return 1.0; }
38
- let bias = max(0.0006 * (1.0 - ndl), 0.0004);
40
+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 || proj.z > 1.0 || proj.z < 0.0) {
41
+ *inside = false; return 1.0;
42
+ }
43
+ *inside = true;
44
+ let bias = max(0.0006 * (1.0 - ndl), 0.0004) * (1.0 + f32(layer) * 1.5);
39
45
  let texel = 1.0 / 2048.0;
40
46
  var s = 0.0;
41
47
  for (var dy = -1; dy <= 1; dy = dy + 1) {
42
48
  for (var dx = -1; dx <= 1; dx = dx + 1) {
43
- s = s + textureSampleCompareLevel(shadowMap, shadowSamp, uv + vec2(f32(dx), f32(dy)) * texel, proj.z - bias);
49
+ s = s + textureSampleCompareLevel(shadowMap, shadowSamp, uv + vec2(f32(dx), f32(dy)) * texel, layer, proj.z - bias);
44
50
  }
45
51
  }
46
52
  return s / 9.0;
47
53
  }
54
+ // Tightest cascade CONTAINING the point — the same rule gpuShadow and gpuProps use, so a creature
55
+ // and the ground it stands on can never disagree about being in shadow.
56
+ fn shadowFactor(world: vec3<f32>, ndl: f32) -> f32 {
57
+ let n = i32(u.csm.x);
58
+ var inside = false;
59
+ for (var c = 0; c < n; c = c + 1) {
60
+ let f = pcfLayer(world, ndl, c, &inside);
61
+ if (inside) { return f; }
62
+ }
63
+ return 1.0;
64
+ }
48
65
  @fragment fn fs(i: VOut) -> @location(0) vec4<f32> {
49
66
  let d = clamp(dot(normalize(i.n), -normalize(u.sun.xyz)), 0.0, 1.0);
50
67
  let sh = mix(1.0, shadowFactor(i.world, d), u.sun.w); // u.sun.w = shadow-receive enable (0 ⇒ off, byte-identical for demo)
@@ -106,7 +123,7 @@ export class GpuSkinRenderer {
106
123
  format: 'depth32float',
107
124
  usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT,
108
125
  });
109
- this.dummyShadowView = dummy.createView();
126
+ this.dummyShadowView = dummy.createView({ dimension: '2d-array' }); // the binding is an array now
110
127
  this.dummyShadowSamp = device.createSampler({ compare: 'less' });
111
128
  }
112
129
  setCreatures(list) {
@@ -167,7 +184,7 @@ export class GpuSkinRenderer {
167
184
  ],
168
185
  });
169
186
  const uBuf = dev.createBuffer({
170
- size: 96 + 16 * 7 + 64, // + lightVP mat4 for shadow-receive
187
+ size: 96 + 16 * 7 + 64 + 16 + 64 * MAX_CASCADES, // + csm vec4 + the cascade matrices
171
188
  usage: U.UNIFORM | U.COPY_DST,
172
189
  });
173
190
  const uBG = dev.createBindGroup({
@@ -196,6 +213,7 @@ export class GpuSkinRenderer {
196
213
  // sit in the same shadow. Omit all three (the demo path) → no shadowing, byte-identical to before.
197
214
  lightVP, shadowView, shadowSamp) {
198
215
  const receive = !!(lightVP && shadowView && shadowSamp);
216
+ const mats = lightVP ? (Array.isArray(lightVP) ? lightVP : [lightVP]) : [];
199
217
  const cp = enc.beginComputePass();
200
218
  cp.setPipeline(this.skinPipe);
201
219
  for (const p of this.packed) {
@@ -204,15 +222,20 @@ export class GpuSkinRenderer {
204
222
  }
205
223
  cp.end();
206
224
  for (const p of this.packed) {
207
- const u = new Float32Array(68);
225
+ const u = new Float32Array(68 + 4 + 16 * MAX_CASCADES);
208
226
  u.set(mul16(camVP, p.model), 0);
209
- u.set(lightVP ?? IDENTITY4, 16); // lightVP (identity when not receiving — result is gated off by sun.w)
227
+ u.set(mats[0] ?? IDENTITY4, 16); // legacy cascade-0 slot, kept so the offsets above never move
210
228
  u.set([sunDir[0], sunDir[1], sunDir[2], receive ? 1 : 0], 32); // sun.w = shadow-receive enable
211
229
  u.set([sunCol[0], sunCol[1], sunCol[2], 0], 36);
212
230
  u.set([amb[0], amb[1], amb[2], 0], 40);
213
231
  u.set([camPos[0], camPos[1], camPos[2], 0], 44);
214
232
  u.set([fog[0], fog[1], fog[2], fogDensity], 48);
215
233
  u.set(p.model, 52); // world model matrix (for correct fog distance in the vs)
234
+ // csm.x = 0 when not receiving → the loop exits at once and returns fully lit, which is
235
+ // exactly the old no-shadow path.
236
+ u[68] = receive ? Math.min(MAX_CASCADES, mats.length) : 0;
237
+ for (let i = 0; i < Math.min(MAX_CASCADES, mats.length); i++)
238
+ u.set(mats[i], 72 + i * 16);
216
239
  this.device.queue.writeBuffer(p.uBuf, 0, u);
217
240
  }
218
241
  // group 1: the shadow map + comparison sampler (dummy when not receiving). Rebuild only when the view changes.
@@ -130,17 +130,16 @@ export declare class GpuShadowRenderer {
130
130
  /** The sun shadow-map depth view + its comparison sampler + texel size. Feed these into GpuPropsRenderer/
131
131
  * GpuSkinRenderer.frame(lightVP, …) so mesh props & creatures RECEIVE the same sun shadow the cubes sample.
132
132
  *
133
- * CASCADES: this is a plain 2d view of layer 0 — the TIGHTEST cascade. Props and skinned meshes
134
- * sample a `texture_depth_2d`, so handing them the array would be a breaking change to two more
135
- * shaders; layer 0 is what they already effectively received when there was one map, so they are
136
- * unaffected. The consequence is that a distant prop receives no shadow even when the terrain
137
- * around it does. Making those two cascade-aware is the follow-up.
133
+ * CASCADES: this is the 2d-ARRAY view of every cascade layer. GpuPropsRenderer and
134
+ * GpuSkinRenderer sample `texture_depth_2d_array` and run the same tightest-box-containing
135
+ * selection, so a prop or creature resolves against exactly the cascade the terrain beneath it
136
+ * does — pass them the same matrix ARRAY given to `frame`.
138
137
  *
139
138
  * NOTE: recreated when the cascade COUNT changes, so re-read it after a frame that changes it
140
139
  * rather than caching the view across such a change. */
141
140
  get shadowMapView(): GPUTextureView;
142
- /** The full cascade array view, for a consumer that samples `texture_depth_2d_array`. */
143
- get shadowMapArrayView(): GPUTextureView;
141
+ /** A plain 2d view of layer 0 — the tightest cascade — for a consumer that still wants one map. */
142
+ get shadowMapLayer0View(): GPUTextureView;
144
143
  /** How many cascade layers are currently allocated. */
145
144
  get cascadeCount(): number;
146
145
  get shadowMapSampler(): GPUSampler;
package/dist/gpuShadow.js CHANGED
@@ -989,21 +989,20 @@ export class GpuShadowRenderer {
989
989
  /** The sun shadow-map depth view + its comparison sampler + texel size. Feed these into GpuPropsRenderer/
990
990
  * GpuSkinRenderer.frame(lightVP, …) so mesh props & creatures RECEIVE the same sun shadow the cubes sample.
991
991
  *
992
- * CASCADES: this is a plain 2d view of layer 0 — the TIGHTEST cascade. Props and skinned meshes
993
- * sample a `texture_depth_2d`, so handing them the array would be a breaking change to two more
994
- * shaders; layer 0 is what they already effectively received when there was one map, so they are
995
- * unaffected. The consequence is that a distant prop receives no shadow even when the terrain
996
- * around it does. Making those two cascade-aware is the follow-up.
992
+ * CASCADES: this is the 2d-ARRAY view of every cascade layer. GpuPropsRenderer and
993
+ * GpuSkinRenderer sample `texture_depth_2d_array` and run the same tightest-box-containing
994
+ * selection, so a prop or creature resolves against exactly the cascade the terrain beneath it
995
+ * does — pass them the same matrix ARRAY given to `frame`.
997
996
  *
998
997
  * NOTE: recreated when the cascade COUNT changes, so re-read it after a frame that changes it
999
998
  * rather than caching the view across such a change. */
1000
999
  get shadowMapView() {
1001
- return this.shadowView;
1002
- }
1003
- /** The full cascade array view, for a consumer that samples `texture_depth_2d_array`. */
1004
- get shadowMapArrayView() {
1005
1000
  return this.shadowArrayView;
1006
1001
  }
1002
+ /** A plain 2d view of layer 0 — the tightest cascade — for a consumer that still wants one map. */
1003
+ get shadowMapLayer0View() {
1004
+ return this.shadowView;
1005
+ }
1007
1006
  /** How many cascade layers are currently allocated. */
1008
1007
  get cascadeCount() {
1009
1008
  return this.cascades;
@@ -8,6 +8,12 @@
8
8
  export const SHADOW_SIZE = 2048;
9
9
  // Drop-in WGSL: paste into a receiver fragment shader. Expects `shadowMap` (binding 2) + `shadowSamp`
10
10
  // (binding 3) + a `lightVP` mat4 and texel size in scope. Returns 1 = lit, 0 = fully shadowed (PCF 3×3).
11
+ //
12
+ // SINGLE-MAP ONLY. `GpuShadowRenderer` now renders CASCADES into a depth-2d-array and selects the
13
+ // tightest box containing the point (see gpuShadow.ts, and the mirrors in assets/gpuProps.ts and
14
+ // assets/gpuSkin.ts). This helper still takes one `texture_depth_2d`, which is correct for its own
15
+ // consumer — `GpuShadowMap` below is a single 2048² map — but a receiver that wants cascade reach
16
+ // should copy the selection loop from one of those three rather than paste this.
11
17
  export const SHADOW_WGSL = /* wgsl */ `
12
18
  fn shadowFactor(lightVP: mat4x4<f32>, world: vec3<f32>, ndl: f32, texel: f32,
13
19
  shadowMap: texture_depth_2d, shadowSamp: sampler_comparison) -> f32 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {