@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,15 +1,11 @@
1
1
  ---
2
2
  id: guides/testing
3
3
  title: Testing your sketch
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "Hold mode; image tests; reading results; frames that stay the same on every run; browser tests of a whole app."
7
5
  ---
8
6
 
9
7
  # Testing your sketch
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.
12
-
13
9
  ```mermaid
14
10
  flowchart LR
15
11
  start["Page with ?hold=1.5"] --> setup["Sketch setup,<br/>random numbers seeded"]
@@ -23,32 +19,6 @@ flowchart LR
23
19
 
24
20
  An image test draws your sketch at a set time and compares the frame with a reference image. A live engine draws whenever the browser gives it a frame. The time and the steps of a live frame therefore change from run to run. Hold mode fixes both, and the same code then draws the same frame on every run.
25
21
 
26
- ## Check every rendering mode
27
-
28
- A scene that looks right and runs well in one setup can fail in another. Before you call a scene done, check frame rate, memory and looks in each of these:
29
-
30
- | Switch | What it shows |
31
- |---|---|
32
- | `?gpu=webgpu&direct=off` | WebGPU with indirect draws |
33
- | `?gpu=webgpu&direct=on` | WebGPU with direct draws, which holds more memory on some devices |
34
- | `?gpu=compat` | WebGPU's compatibility mode, with fewer features |
35
- | `?gpu=webgl2` | WebGL2, where the CPU culls and the draw calls cost more |
36
- | `?preset=low` to `?preset=ultra` | Each quality preset. High on WebGL2 and compatibility runs at Medium. With no preset, the start-up check picks one |
37
-
38
- Follow these rules when you measure:
39
-
40
- - **Measure the whole camera path.** A part of it can read far better than the worst moment, so never quote a part as the whole.
41
- - **Repeat each run.** One run misleads: two like runs can differ by a third. Fix the pixel ratio, and note what else the machine is doing.
42
- - **Watch it move.** A held frame shows no popping, flicker or lag. Record a live camera and look at the frames.
43
- - **Test on real devices.** Use phones and tablets of different form factors, and large and small screens. [Phones and tablets](phones.md#testing-on-real-devices) says how.
44
-
45
- To read the numbers, open the stats overlay with `?stats=open`:
46
-
47
- - **Frames per second:** read the average and the slowest second, and count the seconds under your target. An average hides a stall.
48
- - **Frame work:** `Sketch`, `Drawing` and `GPU` say which side is slow. A bar past the mark is over the frame's budget.
49
- - **Scale:** under 1.00, the frame-budget governor has lowered the render scale to keep the time, so the frame rate alone flatters the scene.
50
- - **Memory:** read `GPU textures` and `GPU buffers` on each path, and the page's limit in [Phones and tablets](phones.md#memory).
51
-
52
22
  ## Hold mode
53
23
 
54
24
  Start hold mode with the `?hold=<seconds>` switch in the page's address, or with the `hold` option of `createEngine`:
@@ -66,53 +36,35 @@ const { width, height, pixels } = await engine.captureFrame(); // RGBA8 rows, to
66
36
  In hold mode, the engine does this:
67
37
 
68
38
  1. It seeds the engine's random generator, [`math.random`](../api/math.md#random-numbers), in the sketch's thread, and makes `Math.random` draw from it too. This happens before the sketch module loads.
69
- 2. It runs the sketch's setup. The sketch's `assets` calls run one at a time, each once the call before it has answered, in the order the sketch made them. A load makes its textures, meshes and materials when its files arrive, and files arrive in another order on each run. Loads that ran side by side would put the scene's content in another order each time. The held frame would then draw its objects in another order.
39
+ 2. It runs the sketch's setup. The sketch's `assets` calls run one at a time, in the order the sketch made them.
70
40
  3. It steps the sketch from time 0 to the held time. The first frame is at time 0 and its `onUpdate` gets a step of 0. Each later frame adds a fixed step of 1/60 second, and the last one lands on the held time exactly. The sketch's own fixed steps fall due from the sketch time, so every hold runs the same ones. At the default rate, each frame after the first runs one.
71
- 4. It draws the last frame on the canvas, and reads its pixels back through its own GPU code. Motion vectors read the frame before, so with them it draws the frame before the last one too. A mirror or a light probe shows its result a frame late, so with one it draws one more frame at the held time. The GPU passes of the other frames never run, and [`time.drawn`](../api/time.md#the-time-object) is false in them.
41
+ 4. It draws the last frame on the canvas and reads its pixels back. The GPU passes of the other frames never run, and [`time.drawn`](../api/time.md#the-time-object) is false in them.
72
42
  5. It publishes the frame, or the error that stopped it, as `window.__null3dHold`.
73
43
 
74
44
  `createEngine` resolves once the frame is read back, and `engine.captureFrame()` returns that frame. `engine.mode.hold` gives the held time, and it is `null` for a live engine. After the held frame, the engine draws nothing more: it runs no frame loop, so `engine.measure()` finds no frames. The hold's result gives the held frame's own figures instead. The engine draws no frame before the held one, so the held frame creates every GPU object and uploads the whole scene.
75
45
 
76
- A hold at 1.5 seconds runs 91 frames: frame 1 at time 0, then 90 steps. In the last `onUpdate`, `time.now` is 1.5 and `time.frame` is 91. When a pass reads the frame before it, as screen-space bounce light does, the engine draws one more frame at the same sketch time after the held one, so the picture has the light that the earlier frame showed. That frame runs none of the sketch's code and adds no step, so the sketch still ends at frame 91 and the hold reports that number. It draws the debug lines of the last `onUpdate` again, so the picture shows the same lines as the held frame.
46
+ A hold at 1.5 seconds runs 91 frames: frame 1 at time 0, then 90 steps. In the last `onUpdate`, `time.now` is 1.5 and `time.frame` is 91.
77
47
 
78
- Before it draws the held frame, hold mode waits for the tasks that the sketch queued on the job workers. It then runs one more frame at the held time, which draws what they wrote. It waits up to 10 seconds for a task, then warns and draws anyway. The levels of detail that meshes made in code plan are different. Hold mode waits for them until they are in, however long the plans take on a busy machine. It says every 10 seconds which meshes still plan. So the held frame always draws every planned level. A plan that has not answered after five minutes stops the hold with [E1408](../errors/E1408.md), which names the meshes. Give a mesh `levels: false` when a test should draw it without levels. Hold mode also waits for the tasks and plans that the setup started before the first step, with the same limits. So a mesh made in the setup has its levels in every held frame, and a task that never answers delays the hold twice. The plans hand over their levels one at a time in the order they started, whatever order the job workers answer in. So the steps find the same scene on every run, and the meshes of the levels take the same places in engine memory.
48
+ Motion vectors need the frame before the last one, so with them the engine draws that frame too.
79
49
 
80
- The switch wins over the option. A bare `?hold` holds at the time of the `hold` option, or at 0 without one. The time must be from 0 to 600 seconds, or the start fails with [E1407](../errors/E1407.md).
81
-
82
- Hold mode works in every thread mode and on every GPU tier. The single-threaded build runs the sketch on the page's thread, so there the page's `math.random` is seeded too. The page's `Math.random` draws from it until the engine stops.
50
+ Some effects show their result one frame late: screen-space bounce light, mirrors and light probes. Tasks on the job workers can also answer after the last step. In these cases the engine draws one more frame at the held time. That frame runs none of the sketch's code, so the hold still reports the last step's frame number.
83
51
 
84
- ## Reading the result in a test
52
+ Hold mode waits for the sketch's tasks on the job workers, and for the levels of detail that meshes made in code plan. Each of its two waits for the tasks lasts up to 10 seconds, and then it warns and draws anyway. It waits up to five minutes for the plans, then stops with [E1408](../errors/E1408.md). Give a mesh `levels: false` when a test should draw it without levels.
85
53
 
86
- A test runner opens the page with `?hold` and waits for `window.__null3dHold`. The engine sets it the moment the hold ends, so a runner never waits out a timeout on a page that failed. The page needs no test code of its own.
54
+ <details>
55
+ <summary>Technical details: what hold mode waits for</summary>
87
56
 
88
- | Field | Held frame | Failed hold |
89
- | --- | --- | --- |
90
- | `ok` | `true` | `false` |
91
- | `time`, `frame` | The sketch time in seconds, and the frame's number | Absent |
92
- | `tier` | The GPU path that drew the frame | Absent |
93
- | `width`, `height`, `pixels` | The frame's size, and its pixels as RGBA8 rows in a `Uint8Array`, top row first | Absent |
94
- | `stats` | The frame's figures in the form that `engine.measure()` returns: CPU time by thread and phase, draw calls, uploads and pipelines | Absent |
95
- | `code`, `error` | Absent | The error's code, or `null` for an error without one, and its message |
57
+ - Hold mode waits twice: once after the setup and before the first step, and once after the last step, before the extra frame. A task that never answers delays the hold twice.
58
+ - While plans are still running, the console says every 10 seconds which meshes still plan.
59
+ - The plans hand over their levels one at a time, in the order they started, whatever order the job workers answer in. So the steps find the same scene on every run, and the levels' meshes take the same places in engine memory.
60
+ - The extra frame draws the debug lines of the last `onUpdate` again, so the picture shows the same lines as the frame before it.
61
+ - The held frame creates every GPU object and uploads the whole scene.
96
62
 
97
- With Playwright, a test reads the result like this:
63
+ </details>
98
64
 
99
- ```ts
100
- // tests/boat.spec.ts
101
- await page.goto('/?hold=1.5&gpu=webgl2');
102
- await page.waitForFunction(() => (window as any).__null3dHold);
103
- const result = await page.evaluate(() => {
104
- const held = (window as any).__null3dHold;
105
- if (!held.ok) return held;
106
- let binary = '';
107
- for (let i = 0; i < held.pixels.length; i += 0x8000)
108
- binary += String.fromCharCode(...held.pixels.subarray(i, i + 0x8000));
109
- return { ...held, pixels: btoa(binary) };
110
- });
111
- if (!result.ok) throw new Error(result.error);
112
- const pixels = Buffer.from(result.pixels, 'base64'); // compare with the reference image
113
- ```
65
+ The switch wins over the option. A bare `?hold` holds at the time of the `hold` option, or at 0 without one. The time must be from 0 to 600 seconds, or the start fails with [E1407](../errors/E1407.md).
114
66
 
115
- The engine reads the pixels back with its own GPU code and takes no screenshot of the canvas. Some browsers change what a page reads from a canvas, to stop fingerprinting.
67
+ Hold mode works in every thread mode and on every GPU tier. The single-threaded build runs the sketch on the page's thread, so there the page's `math.random` is seeded too. The page's `Math.random` draws from it until the engine stops.
116
68
 
117
69
  ## A held frame from the command line
118
70
 
@@ -132,18 +84,6 @@ bunx @null3d/cli shot --script drive.script --out tour.png
132
84
 
133
85
  [Timed scripts](../cli/null3d.md#timed-scripts) gives the steps and the addresses of objects and properties.
134
86
 
135
- ## Record a session that went wrong
136
-
137
- A bug on a phone can replay on this computer. Open your page with `?record`: the engine records each frame's step and the input that the sketch read, from the page's first frame, and a **Save recording** button appears. Reproduce the bug, tap it, and copy the file to the computer. The recording keeps the sketch's random seed, so the sketch's setup builds the same scene on the replay.
138
-
139
- Open the same page with `?replay=<file>`, or replay a file from anywhere with the command line:
140
-
141
- ```sh
142
- bunx @null3d/cli shot --replay bug.n3dr --out bug.png
143
- ```
144
-
145
- The replay runs the recording's frames in order, with their recorded steps and input, and draws the last one. It reads no live input. Its pixels differ from the phone's as any two GPUs' do, so a replay proves the frames and not the picture. A recording stops at 600 seconds of sketch time.
146
-
147
87
  ## Image tests from the command line
148
88
 
149
89
  `bunx @null3d/cli test` runs your image tests with no test code. List them in `null3d.json` in your project's folder:
@@ -167,6 +107,24 @@ A test can give `script` instead of `hold`. It then draws each shot step of the
167
107
 
168
108
  The first run of a new test fails, because the test has no reference yet. Open its image, and when it is right, keep it with `bunx @null3d/cli test --update-references`. [The `null3d` command](../cli/null3d.md#test) gives the settings of a test, where the files go, and what each line says.
169
109
 
110
+ ## Frames that stay the same on every run
111
+
112
+ ![Glossy balls bouncing in a stone pen, the frame that a hold at 3 seconds draws.](../images/guides/testing/hold-mode-frame.webp)
113
+
114
+ A held frame is the same on every run.
115
+
116
+ - Move things with `time.now`, the frame's step (`dt` or `time.dt`), or in `onFixedUpdate`. `Date.now()` and `performance.now()` change from run to run.
117
+ - Use `math.random` or `Math.random`: hold mode seeds both. Random numbers from another source, such as `crypto.getRandomValues`, are not seeded.
118
+ - Expect no input, unless the test gives a timed script. A plain hold reads none: every key and button stays up, and the pointer stays at the canvas's top-left corner. A script's key and pointer steps reach the sketch at their times.
119
+ - Finish loading in the setup. Await every asset there, because the hold starts when the setup's promise resolves. A sketch that adds large models after the first frame on a live page waits for them when `engine.held` is true ([A fast start](start-time.md#draw-the-first-frame-before-the-large-models)).
120
+ - Pass test settings in the sketch module's address, such as `new URL('./sketch.ts?view=harbor', import.meta.url)`, and read them in the sketch with `new URL(import.meta.url).searchParams`. The page's messages reach the sketch only after the hold, because `createEngine` resolves after it.
121
+ - Keep a reference image per GPU tier, and force the tier with `?gpu=webgpu`, `?gpu=compat` or `?gpu=webgl2`. The tiers can differ slightly at edges.
122
+ - Compare with a small tolerance. A software GPU in CI and a real GPU differ at object edges. `bunx @null3d/cli test` counts a pixel as different past 10% of the color range. It fails an image when more than 0.1% of its pixels differ ([References and results](../cli/null3d.md#references-and-results)).
123
+
124
+ Loads that run side by side are safe in a held frame or a replay. The engine then runs the sketch's `assets` calls one at a time ([Hold mode](#hold-mode)), and a model makes its textures in the file's order.
125
+
126
+ The [hold mode demo](https://github.com/null3d-engine/null3d/tree/main/examples/hold-mode) drops 400 balls from random places, and moves them by each frame's step. Every live run differs. With `?hold=3`, every run draws the same frame.
127
+
170
128
  ## When a hold fails
171
129
 
172
130
  Hold mode stops at the first error and publishes it with `ok: false`:
@@ -178,26 +136,58 @@ Hold mode stops at the first error and publishes it with `ok: false`:
178
136
  | The frame could not be drawn or read back | E1408, with the reason |
179
137
  | The sketch's setup threw, or a thread did not start | The same error that a live start gives, such as [E1405](../errors/E1405.md) |
180
138
  | The browser took the GPU away | [E1302](../errors/E1302.md). Hold mode draws on one device, so it does not start a new one. |
139
+ | A level-of-detail plan did not answer after five minutes | [E1408](../errors/E1408.md), naming the meshes that still plan |
181
140
 
182
141
  A live engine logs an error in `onUpdate` and carries on. Hold mode stops instead, so a test fails at once. The console shows the sketch's error with its stack.
183
142
 
184
- ## Frames that stay the same on every run
143
+ ## Reading the result in a test
185
144
 
186
- - Move things with `time.now`, the frame's step (`dt` or `time.dt`), or in `onFixedUpdate`. `Date.now()` and `performance.now()` change from run to run.
187
- - Use `math.random` or `Math.random`: hold mode seeds both. Random numbers from another source, such as `crypto.getRandomValues`, are not seeded.
188
- - Expect no input, unless the test gives a timed script. A plain hold reads none: every key and button stays up, and the pointer stays at the canvas's top-left corner. A script's key and pointer steps reach the sketch at their times.
189
- - Finish loading in the setup. Await every asset there, because the hold starts when the setup's promise resolves. A sketch that adds large models after the first frame on a live page waits for them when `engine.held` is true ([A fast start](start-time.md#draw-the-first-frame-before-the-large-models)).
190
- - Pass test settings in the sketch module's address, such as `new URL('./sketch.ts?view=harbor', import.meta.url)`, and read them in the sketch with `new URL(import.meta.url).searchParams`. The page's messages reach the sketch only after the hold, because `createEngine` resolves after it.
191
- - Keep a reference image per GPU tier, and force the tier with `?gpu=webgpu`, `?gpu=compat` or `?gpu=webgl2`. The tiers can differ slightly at edges.
192
- - Compare with a small tolerance. A software GPU in CI and a real GPU differ at object edges. `bunx @null3d/cli test` counts a pixel as different past 10% of the color range. It fails an image when more than 0.1% of its pixels differ ([References and results](../cli/null3d.md#references-and-results)).
145
+ A test runner opens the page with `?hold` and waits for `window.__null3dHold`. The engine sets it the moment the hold ends, so a runner never waits out a timeout on a page that failed. The page needs no test code of its own.
146
+
147
+ | Field | Held frame | Failed hold |
148
+ | --- | --- | --- |
149
+ | `ok` | `true` | `false` |
150
+ | `time`, `frame` | The sketch time in seconds, and the frame's number | Absent |
151
+ | `tier` | The GPU path that drew the frame | Absent |
152
+ | `width`, `height`, `pixels` | The frame's size, and its pixels as RGBA8 rows in a `Uint8Array`, top row first | Absent |
153
+ | `stats` | The frame's figures in the form that `engine.measure()` returns: CPU time by thread and phase, draw calls, uploads and pipelines | Absent |
154
+ | `code`, `error` | Absent | The error's code, or `null` for an error without one, and its message |
193
155
 
194
- Loads that run side by side are safe in a held frame. While the engine holds frames or replays, the sketch's `assets` calls run one at a time, in the order the sketch made them. A model makes its textures in the file's order. So a held scene puts its content together in the same order on every run, however its files arrive ([Hold mode](#hold-mode)).
156
+ With Playwright, a test reads the result like this:
195
157
 
196
- The [hold mode demo](https://github.com/null3d-engine/null3d/tree/main/examples/hold-mode) drops 400 balls from random places, and moves them by each frame's step. Every live run differs. With `?hold=3`, every run draws the same frame.
158
+ ```ts
159
+ // tests/boat.spec.ts
160
+ await page.goto('/?hold=1.5&gpu=webgl2');
161
+ await page.waitForFunction(() => (window as any).__null3dHold);
162
+ const result = await page.evaluate(() => {
163
+ const held = (window as any).__null3dHold;
164
+ if (!held.ok) return held;
165
+ let binary = '';
166
+ for (let i = 0; i < held.pixels.length; i += 0x8000)
167
+ binary += String.fromCharCode(...held.pixels.subarray(i, i + 0x8000));
168
+ return { ...held, pixels: btoa(binary) };
169
+ });
170
+ if (!result.ok) throw new Error(result.error);
171
+ const pixels = Buffer.from(result.pixels, 'base64'); // compare with the reference image
172
+ ```
173
+
174
+ The engine reads the pixels back with its own GPU code and takes no screenshot of the canvas. Some browsers change what a page reads from a canvas, to stop fingerprinting.
175
+
176
+ ## Record a session that went wrong
177
+
178
+ A bug on a phone can replay on this computer. Open your page with `?record`: the engine records each frame's step and the input that the sketch read, from the page's first frame, and a **Save recording** button appears. Reproduce the bug, tap it, and copy the file to the computer. The recording keeps the sketch's random seed and [start data](../api/page.md#start-data), so the setup builds the same scene on the replay.
179
+
180
+ Open the same page with `?replay=<file>`, or replay a file from anywhere with the command line:
181
+
182
+ ```sh
183
+ bunx @null3d/cli shot --replay bug.n3dr --out bug.png
184
+ ```
185
+
186
+ The replay runs the recording's frames in order, with their recorded steps and input, and draws the last one. It reads no live input. Its pixels differ from the phone's as any two GPUs' do, so a replay proves the frames and not the picture. A recording stops at 600 seconds of sketch time.
197
187
 
198
188
  ## Browser tests of a whole app
199
189
 
200
- Image tests check pictures. A game or an app also needs a suite that opens its real page in a browser, drives it and checks what it did. The null3d-develop agent skill's `references/e2e-testing.md` gives the whole setup, with a worked Playwright config and spec. Its main rules:
190
+ Image tests check pictures. A game or an app also needs a suite that opens its real page in a browser, drives it and checks what it did. The null3d-develop agent skill's [`references/e2e-testing.md`](https://github.com/null3d-engine/null3d/blob/main/skills/null3d-develop/references/e2e-testing.md) gives the whole setup, with a worked Playwright config and spec. Its main rules:
201
191
 
202
192
  - Run Playwright Test with its own pinned Chromium, installed with `bunx playwright install chromium`. Use one browser version on every machine, and never the installed Google Chrome.
203
193
  - Start the real app with Playwright's `webServer`: the dev server, and the production build through `vite preview`. CI tests the production build.
@@ -209,29 +199,78 @@ Image tests check pictures. A game or an app also needs a suite that opens its r
209
199
  - Give each copy of the project its own port, fail a test on any console error, and record a trace on the first retry.
210
200
  - Keep real phones and tablets, and frame-rate timing, out of CI.
211
201
 
202
+ ### Record the shader words that a test reaches
203
+
204
+ A suite that drives the game's states can also write the list of shader permutation words that a production build copies. Open the page with `withRecordingSwitch(address)` from `@null3d/cli/shaders`, drive it, then call `saveRecordedWords(page, 'shader-permutations.txt')`. It ends the page's recording and adds the words to the list. [Record from your browser tests](assets-pipeline.md#record-from-your-browser-tests) shows a spec.
205
+
206
+ ## Check every rendering mode
207
+
208
+ A scene that looks right and runs well in one setup can fail in another. Before you call a scene done, check frame rate, memory and looks in each of these:
209
+
210
+ | Switch | What it shows |
211
+ |---|---|
212
+ | `?gpu=webgpu&direct=off` | WebGPU with indirect draws |
213
+ | `?gpu=webgpu&direct=on` | WebGPU with direct draws, which holds more memory on some devices |
214
+ | `?gpu=compat` | WebGPU's compatibility mode, with fewer features |
215
+ | `?gpu=webgl2` | WebGL2, where the CPU culls and the draw calls cost more |
216
+ | `?preset=low` to `?preset=ultra` | Each quality preset. High on WebGL2 and compatibility runs at Medium. With no preset, the start-up check picks one |
217
+
218
+ Follow these rules when you measure:
219
+
220
+ - **Measure the whole camera path.** A part of it can read far better than the worst moment, so never quote a part as the whole.
221
+ - **Repeat each run.** One run misleads: two like runs can differ by a third. Fix the pixel ratio, and note what else the machine is doing.
222
+ - **Watch it move.** A held frame shows no popping, flicker or lag. Record a live camera and look at the frames.
223
+ - **Test on real devices.** Use phones and tablets of different form factors, and large and small screens. [Phones and tablets](phones.md#testing-on-real-devices) says how.
224
+
225
+ To read the numbers, open the stats overlay with `?stats=open`:
226
+
227
+ - **Frames per second:** read the average and the slowest second, and count the seconds under your target. An average hides a stall.
228
+ - **Frame work:** `Sketch`, `Drawing` and `GPU` say which side is slow. A bar past the mark is over the frame's budget.
229
+ - **Scale:** under 1.00, the frame-budget governor has lowered the render scale to keep the time, so the frame rate alone flatters the scene.
230
+ - **Memory:** read `GPU textures` and `GPU buffers` on each path, and the page's limit in [Phones and tablets](phones.md#memory).
231
+
212
232
  ## Switches for tests
213
233
 
214
- The engine reads these switches from the page's address in development builds. These are the dev server, the `null3d` command's runs and the CDN build's development entry, `lib-dev/index.js`. A production build ignores them, so a link cannot change how a shipped game runs. The CDN build's production entry, `lib/index.js`, ignores them too. To use them in a production build of test pages, turn on the Vite plugin's `urlSwitches` option: `null3d({ urlSwitches: true })`. For a benchmark page that loads the CDN build, `bun run build:cdn --url-switches` does the same ([Try null3D from a CDN](../getting-started/cdn.md#production-and-development-entries)).
234
+ The engine reads these switches from the page's address in development builds: the dev server, the `null3d` command's runs and the CDN build's development entry, `lib-dev/index.js`. A production build and the CDN build's production entry, `lib/index.js`, ignore them.
235
+
236
+ To use them in a production build of test pages, turn on the Vite plugin's `urlSwitches` option: `null3d({ urlSwitches: true })`. For a benchmark page that loads the CDN build, `bun run build:cdn --url-switches` does the same ([Try null3D from a CDN](../getting-started/cdn.md#production-and-development-entries)).
237
+
238
+ ### Common switches
215
239
 
216
240
  | Switch | Effect |
217
241
  | --- | --- |
218
242
  | `?hold=1.5` | Hold mode at 1.5 seconds of sketch time; a bare `?hold` holds at the `hold` option's time, or at 0 |
219
243
  | `?gpu=webgpu`, `?gpu=compat`, `?gpu=webgl2` | Force a GPU tier, where the device has it |
220
244
  | `?direct=on`, `?direct=off` | On WebGPU, force the direct or the indirect draw path on any device, in place of the start-up probe's choice, to compare GPU time. The probe runs only on an Apple GPU in WebKit. `engine.capabilities.directDraws` says which path the engine took, and `engine.capabilities.drawPath` says why ([Performance guide](performance.md#how-the-engine-batches-builds-pipelines-and-times-frames)) |
245
+ | `?preset=low`, `?preset=medium`, `?preset=high`, `?preset=ultra` | Fix the quality preset, within the GPU path's highest; a crashed start still lowers it by one |
246
+ | `?target-fps=display`, `?target-fps=90` | Set the frame rate that the preset check and the governor defend, in place of the `targetFps` option: the display's full rate, or at most that many frames per second ([The target frame rate](../concepts/quality-presets.md#the-target-frame-rate)) |
247
+ | `?preset-check=during-play`, `?preset-check=before-play` | Set when the preset check measures, in place of the `presetCheck` option: in the first frames of play, or before play, with `createEngine` waiting for it ([The preset check](../concepts/quality-presets.md#the-preset-check)) |
248
+ | `?check=fresh` | Measure the quality preset again, as on a first visit, instead of taking the stored result of an earlier [preset check](../concepts/quality-presets.md#repeat-visits) |
249
+ | `?builds=fresh` | Start each pipeline build when the first frame asks for it, as on a first visit, instead of building the [stored list](loading-screens.md#repeat-visits) of an earlier start's first frame ahead of it |
250
+ | `?latency=pipelined`, `?latency=low` | Pick the latency mode |
251
+ | `?threads=off` | The single-threaded build |
252
+ | `?view=levels` | Draw a debug view, here the levels of detail, with no code change ([Debug views](../api/debug.md#the-view-from-the-address)). The switch takes any view name that `debug.view` takes |
253
+
254
+ ### Act like another browser
255
+
256
+ | Switch | Effect |
257
+ | --- | --- |
221
258
  | `?depth=reversed`, `?depth=reversed-gl`, `?depth=standard` | Force a WebGL2 depth mode. `reversed-gl` draws as browsers without the `EXT_clip_control` extension do, such as Firefox |
222
259
  | `?uploads=copy` | On WebGL2, upload a copy of the data, as browsers that refuse to read shared memory need |
223
260
  | `?multidraw=off` | On WebGL2, draw as a browser without the `WEBGL_multi_draw` extension does: the engine probes none and draws the whole levels of a cluster tree in place of its patches ([Levels of detail](../concepts/lod.md#cluster-levels)) |
224
261
  | `?compile=wait` | On WebGL2, wait for each shader program's compile at its first draw, as browsers without the `KHR_parallel_shader_compile` extension do |
225
- | `?check=fresh` | Measure the quality preset again, as on a first visit, instead of taking the stored result of an earlier [preset check](../concepts/quality-presets.md#repeat-visits) |
226
- | `?builds=fresh` | Start each pipeline build when the first frame asks for it, as on a first visit, instead of building the [stored list](loading-screens.md#repeat-visits) of an earlier start's first frame ahead of it |
227
262
  | `?compression=bc`, `?compression=astc,etc2`, `?compression=none` | Keep KTX2 textures to the compressed formats that the list names, of those the device has, as on a device with only those. `none` gives every KTX2 texture `rgba8unorm` |
228
- | `?derived-cache=off` | Turn the [cache of derived data](../api/assets.md#the-cache-of-derived-data) off, so every load makes its data again, as on a first visit: KTX2 files transcode, and `assets.cache` keeps nothing |
229
- | `?threads=off` | The single-threaded build |
230
263
  | `?wake=message` | Make the worker threads wake each other with messages, as browsers without `Atomics.waitAsync` need, such as Firefox before 145 |
231
264
  | `?render=main` | Draw on the page's main thread |
265
+
266
+ Other switches measure what one engine saving costs.
267
+
268
+ <details>
269
+ <summary>Technical details: switches that measure one engine saving</summary>
270
+
271
+ | Switch | Effect |
272
+ | --- | --- |
232
273
  | `?display-check=off` | Where the page's main thread draws, stop the checks of the display. While the frames run slower than the display, two frame callbacks now and then draw nothing, and the time between them measures the display's refresh rate. The switch measures what they cost |
233
- | `?sketch-thread=main` | Run the sketch on the page's main thread, over the `sketchThread` option |
234
- | `?latency=pipelined`, `?latency=low` | Pick the latency mode |
235
274
  | `?cells=off` | Cull every object, with no [grid cell](../concepts/culling.md) out of view skipped first, to measure what skipping cells saves |
236
275
  | `?skinning=compute` | On WebGPU, skin every skinned mesh once per frame in the skinning pass, a compute pass, instead of in the vertex shader of each pass that draws it, to compare the two ([Animation](../api/animation.md#skinned-meshes)) |
237
276
  | `?skinning=full`, `?skinning=skip`, `?skinning=narrow` | On WebGPU, skin in the skinning pass with fewer of its savings, to measure each one. `full` skins every character that a view draws in every frame, with normals and tangents as 32-bit floats. `skip` keeps only the skip of unchanged poses, and `narrow` keeps only the 8-bit normals and tangents |
@@ -239,7 +278,7 @@ The engine reads these switches from the page's address in development builds. T
239
278
  | `?shadowdepth=32` | Store the directional light's shadow map in 32-bit float depth, instead of 16-bit depth, to compare the two ([Shadows](../concepts/shadows.md#bias)) |
240
279
  | `?half=on`, `?half=off` | Do the scene shaders' color math at half precision, or at full precision. WebGPU needs the device feature `shader-f16`, and a device without it keeps full precision. `engine.capabilities.halfPrecision` says which one the engine took |
241
280
  | `?still-camera=off` | Draw every frame of a view that holds still, without the [still-camera accumulation](../concepts/post-processing.md#still-camera-accumulation): the view neither blends nor rests. Hold mode draws without it too |
242
- | `?preset=low`, `?preset=medium`, `?preset=high`, `?preset=ultra` | Fix the quality preset, within the GPU path's highest; the engine then ignores starts that crashed before |
243
- | `?target-fps=display`, `?target-fps=90` | Set the frame rate that the preset check and the governor defend, in place of the `targetFps` option: the display's full rate, or at most that many frames per second ([The target frame rate](../concepts/quality-presets.md#the-target-frame-rate)) |
244
- | `?preset-check=during-play`, `?preset-check=before-play` | Set when the preset check measures, in place of the `presetCheck` option: in the first frames of play, or before play, with `createEngine` waiting for it ([The preset check](../concepts/quality-presets.md#the-preset-check)) |
245
- | `?view=levels` | Draw a debug view, here the levels of detail, with no code change ([Debug views](../api/debug.md#the-view-from-the-address)). The switch takes any view name that `debug.view` takes |
281
+ | `?derived-cache=off` | Turn the [cache of derived data](../api/assets.md#the-cache-of-derived-data) off, so every load makes its data again, as on a first visit: KTX2 files transcode, and `assets.cache` keeps nothing |
282
+ | `?sketch-thread=main` | Run the sketch on the page's main thread, over the `sketchThread` option |
283
+
284
+ </details>
@@ -1,14 +1,10 @@
1
1
  ---
2
2
  id: guides/ui-overlays
3
- title: "UI, HTML overlays and labels"
4
- status: experimental
5
- since: "0.2"
3
+ title: HTML UI around the scene
6
4
  summary: "HTML UI on the page; labels that follow objects; GUI panels."
7
5
  ---
8
6
 
9
- # UI, HTML overlays and labels
10
-
11
- > Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
7
+ # HTML UI around the scene
12
8
 
13
9
  ```mermaid
14
10
  flowchart LR
@@ -47,7 +43,7 @@ document.querySelector('#pause')!.addEventListener('click', () => engine.postToS
47
43
 
48
44
  ## Labels that follow objects
49
45
 
50
- A label is an element that sits over a scene object. The sketch tracks it with `ui.trackLabel`, and the page binds its element with `engine.labels.bind`. [UI overlays and labels](../api/ui.md) describes both calls.
46
+ A label is an element that sits over a scene object. The sketch tracks it with `ui.trackLabel`, and the page binds its element with `engine.labels.bind`. [Labels that follow objects](../api/ui.md) describes both calls. The [picking demo](https://github.com/null3d-engine/null3d/tree/main/examples/picking) tracks a label on each piece as the plinth turns.
51
47
 
52
48
  This example gives each unit a health bar. The bar follows its unit in every frame, and only the health value travels as a message, when it changes.
53
49
 
@@ -94,9 +90,14 @@ engine.onSketchMessage((type, data) => {
94
90
  });
95
91
  ```
96
92
 
93
+ ```css
94
+ /* page.css */
95
+ .hp { width: 60px; height: 6px; background: linear-gradient(to right, #4caf50 var(--hp), #333 0); }
96
+ ```
97
+
97
98
  Keep label elements light. The engine writes only their `transform` and `visibility`, which the browser applies without a new layout. Text or size changes inside a label do cost a layout, so change them only when the value changes.
98
99
 
99
- The engine holds 4,096 labels at once by default. For more, set `createEngine`'s `maxLabels` option. With many labels, bind elements only for the ones the player can see, and untrack the rest.
100
+ With many labels, bind elements only for the ones the player can see, and untrack the rest. [Labels that follow objects](../api/ui.md#labels-that-follow-objects) gives the limits.
100
101
 
101
102
  ## Labels that are planes of the scene
102
103
 
@@ -111,7 +112,7 @@ ui.trackLabel(panel, 'card-3', { transform: 'world', offset: [0, 1.4, 0] });
111
112
  ui.trackLabel(crown, 'title', { transform: 'billboard', rotation: 0.1 });
112
113
  ```
113
114
 
114
- The page binds the element as for any label. The engine moves it into a container of its own inside the element's parent, and turns it with the camera's perspective. So the parent must cover the canvas.
115
+ The page binds the element as for any label. The parent must cover the canvas, because the engine turns the element with the camera's perspective.
115
116
 
116
117
  ```ts
117
118
  // page.ts
@@ -121,11 +122,11 @@ layer.append(card);
121
122
  engine.labels.bind('card-3', card);
122
123
  ```
123
124
 
124
- An element's CSS pixels are the scene's units for these labels. An element 200 pixels wide is 200 units wide. Size the scene around it to match, and the browser keeps the text sharp at any distance.
125
+ Size the scene around the element's size in CSS pixels, and the browser keeps the text sharp at any distance. [Labels that follow objects](../api/ui.md#labels-that-follow-objects) gives the units. The [3D labels demo](https://github.com/null3d-engine/null3d/tree/main/examples/css3d-labels) sets a card to `world` and its title to `billboard`.
125
126
 
126
127
  A plane follows either lens. An orthographic camera turns and scales the element as a perspective camera does. An element can hold any markup, such as an iframe or a form. Give it `pointer-events: auto` if it takes the pointer, because the layer around it passes the pointer through.
127
128
 
128
- The engine holds 256 planes by default, which take 40 KB of the memory that its threads share. Set `createEngine`'s `maxLabels3d` option for more, or to 0 on a page that shows no plane.
129
+ [Labels that follow objects](../api/ui.md#labels-that-follow-objects) gives the plane limit and the memory it takes.
129
130
 
130
131
  ### A page under the scene
131
132
 
@@ -148,6 +149,8 @@ const pagePlane = scene.createMesh({
148
149
  ui.trackLabel(pagePlane, 'page', { transform: 'world' });
149
150
  ```
150
151
 
152
+ Give the page element the plane's size, 800 by 600 CSS pixels, so that the two rectangles match.
153
+
151
154
  The plane writes its depth and nothing else. Objects behind the page then fail the depth test. Objects in front still draw over it, and a glass object in front still shows the page through itself. An opaque plane would hide the page instead. [Invisible surfaces that hide](../api/materials.md#invisible-surfaces-that-hide) covers the material.
152
155
 
153
156
  The [depth-only demo](https://github.com/null3d-engine/null3d/tree/main/examples/depth-only) shows the pattern, with glass in front of an embedded page and a hall of glowing pylons behind it.
@@ -170,13 +173,15 @@ gui.add(settings, 'bloom').onChange((on: boolean) => engine.postToSketch('bloom'
170
173
  // sketch.ts
171
174
  page.onMessage((type, data) => {
172
175
  if (type === 'exposure') post.set({ exposure: data as number });
176
+ if (type === 'bloom') post.set({ bloom: data ? {} : false });
173
177
  });
174
178
  ```
175
179
 
176
180
  ## Related pages
177
181
 
178
- - [UI overlays and labels](../api/ui.md): `ui.trackLabel` and `engine.labels.bind`.
182
+ - [Labels that follow objects](../api/ui.md): `ui.trackLabel` and `engine.labels.bind`.
179
183
  - [The 3D labels demo](https://github.com/null3d-engine/null3d/tree/main/examples/css3d-labels): cards that turn with a ring.
180
184
  - [Messages between sketch and page](../api/page.md): `page.post`, `page.onMessage` and `engine.postToSketch`.
185
+ - [Messages in both directions](https://github.com/null3d-engine/null3d/tree/main/examples/weighted-transparency): a page button sends a blend to the sketch, and the sketch reports back.
181
186
  - [Cameras](../api/cameras.md): `worldToScreen` places a single point on the canvas.
182
187
  - [Accessibility](accessibility.md): meaning in HTML around the canvas.
@@ -1,15 +1,11 @@
1
1
  ---
2
2
  id: guides/video-textures
3
3
  title: Video textures
4
- status: experimental
5
- since: "0.3"
6
4
  summary: "engine.registerVideo on the page and textures.fromVideo in the sketch; frame sizes and the upload budget; browser limits."
7
5
  ---
8
6
 
9
7
  # Video textures
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
9
  ```mermaid
14
10
  flowchart LR
15
11
  video["Page:<br/>a video element plays"] -->|"engine.registerVideo:<br/>one ImageBitmap a frame"| sketch["Sketch thread:<br/>textures.fromVideo shows the newest frame"]
@@ -35,9 +31,7 @@ video.src = '/clips/intro.mp4';
35
31
  video.muted = true;
36
32
  video.loop = true;
37
33
  video.playsInline = true;
38
- // Keep the element in the page but out of sight. An element that display: none hides may give no
39
- // frame in some browsers, so park it past the page's edge instead. Its sound comes from the page
40
- // as any video's does.
34
+ // Park the element past the page's edge; see Browser limits.
41
35
  video.style.position = 'absolute';
42
36
  video.style.left = '-10000px';
43
37
  video.style.width = '1px';
@@ -65,7 +59,9 @@ export default defineSketch(({ scene, geometry, materials, textures }) => {
65
59
  });
66
60
  ```
67
61
 
68
- The texture follows the video: pause, seek, loop and playback speed all show, because the page sends the frames that the video presents. The video has no pixels until its first frame arrives, and until then the material draws with its color alone. A video that is paused at the call still shows, because the sketch asks for the frame that it holds then.
62
+ The texture follows the video: pause, seek, loop and playback speed all show, because the page sends the frames that the video presents. The engine never plays, pauses or seeks the element. The video has no pixels until its first frame arrives, and until then the material draws with its color alone. A video that is paused at the call still shows, because the sketch asks for the frame that it holds then.
63
+
64
+ A page that shows a video in the scene and on the page at once runs one element and one timeline.
69
65
 
70
66
  Stop the frames with `texture.destroy()` in the sketch, or with the function that `engine.registerVideo` returns on the page.
71
67
 
@@ -93,14 +89,19 @@ The video's own frame rate sets the cost. A 30 frames a second video uploads its
93
89
  ## Browser limits
94
90
 
95
91
  - A browser plays the video formats that it supports, as for any video element. An H.264 MP4 file plays in the browsers that the engine runs on.
96
- - A page shows a video with sound only after the user acts, unless the video is muted. Start a muted video as the example does, or play it from a click.
92
+ - A video with sound plays only after the user acts, unless it is muted. A refused video sends no frames, and the material draws with its color alone, with no error. Start a muted video as the example does, or play it from a click.
97
93
  - A video from another origin needs `video.crossOrigin = 'anonymous'` and the server's CORS headers. Without them, the browser refuses to copy the video's pixels into an image. No frames arrive, and the texture keeps the frame it had.
98
- - A browser that refuses to play the video, as an autoplay policy does before the user acts, sends no frames. The material then draws with its color alone, and the engine reports no error.
99
- - The engine reads each frame through `createImageBitmap`, which every supported browser has. It does not need `VideoFrame`, which Safari and Firefox cannot make from a video element.
94
+ - Safari and Firefox cannot make a `VideoFrame` from a video element.
100
95
  - Keep the element in the page's layout, out of sight. An element that `display: none` hides may give no frame in some browsers.
101
- - A browser reports each frame that the video presents, and the page sends that frame. Some browsers report none for a video element that the page never shows. The page then checks the video's time on each display frame while it plays, and stops that check while the video is paused.
96
+ - Some browsers report no frames for a video that the page never shows.
102
97
  - A phone plays a video at the rate that its heat allows, and the browser may lower that rate. A video that must keep time with the scene, such as a synchronized caption track, reads the video's time in the page.
103
- - The video's own element handles playback. The engine never plays, pauses or seeks it, so a page that shows a video in the scene and on the page at once runs one element and one timeline.
98
+
99
+ <details>
100
+ <summary>Technical details: how the page reads each frame</summary>
101
+
102
+ The page makes each frame with `createImageBitmap`, which every supported browser has, so it does not need `VideoFrame`. It waits for the browser's report of each presented frame. When a browser gives no reports, the page checks the video's time on each display frame while the video plays, and stops that check while it is paused.
103
+
104
+ </details>
104
105
 
105
106
  ## Related pages
106
107