ugly-game 0.15.23 → 0.15.24
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.
- package/dist/gpuShadow.d.ts +16 -0
- package/dist/gpuShadow.js +36 -3
- package/package.json +1 -1
package/dist/gpuShadow.d.ts
CHANGED
|
@@ -571,6 +571,8 @@ export declare class GpuShadowRenderer {
|
|
|
571
571
|
private lightCull;
|
|
572
572
|
private lightCullBG;
|
|
573
573
|
private statsBuf;
|
|
574
|
+
/** Current shadow-map edge length; see setShadowMapSize. */
|
|
575
|
+
private shadowSize;
|
|
574
576
|
/** Last frame's visible counts (main-pass camera cull, shadow-pass light cull) + total — for IR/telemetry. */
|
|
575
577
|
lastCull: {
|
|
576
578
|
total: number;
|
|
@@ -786,6 +788,20 @@ export declare class GpuShadowRenderer {
|
|
|
786
788
|
get cascadeCount(): number;
|
|
787
789
|
get shadowMapSampler(): GPUSampler;
|
|
788
790
|
get shadowMapSize(): number;
|
|
791
|
+
/**
|
|
792
|
+
* Resize the cascaded shadow map. Powers of two 512..4096; anything else is clamped to the nearest.
|
|
793
|
+
*
|
|
794
|
+
* ⚠️ THE FILL, NOT THE INSTANCES, IS WHAT THIS BUYS. Measured in all-mine-sky at N=256: dropping
|
|
795
|
+
* from three cascades to one made the light see 2.9x MORE instances and ran 14.2 ms FASTER, while
|
|
796
|
+
* cutting light-visible instances 56x at three cascades bought only 11.4 ms. The pass is dominated
|
|
797
|
+
* by clearing, rasterizing and storing its depth targets, so edge length is the lever with the
|
|
798
|
+
* squared term in it — and unlike dropping cascades it keeps the cascade STRUCTURE, which is what
|
|
799
|
+
* carries near-field shadow quality.
|
|
800
|
+
*
|
|
801
|
+
* ⚠️ REALLOCATES THE TEXTURE AND EVERY BIND GROUP THAT SAMPLES IT. Cheap once, ruinous per frame —
|
|
802
|
+
* this is a settings-change call, not something to drive from a slider's every tick.
|
|
803
|
+
*/
|
|
804
|
+
setShadowMapSize(px: number): void;
|
|
789
805
|
/** camVP/lightVP: column-major Float32Array(16). sunDir: travel direction. Pass `occlusion` (the depth target +
|
|
790
806
|
* its size) to enable Hi-Z occlusion culling on the camera pass — the renderer rebuilds a coarse Hi-Z from that
|
|
791
807
|
* depth each frame and the NEXT frame's cull uses it (hole-free: the first frame + any resize skip occlusion). */
|
package/dist/gpuShadow.js
CHANGED
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
import { frustumPlanes } from './mat4';
|
|
15
15
|
import { GI_WGSL, PROBE_STRIDE } from './giProbes';
|
|
16
16
|
const SHADOW_SIZE = 2048;
|
|
17
|
+
/**
|
|
18
|
+
* Shadow-map edge lengths a caller may ask for. Powers of two only, and bounded at both ends: below
|
|
19
|
+
* 512 a cascade cannot resolve a block at any useful range, and above 4096 the allocation is larger
|
|
20
|
+
* than most of the frame's other targets combined.
|
|
21
|
+
*/
|
|
22
|
+
const SHADOW_SIZES = [512, 1024, 1536, 2048, 3072, 4096];
|
|
17
23
|
// CASCADED SHADOW MAPS. One ortho map has to choose between resolution and reach: AMS ran a single
|
|
18
24
|
// 90-block box against a 280-block draw distance, so everything past it was simply unshadowed and
|
|
19
25
|
// the far terrain read flat. Cascades split the range into nested boxes — tight and crisp near the
|
|
@@ -2781,6 +2787,8 @@ export class GpuShadowRenderer {
|
|
|
2781
2787
|
lightCull = [];
|
|
2782
2788
|
lightCullBG = [];
|
|
2783
2789
|
statsBuf; // readback: [camVisible, lightVisible] for the IR/tests
|
|
2790
|
+
/** Current shadow-map edge length; see setShadowMapSize. */
|
|
2791
|
+
shadowSize = SHADOW_SIZE;
|
|
2784
2792
|
/** Last frame's visible counts (main-pass camera cull, shadow-pass light cull) + total — for IR/telemetry. */
|
|
2785
2793
|
lastCull = { total: 0, camVisible: 0, lightVisible: 0 };
|
|
2786
2794
|
// Hi-Z OCCLUSION: a coarse max-depth buffer rebuilt from each frame's depth, sampled by next frame's camera cull.
|
|
@@ -3223,7 +3231,7 @@ export class GpuShadowRenderer {
|
|
|
3223
3231
|
b.destroy();
|
|
3224
3232
|
this.cascades = n;
|
|
3225
3233
|
this.shadowTex = this.device.createTexture({
|
|
3226
|
-
size: [
|
|
3234
|
+
size: [this.shadowSize, this.shadowSize, n],
|
|
3227
3235
|
format: 'depth32float',
|
|
3228
3236
|
dimension: '2d',
|
|
3229
3237
|
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
|
|
@@ -3684,7 +3692,32 @@ export class GpuShadowRenderer {
|
|
|
3684
3692
|
return this.shadowSampler;
|
|
3685
3693
|
}
|
|
3686
3694
|
get shadowMapSize() {
|
|
3687
|
-
return
|
|
3695
|
+
return this.shadowSize;
|
|
3696
|
+
}
|
|
3697
|
+
/**
|
|
3698
|
+
* Resize the cascaded shadow map. Powers of two 512..4096; anything else is clamped to the nearest.
|
|
3699
|
+
*
|
|
3700
|
+
* ⚠️ THE FILL, NOT THE INSTANCES, IS WHAT THIS BUYS. Measured in all-mine-sky at N=256: dropping
|
|
3701
|
+
* from three cascades to one made the light see 2.9x MORE instances and ran 14.2 ms FASTER, while
|
|
3702
|
+
* cutting light-visible instances 56x at three cascades bought only 11.4 ms. The pass is dominated
|
|
3703
|
+
* by clearing, rasterizing and storing its depth targets, so edge length is the lever with the
|
|
3704
|
+
* squared term in it — and unlike dropping cascades it keeps the cascade STRUCTURE, which is what
|
|
3705
|
+
* carries near-field shadow quality.
|
|
3706
|
+
*
|
|
3707
|
+
* ⚠️ REALLOCATES THE TEXTURE AND EVERY BIND GROUP THAT SAMPLES IT. Cheap once, ruinous per frame —
|
|
3708
|
+
* this is a settings-change call, not something to drive from a slider's every tick.
|
|
3709
|
+
*/
|
|
3710
|
+
setShadowMapSize(px) {
|
|
3711
|
+
const want = SHADOW_SIZES.reduce((best, s) => Math.abs(s - px) < Math.abs(best - px) ? s : best);
|
|
3712
|
+
if (want === this.shadowSize)
|
|
3713
|
+
return;
|
|
3714
|
+
this.shadowSize = want;
|
|
3715
|
+
// Force the reallocation: allocCascades is the only thing that sizes the texture, and
|
|
3716
|
+
// ensureCascades short-circuits when the COUNT is unchanged, which it is here.
|
|
3717
|
+
const n = Math.max(1, this.cascades);
|
|
3718
|
+
this.allocCascades(n);
|
|
3719
|
+
if (this.sceneReady)
|
|
3720
|
+
this.makeBindGroups();
|
|
3688
3721
|
}
|
|
3689
3722
|
/** camVP/lightVP: column-major Float32Array(16). sunDir: travel direction. Pass `occlusion` (the depth target +
|
|
3690
3723
|
* its size) to enable Hi-Z occlusion culling on the camera pass — the renderer rebuilds a coarse Hi-Z from that
|
|
@@ -3715,7 +3748,7 @@ export class GpuShadowRenderer {
|
|
|
3715
3748
|
this.cam[S + 4] = sunCol[0];
|
|
3716
3749
|
this.cam[S + 5] = sunCol[1];
|
|
3717
3750
|
this.cam[S + 6] = sunCol[2];
|
|
3718
|
-
this.cam[S + 7] =
|
|
3751
|
+
this.cam[S + 7] = this.shadowSize; // sunCol.w — the PCF texel step reads this, so it MUST follow a resize
|
|
3719
3752
|
this.cam[S + 8] = tint[0];
|
|
3720
3753
|
this.cam[S + 9] = tint[1];
|
|
3721
3754
|
this.cam[S + 10] = tint[2];
|