Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Keep the single sun shadow map at one texel under cascades and size it to the casters (part of #287)

Nguyen Xuan An2ed5d564a86e
diff --git a/bench/runtime/README.md b/bench/runtime/README.md
index 634dd845..dfd4cdfb 100644
--- a/bench/runtime/README.md
+++ b/bench/runtime/README.md
@@ -23,48 +23,50 @@ CI does not run this suite. It needs Chrome and a GPU, and `tests/runtime-report
## Result
-Measured on 2026-11-04 at 960 by 540 with 4 MSAA samples, against three.js 0.187.0, after the issue 74 and issue 287 changes. The GPU was shared with other jobs during this run (`gpuBusyBefore` in `report.json`: 8 to 26 percent before each scene, 95 percent before `many-materials`), so treat the RTX 3060 rows as noisy and compare the SwiftShader table. A ratio above 1 means that 67js costs more.
+Measured twice on 2026-11-04 at 960 by 540 with 4 MSAA samples, against three.js 0.187.0, after the issue 74 and issue 287 changes. Each cell is the lowest to the highest of the two full runs, because the machine is shared. The RTX 3060 was busy with other jobs before every scene (`gpuBusyBefore` in `report.json`: 4 to 86 percent in the first run, 17 to 95 percent in the second), so treat the RTX 3060 rows as noisy and compare the SwiftShader table first. A ratio above 1 means that 67js costs more; it divides the middle of the 67js range by the middle of the three.js range.
**Full frame on SwiftShader, in milliseconds.** This is the path that a headless agent uses.
-| Scene | 67js | three.js | Ratio |
+| Scene | 67js | three.js | Ratio of middles |
| --- | --- | --- | --- |
-| `instanced-objects` | 107 | 33 (instanced 33) | 3.2 |
-| `many-materials` | 344 | 152 | 2.3 |
-| `many-lights` | 278 | 111 | 2.5 |
-| `transparency` | 238 | 52 | 4.6 |
-| `moving-shadows` | 66 | 19 | 3.4 |
-| `large-mesh` | 362 | 159 | 2.3 |
-| `skinned-characters` | 101 | 25 | 4.0 |
+| `instanced-objects` | 104 to 119 | 34 to 35 (instanced 34) | 3.2 |
+| `many-materials` | 369 to 393 | 153 to 156 | 2.5 |
+| `many-lights` | 308 to 318 | 113 to 115 | 2.7 |
+| `transparency` | 264 to 322 | 56 to 59 | 5.1 |
+| `moving-shadows` | 69 to 72 | 20 to 21 | 3.4 |
+| `large-mesh` | 364 to 386 | 160 to 174 | 2.2 |
+| `skinned-characters` | 106 to 109 | 25 to 28 | 4.0 |
**Full frame on an RTX 3060, in milliseconds.** Other jobs shared the GPU during parts of this run, so these numbers are noisy.
-| Scene | 67js | three.js | Ratio |
+| Scene | 67js | three.js | Ratio of middles |
| --- | --- | --- | --- |
-| `instanced-objects` | 0.80 | 2.17 (instanced 0.24) | 0.4 |
-| `many-materials` | 2.31 | 1.35 | 1.7 |
-| `many-lights` | 1.52 | 0.78 | 1.9 |
-| `transparency` | 1.03 | 0.70 | 1.5 |
-| `moving-shadows` | 0.79 | 1.12 | 0.7 |
-| `large-mesh` | 1.86 | 0.34 | 5.5 |
-| `skinned-characters` | 3.44 | 1.55 | 2.2 |
+| `instanced-objects` | 0.83 to 1.04 | 2.44 to 2.61 (instanced 0.25) | 0.4 |
+| `many-materials` | 2.02 to 2.15 | 1.68 to 1.77 | 1.2 |
+| `many-lights` | 1.56 to 1.75 | 0.79 to 0.92 | 1.9 |
+| `transparency` | 1.09 to 1.18 | 0.72 to 0.80 | 1.5 |
+| `moving-shadows` | 0.79 to 0.82 | 1.15 to 1.25 | 0.7 |
+| `large-mesh` | 2.42 to 2.77 | 0.35 to 0.37 | 7.2 |
+| `skinned-characters` | 3.88 to 3.94 | 1.67 to 1.73 | 2.3 |
**First frame on an RTX 3060, in milliseconds.** Each run has an empty browser profile, so no shader cache helps either engine.
-| Scene | 67js | three.js | Ratio |
+| Scene | 67js | three.js | Ratio of middles |
| --- | --- | --- | --- |
-| `instanced-objects` | 235 | 97 (instanced 87) | 2.4 |
-| `many-materials` | 214 | 98 | 2.2 |
-| `many-lights` | 240 | 128 | 1.9 |
-| `transparency` | 201 | 111 | 1.8 |
-| `moving-shadows` | 215 | 91 | 2.4 |
-| `large-mesh` | 371 | 233 | 1.6 |
-| `skinned-characters` | 276 | 219 | 1.3 |
+| `instanced-objects` | 226 to 278 | 91 to 111 (instanced 92 to 93) | 2.5 |
+| `many-materials` | 228 to 248 | 77 to 162 | 2.0 |
+| `many-lights` | 184 to 199 | 102 to 140 | 1.6 |
+| `transparency` | 213 to 220 | 111 to 128 | 1.8 |
+| `moving-shadows` | 221 to 230 | 106 to 111 | 2.1 |
+| `large-mesh` | 376 to 446 | 242 to 255 | 1.7 |
+| `skinned-characters` | 381 to 386 | 267 to 284 | 1.4 |
## GPU memory per render target
Each 67js result in `report.json` lists its render targets (`renderTargets`: name, size, format, samples, bytes). The same list comes from `renderer.memoryReport()`. At 960 by 540 with 4 samples, for `instanced-objects` and `large-outdoor` alike: `shadowMap` 16 MB (2048 by 2048 depth), `multisampleColor` 15.82 MB (RGBA16F), `multisampleDepth` 3.96 MB (16 bits, it was 7.91 MB with 24 bits) and `frameColor` 3.96 MB. The counter totals 41.36 MB and 43.58 MB, so 1.4 to 3.6 MB is geometry and textures.
+**At 1920 by 1080** (4 samples, no depth texture; measured with `renderer.memoryReport()`, the same for all seven scenes) a plain lit scene holds 110.92 MB of render targets: `multisampleColor` 63.28 MB (RGBA16F, 4 samples), `shadowMap` 16 MB, `multisampleDepth` 15.82 MB and `frameColor` 15.82 MB. The multisampled colour is 57 percent of it, so only a smaller colour format or fewer samples can halve the total, and both change pixels. With `shadowCascades` on, a scene also holds the cascade array (48 MB for three 2048 slices); the single map used to stay beside it, and now it is one texel unless volume fog or a `subsurface` material reads it. At 960 by 540 that takes 20 of the 26 reference scenes 16 MB lower (a plain scene from 93.66 MB to 77.66 MB; the 6 scenes with volume fog or subsurface keep the map), with byte-identical pictures.
+
Issue 287 asked for at most 23.25 MB, half of the 46.5 MB the first run showed. It is not met: 41.36 MB is the most the pictures allow today. Each step was scored by FLIP of the new 67js picture against the old one, over the 25 reference scenes, and the limit was 0.002. The 16-bit multisampled depth scored 0.0000 everywhere and is in. Left out: an R11G11B10F colour target (saves 9.9 MB; 0.002 to 0.034, about 0.02 on most scenes, because the packed format truncates), a 1024 shadow map for small views (saves 12 MB; `subsurface` 0.006) and a 16-bit sun shadow map (saves 8 MB; `brick-flat` 0.0023 and `brick-graph` 0.0031). A renderer that needs the alpha of the colour target would also have to keep RGBA16F, so the packed format would need a flag for such an addon.
## Where each engine wins
diff --git a/bench/runtime/report.json b/bench/runtime/report.json
index ad637091..b13f78d7 100644
--- a/bench/runtime/report.json
+++ b/bench/runtime/report.json
@@ -12,11 +12,11 @@
"gpu": {
"instanced-objects": {
"67js": {
- "firstFrameMilliseconds": 235,
+ "firstFrameMilliseconds": 226,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.27,
- "gpuMilliseconds": 0.25,
- "fullFrameMilliseconds": 0.8,
+ "renderCpuMilliseconds": 0.31,
+ "gpuMilliseconds": 0.26,
+ "fullFrameMilliseconds": 1.04,
"drawCalls": 3,
"triangles": 49850,
"gpuMegabytes": 41.36,
@@ -63,42 +63,42 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 11
+ "gpuBusyBefore": 31
},
"three": {
- "firstFrameMilliseconds": 97,
+ "firstFrameMilliseconds": 111,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 1.88,
- "gpuMilliseconds": 0.1,
- "fullFrameMilliseconds": 2.17,
+ "renderCpuMilliseconds": 2.1,
+ "gpuMilliseconds": 0.09,
+ "fullFrameMilliseconds": 2.61,
"drawCalls": 4154,
"triangles": 49848,
"gpuMegabytes": 0,
"heapMegabytes": 8.5,
"renderTargets": null,
- "gpuBusyBefore": 20
+ "gpuBusyBefore": 61
},
"three-instanced": {
- "firstFrameMilliseconds": 87,
+ "firstFrameMilliseconds": 92,
"updateMilliseconds": 0,
"renderCpuMilliseconds": 0.04,
"gpuMilliseconds": 0.05,
- "fullFrameMilliseconds": 0.24,
+ "fullFrameMilliseconds": 0.25,
"drawCalls": 1,
"triangles": 60000,
"gpuMegabytes": 0.31,
"heapMegabytes": 2.4,
"renderTargets": null,
- "gpuBusyBefore": 9
+ "gpuBusyBefore": 37
}
},
"large-outdoor": {
"67js": {
- "firstFrameMilliseconds": 227,
+ "firstFrameMilliseconds": 229,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.4,
- "gpuMilliseconds": 0.76,
- "fullFrameMilliseconds": 1.55,
+ "renderCpuMilliseconds": 0.38,
+ "gpuMilliseconds": 0.72,
+ "fullFrameMilliseconds": 1.64,
"drawCalls": 6,
"triangles": 270474,
"gpuMegabytes": 43.58,
@@ -145,27 +145,27 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 9
+ "gpuBusyBefore": 32
},
"three": {
- "firstFrameMilliseconds": 94,
+ "firstFrameMilliseconds": 105,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 3.58,
- "gpuMilliseconds": 0.73,
- "fullFrameMilliseconds": 4.33,
+ "renderCpuMilliseconds": 4.02,
+ "gpuMilliseconds": 0.95,
+ "fullFrameMilliseconds": 5.03,
"drawCalls": 4542,
"triangles": 4359372,
"gpuMegabytes": 0.03,
"heapMegabytes": 9.9,
"renderTargets": null,
- "gpuBusyBefore": 59
+ "gpuBusyBefore": 40
},
"67js-no-lod": {
- "firstFrameMilliseconds": 537,
+ "firstFrameMilliseconds": 327,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.41,
- "gpuMilliseconds": 6.54,
- "fullFrameMilliseconds": 7.39,
+ "renderCpuMilliseconds": 0.49,
+ "gpuMilliseconds": 6.88,
+ "fullFrameMilliseconds": 8.38,
"drawCalls": 4,
"triangles": 4359374,
"gpuMegabytes": 41.7,
@@ -212,14 +212,14 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 26
+ "gpuBusyBefore": 56
},
"67js-no-culling": {
- "firstFrameMilliseconds": 234,
+ "firstFrameMilliseconds": 223,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.11,
- "gpuMilliseconds": 8.08,
- "fullFrameMilliseconds": 8.56,
+ "renderCpuMilliseconds": 0.12,
+ "gpuMilliseconds": 10.46,
+ "fullFrameMilliseconds": 11.22,
"drawCalls": 4,
"triangles": 5760014,
"gpuMegabytes": 40.76,
@@ -266,16 +266,16 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 88
+ "gpuBusyBefore": 95
}
},
"many-materials": {
"67js": {
- "firstFrameMilliseconds": 214,
+ "firstFrameMilliseconds": 228,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.12,
- "gpuMilliseconds": 1.86,
- "fullFrameMilliseconds": 2.31,
+ "renderCpuMilliseconds": 0.13,
+ "gpuMilliseconds": 1.56,
+ "fullFrameMilliseconds": 2.15,
"drawCalls": 4,
"triangles": 925454,
"gpuMegabytes": 40.14,
@@ -322,29 +322,29 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 95
+ "gpuBusyBefore": 68
},
"three": {
- "firstFrameMilliseconds": 98,
+ "firstFrameMilliseconds": 77,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.92,
- "gpuMilliseconds": 0.19,
- "fullFrameMilliseconds": 1.35,
+ "renderCpuMilliseconds": 1.23,
+ "gpuMilliseconds": 0.2,
+ "fullFrameMilliseconds": 1.77,
"drawCalls": 965,
"triangles": 925452,
"gpuMegabytes": 0.03,
"heapMegabytes": 13,
"renderTargets": null,
- "gpuBusyBefore": 86
+ "gpuBusyBefore": 18
}
},
"many-lights": {
"67js": {
- "firstFrameMilliseconds": 240,
+ "firstFrameMilliseconds": 199,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.12,
- "gpuMilliseconds": 1.05,
- "fullFrameMilliseconds": 1.52,
+ "renderCpuMilliseconds": 0.14,
+ "gpuMilliseconds": 1.15,
+ "fullFrameMilliseconds": 1.75,
"drawCalls": 4,
"triangles": 368654,
"gpuMegabytes": 39.95,
@@ -391,29 +391,29 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 25
+ "gpuBusyBefore": 36
},
"three": {
- "firstFrameMilliseconds": 128,
+ "firstFrameMilliseconds": 102,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.24,
+ "renderCpuMilliseconds": 0.27,
"gpuMilliseconds": 0.33,
- "fullFrameMilliseconds": 0.78,
+ "fullFrameMilliseconds": 0.92,
"drawCalls": 385,
"triangles": 368652,
"gpuMegabytes": 0.03,
"heapMegabytes": 2.4,
"renderTargets": null,
- "gpuBusyBefore": 76
+ "gpuBusyBefore": 17
}
},
"transparency": {
"67js": {
- "firstFrameMilliseconds": 201,
+ "firstFrameMilliseconds": 213,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.12,
- "gpuMilliseconds": 0.68,
- "fullFrameMilliseconds": 1.03,
+ "renderCpuMilliseconds": 0.13,
+ "gpuMilliseconds": 0.69,
+ "fullFrameMilliseconds": 1.09,
"drawCalls": 4,
"triangles": 288014,
"gpuMegabytes": 39.87,
@@ -460,28 +460,28 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 29
},
"three": {
"firstFrameMilliseconds": 111,
"updateMilliseconds": 0,
"renderCpuMilliseconds": 0.33,
"gpuMilliseconds": 0.17,
- "fullFrameMilliseconds": 0.7,
+ "fullFrameMilliseconds": 0.72,
"drawCalls": 301,
"triangles": 288012,
"gpuMegabytes": 0.03,
"heapMegabytes": 5.5,
"renderTargets": null,
- "gpuBusyBefore": 73
+ "gpuBusyBefore": 19
}
},
"moving-shadows": {
"67js": {
- "firstFrameMilliseconds": 215,
- "updateMilliseconds": 0.11,
+ "firstFrameMilliseconds": 221,
+ "updateMilliseconds": 0.1,
"renderCpuMilliseconds": 0.19,
- "gpuMilliseconds": 0.3,
+ "gpuMilliseconds": 0.31,
"fullFrameMilliseconds": 0.79,
"drawCalls": 4,
"triangles": 12026,
@@ -529,29 +529,29 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 22
+ "gpuBusyBefore": 33
},
"three": {
- "firstFrameMilliseconds": 91,
+ "firstFrameMilliseconds": 106,
"updateMilliseconds": 0.03,
- "renderCpuMilliseconds": 0.75,
- "gpuMilliseconds": 0.17,
- "fullFrameMilliseconds": 1.12,
+ "renderCpuMilliseconds": 0.78,
+ "gpuMilliseconds": 0.16,
+ "fullFrameMilliseconds": 1.25,
"drawCalls": 1002,
"triangles": 12024,
"gpuMegabytes": 32,
"heapMegabytes": 2.1,
"renderTargets": null,
- "gpuBusyBefore": 17
+ "gpuBusyBefore": 54
}
},
"large-mesh": {
"67js": {
- "firstFrameMilliseconds": 371,
+ "firstFrameMilliseconds": 446,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.06,
- "gpuMilliseconds": 1.55,
- "fullFrameMilliseconds": 1.86,
+ "renderCpuMilliseconds": 0.11,
+ "gpuMilliseconds": 2.28,
+ "fullFrameMilliseconds": 2.77,
"drawCalls": 3,
"triangles": 1046530,
"gpuMegabytes": 67.82,
@@ -598,29 +598,29 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 26
+ "gpuBusyBefore": 22
},
"three": {
- "firstFrameMilliseconds": 233,
+ "firstFrameMilliseconds": 255,
"updateMilliseconds": 0,
"renderCpuMilliseconds": 0.04,
"gpuMilliseconds": 0.15,
- "fullFrameMilliseconds": 0.34,
+ "fullFrameMilliseconds": 0.37,
"drawCalls": 1,
"triangles": 1046528,
"gpuMegabytes": 24.01,
"heapMegabytes": 29,
"renderTargets": null,
- "gpuBusyBefore": 68
+ "gpuBusyBefore": 90
}
},
"skinned-characters": {
"67js": {
- "firstFrameMilliseconds": 276,
- "updateMilliseconds": 4.77,
- "renderCpuMilliseconds": 0.64,
- "gpuMilliseconds": 1.75,
- "fullFrameMilliseconds": 3.44,
+ "firstFrameMilliseconds": 381,
+ "updateMilliseconds": 5.06,
+ "renderCpuMilliseconds": 0.77,
+ "gpuMilliseconds": 1.93,
+ "fullFrameMilliseconds": 3.94,
"drawCalls": 308,
"triangles": 51818,
"gpuMegabytes": 43.09,
@@ -667,31 +667,31 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 25
+ "gpuBusyBefore": 58
},
"three": {
- "firstFrameMilliseconds": 219,
- "updateMilliseconds": 0.02,
- "renderCpuMilliseconds": 0.7,
- "gpuMilliseconds": 0.39,
- "fullFrameMilliseconds": 1.55,
+ "firstFrameMilliseconds": 284,
+ "updateMilliseconds": 0.03,
+ "renderCpuMilliseconds": 0.78,
+ "gpuMilliseconds": 0.37,
+ "fullFrameMilliseconds": 1.73,
"drawCalls": 306,
"triangles": 51816,
"gpuMegabytes": 32.34,
- "heapMegabytes": 4.2,
+ "heapMegabytes": 4.1,
"renderTargets": null,
- "gpuBusyBefore": 21
+ "gpuBusyBefore": 33
}
}
},
"cpu": {
"instanced-objects": {
"67js": {
- "firstFrameMilliseconds": 434,
+ "firstFrameMilliseconds": 416,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.53,
- "gpuMilliseconds": 105.15,
- "fullFrameMilliseconds": 106.66,
+ "renderCpuMilliseconds": 0.62,
+ "gpuMilliseconds": 117.43,
+ "fullFrameMilliseconds": 119.39,
"drawCalls": 3,
"triangles": 49850,
"gpuMegabytes": 41.36,
@@ -738,42 +738,42 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 14
},
"three": {
- "firstFrameMilliseconds": 232,
+ "firstFrameMilliseconds": 237,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 2.36,
- "gpuMilliseconds": 29.16,
- "fullFrameMilliseconds": 33.22,
+ "renderCpuMilliseconds": 2.48,
+ "gpuMilliseconds": 29.6,
+ "fullFrameMilliseconds": 34.01,
"drawCalls": 4154,
"triangles": 49848,
"gpuMegabytes": 0,
"heapMegabytes": 8.5,
"renderTargets": null,
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 20
},
"three-instanced": {
- "firstFrameMilliseconds": 218,
+ "firstFrameMilliseconds": 249,
"updateMilliseconds": 0,
"renderCpuMilliseconds": 0.11,
- "gpuMilliseconds": 32.34,
- "fullFrameMilliseconds": 33.06,
+ "gpuMilliseconds": 33.48,
+ "fullFrameMilliseconds": 34.25,
"drawCalls": 1,
"triangles": 60000,
"gpuMegabytes": 0.31,
"heapMegabytes": 2.4,
"renderTargets": null,
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 26
}
},
"large-outdoor": {
"67js": {
- "firstFrameMilliseconds": 443,
+ "firstFrameMilliseconds": 529,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.57,
- "gpuMilliseconds": 158.4,
- "fullFrameMilliseconds": 159.78,
+ "renderCpuMilliseconds": 0.56,
+ "gpuMilliseconds": 165.52,
+ "fullFrameMilliseconds": 166.81,
"drawCalls": 6,
"triangles": 270474,
"gpuMegabytes": 43.58,
@@ -820,27 +820,27 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 16
},
"three": {
- "firstFrameMilliseconds": 885,
+ "firstFrameMilliseconds": 809,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 4.63,
- "gpuMilliseconds": 714.22,
- "fullFrameMilliseconds": 720.31,
+ "renderCpuMilliseconds": 4.48,
+ "gpuMilliseconds": 719.91,
+ "fullFrameMilliseconds": 725.85,
"drawCalls": 4542,
"triangles": 4359372,
"gpuMegabytes": 0.03,
"heapMegabytes": 9.8,
"renderTargets": null,
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 13
},
"67js-no-lod": {
- "firstFrameMilliseconds": 1581,
+ "firstFrameMilliseconds": 1748,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.69,
- "gpuMilliseconds": 1296.78,
- "fullFrameMilliseconds": 1298.2,
+ "renderCpuMilliseconds": 0.75,
+ "gpuMilliseconds": 1489.98,
+ "fullFrameMilliseconds": 1493.45,
"drawCalls": 4,
"triangles": 4359374,
"gpuMegabytes": 41.7,
@@ -887,14 +887,14 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 11
},
"67js-no-culling": {
- "firstFrameMilliseconds": 1924,
+ "firstFrameMilliseconds": 2354,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.17,
- "gpuMilliseconds": 1445.71,
- "fullFrameMilliseconds": 1447.03,
+ "renderCpuMilliseconds": 0.24,
+ "gpuMilliseconds": 1800.7,
+ "fullFrameMilliseconds": 1801.81,
"drawCalls": 4,
"triangles": 5760014,
"gpuMegabytes": 40.76,
@@ -941,16 +941,16 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 31
}
},
"many-materials": {
"67js": {
- "firstFrameMilliseconds": 687,
+ "firstFrameMilliseconds": 728,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.3,
- "gpuMilliseconds": 343.17,
- "fullFrameMilliseconds": 344.06,
+ "renderCpuMilliseconds": 0.33,
+ "gpuMilliseconds": 390.97,
+ "fullFrameMilliseconds": 392.68,
"drawCalls": 4,
"triangles": 925454,
"gpuMegabytes": 40.14,
@@ -997,29 +997,29 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 7
},
"three": {
- "firstFrameMilliseconds": 362,
+ "firstFrameMilliseconds": 376,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 1.69,
- "gpuMilliseconds": 149.51,
- "fullFrameMilliseconds": 152.28,
+ "renderCpuMilliseconds": 2.42,
+ "gpuMilliseconds": 148.59,
+ "fullFrameMilliseconds": 152.83,
"drawCalls": 965,
"triangles": 925452,
"gpuMegabytes": 0.03,
"heapMegabytes": 13,
"renderTargets": null,
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 7
}
},
"many-lights": {
"67js": {
- "firstFrameMilliseconds": 585,
+ "firstFrameMilliseconds": 638,
"updateMilliseconds": 0,
"renderCpuMilliseconds": 0.27,
- "gpuMilliseconds": 276.98,
- "fullFrameMilliseconds": 277.95,
+ "gpuMilliseconds": 316.87,
+ "fullFrameMilliseconds": 318.23,
"drawCalls": 4,
"triangles": 368654,
"gpuMegabytes": 39.95,
@@ -1069,26 +1069,26 @@
"gpuBusyBefore": 8
},
"three": {
- "firstFrameMilliseconds": 312,
+ "firstFrameMilliseconds": 337,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.59,
- "gpuMilliseconds": 109.15,
- "fullFrameMilliseconds": 111.33,
+ "renderCpuMilliseconds": 0.66,
+ "gpuMilliseconds": 111.06,
+ "fullFrameMilliseconds": 112.69,
"drawCalls": 385,
"triangles": 368652,
"gpuMegabytes": 0.03,
"heapMegabytes": 2.3,
"renderTargets": null,
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 2
}
},
"transparency": {
"67js": {
- "firstFrameMilliseconds": 574,
+ "firstFrameMilliseconds": 604,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.31,
- "gpuMilliseconds": 236.9,
- "fullFrameMilliseconds": 238.05,
+ "renderCpuMilliseconds": 0.28,
+ "gpuMilliseconds": 262.84,
+ "fullFrameMilliseconds": 264.02,
"drawCalls": 4,
"triangles": 288014,
"gpuMegabytes": 39.87,
@@ -1135,29 +1135,29 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 4
},
"three": {
- "firstFrameMilliseconds": 279,
+ "firstFrameMilliseconds": 241,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.67,
- "gpuMilliseconds": 50.21,
- "fullFrameMilliseconds": 51.78,
+ "renderCpuMilliseconds": 0.68,
+ "gpuMilliseconds": 53.65,
+ "fullFrameMilliseconds": 55.54,
"drawCalls": 301,
"triangles": 288012,
"gpuMegabytes": 0.03,
"heapMegabytes": 5,
"renderTargets": null,
- "gpuBusyBefore": 0
+ "gpuBusyBefore": 4
}
},
"moving-shadows": {
"67js": {
- "firstFrameMilliseconds": 367,
- "updateMilliseconds": 0.15,
- "renderCpuMilliseconds": 0.32,
- "gpuMilliseconds": 64.74,
- "fullFrameMilliseconds": 66,
+ "firstFrameMilliseconds": 281,
+ "updateMilliseconds": 0.17,
+ "renderCpuMilliseconds": 0.28,
+ "gpuMilliseconds": 68.27,
+ "fullFrameMilliseconds": 69.31,
"drawCalls": 4,
"triangles": 12026,
"gpuMegabytes": 39.87,
@@ -1204,29 +1204,29 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 2
},
"three": {
- "firstFrameMilliseconds": 232,
- "updateMilliseconds": 0.09,
- "renderCpuMilliseconds": 0.99,
- "gpuMilliseconds": 17.43,
- "fullFrameMilliseconds": 19.37,
+ "firstFrameMilliseconds": 248,
+ "updateMilliseconds": 0.12,
+ "renderCpuMilliseconds": 1.03,
+ "gpuMilliseconds": 18.99,
+ "fullFrameMilliseconds": 20.79,
"drawCalls": 1002,
"triangles": 12024,
"gpuMegabytes": 32,
"heapMegabytes": 2.1,
"renderTargets": null,
- "gpuBusyBefore": 0
+ "gpuBusyBefore": 7
}
},
"large-mesh": {
"67js": {
- "firstFrameMilliseconds": 741,
+ "firstFrameMilliseconds": 767,
"updateMilliseconds": 0,
- "renderCpuMilliseconds": 0.17,
- "gpuMilliseconds": 360.86,
- "fullFrameMilliseconds": 361.91,
+ "renderCpuMilliseconds": 0.16,
+ "gpuMilliseconds": 384.66,
+ "fullFrameMilliseconds": 385.7,
"drawCalls": 3,
"triangles": 1046530,
"gpuMegabytes": 67.82,
@@ -1273,33 +1273,33 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 6
},
"three": {
- "firstFrameMilliseconds": 383,
+ "firstFrameMilliseconds": 397,
"updateMilliseconds": 0,
"renderCpuMilliseconds": 0.13,
- "gpuMilliseconds": 157.79,
- "fullFrameMilliseconds": 158.72,
+ "gpuMilliseconds": 159.33,
+ "fullFrameMilliseconds": 160.28,
"drawCalls": 1,
"triangles": 1046528,
"gpuMegabytes": 24.01,
"heapMegabytes": 29,
"renderTargets": null,
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 12
}
},
"skinned-characters": {
"67js": {
- "firstFrameMilliseconds": 378,
- "updateMilliseconds": 6.02,
- "renderCpuMilliseconds": 0.79,
- "gpuMilliseconds": 97.63,
- "fullFrameMilliseconds": 100.67,
+ "firstFrameMilliseconds": 478,
+ "updateMilliseconds": 6.44,
+ "renderCpuMilliseconds": 0.71,
+ "gpuMilliseconds": 101.64,
+ "fullFrameMilliseconds": 105.87,
"drawCalls": 308,
"triangles": 51818,
"gpuMegabytes": 43.09,
- "heapMegabytes": 17.3,
+ "heapMegabytes": 16.9,
"renderTargets": [
{
"name": "shadowMap",
@@ -1342,20 +1342,20 @@
"megabytes": 3.96
}
],
- "gpuBusyBefore": 8
+ "gpuBusyBefore": 4
},
"three": {
- "firstFrameMilliseconds": 361,
+ "firstFrameMilliseconds": 331,
"updateMilliseconds": 0.05,
- "renderCpuMilliseconds": 1.06,
- "gpuMilliseconds": 22.73,
- "fullFrameMilliseconds": 25.11,
+ "renderCpuMilliseconds": 1.15,
+ "gpuMilliseconds": 25.57,
+ "fullFrameMilliseconds": 28.17,
"drawCalls": 306,
"triangles": 51816,
"gpuMegabytes": 32.34,
- "heapMegabytes": 4.5,
+ "heapMegabytes": 5.5,
"renderTargets": null,
- "gpuBusyBefore": 1
+ "gpuBusyBefore": 7
}
}
}
diff --git a/changes/287-cascade-shadow-map.md b/changes/287-cascade-shadow-map.md
new file mode 100644
index 00000000..e0c55f3d
--- /dev/null
+++ b/changes/287-cascade-shadow-map.md
@@ -0,0 +1 @@
+- Keep the single 2048 x 2048 sun shadow map at one texel when cascades are on and nothing else reads it (issue #287). With `shadowCascades`, the main shader and the underwater lookup read the cascade array, so the single map was drawn and held for nothing: 16 MB of depth and one more shadow pass per caster change. It is still allocated and drawn when volume fog is on or a material has `subsurface`, the two places that read it. A cascaded scene at 960 by 540 allocates 77.66 MB of render targets instead of 93.66 MB (20 of 26 reference scenes drop 16 MB; the 6 with volume fog or subsurface keep the map), and 52 reference draws (26 scenes with and without 3 cascades) are byte-identical PNGs to `main`. The map also follows the casters now: a renderer that starts with nothing to cast and gets casters from `replaceParts` allocates the full map instead of keeping one texel.
diff --git a/changes/287-cascade-shadow-map.size.md b/changes/287-cascade-shadow-map.size.md
new file mode 100644
index 00000000..32945eed
--- /dev/null
+++ b/changes/287-cascade-shadow-map.size.md
@@ -0,0 +1,3 @@
+- scene:agent-scene+lazy: the single shadow map follows its casters and shrinks to one texel under cascades; the cascade addon adds 51 B and the core 41 to 44 B, for 16 MB less render target memory in every cascaded scene without volume fog or subsurface.
+- goal:lit-box: +41 B gzip (50029 to 50070) for the shadow map sizing above; needs An's acceptance, since lit-box is over its 50000 goal and may otherwise only shrink.
+- goal:agent-scene: +38 B gzip (102902 to 102940) for the same change; needs An's acceptance, since agent-scene is over its 100000 goal and may otherwise only shrink.
diff --git a/docs/lighting.md b/docs/lighting.md
index 0ad979f4..910a070e 100644
--- a/docs/lighting.md
+++ b/docs/lighting.md
@@ -170,7 +170,7 @@ const renderer = new Renderer67(canvas, parts, {
});
```
-Options: `count` (1 to 4, default 3), `resolution` (256 to 4096, default 2048), `maximumDistance` (default 150 m; farther surfaces are lit), `splitLambda` (0 uniform to 1 logarithmic, default 0.7) and `casterReach` (how far toward the light a caster may stand, default 200 m). Each slice is a bounding sphere, so turning the camera does not change its size, and its centre snaps to whole texels, so edges do not crawl. The last tenth of a slice blends into the next. The slice maps are drawn again when the camera, the light or a caster moves, so a still camera pays the depth passes once and a moving one pays `count` passes per frame; the measured cost is in `bench/reference/README.md`. Three slices of 2048 x 2048 are a 48 MiB depth array. The single map is still drawn for volume fog and water, which do not read the cascades. A scene without cascades compiles none of this code.
+Options: `count` (1 to 4, default 3), `resolution` (256 to 4096, default 2048), `maximumDistance` (default 150 m; farther surfaces are lit), `splitLambda` (0 uniform to 1 logarithmic, default 0.7) and `casterReach` (how far toward the light a caster may stand, default 200 m). Each slice is a bounding sphere, so turning the camera does not change its size, and its centre snaps to whole texels, so edges do not crawl. The last tenth of a slice blends into the next. The slice maps are drawn again when the camera, the light or a caster moves, so a still camera pays the depth passes once and a moving one pays `count` passes per frame; the measured cost is in `bench/reference/README.md`. Three slices of 2048 x 2048 are a 48 MiB depth array. The single map shrinks to one texel while cascades are on, because the main shader and the underwater lookup read the cascades; it is allocated and drawn at 2048 x 2048 again only on a frame with volume fog, or when a material has `subsurface`, which still read it (a cascaded scene at 960 x 540 holds 77.66 MiB of render targets, 93.66 MiB with the single map). A scene without cascades compiles none of this code.
Recipes reach it through `environment.shadowCascades` (an integer from 1 to 4, or 0 for the single map). Without the field a scene gets three cascades when `shadow.extent` is above 40, because the single map then covers more than 80 m and a texel is 4 cm or wider (`extent / 1024` metres); a scene with the default extent of 3.5 and any scene at or below 40 draws exactly as before. The rule reads only recipe numbers, so a recipe always resolves the same way; set `shadowCascades: 0` to keep the single map on a wide scene. The preview loads the cascade code only for a scene that gets cascades, and rebuilds its renderer when the count changes.
diff --git a/src/cascaded-shadows.js b/src/cascaded-shadows.js
index a7f32d3b..fa047193 100644
--- a/src/cascaded-shadows.js
+++ b/src/cascaded-shadows.js
@@ -5,14 +5,14 @@ import { resolveShadowLight } from './shadow-light.js';
// Cascaded sun shadows. The camera frustum is cut into up to four slices by view depth; each slice gets its own depth
// map, fitted to a bounding sphere of the slice, so a shadow near the camera is sharp and a far one is coarse. Pass
// `shadowCascades: createCascadedShadows({ count: 3 })` to the Renderer. The code lives here, not in the renderer, so a
-// scene without cascades never downloads it. The classic single map is still drawn for volume fog and water.
+// scene without cascades never downloads it. The classic single map shrinks to one texel unless volume fog or subsurface still reads it.
// The GLSL has no comments, because comments ship to every page:
// - cascadeMatrices take a world position to the clip space of each slice, cascadeSplits holds the view depth where each
// slice ends, cascadeTexels the world size of one shadow texel and cascadeRanges the depth range in metres, and
// cascadeFrame the camera forward axis with the slice count.
// - The receiver is pushed off its surface by 1.5 texels and the depth bias is one texel, as the local shadows do.
// - The last tenth of each slice blends into the next, so no seam shows.
-// - The final #define makes the main shader's shadowVisibility(normal) call read the cascades; the classic map stays unused.
+// - The final #define makes the main shader's shadowVisibility(normal) call read the cascades; the classic map is not read.
export const MAXIMUM_CASCADES = 4;
const AUTOMATIC_CASCADE_EXTENT = 40;
@@ -217,6 +217,11 @@ export class CascadedShadows {
return this.matrices.some((value, index) => value !== this.previousMatrices[index]);
}
+ /** Whether the main shader reads the cascades alone: volume fog and subsurface thickness still read the single map. */
+ replacesSingleMap(renderer) {
+ return !renderer.volumeShadowWanted && !renderer.shaderFeatures.has('subsurface');
+ }
+
/** Redraws the slice maps when the camera, the light or a caster moved. Call once a frame after the camera is set. */
update(renderer, casterChanged) {
const context = renderer.context;
diff --git a/src/renderer.js b/src/renderer.js
index 84f04b88..a8b9f3c8 100644
--- a/src/renderer.js
+++ b/src/renderer.js
@@ -1276,16 +1276,21 @@ export class Renderer67 {
this.context.vertexAttribDivisor(location, 1);
}
+ // A one texel map stays cleared to the far depth, so every point reads as lit. That is exact when nothing casts, and when
+ // cascades replace the main shader's lookup and nothing else (volume fog, subsurface thickness) still reads this map.
+ shadowMapSizeWanted() {
+ const casts = this.batches.some(batch => !batch.floor && batch.castShadow);
+ return casts && !this.shadowCascades?.replacesSingleMap(this) ? SHADOW_MAP_SIZE : 1;
+ }
+
createShadowMap() {
const context = this.context;
- const allocateShadow = !this.shadowTexture;
- // A scene with nothing to cast keeps a one texel map that stays cleared to the far depth, so every point reads as lit.
- this.shadowMapSize ??= this.batches.some(batch => !batch.floor && batch.castShadow) ? SHADOW_MAP_SIZE : 1;
- const mapSize = this.shadowMapSize;
- if (allocateShadow) this.shadowTexture = context.createTexture();
+ const mapSize = this.shadowMapSizeWanted();
+ this.shadowTexture ??= context.createTexture();
context.activeTexture(context.TEXTURE0);
context.bindTexture(context.TEXTURE_2D, this.shadowTexture);
- if (allocateShadow) {
+ if (mapSize !== this.shadowMapSize) {
+ this.shadowMapSize = mapSize;
context.texImage2D(context.TEXTURE_2D, 0, context.DEPTH_COMPONENT24, mapSize, mapSize, 0, context.DEPTH_COMPONENT, context.UNSIGNED_INT, null);
this.renderTargets.record('shadowMap', { width: mapSize, height: mapSize, format: 'DEPTH_COMPONENT24' });
}
@@ -2072,7 +2077,8 @@ export class Renderer67 {
this.requireFeatureNames(shaderFeaturesOfLighting(this.lighting));
const passMode = this.preparePass(frame);
this.renderingPass = passMode > 0;
- if (casterChanged) {
+ this.volumeShadowWanted = volume.density > 0;
+ if (casterChanged || this.shadowMapSizeWanted() !== this.shadowMapSize) {
this.assemblyAmount = assemblyAmount;
this.createShadowMap();
}
diff --git a/tests/render-target-memory.test.js b/tests/render-target-memory.test.js
index 9e9c5bbf..e12610de 100644
--- a/tests/render-target-memory.test.js
+++ b/tests/render-target-memory.test.js
@@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import { Renderer67 } from '../src/renderer.js';
import { RenderTargetLedger } from '../src/render-target-ledger.js';
+import { CascadedShadows } from '../src/cascaded-shadows.js';
const BYTES_PER_MEGABYTE = 1048576;
@@ -90,3 +91,31 @@ test('the multisampled depth uses 16 bits unless a depth texture needs the same
assert.equal(textureDepth.format, 'DEPTH_COMPONENT24');
assert.equal(textureDepth.bytes, 960 * 540 * 4 * 4);
});
+
+test('the single shadow map follows the casters: it grows when casters arrive and shrinks when they leave', () => {
+ const batches = [{ floor: true, castShadow: true }];
+ const { renderer, sizes } = shadowRenderer(batches);
+ renderer.createShadowMap();
+ batches.push({ castShadow: true });
+ renderer.createShadowMap();
+ batches.pop();
+ renderer.createShadowMap();
+ assert.deepEqual(sizes.map(size => size[0]), [1, 2048, 1]);
+ assert.equal(renderer.memoryReport().totalBytes, 4);
+});
+
+test('with cascades the single shadow map stays one texel unless volume fog or subsurface reads it', () => {
+ const cascaded = shadowRenderer([{ castShadow: true }]);
+ cascaded.renderer.shadowCascades = { replacesSingleMap: CascadedShadows.prototype.replacesSingleMap };
+ cascaded.renderer.shaderFeatures = new Set();
+ cascaded.renderer.createShadowMap();
+ assert.equal(cascaded.sizes[0][0], 1);
+ cascaded.renderer.volumeShadowWanted = true;
+ cascaded.renderer.createShadowMap();
+ assert.equal(cascaded.sizes[1][0], 2048);
+ const subsurface = shadowRenderer([{ castShadow: true }]);
+ subsurface.renderer.shadowCascades = { replacesSingleMap: CascadedShadows.prototype.replacesSingleMap };
+ subsurface.renderer.shaderFeatures = new Set(['subsurface']);
+ subsurface.renderer.createShadowMap();
+ assert.equal(subsurface.sizes[0][0], 2048);
+});