@null3d/engine 0.0.0 → 0.1.1

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.
Files changed (517) hide show
  1. package/README.md +109 -0
  2. package/THIRD-PARTY-NOTICES.txt +0 -1
  3. package/dist/wasm/single/null3d.js +25 -10
  4. package/dist/wasm/single/null3d_bg.wasm +0 -0
  5. package/dist/wasm/threaded/null3d.js +25 -10
  6. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  7. package/docs/api/animation.md +114 -86
  8. package/docs/api/assets.md +135 -49
  9. package/docs/api/cameras.md +45 -12
  10. package/docs/api/controls.md +88 -62
  11. package/docs/api/debug.md +116 -41
  12. package/docs/api/engine.md +117 -35
  13. package/docs/api/feature-draws.md +23 -17
  14. package/docs/api/feature-effects.md +11 -11
  15. package/docs/api/feature-instances.md +70 -19
  16. package/docs/api/features.md +77 -47
  17. package/docs/api/geometry.md +132 -82
  18. package/docs/api/grass.md +55 -13
  19. package/docs/api/impostors.md +175 -22
  20. package/docs/api/input.md +24 -18
  21. package/docs/api/lights.md +78 -51
  22. package/docs/api/lines.md +41 -33
  23. package/docs/api/materials.md +248 -121
  24. package/docs/api/math.md +12 -13
  25. package/docs/api/objects.md +47 -22
  26. package/docs/api/page.md +58 -7
  27. package/docs/api/particles.md +33 -20
  28. package/docs/api/points.md +19 -31
  29. package/docs/api/post.md +75 -42
  30. package/docs/api/quality.md +42 -17
  31. package/docs/api/raycast.md +65 -51
  32. package/docs/api/reference/animation.md +10 -11
  33. package/docs/api/reference/assets.md +25 -22
  34. package/docs/api/reference/cameras.md +8 -4
  35. package/docs/api/reference/controls.md +134 -25
  36. package/docs/api/reference/debug.md +81 -14
  37. package/docs/api/reference/engine.md +58 -17
  38. package/docs/api/reference/feature-draws.md +3 -4
  39. package/docs/api/reference/feature-effects.md +2 -3
  40. package/docs/api/reference/feature-instances.md +5 -4
  41. package/docs/api/reference/features.md +7 -4
  42. package/docs/api/reference/geometry.md +287 -97
  43. package/docs/api/reference/grass.md +63 -3
  44. package/docs/api/reference/impostors.md +208 -13
  45. package/docs/api/reference/input.md +4 -5
  46. package/docs/api/reference/lights.md +13 -12
  47. package/docs/api/reference/lines.md +10 -11
  48. package/docs/api/reference/materials.md +54 -53
  49. package/docs/api/reference/math.md +35 -24
  50. package/docs/api/reference/objects.md +11 -12
  51. package/docs/api/reference/particles.md +31 -6
  52. package/docs/api/reference/points.md +6 -7
  53. package/docs/api/reference/post.md +21 -20
  54. package/docs/api/reference/quality.md +8 -5
  55. package/docs/api/reference/raycast.md +7 -8
  56. package/docs/api/reference/render.md +5 -4
  57. package/docs/api/reference/scene.md +52 -30
  58. package/docs/api/reference/sketch.md +15 -11
  59. package/docs/api/reference/sound.md +234 -0
  60. package/docs/api/reference/splats.md +42 -3
  61. package/docs/api/reference/sprites.md +7 -8
  62. package/docs/api/reference/tasks.md +16 -3
  63. package/docs/api/reference/terrain.md +27 -5
  64. package/docs/api/reference/textures.md +5 -6
  65. package/docs/api/reference/three-compat.md +18 -7
  66. package/docs/api/reference/time.md +1 -2
  67. package/docs/api/reference/ui.md +12 -9
  68. package/docs/api/reference/vertex-draws.md +5 -6
  69. package/docs/api/reference/water.md +153 -9
  70. package/docs/api/reference/wind.md +17 -4
  71. package/docs/api/render.md +73 -29
  72. package/docs/api/scene.md +164 -60
  73. package/docs/api/sketch.md +102 -15
  74. package/docs/api/sound.md +205 -0
  75. package/docs/api/splats.md +46 -12
  76. package/docs/api/sprites.md +10 -24
  77. package/docs/api/tasks.md +33 -24
  78. package/docs/api/terrain.md +42 -22
  79. package/docs/api/textures.md +68 -19
  80. package/docs/api/three-compat.md +15 -7
  81. package/docs/api/time.md +3 -5
  82. package/docs/api/ui.md +19 -23
  83. package/docs/api/vertex-draws.md +13 -12
  84. package/docs/api/water.md +262 -35
  85. package/docs/api/wind.md +63 -17
  86. package/docs/cli/null3d.md +177 -27
  87. package/docs/concepts/architecture.md +73 -27
  88. package/docs/concepts/assets.md +57 -33
  89. package/docs/concepts/backends.md +69 -27
  90. package/docs/concepts/color-management.md +54 -36
  91. package/docs/concepts/culling.md +68 -47
  92. package/docs/concepts/handles.md +14 -5
  93. package/docs/concepts/instances.md +74 -25
  94. package/docs/concepts/large-worlds.md +18 -8
  95. package/docs/concepts/lighting.md +155 -87
  96. package/docs/concepts/lod.md +126 -44
  97. package/docs/concepts/materials.md +58 -27
  98. package/docs/concepts/particle-buffer.md +48 -35
  99. package/docs/concepts/post-processing.md +84 -43
  100. package/docs/concepts/quality-preset-tables.md +56 -52
  101. package/docs/concepts/quality-presets.md +164 -52
  102. package/docs/concepts/render-graph.md +69 -29
  103. package/docs/concepts/render-layers.md +11 -21
  104. package/docs/concepts/shadows.md +105 -52
  105. package/docs/concepts/static-dynamic.md +22 -7
  106. package/docs/cookbook/index.md +164 -120
  107. package/docs/data/threejs-mapping.json +362 -367
  108. package/docs/errors/E1101.md +23 -5
  109. package/docs/errors/E1102.md +11 -3
  110. package/docs/errors/E1103.md +11 -3
  111. package/docs/errors/E1104.md +11 -3
  112. package/docs/errors/E1105.md +13 -5
  113. package/docs/errors/E1106.md +11 -3
  114. package/docs/errors/E1107.md +15 -5
  115. package/docs/errors/E1108.md +11 -3
  116. package/docs/errors/E1109.md +32 -6
  117. package/docs/errors/E1110.md +23 -5
  118. package/docs/errors/E1111.md +11 -3
  119. package/docs/errors/E1112.md +11 -3
  120. package/docs/errors/E1203.md +12 -4
  121. package/docs/errors/E1204.md +11 -3
  122. package/docs/errors/E1205.md +11 -3
  123. package/docs/errors/E1206.md +28 -6
  124. package/docs/errors/E1207.md +11 -3
  125. package/docs/errors/E1208.md +12 -3
  126. package/docs/errors/E1209.md +11 -3
  127. package/docs/errors/E1213.md +27 -5
  128. package/docs/errors/E1214.md +14 -6
  129. package/docs/errors/E1215.md +31 -6
  130. package/docs/errors/E1216.md +31 -6
  131. package/docs/errors/E1217.md +29 -6
  132. package/docs/errors/E1218.md +22 -6
  133. package/docs/errors/E1219.md +11 -3
  134. package/docs/errors/E1220.md +24 -5
  135. package/docs/errors/E1221.md +24 -5
  136. package/docs/errors/E1222.md +11 -3
  137. package/docs/errors/E1223.md +39 -6
  138. package/docs/errors/E1224.md +11 -3
  139. package/docs/errors/E1225.md +11 -3
  140. package/docs/errors/E1301.md +11 -3
  141. package/docs/errors/E1302.md +11 -3
  142. package/docs/errors/E1303.md +11 -3
  143. package/docs/errors/E1304.md +11 -3
  144. package/docs/errors/E1305.md +13 -3
  145. package/docs/errors/E1306.md +11 -3
  146. package/docs/errors/E1307.md +40 -0
  147. package/docs/errors/E1401.md +11 -3
  148. package/docs/errors/E1402.md +13 -5
  149. package/docs/errors/E1403.md +11 -3
  150. package/docs/errors/E1404.md +13 -3
  151. package/docs/errors/E1405.md +15 -4
  152. package/docs/errors/E1406.md +31 -5
  153. package/docs/errors/E1407.md +11 -3
  154. package/docs/errors/E1408.md +11 -3
  155. package/docs/errors/E1409.md +11 -3
  156. package/docs/errors/E1410.md +13 -5
  157. package/docs/errors/E1411.md +11 -3
  158. package/docs/errors/E1412.md +29 -6
  159. package/docs/errors/E1413.md +11 -3
  160. package/docs/errors/E1414.md +11 -3
  161. package/docs/errors/E1415.md +11 -3
  162. package/docs/errors/E1416.md +27 -6
  163. package/docs/errors/E1417.md +11 -3
  164. package/docs/errors/E1418.md +12 -3
  165. package/docs/errors/E1419.md +13 -5
  166. package/docs/errors/E1420.md +14 -6
  167. package/docs/errors/E1421.md +11 -3
  168. package/docs/errors/E1422.md +12 -3
  169. package/docs/errors/E1423.md +12 -3
  170. package/docs/errors/E1424.md +24 -5
  171. package/docs/errors/E1425.md +11 -3
  172. package/docs/errors/E1426.md +11 -3
  173. package/docs/errors/E1430.md +11 -3
  174. package/docs/errors/E1431.md +11 -3
  175. package/docs/errors/E1432.md +11 -3
  176. package/docs/errors/E1433.md +11 -3
  177. package/docs/errors/E1434.md +15 -6
  178. package/docs/errors/E1435.md +11 -3
  179. package/docs/errors/E1436.md +11 -3
  180. package/docs/errors/E1437.md +14 -6
  181. package/docs/errors/E1501.md +41 -6
  182. package/docs/errors/E1502.md +13 -3
  183. package/docs/errors/E1503.md +11 -3
  184. package/docs/errors/E1504.md +11 -3
  185. package/docs/errors/E1505.md +23 -5
  186. package/docs/errors/E1506.md +11 -3
  187. package/docs/errors/index.md +54 -30
  188. package/docs/getting-started/cdn.md +32 -10
  189. package/docs/getting-started/first-scene.md +21 -13
  190. package/docs/getting-started/hosting.md +152 -63
  191. package/docs/getting-started/install.md +44 -28
  192. package/docs/getting-started/network-use.md +33 -15
  193. package/docs/getting-started/project-structure.md +33 -12
  194. package/docs/getting-started/third-party-notices.md +12 -14
  195. package/docs/guides/accessibility.md +5 -5
  196. package/docs/guides/add-ons.md +86 -15
  197. package/docs/guides/agents.md +16 -9
  198. package/docs/guides/assets-pipeline.md +259 -82
  199. package/docs/guides/audio.md +115 -128
  200. package/docs/guides/baked-light-data.md +44 -23
  201. package/docs/guides/car-paint.md +38 -32
  202. package/docs/guides/content-pages.md +63 -35
  203. package/docs/guides/custom-passes.md +65 -22
  204. package/docs/guides/custom-shaders.md +59 -39
  205. package/docs/guides/debugging.md +74 -10
  206. package/docs/guides/deploying.md +85 -6
  207. package/docs/guides/deterministic-simulation.md +24 -17
  208. package/docs/guides/first-use-shaders.md +83 -45
  209. package/docs/guides/lens-kit.md +29 -26
  210. package/docs/guides/loading-screens.md +132 -47
  211. package/docs/guides/multiple-views.md +63 -13
  212. package/docs/guides/performance.md +192 -38
  213. package/docs/guides/phones.md +78 -15
  214. package/docs/guides/physics.md +7 -11
  215. package/docs/guides/screens.md +47 -33
  216. package/docs/guides/start-time.md +363 -0
  217. package/docs/guides/testing.md +152 -95
  218. package/docs/guides/ui-overlays.md +19 -14
  219. package/docs/guides/video-textures.md +14 -13
  220. package/docs/images/api/animation/character.webp +0 -0
  221. package/docs/images/api/animation/look-at-ring.webp +0 -0
  222. package/docs/images/api/animation/morph-tulips.webp +0 -0
  223. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  224. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  225. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  226. package/docs/images/api/debug/debug-shapes.webp +0 -0
  227. package/docs/images/api/debug/levels-view.webp +0 -0
  228. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  229. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  230. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  231. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  232. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  233. package/docs/images/api/geometry/generators.webp +0 -0
  234. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  235. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  236. package/docs/images/api/grass/grass-grove.webp +0 -0
  237. package/docs/images/api/grass/grass-presets.webp +0 -0
  238. package/docs/images/api/grass/grass-shadow.webp +0 -0
  239. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  240. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  241. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  242. package/docs/images/api/lights/spot-cookies.webp +0 -0
  243. package/docs/images/api/lines/lines-lit.webp +0 -0
  244. package/docs/images/api/lines/lines-widths.webp +0 -0
  245. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  246. package/docs/images/api/materials/decals.webp +0 -0
  247. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  248. package/docs/images/api/materials/relief.webp +0 -0
  249. package/docs/images/api/materials/shader-inputs.webp +0 -0
  250. package/docs/images/api/materials/standard-grid.webp +0 -0
  251. package/docs/images/api/materials/subsurface.webp +0 -0
  252. package/docs/images/api/materials/translucency.webp +0 -0
  253. package/docs/images/api/objects/objects-turntable.webp +0 -0
  254. package/docs/images/api/particles/campfire.webp +0 -0
  255. package/docs/images/api/points/galaxy.webp +0 -0
  256. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  257. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  258. package/docs/images/api/render/reflection-mirror.webp +0 -0
  259. package/docs/images/api/render/security-camera.webp +0 -0
  260. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  261. package/docs/images/api/sound/sound-demo.webp +0 -0
  262. package/docs/images/api/splats/splats-demo.webp +0 -0
  263. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  264. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  265. package/docs/images/api/textures/canvas-screen.webp +0 -0
  266. package/docs/images/api/textures/mipmaps.webp +0 -0
  267. package/docs/images/api/vertex-draws/rain.webp +0 -0
  268. package/docs/images/api/water/ocean.webp +0 -0
  269. package/docs/images/api/water/water-demo.webp +0 -0
  270. package/docs/images/api/water/water-rain.webp +0 -0
  271. package/docs/images/api/water/waterfall.webp +0 -0
  272. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  273. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  274. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  275. package/docs/images/concepts/instances/instances.webp +0 -0
  276. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  277. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  278. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  279. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  280. package/docs/images/concepts/lighting/environment.webp +0 -0
  281. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  282. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  283. package/docs/images/concepts/lod/forest.webp +0 -0
  284. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  285. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  286. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  287. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  288. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  289. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  290. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  291. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  292. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  293. package/docs/images/cookbook/index/picking.webp +0 -0
  294. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  295. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  296. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  297. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  298. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  299. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  300. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  301. package/docs/images/index/showcase-island.webp +0 -0
  302. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  303. package/docs/images/shaders/builtins/builtins.webp +0 -0
  304. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  305. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  306. package/docs/images/shots.json +2231 -0
  307. package/docs/index.md +18 -23
  308. package/docs/moves.json +1 -0
  309. package/docs/nav.json +300 -0
  310. package/docs/pages.md +230 -209
  311. package/docs/porting/react-three-fiber.md +225 -6
  312. package/docs/porting/threejs-loop-and-threads.md +217 -7
  313. package/docs/porting/threejs-mapping.md +1249 -233
  314. package/docs/porting/threejs-materials.md +218 -6
  315. package/docs/porting/threejs-overview.md +240 -7
  316. package/docs/porting/threejs-postprocessing.md +4 -8
  317. package/docs/porting/threejs-shaders.md +301 -6
  318. package/docs/porting/threejs-unsupported.md +83 -7
  319. package/docs/porting/verification.md +178 -6
  320. package/docs/shaders/builtins.md +15 -4
  321. package/docs/shaders/library.md +72 -45
  322. package/docs/shaders/surface-functions.md +59 -23
  323. package/docs/shaders/wgsl-rules.md +12 -5
  324. package/lib/debug/channel.d.ts +103 -0
  325. package/lib/debug/channel.js +269 -0
  326. package/lib/debug/debug.d.ts +11 -9
  327. package/lib/debug/draw.d.ts +11 -2
  328. package/lib/debug/draw.js +57 -6
  329. package/lib/debug/inspector.d.ts +60 -0
  330. package/lib/debug/inspector.js +475 -0
  331. package/lib/debug/overlay-look.d.ts +6 -0
  332. package/lib/debug/overlay-look.js +29 -7
  333. package/lib/debug/overlay.js +15 -11
  334. package/lib/debug/stats-options.d.ts +13 -0
  335. package/lib/debug/stats-panel.d.ts +22 -7
  336. package/lib/debug/stats-panel.js +80 -13
  337. package/lib/debug/stats.d.ts +2 -3
  338. package/lib/errors/codes.d.ts +17 -3
  339. package/lib/errors/codes.js +117 -105
  340. package/lib/errors/engine-error.js +25 -10
  341. package/lib/errors/fixes.d.ts +1 -0
  342. package/lib/errors/fixes.js +20 -19
  343. package/lib/generated/core.d.ts +1 -1
  344. package/lib/generated/core.js +1 -1
  345. package/lib/gpu/early-builds.d.ts +68 -0
  346. package/lib/gpu/early-builds.js +158 -0
  347. package/lib/gpu/pipeline-name.d.ts +6 -0
  348. package/lib/gpu/pipeline-name.js +23 -0
  349. package/lib/gpu/variants.d.ts +8 -2
  350. package/lib/gpu/variants.js +39 -7
  351. package/lib/gpu/webgl2/backend.d.ts +63 -2
  352. package/lib/gpu/webgl2/backend.js +226 -8
  353. package/lib/gpu/webgl2/programs.d.ts +18 -0
  354. package/lib/gpu/webgl2/programs.js +5 -2
  355. package/lib/gpu/webgpu/backend.d.ts +89 -2
  356. package/lib/gpu/webgpu/backend.js +255 -8
  357. package/lib/gpu/webgpu/pipelines.d.ts +13 -0
  358. package/lib/gpu/webgpu/pipelines.js +28 -14
  359. package/lib/index.d.ts +7 -5
  360. package/lib/index.js +3 -2
  361. package/lib/math/color.d.ts +5 -5
  362. package/lib/math/color.js +5 -5
  363. package/lib/math/mat4.d.ts +6 -12
  364. package/lib/math/mat4.js +6 -12
  365. package/lib/math/namespaces/quat.d.ts +3 -3
  366. package/lib/math/namespaces/quat.js +3 -3
  367. package/lib/math/quat.d.ts +8 -12
  368. package/lib/math/quat.js +8 -12
  369. package/lib/math/random.d.ts +2 -3
  370. package/lib/math/random.js +2 -3
  371. package/lib/math/types.d.ts +4 -4
  372. package/lib/math/vec3.d.ts +3 -6
  373. package/lib/math/vec3.js +3 -6
  374. package/lib/page/capabilities.d.ts +8 -8
  375. package/lib/page/capabilities.js +39 -25
  376. package/lib/page/check-store.d.ts +14 -2
  377. package/lib/page/check-store.js +34 -11
  378. package/lib/page/engine.d.ts +117 -31
  379. package/lib/page/engine.js +438 -99
  380. package/lib/page/first-frame.d.ts +16 -0
  381. package/lib/page/first-frame.js +35 -0
  382. package/lib/page/frame-stats.d.ts +34 -1
  383. package/lib/page/frame-stats.js +15 -0
  384. package/lib/page/label-loop.d.ts +7 -3
  385. package/lib/page/label-loop.js +26 -14
  386. package/lib/page/labels.d.ts +3 -3
  387. package/lib/page/pipeline-store.d.ts +25 -0
  388. package/lib/page/pipeline-store.js +84 -0
  389. package/lib/page/start-marker.d.ts +4 -1
  390. package/lib/page/start-marker.js +5 -2
  391. package/lib/page/stats-switch.js +2 -0
  392. package/lib/page/switches.d.ts +38 -6
  393. package/lib/page/switches.js +29 -5
  394. package/lib/quality/check.d.ts +24 -3
  395. package/lib/quality/check.js +21 -7
  396. package/lib/quality/chooser.d.ts +6 -0
  397. package/lib/quality/chooser.js +8 -0
  398. package/lib/quality/governor.d.ts +98 -6
  399. package/lib/quality/governor.js +250 -20
  400. package/lib/quality/preset-docs.d.ts +16 -1
  401. package/lib/quality/preset-docs.js +3 -0
  402. package/lib/quality/presets.d.ts +84 -7
  403. package/lib/quality/presets.js +94 -2
  404. package/lib/render/draw.d.ts +3 -2
  405. package/lib/render/draw.js +15 -5
  406. package/lib/render/load-draw.d.ts +7 -5
  407. package/lib/render/load-draw.js +7 -5
  408. package/lib/render/loss.d.ts +28 -10
  409. package/lib/render/loss.js +50 -22
  410. package/lib/render/recovery.d.ts +20 -0
  411. package/lib/render/recovery.js +44 -4
  412. package/lib/render/renderer.d.ts +85 -9
  413. package/lib/render/renderer.js +181 -42
  414. package/lib/render/scene-renderer.d.ts +19 -1
  415. package/lib/render/scene-renderer.js +25 -1
  416. package/lib/render/webgl2-renderers.js +8 -5
  417. package/lib/render/webgpu-renderers.js +5 -4
  418. package/lib/scene/animation.d.ts +28 -32
  419. package/lib/scene/animation.js +12 -15
  420. package/lib/scene/assets.d.ts +61 -86
  421. package/lib/scene/assets.js +103 -236
  422. package/lib/scene/background.d.ts +14 -18
  423. package/lib/scene/background.js +5 -2
  424. package/lib/scene/baked-light.d.ts +2 -2
  425. package/lib/scene/color.d.ts +3 -3
  426. package/lib/scene/downloads.d.ts +2 -0
  427. package/lib/scene/downloads.js +371 -0
  428. package/lib/scene/environment.d.ts +7 -7
  429. package/lib/scene/environment.js +1 -1
  430. package/lib/scene/fake-call-values.js +3 -3
  431. package/lib/scene/fog.d.ts +11 -4
  432. package/lib/scene/fog.js +8 -2
  433. package/lib/scene/frame-cameras.d.ts +35 -4
  434. package/lib/scene/frame-cameras.js +86 -10
  435. package/lib/scene/gltf.d.ts +33 -3
  436. package/lib/scene/gltf.js +78 -49
  437. package/lib/scene/grading.d.ts +2 -2
  438. package/lib/scene/grading.js +3 -3
  439. package/lib/scene/ktx2.d.ts +9 -1
  440. package/lib/scene/ktx2.js +3 -2
  441. package/lib/scene/level-rule.d.ts +121 -0
  442. package/lib/scene/level-rule.js +130 -0
  443. package/lib/scene/lines.d.ts +13 -17
  444. package/lib/scene/lines.js +3 -3
  445. package/lib/scene/lut.d.ts +1 -2
  446. package/lib/scene/lut.js +1 -2
  447. package/lib/scene/particles.d.ts +7 -3
  448. package/lib/scene/particles.js +3 -1
  449. package/lib/scene/picks.d.ts +2 -2
  450. package/lib/scene/pointer-events.d.ts +4 -7
  451. package/lib/scene/post.d.ts +39 -43
  452. package/lib/scene/post.js +4 -1
  453. package/lib/scene/prefab.d.ts +7 -8
  454. package/lib/scene/prefab.js +7 -8
  455. package/lib/scene/property-animation.d.ts +1 -1
  456. package/lib/scene/property-animation.js +1 -1
  457. package/lib/scene/queries.d.ts +7 -13
  458. package/lib/scene/resources.d.ts +238 -261
  459. package/lib/scene/resources.js +179 -81
  460. package/lib/scene/scene.d.ts +167 -120
  461. package/lib/scene/scene.js +243 -103
  462. package/lib/scene/serial-loads.d.ts +29 -0
  463. package/lib/scene/serial-loads.js +68 -0
  464. package/lib/scene/shader-preloads.d.ts +34 -0
  465. package/lib/scene/shader-preloads.js +38 -0
  466. package/lib/scene/sprites.d.ts +14 -17
  467. package/lib/scene/sprites.js +5 -6
  468. package/lib/scene/textures.d.ts +11 -12
  469. package/lib/scene/textures.js +9 -10
  470. package/lib/scene/time-of-day.d.ts +11 -7
  471. package/lib/scene/time-of-day.js +11 -8
  472. package/lib/scene/vertex-draws.d.ts +5 -4
  473. package/lib/scene/vertex-draws.js +7 -5
  474. package/lib/shader-artifact.json +1 -0
  475. package/lib/shared/core.d.ts +5 -0
  476. package/lib/shared/core.js +1 -0
  477. package/lib/shared/import-once.d.ts +6 -0
  478. package/lib/shared/import-once.js +19 -0
  479. package/lib/shared/labels.d.ts +5 -2
  480. package/lib/shared/labels.js +5 -2
  481. package/lib/shared/metrics.d.ts +38 -0
  482. package/lib/shared/metrics.js +62 -1
  483. package/lib/shared/permutation-words.d.ts +2 -0
  484. package/lib/shared/permutation-words.js +8 -0
  485. package/lib/shared/recording.d.ts +13 -5
  486. package/lib/shared/recording.js +31 -10
  487. package/lib/shared/run-task.js +7 -1
  488. package/lib/shared/sketch-data.d.ts +9 -0
  489. package/lib/shared/sketch-data.js +57 -0
  490. package/lib/shared/task-pending.d.ts +12 -0
  491. package/lib/shared/task-pending.js +61 -1
  492. package/lib/shared/tasks.js +79 -32
  493. package/lib/shared/version.d.ts +17 -1
  494. package/lib/shared/version.js +19 -1
  495. package/lib/shared/wasm.d.ts +12 -4
  496. package/lib/shared/wasm.js +50 -27
  497. package/lib/shared/worker-start.d.ts +7 -0
  498. package/lib/shared/worker-start.js +27 -0
  499. package/lib/sketch/define-sketch.d.ts +51 -7
  500. package/lib/sketch/define-sketch.js +2 -1
  501. package/lib/sketch/input.d.ts +2 -2
  502. package/lib/sketch/preset-check.d.ts +20 -6
  503. package/lib/sketch/preset-check.js +42 -17
  504. package/lib/sketch/quality.d.ts +69 -11
  505. package/lib/sketch/quality.js +54 -13
  506. package/lib/sketch/runner.d.ts +80 -9
  507. package/lib/sketch/runner.js +390 -52
  508. package/lib/sketch/ui.d.ts +5 -8
  509. package/lib/sketch/ui.js +4 -2
  510. package/lib/stats.d.ts +1 -0
  511. package/lib/workers/probe-worker.d.ts +5 -0
  512. package/lib/workers/probe-worker.js +13 -4
  513. package/lib/workers/protocol.d.ts +71 -13
  514. package/lib/workers/protocol.js +4 -0
  515. package/lib/workers/render-worker.js +29 -5
  516. package/lib/workers/sketch-worker.js +108 -16
  517. package/package.json +2 -2
@@ -1,18 +1,18 @@
1
1
  ---
2
2
  id: guides/performance
3
3
  title: Performance guide
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "Measuring; the frame budget on computers, phones and tablets; common causes of slow frames and their fixes."
7
5
  ---
8
6
 
9
7
  # Performance guide
10
8
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
9
+ null3D is built to be faster than three.js, and it beats three.js in five of its six benchmark scenes ([the one it loses](#moving-objects-cost-uploads)). It keeps its own work per frame small, so your sketch code usually decides how long a frame takes. This guide shows where frame time goes, how to write per-frame code that stays fast, and how to measure. The figures come from the engine's benchmark scenes, which the engine's repository runs with `bun run bench:run`.
12
10
 
13
- null3D keeps its own work per frame small, so your sketch code usually decides how long a frame takes. This guide shows where frame time goes, how to write per-frame code that stays fast, and how to measure. The figures come from the engine's benchmark scenes, which the engine's repository runs with `bun run bench:run`.
11
+ This guide covers the frames. [A fast start](start-time.md) covers the wait before the first frame: the host, the downloads and the setup.
14
12
 
15
- Measure in every rendering mode and preset, over the whole camera path, with repeats: [Testing your sketch](testing.md#check-every-rendering-mode) says how.
13
+ ## Measure first
14
+
15
+ Measure before you change anything, so you know which cost matters. Add `?stats` to the page's address for a live overlay, or call `debug.stats(true)` in the sketch. Call `engine.measure(5)` for figures over a window. Run `bunx @null3d/cli bench` to measure a production build with no test code. Measure in every rendering mode and preset, over the whole camera path, with repeats: [Testing your sketch](testing.md#check-every-rendering-mode) says how. [Measure](#measure) below gives each figure.
16
16
 
17
17
  ## Where frame time goes
18
18
 
@@ -88,13 +88,25 @@ The engine kept the full render scale and every setting on both devices. On the
88
88
 
89
89
  ### Quality presets
90
90
 
91
- The engine picks a [quality preset](../concepts/quality-presets.md) for each device when it starts. It picks Low on phones, Medium on tablets and High on computers. The GPU path can cap it lower. A warm tablet can run Medium below 60 frames per second, so name Low on tablets where a steady rate matters most ([Quality presets](../concepts/quality-presets.md#how-the-engine-chooses-a-preset)). When the page names no preset, the engine checks its choice after the first frame. It measures the frame rate of the scene that the setup built, and lowers the preset until one holds the target. The preset sets the pixel ratio cap and the anti-aliasing mode. It also sets the shadow settings, the texture filtering cap, the texture upload budget and the texture memory budget. It sets the size of bloom and of ambient occlusion. On WebGL2 it sets the depth prepass, occlusion culling and the most morph targets per object.
91
+ The engine picks a [quality preset](../concepts/quality-presets.md) for each device when it starts. It picks Low on phones, Medium on tablets and High on computers. The GPU path can cap it lower. A warm tablet can run Medium below 60 frames per second, so name Low on tablets where a steady rate matters most ([Quality presets](../concepts/quality-presets.md#how-the-engine-chooses-a-preset)).
92
+
93
+ When the page names no preset, the engine checks its choice after the first frame. It measures the frame rate of the scene that the setup built, and lowers the preset until one holds the target.
94
+
95
+ The preset sets:
96
+
97
+ - the pixel ratio cap and the anti-aliasing mode;
98
+ - the shadow settings;
99
+ - the texture filtering cap, the texture upload budget and the texture memory budget;
100
+ - the size of bloom and of ambient occlusion;
101
+ - the most morph targets per object, on WebGL2.
102
+
103
+ WebGL2 draws the depth prepass on every preset, and no preset turns on occlusion culling there.
92
104
 
93
105
  The pixel ratio cap often decides GPU time on a phone, because the GPU shades each device pixel. Low caps the ratio at 1.5, which fills a quarter of the pixels of a phone screen at ratio 3.
94
106
 
95
107
  Measure at the presets that your users get. `engine.mode.preset` names the preset that runs, and the `?preset=low` switch fixes one for a test.
96
108
 
97
- When frames take too long during play, the frame-budget governor lowers a sketch's budgets and the render scale in turn, a budget's step first, and then the live shadow settings, bloom's base, the size of ambient occlusion and last the effect itself ([Quality presets](../concepts/quality-presets.md#the-frame-budget-governor)). It hides some of a slow scene's cost. To measure the scene's own cost, turn it off with `quality.set({ governor: false })`, so every run draws the same frames.
109
+ When frames take too long during play, the frame-budget governor lowers the render scale, together with any budgets that the sketch registers. Then it lowers the detail, shadow and effect settings one step at a time ([Quality presets](../concepts/quality-presets.md#the-frame-budget-governor) lists the steps). It hides some of a slow scene's cost. To measure the scene's own cost, turn it off with `quality.set({ governor: false })`, so every run draws the same frames.
98
110
 
99
111
  ## Put performance-sensitive work in Rust
100
112
 
@@ -120,9 +132,35 @@ Garbage collection pauses the thread that allocated the memory. The render worke
120
132
  - Keep reused arrays at their size. Setting `length = 0` frees an array's storage, so the next write allocates it again.
121
133
  - Do not wrap a browser promise in an `async` function every frame. Each call makes a promise of its own.
122
134
  - Keep closures out of functions that run every frame, even in a branch that rarely runs. Until the browser optimizes the function, the variables a closure captures are allocated on every call. Move such a branch into a function of its own.
123
- - A light's, the camera's, a line's and the background's setters write their numbers into the engine's memory. They call the core with whole numbers only, so they allocate nothing, a color included. Call them from a small function of their own, as a game's update does. The browser then inlines each setter, and a fraction that it does not inline becomes an object. A line material's `set` allocates nothing too. A material's `set` is for setup: it reads its numbers from an options object, and the browser boxes a read where it cannot keep the fields unboxed. Change a value that a frame changes with `material.setUniform(name, value)`, which takes the value itself, and change a camera's pose with `camera.setPose(position, rotation)` from the arrays that hold it.
135
+ - A light's, the camera's, a line's and the background's setters write their numbers into the engine's memory. They allocate nothing, a color included. Call them from a small function of their own, as a game's update does. A line material's `set` allocates nothing too.
136
+ - A material's `set` is for setup: it reads its numbers from an options object, and the browser boxes a read where it cannot keep the fields unboxed.
137
+ - Change a value that a frame changes with `material.setUniform(name, value)`, which takes the value itself. Change a camera's pose with `camera.setPose(position, rotation)` from arrays that you keep outside the frame function.
138
+
139
+ ```ts
140
+ const offset = new Float32Array(3);
141
+
142
+ // Runs every frame: no new arrays and no options objects.
143
+ function updateGlow(material, time, boxes, count) {
144
+ material.setUniform('glow', Math.sin(time) * 0.5 + 0.5);
145
+ offset[0] = 0.01;
146
+ offset[1] = 0.02;
147
+ offset[2] = 0.03;
148
+ for (let i = 0; i < count; i += 1) {
149
+ boxes[i * 3] += offset[0];
150
+ boxes[i * 3 + 1] += offset[1];
151
+ boxes[i * 3 + 2] += offset[2];
152
+ }
153
+ }
154
+ ```
155
+
156
+ <details>
157
+ <summary>Technical details: why some calls allocate in hot code</summary>
124
158
 
125
- Decimal numbers are a special case. Until the browser optimizes a function, the numbers it computes are stored as small objects. Code that runs once per frame gets optimized only after thousands of frames, so judge allocation after about 30 seconds of play.
159
+ The browser inlines a setter that a small function calls, and a fraction that it does not inline becomes an object. `material.set` reads its numbers from an options object, and the browser boxes a read that it cannot keep in a field unbox.
160
+
161
+ </details>
162
+
163
+ Decimal numbers are a special case. Until the browser optimizes a function, the numbers it computes are stored as small objects. Code that runs once per frame gets optimized only after thousands of frames, so judge allocation after about 30 seconds of play. The [vertex updates demo](https://github.com/null3d-engine/null3d/tree/main/examples/vertex-updates) rewrites its pool's arrays every frame and passes them to `mesh.updateVertices`, which allocates nothing.
126
164
 
127
165
  ## Objects during play
128
166
 
@@ -143,11 +181,11 @@ The engine keeps each scene's draw tables and every object's matrix on the GPU,
143
181
  | `setCastShadows` and `setReceiveShadows`, on meshes and on lights | A rebuild |
144
182
  | `setLevelBias`, which changes the bucket that the object draws from | A rebuild |
145
183
  | `setOutlined`, and `post.set` with `outline` turned on or off | A rebuild |
184
+ | `texture.update()` with an image of another size, and `texture.destroy()` | A rebuild |
146
185
  | `setMorphWeight` | The object's weights. On WebGPU, the skinning pass morphs the mesh again |
147
186
  | `post.set` that turns bloom or ambient occlusion on or off, and `post.addEffect` or `post.removeEffect` | New passes. The last image stays on screen while their pipelines build |
148
187
  | `render.addPass`, `render.removePass` | New passes, and the pass's texture |
149
188
  | `render.setPassEnabled`, `post.setEffectUniform`, `scene.setBackground` and `scene.setEnvironment` | Nothing: they change values that the GPU reads. The first background of each kind builds one pipeline |
150
- | `texture.update()` with an image of another size, and `texture.destroy()` | A rebuild |
151
189
 
152
190
  These habits keep play free of rebuilds:
153
191
 
@@ -158,22 +196,69 @@ These habits keep play free of rebuilds:
158
196
  - For a look that changes often, such as a highlight, keep two objects and swap their visibility. Keep `setMaterial` and `setMesh` for rare changes.
159
197
  - Give bounds of your own with `setBounds` to few objects, and set them once: each call rebuilds the draw tables. On WebGPU, each object with bounds of its own takes a draw of its own. Objects that share a mesh and a material share one draw.
160
198
  - Give a threshold bias with `setLevelBias` to few objects too, such as a hero object. On WebGPU, each object with a bias of its own takes a draw of its own.
161
- - Every row of a batch counts toward the scene's limit of objects and instance rows, active or not. On WebGPU every device draws 2,097,152. On WebGL2 the limit follows the largest texture the device allows. It is 1,048,576 at 2,048 pixels, the least that WebGL2 allows. For the device the page runs on, `engine.capabilities.maxInstances` gives the limit (E1501). The places in the scene's object tables count toward it too, so batches hold at most the limit less those places. Engine memory holds about 5 million rows (E1109). So size each batch for the rows it uses.
162
- - Check with `measure`. A `rebuilds` count above zero during play points to one of the calls in the lower rows of the table.
199
+ - Every row of a batch counts toward the scene's limit of objects and instance rows, active or not. On WebGPU every device draws 2,097,152. On WebGL2 the limit follows the largest texture the device allows. It is 1,048,576 at 2,048 pixels, the least that WebGL2 allows. For the device the page runs on, `engine.capabilities.maxInstances` gives the limit (E1501).
200
+
201
+ The places in the scene's object tables count toward it too, so batches hold at most the limit less those places. Engine memory holds about 5 million rows (E1109). So size each batch for the rows it uses.
202
+ - Check with `measure`. A `rebuilds` count above zero during play points to one of the calls whose cost is a rebuild in the table. New passes show in `pipelines`, not in `rebuilds`.
203
+
204
+ The [factory comparison](https://github.com/null3d-engine/null3d/tree/main/examples/compare/factory) changes its robot arms during play, in both engines.
163
205
 
164
206
  ## How the engine batches, builds pipelines and times frames
165
207
 
166
208
  Performance advice written for other engines often assumes things that do not hold here. These are null3D's answers to the questions that such advice depends on.
167
209
 
168
- | Question | null3D's answer |
169
- | --- | --- |
170
- | What makes the GPU build a pipeline? | The material's kind, standard, unlit or custom, and the [options that it fixes](../api/materials.md#options-fixed-at-creation) when you create it, apart from `flatShading` and `fog`. Each custom material's WGSL is a shader of its own. The mesh's vertex format, and the pass's color format, depth format and sample count. Other material values never do: materials are rows in one shared table. So a thousand standard materials in different colors share one pipeline for each vertex format. Tone mapping and exposure are values the shaders read, so changing them builds nothing. Shadow passes and the depth prepass build depth-only pipelines of their own. |
171
- | When are pipelines built? | In the background, from the first frame that draws a shading model with a vertex format, and again after the browser replaces the GPU. The first frame waits for its pipelines, and so does the first frame after `quality.setPreset`. After that, an object whose pipeline is still building draws nothing until it is built. `scene.warmUp()` resolves once every pipeline is built. `measure` counts builds in `pipelines`, and the draws that a building pipeline kept from drawing in `skippedDraws`. |
172
- | What does the engine batch by itself? | Every object and instance row with the same shading model, mesh and material goes into one bucket, which one draw call draws. On WebGPU the draw is indirect. On an Apple GPU in Safari, or in any browser on iPhone and iPad, a start-up measurement can find direct draws clearly faster, and the draw is then direct. `engine.capabilities.directDraws` says which the engine took, and `engine.capabilities.drawPath` says why. A mesh over 65,535 vertices takes one draw per part, unless it draws its cluster patches, which take one draw. Separate objects from `createMesh` batch the same way as the rows of an instance batch. |
173
- | Which passes walk the scene? | On WebGPU, a culling pass on the GPU tests each object and row against the view. The opaque pass then replays a draw bundle. The engine records the bundle again only when the scene's structure changes. On a device that draws the direct path, the job workers cull on the CPU as they do on WebGL2, and the opaque pass records the buckets' draws in its own pass. On WebGL2 the job workers cull on the CPU, and the opaque pass draws the objects in view. On both paths, culling first skips the still objects of grid cells out of view: [Large worlds](#large-worlds). Shadows add a pass for each cascade and shadow tile that draws in the frame, and its culling. Each scene pass culls and draws the scene once more, from its own camera. The depth prepass, when on, walks the opaque objects once more, and ambient occlusion turns it on. Outlines draw the outlined meshes twice into a mask. GPU occlusion culling adds a depth draw of the occluders and a second culling pass. Blended objects draw in the transparent pass. Where the scene draws HDR color, a final pass then reads each pixel once to tone map it, whatever the scene holds. [Architecture](../concepts/architecture.md#the-passes-of-a-frame) lists every pass. |
174
- | Does the engine know when the GPU finished a frame? | Yes, for every frame. It listens to the WebGPU queue, or checks a WebGL2 fence, and blocks no thread. `measure` reports `completedFps` and `gpuLatencyMs`. Sketch code never waits for the GPU. |
175
- | How many frames can wait on the GPU? | Two. While two frames are unfinished, the thread that draws takes no new frame, and the sketch worker waits for it. Without that limit, browsers let from 4 to more than 80 frames queue when the GPU falls behind, and each adds a frame of input lag. |
176
- | What must stay the same for the engine to reuse its work? | The scene's structure. A static object costs nothing until a setter changes it. The calls that rebuild the draw tables are listed in [Objects during play](#objects-during-play). |
210
+ ### What makes the GPU build a pipeline?
211
+
212
+ The material's kind, standard, unlit or custom, and the [options that it fixes](../api/materials.md#options-fixed-at-creation) when you create it, apart from `flatShading` and `fog`. Each custom material's WGSL is a shader of its own.
213
+
214
+ The mesh's vertex format, and the pass's color format, depth format and sample count.
215
+
216
+ Other material values never do: materials are rows in one shared table. So a thousand standard materials in different colors share one pipeline for each vertex format. Tone mapping and exposure are values the shaders read, so changing them builds nothing. Shadow passes and the depth prepass build depth-only pipelines of their own.
217
+
218
+ ### When are pipelines built?
219
+
220
+ In the background, from the first frame that draws a shading model with a vertex format, and again after the browser replaces the GPU. The first frame waits for its pipelines, and so does the first frame after `quality.setPreset`. After that, an object whose pipeline is still building draws nothing until it is built. `scene.warmUp()` resolves once every pipeline is built. `measure` counts builds in `pipelines`, and the draws that a building pipeline kept from drawing in `skippedDraws`.
221
+
222
+ The engine's own passes build for the first frame only what it draws with. Their other pipelines build in the background once the first frame shows, as [A fast start](start-time.md#pipelines-on-phones) lists.
223
+
224
+ ### What does the engine batch by itself?
225
+
226
+ Every object and instance row with the same shading model, mesh and material goes into one bucket, which one draw call draws. Separate objects from `createMesh` batch the same way as the rows of an instance batch.
227
+
228
+ <details>
229
+ <summary>Technical details: direct and indirect draws</summary>
230
+
231
+ On WebGPU the draw is indirect. On an Apple GPU in Safari, or in any browser on iPhone and iPad, a start-up measurement can find direct draws clearly faster, and the engine then draws directly. `engine.capabilities.directDraws` says which path the engine took, and `engine.capabilities.drawPath` says why. A mesh over 65,535 vertices takes one draw per part, unless it draws its cluster patches, which take one draw.
232
+
233
+ </details>
234
+
235
+ ### Which passes walk the scene?
236
+
237
+ - Culling, on the GPU on WebGPU and by the job workers on WebGL2.
238
+ - The opaque pass.
239
+ - A shadow pass for each cascade and shadow tile that draws.
240
+ - Each scene pass.
241
+ - The depth prepass when it is on, for the opaque objects only.
242
+ - The two outline mask draws.
243
+ - The occluder draw and second culling pass of GPU occlusion culling.
244
+ - The transparent pass.
245
+ - The final tone-map pass on the HDR path.
246
+
247
+ On WebGPU, a culling pass on the GPU tests each object and row against the view, and the opaque pass replays a draw bundle. The engine records the bundle again only when the scene's structure changes. On a device that draws the direct path, the job workers cull on the CPU as they do on WebGL2. On WebGL2 the job workers cull on the CPU, and the opaque pass draws the objects in view.
248
+
249
+ On both paths, culling first skips the still objects of grid cells out of view: [Large worlds](#large-worlds). [Architecture](../concepts/architecture.md#the-passes-of-a-frame) lists every pass.
250
+
251
+ ### Does the engine know when the GPU finished a frame?
252
+
253
+ Yes, for every frame. It listens to the WebGPU queue, or checks a WebGL2 fence, and blocks no thread. `measure` reports `completedFps` and `gpuLatencyMs`. Sketch code never waits for the GPU.
254
+
255
+ ### How many frames can wait on the GPU?
256
+
257
+ Two. While two frames are unfinished, the thread that draws takes no new frame, and the sketch worker waits for it. Without that limit, browsers let from 4 to more than 80 frames queue when the GPU falls behind, and each adds a frame of input lag.
258
+
259
+ ### What must stay the same for the engine to reuse its work?
260
+
261
+ The scene's structure. A static object costs nothing until a setter changes it. The calls that rebuild the draw tables are listed in [Objects during play](#objects-during-play).
177
262
 
178
263
  So some common advice does not apply:
179
264
 
@@ -189,11 +274,20 @@ So some common advice does not apply:
189
274
 
190
275
  Each dynamic instance uploads its 48-byte world matrix in every frame, so 100,000 moving boxes upload 4.8 MB per frame. A static batch uploads its matrices once and then nothing. The S1-static benchmark draws the same 100,000 boxes standing still. It uploads no matrices per frame. In a production build in Chrome on a MacBook Pro, its busiest thread took 0.07 ms per frame with WebGPU and 0.05 ms with WebGL2.
191
276
 
277
+ S1-static is the one benchmark scene that three.js wins. Any WebGPU frame in Chrome costs about 0.075 ms of CPU time, even an empty one, and three.js's WebGL renderer draws the still boxes in about 0.07 ms. [Porting from three.js](../porting/threejs-overview.md) has the full comparison.
278
+
192
279
  On WebGL2 the job workers cull, so a frame whose view changed also uploads its list of visible objects, at 4 bytes per entry. Each visible object or instance row is one entry, and so is each visible group of 64 rows in a static batch. The `visibleEntries` figure of `measure` counts them. Divide `uploadBytes` by it: when only the camera moves, the result is about 4 bytes.
193
280
 
194
281
  Mark objects and batches static when they rarely move, and call `markDirty` for the rows that you change. See [Static and dynamic objects](../concepts/static-dynamic.md).
195
282
 
196
- The render worker picks how each upload travels, so you do not need to. Uploads from 64 KiB up to 4 MiB have two routes: the direct write call, and staging buffers that the browser keeps mapped. The render worker times both on the device and uses the faster one. In Chrome the staging buffers are 3 to 6 times faster. In Safari the direct call is faster at every size.
283
+ The render worker picks how each upload travels, so you do not need to. The [instancing demo](https://github.com/null3d-engine/null3d/tree/main/examples/instances) moves 100,000 columns this way, by rewriting their rows in every frame.
284
+
285
+ <details>
286
+ <summary>Technical details: how uploads travel</summary>
287
+
288
+ Uploads from 64 KiB up to 4 MiB have two routes: the direct write call, and staging buffers that the browser keeps mapped. The render worker times both on the device and uses the faster one. In Chrome the staging buffers are 3 to 6 times faster. In Safari the direct call is faster at every size.
289
+
290
+ </details>
197
291
 
198
292
  Textures upload in bands of rows, spread over frames. Each frame sends no more texel bytes than the preset's upload budget, from 2 MiB on Low to 16 MiB on Ultra. So loading many textures does not make one frame slow, but a large texture takes several frames to arrive. [Textures](../api/textures.md) covers the budget, and [Phones and tablets](phones.md) covers texture memory.
199
293
 
@@ -209,11 +303,11 @@ Animated characters also cost skinning work and memory:
209
303
  - The skinning pass holds at most 1 GiB of skinned vertices on most devices. A crowd past it gets [E1501](../errors/E1501.md). [Limits of skinning](../api/animation.md#limits-of-skinning) lists every limit.
210
304
  - The job workers sample and blend each character's clips in every frame. Give a far character more frames between its updates with [`animator.setUpdateInterval`](../api/animation.md#crowds), and hold the ones near the camera at 1. The `farAnimationInterval` quality setting gives the interval for far characters, and the governor raises it when frames take too long.
211
305
 
212
- For a large crowd, use models with fewer vertices, give far characters a longer update interval, and draw fewer shadow cascades on phones.
306
+ For a large crowd, use models with fewer vertices, give far characters a longer update interval, and draw fewer shadow cascades on phones. The [battle comparison](https://github.com/null3d-engine/null3d/tree/main/examples/compare/battle) draws a crowd of animated knights and mechs in both engines.
213
307
 
214
308
  ## See-through objects
215
309
 
216
- Blended objects draw after the opaque ones, farthest first, and a run of neighbors that share a mesh and a material draws together. Many blended objects therefore cost many draws. A double-sided blended material draws twice, back faces first, as three.js draws it, so its near side always covers its far side. Solid double-sided materials draw once.
310
+ Blended objects draw after the opaque ones, farthest first, and a run of neighbors that share a mesh and a material draws together. Many blended objects therefore cost many draws. A double-sided blended material draws twice, back faces first, so its near side always covers its far side. Solid double-sided materials draw once.
217
311
 
218
312
  The second draw costs about as much as the first. In the S2 benchmark with every box blended and double-sided, the transparent pass took 1.88 ms of GPU time on a Mac with one draw per box, and 4.09 ms with two. For flat surfaces, such as leaves and panes of glass, whose two faces never overlap on screen, set `forceSinglePass: true`. It saves the second draw: [Double-sided blended surfaces](../api/materials.md#double-sided-blended-surfaces). Masked and hashed materials need no sort and no second draw, and neither do materials with alpha to coverage.
219
313
 
@@ -227,7 +321,7 @@ Textures take most of a scene's GPU memory. Each preset gives textures a memory
227
321
 
228
322
  ## Picking, labels, sprites and lines
229
323
 
230
- - Pointer events on objects cast one ray for each event, only while some object has a handler. A raycast tests only the triangles near the ray, through a tree over each mesh. The job workers build a mesh's tree on its first query. For large meshes, `assets optimize` stores the trees in the file, so their first query waits for no build ([Blockers and stored trees](assets-pipeline.md#blockers-and-stored-trees)). The call `scene.raycastBatch` casts many rays at once on the job workers ([Raycasting](../api/raycast.md)).
324
+ - Pointer events on objects cast one ray for each event, only while some object has a handler. A raycast tests only the triangles near the ray, through a tree over each mesh. The job workers build a mesh's tree on its first query. For large meshes, `assets optimize` stores the trees in the file, so their first query waits for no build ([Stored raycast trees](assets-pipeline.md#stored-raycast-trees)). The call `scene.raycastBatch` casts many rays at once on the job workers ([Raycasting](../api/raycast.md)).
231
325
  - Labels move their HTML elements only when they move by half a CSS pixel or more. The page reads every label before it writes any style. So the page runs no layout between them ([Labels](../api/ui.md)).
232
326
  - A sprite, point or line batch is one draw, whatever its size. Each sprite, point or segment costs about what an instance row costs, so the rules of [Moving objects cost uploads](#moving-objects-cost-uploads) apply to them too.
233
327
  - On WebGL2, the vertex shader of each pass morphs a morphed mesh again, and each object keeps only its largest weights: 8 on Low. On WebGPU, the skinning pass morphs each mesh once per frame.
@@ -241,7 +335,7 @@ The S1-cells benchmark spreads S1-static's 100,000 boxes over 8 x 8 cells, 8 km
241
335
  - On WebGL2, cells cut the busiest thread's CPU time from 0.21 ms to 0.07 ms per frame. The list of visible objects fell from 1,517 entries to 79.
242
336
  - On WebGPU the GPU culls, so the CPU time stayed at 0.10 ms. The culling pass took 0.025 ms of GPU time with cells, and 0.039 ms without them.
243
337
 
244
- So in a large world, keep the objects that never move static, under static parents. A static object under a dynamic parent moves with it, so every view tests it. The `?cells=off` switch culls without cells, to compare.
338
+ So in a large world, keep the objects that never move static, under static parents. A static object under a dynamic parent moves with it, so every view tests it. The `?cells=off` switch culls without cells, to compare. The [large world demo](https://github.com/null3d-engine/null3d/tree/main/examples/large-world) spreads static batches across several grid cells on a road 6,378 km from the origin.
245
339
 
246
340
  ## Point and spot lights
247
341
 
@@ -249,14 +343,26 @@ The engine lights each pixel with the point and spot lights of its cluster only,
249
343
 
250
344
  - A pixel's cost grows with the lights whose ranges reach its cluster. Give each light the shortest range that keeps its look, because a longer range reaches more clusters.
251
345
  - A light near the camera covers much of the screen, and its range reaches many clusters. Many large lights near the camera cost the most.
252
- - Each frame the engine lists the lights of each cluster. On WebGPU a compute pass does it on the GPU, and the CPU only uploads the light list. On WebGL2 the job workers do it on the CPU. There, a few hundred small lights take a fraction of a millisecond, on the sketch thread alone when the work is small.
346
+ - Each frame the engine lists the lights of each cluster. On WebGPU a compute pass does it on the GPU, and the CPU only uploads the light list. Its pipelines come with the first frame only when the scene holds a point, spot or area light. Otherwise they build once the first frame shows, and a light that comes in the first frames after it lights nothing until they are built. On WebGL2 the job workers do it on the CPU. There, a few hundred small lights take a fraction of a millisecond, on the sketch thread alone when the work is small.
253
347
  - A frame uploads its lights when the lights or the camera moved: 80 bytes for each light. On WebGL2 it also uploads the lists: 14 KB for the clusters, and 4 bytes for each light in each cluster. A still scene seen from a still camera uploads nothing.
254
348
 
255
349
  The camera lists up to 1,024 point and spot lights in a frame, the ones nearest to it, and up to 128 in each cluster.
256
350
 
257
- Rectangle and tube lights join the same clusters, and cost a pixel several times what a point light costs. Each takes two integrals over the light's outline, and the first area light of a pixel's cluster reads their tables. A light with an image adds two more reads. The quality preset's `areaLights` caps how many shade in a frame, the ones that give the camera the most light first. The caps are 4 on Low, 8 on Medium, 16 on High and 32 on Ultra. A light that crosses the cap fades over 8 frames, and while it fades, it shades beside the lights that the cap keeps. Give area lights short ranges, as for point lights. A pixel whose cluster holds no area light pays nothing for them. A scene without area lights draws with shaders that leave their code out.
351
+ Rectangle and tube lights join the same clusters, and cost a pixel several times what a point light costs.
352
+
353
+ - The quality preset's `areaLights` caps how many shade in a frame, the ones that give the camera the most light first. The caps are 4 on Low, 8 on Medium, 16 on High and 32 on Ultra.
354
+ - A light that crosses the cap fades over 8 frames, and while it fades, it shades beside the lights that the cap keeps.
355
+ - Give area lights short ranges, as for point lights.
356
+ - A pixel whose cluster holds no area light pays nothing for them. A scene without area lights draws with shaders that leave their code out.
258
357
 
259
- The S3 benchmark lights 20,000 still boxes with 256 moving point lights. In Chrome on a MacBook Pro, the engine's own work took 0.07 ms per frame on WebGPU, where the GPU lists the lights. The compute pass that lists them took about 0.2 ms of GPU time. three.js's WebGL renderer cannot draw this scene on that Mac. Its shader for 256 point lights needs more uniforms than the GPU gives a fragment shader.
358
+ <details>
359
+ <summary>Technical details: what an area light costs</summary>
360
+
361
+ Each area light takes two integrals over the light's outline, and the first area light of a pixel's cluster reads their tables. A light with an image adds two more reads.
362
+
363
+ </details>
364
+
365
+ The S3 benchmark lights 20,000 still boxes with 256 moving point lights. In Chrome on a MacBook Pro, the engine's own work took 0.07 ms per frame on WebGPU, where the GPU lists the lights. The compute pass that lists them took about 0.2 ms of GPU time. three.js's WebGL renderer cannot draw this scene on that Mac. Its shader for 256 point lights needs more uniforms than the GPU gives a fragment shader. The [area lights demo](https://github.com/null3d-engine/null3d/tree/main/examples/area-lights) lights a wet street with rectangle windows and tube-light neon. The [night town comparison](https://github.com/null3d-engine/null3d/tree/main/examples/compare/night-town) puts many lights in both engines.
260
366
 
261
367
  ## Shadows
262
368
 
@@ -277,31 +383,55 @@ Each post effect adds full-screen work, which grows with the pixels drawn:
277
383
  - Each custom effect that reads other pixels costs a full-screen pass. The engine joins the effects that read only their own pixel, and can fold the last into the final pass ([Custom passes](custom-passes.md#cost)).
278
384
  - A scene pass culls and draws the scene again, at the size of its texture. Keep the texture small, and give the pass a cadence with `render.setPassEvery` so it draws in some frames only. A pass that nothing shows costs nothing ([Render to a texture](custom-passes.md#drawing-less-often)).
279
385
 
386
+ The [post effects demo](https://github.com/null3d-engine/null3d/tree/main/examples/post-effects) chains several effects in one neon alley. The [security camera demo](https://github.com/null3d-engine/null3d/tree/main/examples/security-camera) draws a scene pass into a monitor.
387
+
280
388
  ## Occlusion culling
281
389
 
282
390
  Occlusion culling skips the objects that lie wholly behind others. Each GPU path does this work in its own place, so each costs something different.
283
391
 
284
392
  ### Blockers on WebGL2
285
393
 
286
- On WebGL2, the `softwareOcclusion` option of `createEngine` turns occlusion culling on, and every preset leaves it off. Objects marked with `setOccluder(true)` or the `occluder` option then hide what lies wholly behind them, and the GPU skips it. The job workers draw the blockers into a small depth buffer each frame, so each blocker costs CPU time on them. Mark a few large, solid objects that hide many others, such as the buildings along a street. A model from `assets optimize` blocks with every mesh that got a blocker, small props too. Each such blocker takes only a few dozen triangles, and the engine skips those under 2 pixels of the buffer. Where the job workers' time grows, keep the small ones from blocking with `setOccluder(false)`, or with `"occluder": false` in the mesh's extras ([Blockers and stored trees](assets-pipeline.md#blockers-and-stored-trees)). Then compare `occludedEntries` with `visibleEntries` in `measure`, and the job workers' time with the `softwareOcclusion` setting on and off. [Culling](../concepts/culling.md#software-occlusion-culling-on-webgl2) explains the method and its limits.
394
+ On WebGL2, the `softwareOcclusion` option of `createEngine` turns occlusion culling on, and every preset leaves it off. Objects marked with `setOccluder(true)` or the `occluder` option then hide what lies wholly behind them, and the GPU skips it. The job workers draw the blockers into a small depth buffer each frame, so each blocker costs CPU time on them.
395
+
396
+ Mark a few large, solid objects that hide many others, such as the buildings along a street. Where the job workers' time grows, keep the small ones from blocking with `setOccluder(false)`, or with `"occluder": false` in the mesh's extras ([Blockers](assets-pipeline.md#blockers)). Then compare `occludedEntries` with `visibleEntries` in `measure`, and the job workers' time with the `softwareOcclusion` setting on and off. [Culling](../concepts/culling.md#software-occlusion-culling-on-webgl2) explains the method and its limits.
397
+
398
+ <details>
399
+ <summary>Technical details: what a blocker costs</summary>
400
+
401
+ A model from `assets optimize` blocks with every mesh that got a blocker, small props too. Each such blocker takes only a few dozen triangles, and the engine skips those under 2 pixels of the buffer.
402
+
403
+ </details>
287
404
 
288
405
  ### Occlusion culling on the GPU
289
406
 
290
- On WebGPU, occlusion culling runs on the GPU, in two phases for each camera, and High and Ultra turn it on for desktops. The GPU picks the large opaque objects that hide others itself. It adds a depth draw of those objects, a depth pyramid and a second culling pass. A check during play keeps these passes only while they hide at least a tenth of the objects in view and the GPU's frame gets no longer. `setOccluder(false)` keeps an object whose depth costs more than it hides out of the occluders. Compare `gpuMs` with `?occlusion=on` and `?occlusion=off` to see what it saves ([Culling](../concepts/culling.md#gpu-occlusion-culling-on-webgpu)).
407
+ On WebGPU, occlusion culling runs on the GPU, in two phases for each camera, and High and Ultra turn it on for desktops. The GPU picks the large opaque objects that hide others itself. It adds a depth draw of those objects, a depth pyramid and a second culling pass.
408
+
409
+ A check during play keeps these passes only while they hide at least a tenth of the objects in view and the GPU's frame gets no longer. `setOccluder(false)` keeps an object whose depth costs more than it hides out of the occluders. Compare `gpuMs` with `?occlusion=on` and `?occlusion=off` to see what it saves ([Culling](../concepts/culling.md#gpu-occlusion-culling-on-webgpu)).
291
410
 
292
411
  ## The depth prepass
293
412
 
294
413
  With the depth prepass, the engine draws the depth of the opaque objects first. The opaque pass then shades each pixel once, for its nearest surface. It saves GPU time where objects hide many others and their shading costs much. It always costs a second pass over the vertices.
295
414
 
415
+ ![A small test scene in the overdraw view, brighter where surfaces overlap under a see-through box.](../images/guides/performance/overdraw-view.webp)
416
+
417
+ The overdraw view.
418
+
296
419
  On WebGL2, every preset draws the prepass. On Apple GPUs, a depth prepass restores early rejection of hidden pixels in WebGL2. In the S4 benchmark on an iPad, the prepass took WebGL2 from 38 to 60 frames per second on Low. On Medium it went from 17 to 37. On Android phones it kept their frame rates. [Quality presets](../concepts/quality-presets.md#the-depth-prepass) gives the figures.
297
420
 
298
- On WebGPU, every preset leaves it off. In the S2 benchmark in Chrome on a MacBook Pro, the prepass raised WebGPU's GPU time per frame from 0.28 ms to 0.40 ms. It doubled the draw calls, from 101 to 201. S2's trees hide few others, and their shading is cheap. The `depthPrepass` option of `createEngine` replaces the preset's choice on either path. Measure your own scene with `?prepass=on` and `?prepass=off`, and compare `gpuMs`. `debug.view('overdraw')` shows where many surfaces cover one pixel, in development builds ([Debug drawing and stats](../api/debug.md)).
421
+ On WebGPU, every preset leaves it off. In the S2 benchmark in Chrome on a MacBook Pro, the prepass raised WebGPU's GPU time per frame from 0.28 ms to 0.40 ms. It doubled the draw calls, from 101 to 201. S2's trees hide few others, and their shading is cheap.
422
+
423
+ The `depthPrepass` option of `createEngine` replaces the preset's choice on either path. Measure your own scene with `?prepass=on` and `?prepass=off`, and compare `gpuMs`. `debug.view('overdraw')` shows where many surfaces cover one pixel, in development builds ([Debug drawing and stats](../api/debug.md)).
299
424
 
300
425
  ## Measure
301
426
 
302
- For a quick look while the scene runs, add `?stats` to the page's address, or call `debug.stats(true)` in the sketch. The overlay's header shows the frame rate. Its card shows each thread's CPU time and the GPU's time against the engine's target frame rate, with your code apart from the engine's work. It also shows memory, draw calls, triangles and objects drawn, and what holds the frame rate back ([Debug drawing and stats](../api/debug.md#stats-overlay-and-frame-figures)). While the card is open, the engine times one frame in eleven on the GPU, which costs a little GPU time. For figures that you compare between changes, measure.
427
+ For a quick look while the scene runs, add `?stats` to the page's address, or call `debug.stats(true)` in the sketch. The overlay's header shows the frame rate. Its card shows each thread's CPU time and the GPU's time against the engine's target frame rate, with your code apart from the engine's work. It also shows memory, draw calls, triangles and objects drawn, and what holds the frame rate back ([Debug drawing and stats](../api/debug.md#stats-overlay-and-frame-figures)).
303
428
 
304
- `engine.measure(seconds)` on the page records every frame for that many seconds and returns these figures:
429
+ While the card is open, the engine times one frame in eleven on the GPU, which costs a little GPU time. For figures that you compare between changes, measure.
430
+
431
+ `engine.measure(seconds)` on the page records every frame for that many seconds and returns these figures. The [FrameMetrics type reference](../api/reference/debug.md#framemetrics) gives their types.
432
+
433
+ <details>
434
+ <summary>Technical details: every figure that engine.measure returns</summary>
305
435
 
306
436
  | Figure | What it is |
307
437
  | --- | --- |
@@ -326,19 +456,35 @@ For a quick look while the scene runs, add `?stats` to the page's address, or ca
326
456
  | `pipelines` | GPU pipelines built, which can stall the frame they happen in |
327
457
  | `skippedDraws` | Draws skipped because their pipeline was still building, so their objects were missing from those frames |
328
458
  | `memory` | The engine's WebAssembly memory and the JavaScript heap |
329
- | `load` | The start's times in milliseconds: the GPU probe, the core's download and compile, `createEngine`, and the first frame's submit and finish. It also gives the pipelines that the first frame built, and how long they took |
459
+ | `load` | The start's times in milliseconds: the GPU probe, the core's download and compile, `createEngine`, and the first frame's submit and finish. `load.drawingStart` gives when the thread that draws had its GPU device, its shader file and its renderer. It also gives the pipelines that the first frame built, and how long they took ([A fast start](start-time.md#measure-a-start)) |
330
460
  | `downloadBytes` | The size of the engine core's WebAssembly file as the page downloaded it |
331
461
  | `gpuLosses` | Times the browser took the GPU away and the engine carried on with a new device |
332
462
  | `lostRecords` | Frames that the figures miss, because the page read their records too late. It is 0 in a clean run |
333
463
  | `slow` | With `slowMs`, every frame whose interval broke it: the frame's index, the time it presented, the intervals before and after it, whether it is the window's first frame, and the frame's own GPU parts and thread times |
334
464
 
465
+ </details>
466
+
335
467
  The sketch worker's steps are `update`, `commands`, `transforms`, `batches`, `cull` and `record`, and the render worker's is `replay`. A thread's time less its `update` step is the engine's own work on that thread.
336
468
 
337
- `engine.measure(seconds, { slowMs: 50 })` reports each frame that breaks the ceiling, with the frame's own figures rather than an average over many frames. Each slow frame gives the pass that stalled rather than the passes of a nearby sampled frame: add `?gpu-samples=every` to the page's address, and the engine times every drawn frame instead of one in eleven. The timing costs the draw, so a rate taken with it is not the device's rate. The measuring code itself loads before the window opens, so the window's first frame is the scene's own and not the engine's bookkeeping.
469
+ `engine.measure(seconds, { slowMs: 50 })` reports each frame that breaks the ceiling, with the frame's own figures rather than an average over many frames. Each slow frame gives the pass that stalled rather than the passes of a nearby sampled frame: add `?gpu-samples=every` to the page's address, and the engine times every drawn frame instead of one in eleven. The timing costs the draw, so a rate taken with it is not the device's rate.
470
+
471
+ <details>
472
+ <summary>Technical details: how the slow-frame timing works</summary>
473
+
474
+ The measuring code itself loads before the window opens, so the window's first frame is the scene's own and not the engine's bookkeeping.
475
+
476
+ </details>
338
477
 
339
478
  To measure your page with no code, run `bunx @null3d/cli bench` in your project's folder. It builds the project for production and opens the page in a headless browser with the `?bench` switch. That switch publishes the running engine as `window.__null3dEngine`. Then `bench` takes 5 fresh runs of 30 seconds, each after 5 seconds of warm-up. It prints the median and the spread of the figures above ([The `null3d` command](../cli/null3d.md#bench)).
340
479
 
341
- Chrome measures the heap of the page and its workers only when every worker answers, or after a minute. While a measurement runs, the engine's idle job workers stop waiting in the job loop and answer it between frame jobs, so a sample takes about a second. Chrome also adds shared memory, such as the engine's own, to each worker's figure. A render worker whose own heap is 1.4 MB can show as 52 MB. The `jsHeapNote` field says when the figures cover only the page.
480
+ Chrome adds shared memory, such as the engine's own, to each worker's heap figure. A render worker whose own heap is 1.4 MB can show as 52 MB. The `jsHeapNote` field says when the figures cover only the page.
481
+
482
+ <details>
483
+ <summary>Technical details: how Chrome measures the heap</summary>
484
+
485
+ Chrome measures the heap of the page and its workers only when every worker answers, or after a minute. While a measurement runs, the engine's idle job workers stop waiting in the job loop and answer it between frame jobs, so a sample takes about a second.
486
+
487
+ </details>
342
488
 
343
489
  ### The presented rate, the completed rate and GPU time
344
490
 
@@ -350,7 +496,14 @@ Three figures show whether the GPU keeps up:
350
496
 
351
497
  The lower of the two rates is the rate that users see. The engine lets at most two frames wait unfinished on the GPU. So when the GPU falls behind, the presented rate falls to the completed rate, and `gpuLatencyMs` stays near two completed frame intervals. A rate below `refreshHz` with `gpuLatencyMs` near two frame intervals means that the GPU limits the frame rate. On WebGL2, and on a device without GPU timers, `completedFps` and `gpuLatencyMs` are the GPU's only signal.
352
498
 
353
- Firefox reports finished WebGPU frames to the engine about a frame late. There the limit holds back frames that the GPU has already finished, which costs frame rate when the GPU is busy. In a GPU-bound test on a Mac, Firefox's WebGPU path drew 15% fewer frames at a load that used 60% of the GPU. Under heavier load it drew far fewer. Firefox's WebGL2 path lost none.
499
+ Firefox reports finished WebGPU frames to the engine about a frame late. There the limit holds back frames that the GPU has already finished, which costs frame rate when the GPU is busy.
500
+
501
+ <details>
502
+ <summary>Technical details: Firefox's WebGPU frame rate</summary>
503
+
504
+ In a GPU-bound test on a Mac, Firefox's WebGPU path drew 15% fewer frames at a load that used 60% of the GPU. Under heavier load it drew far fewer. Firefox's WebGL2 path lost none.
505
+
506
+ </details>
354
507
 
355
508
  The engine checks a WebGL2 fence at its next frame callback, so there `gpuLatencyMs` rounds up to a frame interval. In Safari, a worker that draws with WebGPU waits for the GPU at the end of each frame, so there `gpuLatencyMs` stays near one frame interval. Some GPUs, such as Apple's, work on two frames at once, so a frame's `gpuMs` can be longer than the time between completed frames.
356
509
 
@@ -359,6 +512,7 @@ The engine checks a WebGL2 fence at its next frame callback, so there `gpuLatenc
359
512
  - Measure a production build, as your users get it. Development builds check each call's arguments. In each frame they also check every static object, and a share of the rows of static batches. In the S2 benchmark on a MacBook Pro, the check of static objects cost about 0.06 ms per frame on WebGPU. It cost 0.03 ms on WebGL2. These checks grow with the scene, so a large scene pays more.
360
513
  - Know which build a page runs. `vite build` with the null3D plugin makes a production build, and so does the CDN build's production entry, `lib/index.js`. These run as development builds: the Vite dev server, `bunx @null3d/cli shot` and `test`, and the CDN build's development entry, `lib-dev/index.js`. So does engine code built without the null3D plugin, or with no bundler at all ([Try null3D from a CDN](../getting-started/cdn.md#production-and-development-entries)).
361
514
  - To compare null3D with three.js, time a production build of each engine, on the same page size and the same computer.
515
+ - Start a measurement of steady play once `engine.presetChecked` has resolved. On a first visit the preset check runs in the first frames of play. It can lower the preset inside your window ([The preset check](../concepts/quality-presets.md#the-preset-check)). `bunx @null3d/cli bench` waits for it.
362
516
  - Let the sketch run for several seconds before you measure, so that the browser has optimized your per-frame code.
363
517
  - Keep the page visible, the screen unlocked and the display awake. Safari stops running a page while the Mac is locked.
364
518
  - Compare runs at the same display refresh rate. `refreshHz` records it with each measurement. Runs at 120 and at 144 frames per second differed by about 10% for both engines.