@null3d/engine 0.1.0 → 0.1.2

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 (388) hide show
  1. package/dist/wasm/single/null3d.js +10 -8
  2. package/dist/wasm/single/null3d_bg.wasm +0 -0
  3. package/dist/wasm/threaded/null3d.js +10 -8
  4. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  5. package/docs/api/animation.md +96 -24
  6. package/docs/api/assets.md +99 -29
  7. package/docs/api/cameras.md +38 -7
  8. package/docs/api/controls.md +47 -23
  9. package/docs/api/debug.md +105 -35
  10. package/docs/api/engine.md +108 -32
  11. package/docs/api/feature-draws.md +21 -15
  12. package/docs/api/feature-effects.md +8 -8
  13. package/docs/api/feature-instances.md +68 -17
  14. package/docs/api/features.md +68 -37
  15. package/docs/api/geometry.md +83 -14
  16. package/docs/api/grass.md +55 -13
  17. package/docs/api/impostors.md +92 -50
  18. package/docs/api/input.md +22 -9
  19. package/docs/api/lights.md +67 -16
  20. package/docs/api/lines.md +38 -13
  21. package/docs/api/materials.md +187 -59
  22. package/docs/api/math.md +6 -6
  23. package/docs/api/objects.md +40 -15
  24. package/docs/api/page.md +58 -7
  25. package/docs/api/particles.md +36 -11
  26. package/docs/api/points.md +18 -8
  27. package/docs/api/post.md +57 -23
  28. package/docs/api/quality.md +36 -16
  29. package/docs/api/raycast.md +57 -24
  30. package/docs/api/reference/animation.md +1 -2
  31. package/docs/api/reference/assets.md +7 -4
  32. package/docs/api/reference/cameras.md +3 -2
  33. package/docs/api/reference/controls.md +59 -2
  34. package/docs/api/reference/debug.md +58 -6
  35. package/docs/api/reference/engine.md +40 -10
  36. package/docs/api/reference/feature-draws.md +3 -4
  37. package/docs/api/reference/feature-effects.md +2 -3
  38. package/docs/api/reference/feature-instances.md +5 -4
  39. package/docs/api/reference/features.md +7 -4
  40. package/docs/api/reference/geometry.md +132 -21
  41. package/docs/api/reference/grass.md +62 -2
  42. package/docs/api/reference/impostors.md +120 -16
  43. package/docs/api/reference/input.md +1 -2
  44. package/docs/api/reference/lights.md +4 -3
  45. package/docs/api/reference/lines.md +3 -4
  46. package/docs/api/reference/materials.md +7 -6
  47. package/docs/api/reference/math.md +13 -2
  48. package/docs/api/reference/objects.md +2 -3
  49. package/docs/api/reference/particles.md +31 -6
  50. package/docs/api/reference/points.md +2 -3
  51. package/docs/api/reference/post.md +4 -3
  52. package/docs/api/reference/quality.md +1 -2
  53. package/docs/api/reference/raycast.md +1 -2
  54. package/docs/api/reference/render.md +4 -3
  55. package/docs/api/reference/scene.md +24 -5
  56. package/docs/api/reference/sketch.md +11 -11
  57. package/docs/api/reference/sound.md +33 -2
  58. package/docs/api/reference/splats.md +42 -3
  59. package/docs/api/reference/sprites.md +2 -3
  60. package/docs/api/reference/tasks.md +16 -3
  61. package/docs/api/reference/terrain.md +26 -5
  62. package/docs/api/reference/textures.md +1 -2
  63. package/docs/api/reference/three-compat.md +18 -7
  64. package/docs/api/reference/time.md +1 -2
  65. package/docs/api/reference/ui.md +10 -7
  66. package/docs/api/reference/vertex-draws.md +2 -3
  67. package/docs/api/reference/water.md +78 -5
  68. package/docs/api/reference/wind.md +15 -2
  69. package/docs/api/render.md +67 -25
  70. package/docs/api/scene.md +129 -36
  71. package/docs/api/sketch.md +45 -19
  72. package/docs/api/sound.md +48 -12
  73. package/docs/api/splats.md +42 -15
  74. package/docs/api/sprites.md +8 -6
  75. package/docs/api/tasks.md +31 -22
  76. package/docs/api/terrain.md +44 -12
  77. package/docs/api/textures.md +61 -12
  78. package/docs/api/three-compat.md +15 -7
  79. package/docs/api/time.md +3 -5
  80. package/docs/api/ui.md +18 -10
  81. package/docs/api/vertex-draws.md +13 -12
  82. package/docs/api/water.md +111 -67
  83. package/docs/api/wind.md +61 -15
  84. package/docs/cli/null3d.md +90 -15
  85. package/docs/concepts/architecture.md +69 -23
  86. package/docs/concepts/assets.md +57 -16
  87. package/docs/concepts/backends.md +68 -24
  88. package/docs/concepts/color-management.md +42 -13
  89. package/docs/concepts/culling.md +68 -47
  90. package/docs/concepts/handles.md +14 -5
  91. package/docs/concepts/instances.md +72 -23
  92. package/docs/concepts/large-worlds.md +17 -7
  93. package/docs/concepts/lighting.md +117 -44
  94. package/docs/concepts/lod.md +128 -33
  95. package/docs/concepts/materials.md +43 -12
  96. package/docs/concepts/particle-buffer.md +48 -35
  97. package/docs/concepts/post-processing.md +77 -14
  98. package/docs/concepts/quality-preset-tables.md +3 -2
  99. package/docs/concepts/quality-presets.md +122 -39
  100. package/docs/concepts/render-graph.md +56 -21
  101. package/docs/concepts/render-layers.md +9 -5
  102. package/docs/concepts/shadows.md +96 -25
  103. package/docs/concepts/static-dynamic.md +22 -7
  104. package/docs/cookbook/index.md +163 -119
  105. package/docs/data/threejs-mapping.json +301 -340
  106. package/docs/errors/E1101.md +23 -5
  107. package/docs/errors/E1102.md +11 -3
  108. package/docs/errors/E1103.md +11 -3
  109. package/docs/errors/E1104.md +11 -3
  110. package/docs/errors/E1105.md +13 -5
  111. package/docs/errors/E1106.md +11 -3
  112. package/docs/errors/E1107.md +15 -5
  113. package/docs/errors/E1108.md +11 -3
  114. package/docs/errors/E1109.md +32 -6
  115. package/docs/errors/E1110.md +23 -5
  116. package/docs/errors/E1111.md +11 -3
  117. package/docs/errors/E1112.md +11 -3
  118. package/docs/errors/E1203.md +12 -4
  119. package/docs/errors/E1204.md +11 -3
  120. package/docs/errors/E1205.md +11 -3
  121. package/docs/errors/E1206.md +28 -6
  122. package/docs/errors/E1207.md +11 -3
  123. package/docs/errors/E1208.md +12 -3
  124. package/docs/errors/E1209.md +11 -3
  125. package/docs/errors/E1213.md +27 -5
  126. package/docs/errors/E1214.md +11 -3
  127. package/docs/errors/E1215.md +31 -6
  128. package/docs/errors/E1216.md +31 -6
  129. package/docs/errors/E1217.md +29 -6
  130. package/docs/errors/E1218.md +22 -6
  131. package/docs/errors/E1219.md +11 -3
  132. package/docs/errors/E1220.md +24 -5
  133. package/docs/errors/E1221.md +24 -5
  134. package/docs/errors/E1222.md +11 -3
  135. package/docs/errors/E1223.md +39 -6
  136. package/docs/errors/E1224.md +11 -3
  137. package/docs/errors/E1225.md +11 -3
  138. package/docs/errors/E1301.md +11 -3
  139. package/docs/errors/E1302.md +11 -3
  140. package/docs/errors/E1303.md +11 -3
  141. package/docs/errors/E1304.md +11 -3
  142. package/docs/errors/E1305.md +13 -3
  143. package/docs/errors/E1306.md +11 -3
  144. package/docs/errors/E1307.md +23 -6
  145. package/docs/errors/E1308.md +31 -0
  146. package/docs/errors/E1401.md +11 -3
  147. package/docs/errors/E1402.md +13 -5
  148. package/docs/errors/E1403.md +11 -3
  149. package/docs/errors/E1404.md +13 -3
  150. package/docs/errors/E1405.md +15 -4
  151. package/docs/errors/E1406.md +31 -5
  152. package/docs/errors/E1407.md +11 -3
  153. package/docs/errors/E1408.md +11 -3
  154. package/docs/errors/E1409.md +11 -3
  155. package/docs/errors/E1410.md +13 -5
  156. package/docs/errors/E1411.md +11 -3
  157. package/docs/errors/E1412.md +29 -6
  158. package/docs/errors/E1413.md +11 -3
  159. package/docs/errors/E1414.md +11 -3
  160. package/docs/errors/E1415.md +11 -3
  161. package/docs/errors/E1416.md +27 -6
  162. package/docs/errors/E1417.md +11 -3
  163. package/docs/errors/E1418.md +12 -3
  164. package/docs/errors/E1419.md +13 -5
  165. package/docs/errors/E1420.md +11 -3
  166. package/docs/errors/E1421.md +11 -3
  167. package/docs/errors/E1422.md +12 -3
  168. package/docs/errors/E1423.md +12 -3
  169. package/docs/errors/E1424.md +24 -5
  170. package/docs/errors/E1425.md +11 -3
  171. package/docs/errors/E1426.md +11 -3
  172. package/docs/errors/E1430.md +11 -3
  173. package/docs/errors/E1431.md +11 -3
  174. package/docs/errors/E1432.md +11 -3
  175. package/docs/errors/E1433.md +11 -3
  176. package/docs/errors/E1434.md +15 -6
  177. package/docs/errors/E1435.md +11 -3
  178. package/docs/errors/E1436.md +11 -3
  179. package/docs/errors/E1437.md +14 -6
  180. package/docs/errors/E1501.md +41 -6
  181. package/docs/errors/E1502.md +13 -3
  182. package/docs/errors/E1503.md +11 -3
  183. package/docs/errors/E1504.md +11 -3
  184. package/docs/errors/E1505.md +23 -5
  185. package/docs/errors/E1506.md +11 -3
  186. package/docs/errors/index.md +53 -29
  187. package/docs/getting-started/cdn.md +15 -9
  188. package/docs/getting-started/first-scene.md +20 -12
  189. package/docs/getting-started/hosting.md +113 -63
  190. package/docs/getting-started/install.md +39 -24
  191. package/docs/getting-started/network-use.md +31 -21
  192. package/docs/getting-started/project-structure.md +20 -8
  193. package/docs/getting-started/third-party-notices.md +6 -10
  194. package/docs/guides/accessibility.md +4 -4
  195. package/docs/guides/add-ons.md +83 -13
  196. package/docs/guides/agents.md +13 -14
  197. package/docs/guides/assets-pipeline.md +294 -72
  198. package/docs/guides/audio.md +17 -15
  199. package/docs/guides/baked-light-data.md +44 -23
  200. package/docs/guides/car-paint.md +37 -31
  201. package/docs/guides/content-pages.md +86 -29
  202. package/docs/guides/custom-passes.md +59 -17
  203. package/docs/guides/custom-shaders.md +54 -37
  204. package/docs/guides/debugging.md +31 -41
  205. package/docs/guides/deploying.md +10 -27
  206. package/docs/guides/deterministic-simulation.md +23 -16
  207. package/docs/guides/first-use-shaders.md +83 -45
  208. package/docs/guides/lens-kit.md +29 -26
  209. package/docs/guides/loading-screens.md +74 -30
  210. package/docs/guides/multiple-views.md +22 -11
  211. package/docs/guides/performance.md +188 -37
  212. package/docs/guides/phones.md +71 -19
  213. package/docs/guides/physics.md +6 -10
  214. package/docs/guides/screens.md +41 -29
  215. package/docs/guides/start-time.md +126 -85
  216. package/docs/guides/testing.md +137 -98
  217. package/docs/guides/ui-overlays.md +17 -12
  218. package/docs/guides/video-textures.md +14 -13
  219. package/docs/images/api/animation/character.webp +0 -0
  220. package/docs/images/api/animation/look-at-ring.webp +0 -0
  221. package/docs/images/api/animation/morph-tulips.webp +0 -0
  222. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  223. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  224. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  225. package/docs/images/api/debug/debug-shapes.webp +0 -0
  226. package/docs/images/api/debug/levels-view.webp +0 -0
  227. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  228. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  229. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  230. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  231. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  232. package/docs/images/api/geometry/generators.webp +0 -0
  233. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  234. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  235. package/docs/images/api/grass/grass-grove.webp +0 -0
  236. package/docs/images/api/grass/grass-presets.webp +0 -0
  237. package/docs/images/api/grass/grass-shadow.webp +0 -0
  238. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  239. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  240. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  241. package/docs/images/api/lights/spot-cookies.webp +0 -0
  242. package/docs/images/api/lines/lines-lit.webp +0 -0
  243. package/docs/images/api/lines/lines-widths.webp +0 -0
  244. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  245. package/docs/images/api/materials/decals.webp +0 -0
  246. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  247. package/docs/images/api/materials/relief.webp +0 -0
  248. package/docs/images/api/materials/shader-inputs.webp +0 -0
  249. package/docs/images/api/materials/standard-grid.webp +0 -0
  250. package/docs/images/api/materials/subsurface.webp +0 -0
  251. package/docs/images/api/materials/translucency.webp +0 -0
  252. package/docs/images/api/objects/objects-turntable.webp +0 -0
  253. package/docs/images/api/particles/campfire.webp +0 -0
  254. package/docs/images/api/points/galaxy.webp +0 -0
  255. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  256. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  257. package/docs/images/api/render/reflection-mirror.webp +0 -0
  258. package/docs/images/api/render/security-camera.webp +0 -0
  259. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  260. package/docs/images/api/sound/sound-demo.webp +0 -0
  261. package/docs/images/api/splats/splats-demo.webp +0 -0
  262. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  263. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  264. package/docs/images/api/textures/canvas-screen.webp +0 -0
  265. package/docs/images/api/textures/mipmaps.webp +0 -0
  266. package/docs/images/api/vertex-draws/rain.webp +0 -0
  267. package/docs/images/api/water/ocean.webp +0 -0
  268. package/docs/images/api/water/water-demo.webp +0 -0
  269. package/docs/images/api/water/water-rain.webp +0 -0
  270. package/docs/images/api/water/waterfall.webp +0 -0
  271. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  272. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  273. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  274. package/docs/images/concepts/instances/instances.webp +0 -0
  275. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  276. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  277. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  278. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  279. package/docs/images/concepts/lighting/environment.webp +0 -0
  280. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  281. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  282. package/docs/images/concepts/lod/forest.webp +0 -0
  283. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  284. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  285. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  286. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  287. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  288. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  289. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  290. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  291. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  292. package/docs/images/cookbook/index/picking.webp +0 -0
  293. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  294. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  295. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  296. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  297. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  298. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  299. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  300. package/docs/images/index/showcase-island.webp +0 -0
  301. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  302. package/docs/images/shaders/builtins/builtins.webp +0 -0
  303. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  304. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  305. package/docs/images/shots.json +2231 -0
  306. package/docs/index.md +14 -23
  307. package/docs/moves.json +1 -0
  308. package/docs/nav.json +300 -0
  309. package/docs/pages.md +230 -212
  310. package/docs/porting/react-three-fiber.md +2 -6
  311. package/docs/porting/threejs-loop-and-threads.md +1 -5
  312. package/docs/porting/threejs-mapping.md +1248 -234
  313. package/docs/porting/threejs-materials.md +10 -5
  314. package/docs/porting/threejs-overview.md +26 -6
  315. package/docs/porting/threejs-postprocessing.md +2 -6
  316. package/docs/porting/threejs-shaders.md +16 -14
  317. package/docs/porting/threejs-unsupported.md +6 -6
  318. package/docs/porting/verification.md +0 -4
  319. package/docs/shaders/builtins.md +15 -4
  320. package/docs/shaders/library.md +9 -6
  321. package/docs/shaders/surface-functions.md +51 -16
  322. package/docs/shaders/wgsl-rules.md +12 -5
  323. package/lib/debug/debug.d.ts +2 -2
  324. package/lib/debug/draw.d.ts +2 -2
  325. package/lib/debug/draw.js +8 -4
  326. package/lib/debug/overlay-look.d.ts +6 -0
  327. package/lib/debug/overlay-look.js +29 -7
  328. package/lib/debug/overlay.js +15 -11
  329. package/lib/debug/stats-options.d.ts +13 -0
  330. package/lib/debug/stats-panel.d.ts +21 -6
  331. package/lib/debug/stats-panel.js +80 -13
  332. package/lib/errors/codes.d.ts +17 -3
  333. package/lib/errors/codes.js +116 -105
  334. package/lib/errors/engine-error.js +1 -1
  335. package/lib/errors/fixes.d.ts +1 -0
  336. package/lib/errors/fixes.js +19 -18
  337. package/lib/generated/shader-permutations.d.ts +6 -0
  338. package/lib/generated/shader-permutations.js +6 -0
  339. package/lib/gpu/variants.d.ts +8 -2
  340. package/lib/gpu/variants.js +39 -7
  341. package/lib/gpu/webgl2/programs.js +1 -1
  342. package/lib/gpu/webgpu/pipelines.js +13 -13
  343. package/lib/index.d.ts +1 -1
  344. package/lib/page/capabilities.d.ts +1 -1
  345. package/lib/page/engine.d.ts +29 -7
  346. package/lib/page/engine.js +79 -7
  347. package/lib/page/label-loop.js +9 -4
  348. package/lib/page/stats-switch.js +2 -0
  349. package/lib/page/switches.d.ts +6 -4
  350. package/lib/page/switches.js +20 -4
  351. package/lib/scene/baked-light.d.ts +2 -2
  352. package/lib/scene/fake-call-values.js +2 -2
  353. package/lib/scene/frame-cameras.d.ts +16 -4
  354. package/lib/scene/frame-cameras.js +28 -10
  355. package/lib/scene/gltf.d.ts +1 -1
  356. package/lib/scene/level-rule.d.ts +6 -5
  357. package/lib/scene/level-rule.js +2 -2
  358. package/lib/scene/particles.d.ts +7 -3
  359. package/lib/scene/particles.js +3 -1
  360. package/lib/scene/post.d.ts +3 -2
  361. package/lib/scene/resources.d.ts +15 -9
  362. package/lib/scene/scene.d.ts +18 -2
  363. package/lib/scene/scene.js +47 -5
  364. package/lib/scene/time-of-day.d.ts +10 -5
  365. package/lib/scene/time-of-day.js +11 -7
  366. package/lib/shader-artifact.json +1 -1
  367. package/lib/shared/labels.d.ts +5 -2
  368. package/lib/shared/labels.js +5 -2
  369. package/lib/shared/permutation-words.d.ts +8 -0
  370. package/lib/shared/permutation-words.js +14 -0
  371. package/lib/shared/recording.d.ts +13 -5
  372. package/lib/shared/recording.js +31 -10
  373. package/lib/shared/sketch-data.d.ts +9 -0
  374. package/lib/shared/sketch-data.js +57 -0
  375. package/lib/shared/tier.d.ts +9 -0
  376. package/lib/shared/tier.js +4 -1
  377. package/lib/shared/version.d.ts +1 -1
  378. package/lib/shared/version.js +1 -1
  379. package/lib/sketch/define-sketch.d.ts +16 -7
  380. package/lib/sketch/define-sketch.js +2 -1
  381. package/lib/sketch/runner.d.ts +4 -0
  382. package/lib/sketch/runner.js +5 -0
  383. package/lib/sketch/ui.js +4 -2
  384. package/lib/stats.d.ts +1 -0
  385. package/lib/workers/protocol.d.ts +10 -0
  386. package/lib/workers/render-worker.js +4 -1
  387. package/lib/workers/sketch-worker.js +4 -1
  388. package/package.json +1 -1
@@ -1,16 +1,12 @@
1
1
  ---
2
2
  id: guides/multiple-views
3
3
  title: Multiple views
4
- status: experimental
5
- since: "0.3"
6
4
  summary: "Split screens and picture in picture with scene.createView: a camera and a rectangle of the canvas, drawn after the camera's view in the same frame; per-view culling; the cost of each view."
7
5
  ---
8
6
 
9
7
  # Multiple views
10
8
 
11
- > Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
-
13
- A view draws the scene again from another camera, into a rectangle of the canvas, in the same frame as the camera's view. Use it for a split screen, a picture in picture, a rear-view mirror or a tactical inset. Two kinds of work are different:
9
+ A view draws the scene again from another camera, into a rectangle of the canvas, in the same frame as the camera's view. Use it for a split screen, a picture in picture, a rear-view mirror or a tactical inset. A view is not a render pass:
14
10
 
15
11
  - A **view** draws into the canvas, so the user sees it in place. `scene.createView` makes one.
16
12
  - A **pass** draws into a texture, which a material shows in the world, as a minimap on a screen does. [render.addPass](custom-passes.md#render-to-a-texture) makes one.
@@ -36,6 +32,10 @@ export default defineSketch(({ scene }) => {
36
32
 
37
33
  The camera's view draws the whole canvas first, and each view covers its rectangle afterwards. The camera's aspect ratio is the canvas's, so a half of its image is a crop of a wider view. For two half-width cameras, add a view for each half:
38
34
 
35
+ ![One canvas split into a high wide view and a low view among standing stones.](../images/guides/multiple-views/split-screen.webp)
36
+
37
+ Two cameras in one frame.
38
+
39
39
  ```ts
40
40
  const left = scene.createPerspectiveCamera({ fov: 50, position: [-4, 2, 6], target: [0, 1, 0] });
41
41
  const right = scene.createPerspectiveCamera({ fov: 50, position: [4, 2, 6], target: [0, 1, 0] });
@@ -99,20 +99,30 @@ A view's calls use the view's camera of the frame that last ran, with its lens a
99
99
 
100
100
  Each view culls the scene once more and draws it once more, at its rectangle's pixels. A picture in picture at a tenth of the canvas costs about a tenth of a scene draw. The camera's view always draws first, so a split screen of two halves costs the camera's draw and two view draws.
101
101
 
102
- The shadows cost nothing more: a view draws the sun's cascades and the point and spot lights' shadows that the camera's view made, as a scene pass does. The view draws the background, the environment's light, the material fog and the lights it sees. Its objects take no ambient occlusion or screen-space reflections, which shade the camera's view. The camera's volumetric fog and outline are added to the whole image after the views draw, so they also reach a view's rectangle.
102
+ The shadows cost nothing more: a view reuses the sun's cascades and the point and spot lights' shadows that the camera's view made.
103
103
 
104
- A view has a depth target of the canvas's size, made once in a frame and shared with the other views when their turns do not overlap. The rectangle follows the render scale, as the camera's view does, so a lower scale lowers a view's cost with the rest of the image.
104
+ The rectangle follows the render scale, as the camera's view does, so a lower scale lowers a view's cost with the rest of the image. No preset switches views off or lowers their count. On a phone, keep a picture in picture small: each view costs what its rectangle costs on the preset that the device runs, as [Quality presets](../concepts/quality-presets.md) describes.
105
105
 
106
- Both GPU paths draw views, in every thread mode. The scene culling runs on the GPU on WebGPU and on the job workers on WebGL2, as it does for the camera. On the 8-bit path a view writes display color into the camera's image, and the resolve pass or the final pass draws it to the canvas; the picture looks the same as on the HDR path, with no bloom, as the 8-bit path has none.
106
+ ## What a view draws and its limits
107
107
 
108
- No preset switches views off or lowers their count. On a phone, keep a picture in picture small: each view costs what its rectangle costs on the preset that the device runs, as [Quality presets](../concepts/quality-presets.md) describes.
108
+ Views draw on both GPU paths, in every thread mode.
109
109
 
110
- ## What a view leaves out
110
+ - A view draws: the shadows of the camera's view, the background, the environment's light, the material fog and the lights it sees. The camera's volumetric fog and outline are added to the whole image after the views draw, so they also reach a view's rectangle.
111
+ - A view leaves out: ambient occlusion and screen-space reflections, which shade only the camera's view, and any object whose material shows a render pass's texture.
111
112
 
112
- A view draws no object whose material shows a render pass's texture, since a pass cannot read a target that another pass draws into. Keep such objects in the camera's view, or show the pass's texture on a screen in the world instead.
113
+ A pass cannot read a target that another pass draws into, so keep such objects in the camera's view, or show the pass's texture on a screen in the world instead.
113
114
 
114
115
  A scene and its passes share 32 views, the camera's included. Reflection probes take six while they capture. `scene.createView` throws E1501 when no view is free, and the same error names the limit when a frame draws too many.
115
116
 
117
+ <details>
118
+ <summary>Technical details: how views draw on each GPU path</summary>
119
+
120
+ A view has a depth target of the canvas's size. The engine makes it once in a frame and shares it with the other views when their turns do not overlap. The scene culling runs on the GPU on WebGPU and on the job workers on WebGL2, as it does for the camera.
121
+
122
+ On the 8-bit path a view writes display color into the camera's image. The resolve pass or the final pass draws it to the canvas. The picture looks the same as on the HDR path, with no bloom, as the 8-bit path has none.
123
+
124
+ </details>
125
+
116
126
  ## Related pages
117
127
 
118
128
  - [Scene](../api/scene.md#multiple-views): `createView`, `setCamera`, `setRect` and `destroy`.
@@ -120,3 +130,4 @@ A scene and its passes share 32 views, the camera's included. Reflection probes
120
130
  - [Custom passes and render targets](custom-passes.md#render-to-a-texture): a camera's view in a texture that a material shows.
121
131
  - [The render graph](../concepts/render-graph.md): how the engine plans and orders what it draws.
122
132
  - [Performance](performance.md): the frame budget and the render scale.
133
+ - [A picture in picture](https://github.com/null3d-engine/null3d/tree/main/examples/multiple-views): one scene from a high, wide camera and a low one, split across the canvas or in an inset.
@@ -1,20 +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 is built to be faster than three.js, and it beats three.js in five of its six benchmark scenes. 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`.
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
16
14
 
17
- 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.
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.
18
16
 
19
17
  ## Where frame time goes
20
18
 
@@ -90,13 +88,25 @@ The engine kept the full render scale and every setting on both devices. On the
90
88
 
91
89
  ### Quality presets
92
90
 
93
- 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.
94
104
 
95
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.
96
106
 
97
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.
98
108
 
99
- 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.
100
110
 
101
111
  ## Put performance-sensitive work in Rust
102
112
 
@@ -122,9 +132,35 @@ Garbage collection pauses the thread that allocated the memory. The render worke
122
132
  - Keep reused arrays at their size. Setting `length = 0` frees an array's storage, so the next write allocates it again.
123
133
  - Do not wrap a browser promise in an `async` function every frame. Each call makes a promise of its own.
124
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.
125
- - 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
+ ```
126
155
 
127
- 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.
156
+ <details>
157
+ <summary>Technical details: why some calls allocate in hot code</summary>
158
+
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.
128
164
 
129
165
  ## Objects during play
130
166
 
@@ -145,11 +181,11 @@ The engine keeps each scene's draw tables and every object's matrix on the GPU,
145
181
  | `setCastShadows` and `setReceiveShadows`, on meshes and on lights | A rebuild |
146
182
  | `setLevelBias`, which changes the bucket that the object draws from | A rebuild |
147
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 |
148
185
  | `setMorphWeight` | The object's weights. On WebGPU, the skinning pass morphs the mesh again |
149
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 |
150
187
  | `render.addPass`, `render.removePass` | New passes, and the pass's texture |
151
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 |
152
- | `texture.update()` with an image of another size, and `texture.destroy()` | A rebuild |
153
189
 
154
190
  These habits keep play free of rebuilds:
155
191
 
@@ -160,22 +196,69 @@ These habits keep play free of rebuilds:
160
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.
161
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.
162
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.
163
- - 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.
164
- - 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.
165
205
 
166
206
  ## How the engine batches, builds pipelines and times frames
167
207
 
168
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.
169
209
 
170
- | Question | null3D's answer |
171
- | --- | --- |
172
- | 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. |
173
- | 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`. |
174
- | 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. |
175
- | 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. |
176
- | 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. |
177
- | 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. |
178
- | 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).
179
262
 
180
263
  So some common advice does not apply:
181
264
 
@@ -191,11 +274,20 @@ So some common advice does not apply:
191
274
 
192
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.
193
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
+
194
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.
195
280
 
196
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).
197
282
 
198
- 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>
199
291
 
200
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.
201
293
 
@@ -211,7 +303,7 @@ Animated characters also cost skinning work and memory:
211
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.
212
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.
213
305
 
214
- 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.
215
307
 
216
308
  ## See-through objects
217
309
 
@@ -229,7 +321,7 @@ Textures take most of a scene's GPU memory. Each preset gives textures a memory
229
321
 
230
322
  ## Picking, labels, sprites and lines
231
323
 
232
- - 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)).
233
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)).
234
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.
235
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.
@@ -243,7 +335,7 @@ The S1-cells benchmark spreads S1-static's 100,000 boxes over 8 x 8 cells, 8 km
243
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.
244
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.
245
337
 
246
- 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.
247
339
 
248
340
  ## Point and spot lights
249
341
 
@@ -251,14 +343,26 @@ The engine lights each pixel with the point and spot lights of its cluster only,
251
343
 
252
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.
253
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.
254
- - 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.
255
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.
256
348
 
257
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.
258
350
 
259
- 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.
260
357
 
261
- 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.
262
366
 
263
367
  ## Shadows
264
368
 
@@ -279,31 +383,55 @@ Each post effect adds full-screen work, which grows with the pixels drawn:
279
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)).
280
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)).
281
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
+
282
388
  ## Occlusion culling
283
389
 
284
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.
285
391
 
286
392
  ### Blockers on WebGL2
287
393
 
288
- 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>
289
404
 
290
405
  ### Occlusion culling on the GPU
291
406
 
292
- 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)).
293
410
 
294
411
  ## The depth prepass
295
412
 
296
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.
297
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
+
298
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.
299
420
 
300
- 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)).
301
424
 
302
425
  ## Measure
303
426
 
304
- 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)).
305
428
 
306
- `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>
307
435
 
308
436
  | Figure | What it is |
309
437
  | --- | --- |
@@ -334,13 +462,29 @@ For a quick look while the scene runs, add `?stats` to the page's address, or ca
334
462
  | `lostRecords` | Frames that the figures miss, because the page read their records too late. It is 0 in a clean run |
335
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 |
336
464
 
465
+ </details>
466
+
337
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.
338
468
 
339
- `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>
340
477
 
341
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)).
342
479
 
343
- 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>
344
488
 
345
489
  ### The presented rate, the completed rate and GPU time
346
490
 
@@ -352,7 +496,14 @@ Three figures show whether the GPU keeps up:
352
496
 
353
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.
354
498
 
355
- 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>
356
507
 
357
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.
358
509