@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: api/engine
3
3
  title: "Page API: createEngine"
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "createEngine options and start errors; memory; capabilities and mode; pausing, detaching, failures, measuring, captureFrame, messages, pointer lock and destroy."
7
5
  ---
8
6
 
9
7
  # Page API: createEngine
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
  `createEngine` starts the engine on a canvas and runs a sketch. It returns an `Engine`, the page's handle on the running engine. The page keeps the HTML, and the sketch builds the scene in a worker of its own.
14
10
 
15
11
  ```ts
@@ -33,7 +29,11 @@ try {
33
29
 
34
30
  ## The start
35
31
 
36
- `createEngine` tests what the browser offers, and picks the build and the GPU path from those tests, never from browser or GPU names. It starts the engine's threads, loads the sketch module and runs the sketch's setup. It resolves once the setup has run, and `engine.firstFrame` resolves once the GPU has finished the first frame. The engine can stop drawing before that frame. Then `engine.firstFrame` rejects with the failure that ended its frames, such as [E1404](../errors/E1404.md) when the thread that draws fails. A destroy before the first frame rejects it with [E1420](../errors/E1420.md). When the engine chose the preset itself, its [preset check](../concepts/quality-presets.md#the-preset-check) measures the first frames of play, and `engine.presetChecked` resolves once the check has ended. With the `presetCheck` option's `before-play`, the check runs before play, and `createEngine` waits for it. The first frame is then on the screen before `createEngine` resolves. On a repeat visit, the engine takes the check's stored result instead, and runs no check.
32
+ `createEngine` tests what the browser offers, and picks the build and the GPU path (tier) from those tests, not from browser or GPU names. One later choice on WebGPU does read names: a start-up measurement of the draw path runs only on an Apple GPU in WebKit ([Never branch on GPU names](../concepts/backends.md#never-branch-on-gpu-names)). It starts the engine's threads, loads the sketch module and runs the sketch's setup. It resolves once the setup has run.
33
+
34
+ `engine.firstFrame` resolves once the GPU has finished the first frame. If the engine stops drawing before that frame, `engine.firstFrame` rejects with the failure that ended its frames, such as [E1404](../errors/E1404.md) when the thread that draws fails. A destroy before the first frame rejects it with [E1420](../errors/E1420.md).
35
+
36
+ When the engine chose the preset itself, its [preset check](../concepts/quality-presets.md#the-preset-check) measures the first frames of play, and `engine.presetChecked` resolves once the check has ended. With the `presetCheck` option's `before-play`, the check runs before play, and `createEngine` waits for it. The first frame is then on the screen before `createEngine` resolves. On a repeat visit, the engine takes the check's stored result instead, and runs no check.
37
37
 
38
38
  `onProgress` reports each stage of the start, in this order:
39
39
 
@@ -59,7 +59,7 @@ An `AbortSignal` in `signal` cancels a start in progress. Then `createEngine` st
59
59
  | --- | --- |
60
60
  | [E1407](../errors/E1407.md) | The `hold` option or the `?hold=` switch gives a time that is not a number of seconds from 0 to 600. |
61
61
  | [E1415](../errors/E1415.md) | The sketch would run on the page's main thread, where another engine still runs its sketch. |
62
- | [E1213](../errors/E1213.md) | An option is out of its range: `preset`, `presetCheck`, `targetFps`, `maxPixelRatio`, `antialias` or a shadow option. It can also be `depthPrepass`, `momentTransparency`, `gpuOcclusion`, `softwareOcclusion`, `morphTargets`, `cloudSteps` or `textureMemoryMiB`. It can also be `expectedObjects`, `maxLabels` or `maxLabels3d`. The options table gives each range. |
62
+ | [E1213](../errors/E1213.md) | An option is out of its range: `preset`, `presetCheck`, `targetFps`, `maxPixelRatio`, `antialias` or a shadow option. It can also be `depthPrepass`, `momentTransparency`, `gpuOcclusion`, `softwareOcclusion`, `morphTargets`, `cloudSteps` or `textureMemoryMiB`. It can also be `expectedObjects`, `maxLabels` or `maxLabels3d`. The options table gives each range. `sketchData` that is not plain JSON data, or that takes more than 64 KiB as JSON, also fails with it. |
63
63
  | [E1409](../errors/E1409.md) | The `memory` option asks for a maximum that is not a whole number of MiB from 256 to 4096. |
64
64
  | [E1303](../errors/E1303.md) | The browser runs WebAssembly without SIMD. |
65
65
  | [E1306](../errors/E1306.md) | The browser runs the WebKit engine of a Safari before 18: Safari 17 or older, or any browser on iOS or iPadOS 17 or older. |
@@ -67,7 +67,7 @@ An `AbortSignal` in `signal` cancels a start in progress. Then `createEngine` st
67
67
  | [E1406](../errors/E1406.md) | The engine core's WebAssembly file did not download. |
68
68
  | [E1418](../errors/E1418.md) | The page's Content-Security-Policy blocks WebAssembly: its `script-src` lacks `'wasm-unsafe-eval'`. |
69
69
  | [E1109](../errors/E1109.md) | The browser refused the engine's memory, even after about 45 seconds of tries. |
70
- | [E1402](../errors/E1402.md) | The engine core's file comes from another build than the engine's JavaScript. Every build checks that the threaded core imports shared memory, and development builds also check each function. On null3D's own dev server, they also check that the core was built from the checkout's Rust sources. |
70
+ | [E1402](../errors/E1402.md) | The engine core's file comes from another build than the engine's JavaScript. Every build checks that the threaded core imports shared memory, and development builds also check each function. |
71
71
  | [E1410](../errors/E1410.md) | The sketch module did not load, at the first import or the second: it did not download, or its code threw an error while it loaded. |
72
72
  | [E1401](../errors/E1401.md) | The sketch module's default export is not `defineSketch(...)`. |
73
73
  | [E1214](../errors/E1214.md) | An option of `defineSketch` is out of its range. |
@@ -82,6 +82,8 @@ An error that the sketch's setup throws also rejects the start ([Sketch API](ske
82
82
 
83
83
  `canvas` and `sketch` are required. `sketch` is the address of the sketch module, usually `new URL('./sketch.ts', import.meta.url)`.
84
84
 
85
+ `sketchData` gives the setup a start state, such as the section that the address names ([Start data](page.md#start-data)).
86
+
85
87
  The canvas takes its size from CSS. The engine sizes the canvas's drawing buffer to that size times the screen's pixel ratio, up to the cap that `maxPixelRatio` or the preset sets.
86
88
 
87
89
  - A canvas that no CSS sizes shows its drawing buffer at one CSS pixel per buffer pixel, so each new buffer would make it larger. The engine sets the CSS width and height that the canvas shows when the engine starts.
@@ -91,15 +93,15 @@ The canvas takes its size from CSS. The engine sizes the canvas's drawing buffer
91
93
  | --- | --- | --- |
92
94
  | `preset` | `'auto'` | The quality preset, which the engine chooses for the device unless the page names one: [Quality presets](../concepts/quality-presets.md). The `?preset=` switch wins over it. |
93
95
  | `presetCheck` | `'during-play'` | When the engine checks a preset that it chose: in the first frames of play, while the loading screen is gone, or `'before-play'`, with `createEngine` waiting for it. `engine.presetChecked` resolves once the check has ended: [The preset check](../concepts/quality-presets.md#the-preset-check). The `?preset-check=` switch wins over it. |
94
- | `targetFps` | The display's rate, at most 60 | The frame rate that the engine defends. `'display'` defends the display's full rate, such as 120 or 144 for a game. A whole number caps the target at that rate: [Quality presets](../concepts/quality-presets.md#the-target-frame-rate). The `?target-fps=` switch wins over it. Another value fails with [E1213](../errors/E1213.md). |
96
+ | `targetFps` | The display's rate, at most 60 | The frame rate that the engine defends. `'display'` defends the display's full rate, such as 120 or 144 for a game. A whole number caps the target at that rate: [Quality presets](../concepts/quality-presets.md#the-target-frame-rate). The `?target-fps=` switch wins over it. |
95
97
  | `maxPixelRatio` | The preset's cap | Caps the screen's pixel ratio that the engine draws at, in place of the preset's cap |
96
98
  | `antialias` | The preset's mode | `'msaa'`, `'fxaa'` or `'none'`, in place of the preset's anti-aliasing mode: [GPU tiers and backends](../concepts/backends.md#color-and-anti-aliasing-on-each-tier) |
97
- | `hdr` | The device's path | `false` draws the scene into 8-bit color, where each material's shader applies the output transform, instead of HDR color, which the final pass tone maps. Both paths honour a material's `toneMapped: false`, and the 8-bit path also honours it on a blended surface: [Materials that keep their display color](../concepts/color-management.md#materials-that-keep-their-display-color). The `?hdr=off` switch takes that path too. |
99
+ | `hdr` | The device's path | `false` draws the scene into 8-bit color, where each material's shader applies the output transform, instead of HDR color, which the final pass tone maps. Both paths honor a material's `toneMapped: false`, and the 8-bit path also honors it on a blended surface: [Materials that keep their display color](../concepts/color-management.md#materials-that-keep-their-display-color). The `?hdr=off` switch takes that path too. |
98
100
  | `shadowTiles`, `shadowTileSize`, `pointLightShadows` | The preset's values | The shadows of spot and point lights, in place of the preset's settings: [Shadows](../concepts/shadows.md#settings). Each is fixed while the engine runs. |
99
- | `cloudSteps` | The preset's value | The steps of each ray of the sky's volumetric cloud tier, in place of the preset's value: 0 draws the flat layer, and a number above 0 the volumetric clouds, at that many steps. WebGL2 and compatibility mode stop at Medium, so a page there reaches the tier with this option or with `quality.set`. The tier's noise and shaders load at its first use: [Quality API](quality.md#settings). Another value fails with [E1213](../errors/E1213.md). |
100
- | `shadowCascades`, `shadowMapSize`, `heroTileSize`, `gpuOcclusion`, `morphTargets`, `softwareOcclusion`, `textureMemoryMiB` | The preset's values | These settings, in place of the preset's values: [Quality API](quality.md#settings). Another value fails with [E1213](../errors/E1213.md). |
101
+ | `cloudSteps` | The preset's value | The steps of each ray of the sky's volumetric cloud tier, in place of the preset's value: 0 draws the flat layer, and a number above 0 the volumetric clouds, at that many steps. WebGL2 and compatibility mode stop at Medium, so a page there reaches the tier with this option or with `quality.set`. The tier's noise and shaders load at its first use: [Quality API](quality.md#settings). |
102
+ | `shadowCascades`, `shadowMapSize`, `heroTileSize`, `gpuOcclusion`, `morphTargets`, `softwareOcclusion`, `textureMemoryMiB` | The preset's values | These settings, in place of the preset's values: [Quality API](quality.md#settings). |
101
103
  | `depthPrepass` | `true` on WebGL2 and `false` on WebGPU, on every preset | `true` draws the depth of the opaque objects before they are shaded: [The depth prepass](../concepts/quality-presets.md#the-depth-prepass). The `?prepass=` switch wins over it. |
102
- | `momentTransparency` | `false` on every preset | `true` blends the camera's blended surfaces in a layer that needs no sort, and draws those surfaces twice: [Moment transparency](materials.md#moment-transparency). It stays fixed while the engine runs. The `?moments=` switch wins over it. Another value fails with [E1213](../errors/E1213.md). |
104
+ | `momentTransparency` | `false` on every preset | `true` blends the camera's blended surfaces in a layer that needs no sort, and draws those surfaces twice: [Moment transparency](materials.md#moment-transparency). It stays fixed while the engine runs. The `?moments=` switch wins over it. |
103
105
  | `keepTextureCopies` | `true` on phones and tablets, `false` on desktops | `true` keeps the engine's copy of each texture's texels after their upload, so a texture draws with its map again after the browser takes the GPU away. It costs about one more copy of each image in memory: [When the GPU goes away](../concepts/backends.md#when-the-gpu-goes-away). With it, the engine also gives its GPU back while the page sits in the browser's back-forward cache. |
104
106
  | `gpu` | `'auto'` | Forces a GPU path, for tests only. The `?gpu=` switch in the page's address wins over it, and also takes `compat` for WebGPU's compatibility mode. |
105
107
  | `powerPreference` | `'high-performance'` | Picks the GPU on a device that has two. `'low-power'` saves battery. The engine's start-up tests of the GPU run on the GPU that it picks. |
@@ -108,10 +110,11 @@ The canvas takes its size from CSS. The engine sizes the canvas's drawing buffer
108
110
  | `largeWorld` | false | Keeps the positions of objects exact at any distance from the origin, for scenes the size of a planet: [Large worlds and precision](../concepts/large-worlds.md#large-world-mode) |
109
111
  | `sketchThread` | `'worker'` | The thread that runs the sketch. `'main'` runs it on the page's main thread, where it can reach the DOM: [Where the sketch runs](../concepts/architecture.md#where-the-sketch-runs). The `?sketch-thread=` switch wins over it, and the single-threaded build always runs the sketch on the main thread. |
110
112
  | `memory` | `{ maximumMiB: 1024 }` | The most memory that the engine's threads share: [Memory](#memory) |
111
- | `expectedObjects` | None | The objects that the scene starts with room for, from 1 to 1,048,575, in place of 1,023. A scene that knows its size never grows its tables during play: [Scene limits](scene.md#limits). Another value fails with [E1213](../errors/E1213.md). |
112
- | `maxLabels` | `4096` | The most labels that the sketch tracks at once, from 1 to 65,536: [UI overlays and labels](ui.md). Another value fails with [E1213](../errors/E1213.md). |
113
- | `maxLabels3d` | `256` | The most labels whose `transform` is `'world'` or `'billboard'`, which are planes of the scene, from 0 to 65,536: [Labels as planes of the scene](ui.md#labels-as-planes-of-the-scene). Another value fails with [E1213](../errors/E1213.md). |
113
+ | `expectedObjects` | None | The objects that the scene starts with room for, from 1 to 1,048,575, in place of 1,023. A scene that knows its size never grows its tables during play: [Scene limits](scene.md#limits). |
114
+ | `maxLabels` | `4096` | The most labels that the sketch tracks at once, from 1 to 65,536: [Labels that follow objects](ui.md). |
115
+ | `maxLabels3d` | `256` | The most labels whose `transform` is `'world'` or `'billboard'`, which are planes of the scene, from 0 to 65,536: [Labels as planes of the scene](ui.md#labels-as-planes-of-the-scene). |
114
116
  | `onProgress` | None | Reports each stage of the start, and a download stage's bytes |
117
+ | `sketchData` | None | Start data that the sketch's setup reads as `ctx.data`, before the first frame and in hold mode. It takes plain JSON data, up to 64 KiB as JSON, and another value fails with [E1213](../errors/E1213.md). A recording keeps it: [Start data](page.md#start-data) |
115
118
  | `onSketchMessage` | None | Receives the sketch's messages from the start of its setup: [Messages](page.md) |
116
119
  | `onSketchError` | None | Receives each distinct error that the sketch's frame code throws while the engine runs: [The running engine](#the-running-engine) |
117
120
  | `onWorkerRetry` | None | Called when the engine starts a second copy of a worker whose script did not load: [The start](#the-start) |
@@ -120,12 +123,18 @@ The canvas takes its size from CSS. The engine sizes the canvas's drawing buffer
120
123
  | `input` | true | `false` keeps the engine from listening for input, for a page whose input another library records. The sketch's `ctx.input` then stays at rest, and `requestPointerLock()` fails with [E1426](../errors/E1426.md): [Input off](input.md#input-off) |
121
124
  | `preload` | None | Features whose shaders load before the first frame, such as `['skinning', 'bloom']`, for a game that must fetch nothing while it plays. Each feature's shaders otherwise download the first time the sketch uses it: [Loading screens](../guides/loading-screens.md). A name that the engine does not know throws [E1421](../errors/E1421.md). |
122
125
  | `still` | true | `false` draws every frame of a view that holds still, which otherwise blends its frames into a sharper picture and then stops drawing until something changes: [Still-camera accumulation](../concepts/post-processing.md#still-camera-accumulation). The `?still-camera=off` switch turns it off too. |
123
- | `stats` | false | `true` shows the stats overlay from the first frame, and `{ collapsed: true }` shows it with its card closed: [Stats overlay and frame figures](debug.md#stats-overlay-and-frame-figures). The `?stats` switch shows it too, and `?stats=off` hides it. A held engine shows no overlay. |
126
+ | `stats` | false | `true` shows the stats overlay from the first frame, `{ collapsed: true }` shows it with its card closed, and `{ corner: 'bottom-right' }` puts it over the canvas's bottom-right corner: [Stats overlay and frame figures](debug.md#stats-overlay-and-frame-figures). The `?stats` switch shows it too, and `?stats=off` hides it. A held engine shows no overlay. |
127
+
128
+ A value outside its range fails the start with [E1213](../errors/E1213.md), except `memory`, which fails with [E1409](../errors/E1409.md).
124
129
 
125
130
  ## A transparent canvas
126
131
 
127
132
  With `transparent: true`, the page shows through wherever no object draws. The canvas holds premultiplied alpha, the form that browsers composite. The sketch can still set a background with `scene.setBackground`, which makes the canvas opaque again.
128
133
 
134
+ ![Glass panes over an embedded web page that shows through a see-through canvas.](../images/api/engine/transparent-canvas.webp)
135
+
136
+ A see-through canvas over a page, with a depth-only plane.
137
+
129
138
  ```ts
130
139
  const engine = await createEngine({
131
140
  canvas,
@@ -134,7 +143,7 @@ const engine = await createEngine({
134
143
  });
135
144
  ```
136
145
 
137
- Use it to put a model over the page's own background, such as a product on a marketing page. [Color management](../concepts/color-management.md#transparent-canvases) covers how the edges of objects blend with the page.
146
+ Use it to put a model over the page's own background, such as a product on a marketing page. [Color management](../concepts/color-management.md#transparent-canvases) covers how the edges of objects blend with the page. The [depth-only holdout demo](https://github.com/null3d-engine/null3d/tree/main/examples/depth-only) shows the pattern. The demos' shared runner starts the engine with the option, not the demo's sketch.
138
147
 
139
148
  ## Memory
140
149
 
@@ -146,40 +155,105 @@ const engine = await createEngine({ canvas, sketch, memory: { maximumMiB: 2048 }
146
155
 
147
156
  The browser reserves address space for the whole maximum when the engine starts, and the memory grows into it as the scene needs. Every other engine and WebAssembly module on the page, such as a physics engine, shares the address space that is left. So a larger maximum leaves less room for them. In Safari on an iPad Pro, a page holds the memories of 6 engines at 1024 MiB, and of 3 at 4096 MiB.
148
157
 
149
- Ask for more only when a scene needs it. Each instance row takes about 210 bytes of engine memory, so 1024 MiB holds about 5 million rows with the rest of the scene. Each place for an object takes about 267 bytes in the scene's tables. While the tables grow, the old and the new ones both take memory for a moment. A scene that needs more memory than the maximum fails with [E1109](../errors/E1109.md). A maximum that is not a whole number of MiB from 256 to 4096 fails the start with [E1409](../errors/E1409.md).
158
+ Ask for more only when a scene needs it. A scene that needs more memory than the maximum fails with [E1109](../errors/E1109.md). A maximum that is not a whole number of MiB from 256 to 4096 fails the start with [E1409](../errors/E1409.md).
159
+
160
+ <details>
161
+ <summary>Technical details: how much memory a scene takes</summary>
162
+
163
+ - Each instance row takes about 210 bytes of engine memory, so rows alone fill 1024 MiB at about 5 million. Leave room for the meshes and the rest of the scene, or ask for a larger maximum.
164
+ - Each place for an object takes about 267 bytes in the scene's tables.
165
+ - While the tables grow, the old and the new tables both take memory for a moment.
166
+
167
+ </details>
150
168
 
151
169
  The single-threaded build's memory is not shared. It grows as the scene needs, so the option does not change it. The `?memory=<MiB>` switch in the page's address wins over the option, for tests.
152
170
 
153
171
  ## What the engine reports
154
172
 
155
- - `engine.capabilities` gives the GPU path (`tier`), whether the engine runs threaded, and the optional features and limits of the GPU path. It also gives whether the scene draws HDR color (`hdr`), the depth mode, and the most objects and instance rows that the device draws (`maxInstances`). The `directDraws` field says whether the device draws buckets directly. A start-up measurement picks that path only on an Apple GPU in Safari, or in any browser on iPhone and iPad. The `drawPath` field says why the engine took its path, such as `not-apple-gpu-in-webkit`. The `halfPrecision` field says whether the scene shaders do their color math at half precision, which only the `?half=on` switch turns on. [GPU tiers and backends](../concepts/backends.md) explains each.
156
- - `engine.mode` gives the build, the latency mode, the thread that runs the sketch and the thread that draws. It also gives the most job workers that the engine may start, and the held time in hold mode. The job workers start as the work grows ([Architecture](../concepts/architecture.md#when-the-job-workers-start)). It gives the quality preset that runs now and what the preset check measured. It also gives the starts that crashed the tab before this one, and the memory maximum. While a check runs during play, `presetCheck` is null and the preset can still drop. `engine.presetChecked` resolves once both hold the check's choice. The `keepTextureCopies` field says whether the engine keeps each texture's copy. It restores a map after a GPU loss ([When the GPU goes away](../concepts/backends.md#when-the-gpu-goes-away)). The `renderFallback` field says why the page draws where a worker was meant to, or is null.
173
+ - `engine.capabilities` gives the GPU path that the engine chose and what that path offers: its tier, its features and limits, HDR, depth, and the most objects it draws. [EngineCapabilities](reference/engine.md#enginecapabilities) lists every field. [GPU tiers and backends](../concepts/backends.md) explains each.
174
+ - `engine.mode` gives how the engine runs on this device: its build, its threads, its quality preset and its memory maximum. [EngineMode](reference/engine.md#enginemode) lists every field. `presetCheck` is null while a check runs during play, and `engine.presetChecked` resolves when the check is done. The job workers start as the work grows ([Architecture](../concepts/architecture.md#when-the-job-workers-start)).
157
175
  - `engine.report` holds every result of the start's tests, as plain JSON.
158
176
 
159
177
  ## The running engine
160
178
 
161
179
  - `setPaused(true)` stops the sketch's frames, and `setPaused(false)` resumes them. The first step after a pause is 0 seconds.
162
180
  - `detach()` takes the canvas off the page and pauses the engine, and `attach(container)` puts it back. Use them when a single-page app leaves the view with the canvas and comes back. The engine keeps its threads, its GPU resources and the scene.
163
- - `onFailure(handler)` receives a failure after the start. It can be a GPU that the engine could not get back ([E1302](../errors/E1302.md)), or an engine thread that failed ([E1404](../errors/E1404.md)). It can be a file of a custom shader's builds that a pipeline needs and that did not download ([E1424](../errors/E1424.md)). After E1404 or E1424 the engine stops drawing new frames, and the canvas keeps the last one: destroy the engine and start a new one. It can also be a job worker that did not start ([E1405](../errors/E1405.md)). On WebGPU it can be a GPU that ran out of memory ([E1304](../errors/E1304.md)) or rejected the engine's work ([E1305](../errors/E1305.md)). On either GPU path it can be a pipeline of the scene's objects that the GPU's driver refused twice ([E1307](../errors/E1307.md)). After these three the engine draws on without the objects that failed. The first handler that attaches after a failure that no handler heard still receives it, and the engine also logs the failure to the console. The handler is the only place where these failures show: no promise rejects for them. A failure that ends the frames reaches these handlers before the `onStop` handlers.
164
- - `onStop(handler)` calls the handler once, when the engine stops drawing for good. That happens as `destroy()` begins, or at a failure after which it draws no new frames: [E1302](../errors/E1302.md), [E1404](../errors/E1404.md) or [E1424](../errors/E1424.md). At such a failure, the `onFailure` handlers hear it first. A handler added after that runs at once. A handler that throws reaches the console, and the other handlers and the stop go on. Use it to end the page's own work for the engine, such as a frame loop that sends the sketch messages. It returns a function that removes the handler.
181
+ - `onFailure(handler)` receives a failure after the start. A failure that ends the frames reaches these handlers before the `onStop` handlers. The first handler that attaches after a failure that no handler heard still receives it, and the engine also logs the failure to the console. The handler is the only place where these failures show: no promise rejects for them. [Failures after the start](#failures-after-the-start) lists each code and what happens next.
182
+ - `onStop(handler)` calls the handler once, when the engine stops drawing for good. That happens as `destroy()` begins, or at a failure after which it draws no new frames. At such a failure, the `onFailure` handlers hear it first.
183
+ - A handler added after that runs at once. A handler that throws reaches the console, and the other handlers and the stop go on. Use it to end the page's own work for the engine, such as a frame loop that sends the sketch messages. It returns a function that removes the handler.
165
184
  - `onSketchError(handler)` receives each distinct error that the sketch's frame code threw, or a core call in a frame. The engine keeps drawing frames, so such an error does not stop it. `measure()` counts each frame whose update failed in `updateErrors`, and leaves it out of `updatedFps`. Without a handler, the error reaches the console. The `onSketchError` option adds a handler from the start.
166
185
  - `simulateGpuLoss()` acts out a loss of the GPU, so you can test how the page handles one. The engine starts a new GPU device and draws the whole scene again.
167
186
  - `measure(seconds)` measures the running engine: CPU time per frame by thread, GPU time, frame intervals, uploads, draw calls, memory and load time. [Performance guide](../guides/performance.md) explains the numbers. It measures whatever build the page runs. In a development build, the development checks add to the CPU times, so time a production build ([Measure fairly](../guides/performance.md#measure-fairly)).
168
- - `stats(true)` shows the stats overlay over the canvas, and `stats(false)` hides it: [Stats overlay and frame figures](debug.md#stats-overlay-and-frame-figures). Options in place of `true` set whether the card starts closed, on a shown overlay too. The sketch's `debug.stats` shows and hides the same overlay, and the last call from either side wins.
187
+ - `stats(true)` shows the stats overlay over the canvas, and `stats(false)` hides it: [Stats overlay and frame figures](debug.md#stats-overlay-and-frame-figures). Options in place of `true` set whether the card starts closed and the canvas's corner that the overlay sits in, on a shown overlay too. The sketch's `debug.stats` shows and hides the same overlay, and the last call from either side wins.
169
188
  - `capture()` resolves with a PNG image of the next frame that the engine draws: [Screenshots](#screenshots).
170
- - `captureFrame()` returns the pixels of the next frame that the engine draws, as RGBA8 rows, top row first. The thread that draws waits for its frame loop to take a new frame, then draws that frame again offscreen and reads it back. So captures back to back give newer frames, even on a slow GPU whose readback holds that thread up. In hold mode it returns the held frame and draws nothing. On a transparent canvas the pixels keep their premultiplied alpha. Tests use it: [Testing your sketch](../guides/testing.md).
189
+ - `captureFrame()` returns the pixels of the next frame that the engine draws, as RGBA8 rows, top row first. Tests use it: [Testing your sketch](../guides/testing.md).
190
+
191
+ <details>
192
+ <summary>Technical details: how captureFrame reads a frame</summary>
193
+
194
+ The thread that draws waits for its frame loop to take a new frame, then draws that frame again offscreen and reads it back. So captures back to back give newer frames, even on a slow GPU whose readback holds that thread up. In hold mode it returns the held frame and draws nothing. On a transparent canvas the pixels keep their premultiplied alpha.
195
+
196
+ </details>
197
+
171
198
  - `saveRecording()` resolves with the recording of the session so far, or `undefined` when the page records none. A page records with the `?record` switch, and `?replay=<file>` plays a saved recording: [Record a session that went wrong](../guides/testing.md#record-a-session-that-went-wrong).
172
199
  - `postToSketch` and `onSketchMessage` send and receive [messages](page.md).
173
- - `inspect(call, args)` runs an inspection call against the live scene, for the in-page inspector and the MCP server: `objects`, `object`, `setObject`, `setMaterial`, `stats`, `errors`, `graph`, `setQuality`, `highlight` and `info`. The call runs between frames, in the thread that runs the sketch, and returns a JSON-safe value. The page answers `capture` itself, with `{ png, bytes }`: the PNG image of the next frame as base64 text, and its size in bytes. The method exists only in a development build, which carries the channel, and a production build leaves it out. Code that uses it checks for it first: `await engine.inspect?.('objects')`. [Debugging](../guides/debugging.md#the-in-page-inspector) shows the calls.
174
- - `labels.bind(id, element)` moves an HTML element over the label that the sketch tracks under `id`: [UI overlays and labels](ui.md).
200
+ - `inspect(call, args)` runs an inspection call against the live scene, for the in-page inspector and the MCP server. The method exists only in a development build, which carries the channel, and a production build leaves it out. Code that uses it checks for it first: `await engine.inspect?.('objects')`. [Debugging](../guides/debugging.md#the-in-page-inspector) shows the calls.
201
+
202
+ <details>
203
+ <summary>Technical details: the inspection calls</summary>
204
+
205
+ `inspect` takes `objects`, `object`, `setObject`, `setMaterial`, `stats`, `errors`, `graph`, `setQuality`, `highlight` and `info`. The call runs between frames, in the thread that runs the sketch, and returns a JSON-safe value. The page answers `capture` itself, with `{ png, bytes }`: the PNG image of the next frame as base64 text, and its size in bytes.
206
+
207
+ </details>
208
+
209
+ - `labels.bind(id, element)` moves an HTML element over the label that the sketch tracks under `id`: [Labels that follow objects](ui.md).
175
210
  - `registerVideo(video, { name, maxSize, frameRate })` shows a video element on the page as a texture in the sketch, which makes it with `textures.fromVideo(name)`: [Video textures](../guides/video-textures.md). The page sends one image per frame that the video presents, scaled to `maxSize`, 512 texels by default. The call returns a function that stops the frames.
176
- - `requestPointerLock()` locks the pointer to the canvas, for [first-person controls](controls.md#pointer-lock) and games that turn with the mouse. Call it in a click or key handler: browsers lock the pointer only right after the user acts. It resolves once the lock begins. It fails with [E1425](../errors/E1425.md) when the browser refuses the lock: on a phone, in a frame without `allow-pointer-lock`, or just after the user pressed Esc. The option `{ unadjustedMovement: true }` asks for the mouse's raw movement, which some browsers cannot give. While the lock holds, the sketch's `input.pointer.locked` is true. The user ends the lock with Esc, and the page with `document.exitPointerLock()`. Destroying the engine ends a lock that it took or that its input read. On an engine started with `input: false`, it fails with [E1426](../errors/E1426.md): the code that records the page's input locks the canvas itself. Destroying the engine then leaves that lock.
211
+ - `requestPointerLock()` locks the pointer to the canvas, for [first-person controls](controls.md#pointer-lock) and games that turn with the mouse. Call it in a click or key handler: browsers lock the pointer only right after the user acts. It resolves once the lock begins. It fails with [E1425](../errors/E1425.md) when the browser refuses the lock: on a phone, in a frame without `allow-pointer-lock`, or just after the user pressed Esc.
212
+ - While the lock holds, the sketch's `input.pointer.locked` is true. The user ends the lock with Esc, and the page with `document.exitPointerLock()`. Destroying the engine ends a lock that it took or that its input read.
213
+
214
+ <details>
215
+ <summary>Technical details: pointer lock in edge cases</summary>
216
+
217
+ The option `{ unadjustedMovement: true }` asks for the mouse's raw movement, which some browsers cannot give. On an engine started with `input: false`, the call fails with [E1426](../errors/E1426.md): the code that records the page's input locks the canvas itself. Destroying the engine then leaves that lock.
218
+
219
+ </details>
220
+
177
221
  - `destroy()` stops the engine and its threads, and the engine cannot start again. The sketch's `onDestroy` runs first, and every later call from the sketch's code fails with [E1420](../errors/E1420.md). Wait for its promise before you start another engine on the same page.
178
- - The page keeps the memory that a stopped engine's threads shared, for about 30 seconds. The next engine with the same memory maximum takes it. React's StrictMode, route changes and hot reloads destroy and create the engine again. Such a page then asks the browser for no new memory. Safari can refuse a new memory for some seconds after a page drops one. The page keeps at most 2 memories. Their RAM stays in use until a new engine takes one, the 30 seconds end or the page goes away. Call `destroy({ release: true })` when the page will not start the engine again soon: the browser can then free the memory at once. An engine whose threads did not all stop cleanly leaves no memory to reuse. The single-threaded build's memory is not shared, and the page keeps its core for the next engine.
179
- - A new engine can start on the canvas of an engine that you destroyed. Its start waits until the old engine has stopped, so it can begin before `destroy()` resolves. React's StrictMode needs this, because it starts an effect twice on one `<canvas>`. A canvas that a worker drew on stays with that worker. So the new engine needs the same thread options as the old one. The worker ends when the canvas leaves the page or the page goes away. It also ends when the browser refuses memory for a new engine while no engine runs on the canvas. A new engine on its canvas then fails with [E1419](../errors/E1419.md), as on a canvas whose engine still runs.
180
- - In Safari, a stopped engine's canvas that stays in the page keeps the engine's memory, 1 GiB by default, until that worker ends. A new engine that needs the room gets it. Other code does not: a page that also loads a large WebAssembly module can run out of room. So remove the canvas from the page once you are done with it.
181
- - A page that goes away without `destroy()`, such as a page in a frame that your app removes, still gives back the engine's memory. When the page hides, the engine wakes its job workers and ends their loops. Safari never frees the memory of a worker that it stops while the worker waits for work. Without this, an iPad would run out of room after a few such pages. A page that the browser brings back from its back-forward cache runs on, with the job workers' share of the work on the sketch thread.
182
- - Where the engine keeps texture copies, as phones and tablets do by default, it gives its GPU back. It does so while the browser keeps the page in its back-forward cache. The thread that draws destroys its textures, its buffers and its device. When the page shows again, it starts a new device, as after a GPU loss, and builds every pipeline again before the scene shows. The cached page then leaves its GPU memory to the next page. A repeat visit of a heavy page on a phone with little memory needs that room ([E1307](../errors/E1307.md)).
222
+
223
+ ### Failures after the start
224
+
225
+ | Code | What happens next |
226
+ | --- | --- |
227
+ | [E1302](../errors/E1302.md) | The browser took the GPU away, and no new device started. The engine stops drawing new frames: destroy it and start again. |
228
+ | [E1404](../errors/E1404.md) | An engine thread, or the drawing on the page, failed. The engine stops drawing new frames: destroy it and start again. |
229
+ | [E1424](../errors/E1424.md) | A file of a custom shader's builds that a pipeline needs did not download. The engine stops drawing new frames: destroy it and start again. |
230
+ | [E1405](../errors/E1405.md) | A job worker did not start. The engine draws on without that worker's share of the work. |
231
+ | [E1304](../errors/E1304.md) | The GPU ran out of memory. The engine draws on without the objects that failed. |
232
+ | [E1305](../errors/E1305.md) | The GPU rejected the engine's work. The engine draws on without the objects that failed. |
233
+ | [E1307](../errors/E1307.md) | The GPU's driver refused a pipeline of the scene's objects twice. The engine draws on without the objects that failed. |
234
+
235
+ ### Destroy and start again
236
+
237
+ A new engine can start on the canvas of an engine that you destroyed. Its start waits until the old engine has stopped, so it can begin before `destroy()` resolves. React's StrictMode needs this, because it starts an effect twice on one `<canvas>`. A canvas that a worker drew on stays with that worker, so the new engine needs the same thread options as the old one. That worker ends when the canvas leaves the page or the page goes away.
238
+
239
+ It also ends when the browser refuses memory for a new engine while no engine runs on the canvas. A new engine on its canvas then fails with [E1419](../errors/E1419.md), as on a canvas whose engine still runs.
240
+
241
+ The page keeps the memory that a stopped engine's threads shared for about 30 seconds, and the next engine with the same maximum takes it. Call `destroy({ release: true })` when the page will not start the engine again soon: the browser can then free the memory at once. An engine whose threads did not all stop cleanly leaves no memory to reuse. The single-threaded build's memory is not shared, and the page keeps its core for the next engine.
242
+
243
+ In Safari, a stopped engine's canvas that stays in the page keeps the engine's memory, 1 GiB by default, until that worker ends. A new engine that needs the room gets it, but other code does not: a page that also loads a large WebAssembly module can run out of room. So remove the canvas from the page once you are done with it.
244
+
245
+ <details>
246
+ <summary>Technical details: memory and the GPU when a page goes away</summary>
247
+
248
+ React's StrictMode, route changes and hot reloads destroy and create the engine again. Such a page then asks the browser for no new memory, because the stopped engine's memory is reused. Safari can refuse a new memory for some seconds after a page drops one. The page keeps at most 2 memories, and their RAM stays in use until a new engine takes one, the 30 seconds end, or the page goes away.
249
+
250
+ A page that goes away without `destroy()`, such as a page in a frame that your app removes, still gives back the engine's memory. When the page hides, the engine wakes its job workers and ends their loops. Safari never frees the memory of a worker that it stops while the worker waits for work.
251
+
252
+ Without this, an iPad would run out of room after a few such pages. A page that the browser brings back from its back-forward cache runs on, with the job workers' share of the work on the sketch thread.
253
+
254
+ Where the engine keeps texture copies, as phones and tablets do by default, it gives its GPU back while the browser keeps the page in its back-forward cache. The thread that draws destroys its textures, its buffers and its device. When the page shows again, it starts a new device, as after a GPU loss, and builds every pipeline again before the scene shows. The cached page then leaves its GPU memory to the next page.
255
+
256
+ </details>
183
257
 
184
258
  Each `on...` call returns a function that removes its handler.
185
259
 
@@ -248,6 +322,8 @@ The engine's own add-ons need no range. They ship in step with the engine and us
248
322
  - [Hosting and cross-origin isolation](../getting-started/hosting.md): the headers that let the engine run threaded.
249
323
  - [3D scenes on content pages](../guides/content-pages.md): fallbacks, load deadlines and pausing on product pages.
250
324
  - [Color management](../concepts/color-management.md): HDR color, tone mapping and transparent canvases.
325
+ - [Large worlds](https://github.com/null3d-engine/null3d/tree/main/examples/large-world): a drive along a road on the Earth's surface, with the option on.
326
+ - [Input from the page](https://github.com/null3d-engine/null3d/tree/main/examples/replay): the engine starts with input off, and the demo's page takes the keys and the pointer lock.
251
327
 
252
328
  ## API reference
253
329
 
@@ -1,22 +1,20 @@
1
1
  ---
2
2
  id: api/feature-draws
3
3
  title: Add-on feature draws
4
- status: experimental
5
- since: "0.3"
6
4
  summary: "scene.addFeatureDraw turns a draw feature description into a draw of your WGSL, your vertices, your uniforms and the description's sort place, on both GPU paths and in every thread mode; scene.addFeatureInstances repeats that shape once for each row of a batch."
7
5
  ---
8
6
 
9
7
  # Add-on feature draws
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. A draw records in the main view alone, and at the opaque, the transparent or the resolve point.
9
+ > A draw records in the main view alone, and at the opaque, the transparent or the resolve point.
12
10
 
13
11
  ```mermaid
14
12
  flowchart LR
15
- description["defineFeature<br/>frame 'transparent', kind 'draw'"] --> call["scene.addFeatureDraw"]
16
- shader["Your WGSL"] --> call
17
- vertices["Your vertices"] --> call
18
- uniforms["Your uniforms"] --> call
19
- call --> object["A scene object<br/>your shader, your vertex format"]
13
+ description["defineFeature<br/>frame 'transparent', kind 'draw'"] --> create["scene.addFeatureDraw"]
14
+ shader["Your WGSL"] --> create
15
+ vertices["Your vertices"] --> create
16
+ uniforms["Your uniforms"] --> create
17
+ create --> object["A scene object<br/>your shader, your vertex format"]
20
18
  object --> list["The frame's draw list"]
21
19
  list --> gpu["WebGPU or WebGL2"]
22
20
  ```
@@ -25,7 +23,7 @@ flowchart LR
25
23
 
26
24
  This is the adapter for a [feature description](features.md) with `kind: 'draw'`. The description carries the sorting and the resources; the shader, the vertex format and the uniforms are the draw's own declaration, which this call takes.
27
25
 
28
- ## A point cloud
26
+ ## One soft point
29
27
 
30
28
  ```ts
31
29
  import { defineFeature, defineSketch } from '@null3d/engine';
@@ -38,8 +36,8 @@ struct Uniforms {
38
36
 
39
37
  fn surface(input: SurfaceInput) -> Surface {
40
38
  var s = defaultSurface(input);
41
- const away = length(input.uv - vec2f(0.5)) * 2.0;
42
- const cover = smoothstep(1.0, 1.0 - material.softness, away);
39
+ let away = length(input.uv - vec2f(0.5)) * 2.0;
40
+ let cover = smoothstep(1.0, 1.0 - material.softness, away);
43
41
  s.baseColor = vec3f(0.0);
44
42
  s.emissive = input.vertexColor.rgb * (material.gain * cover);
45
43
  s.alpha = cover;
@@ -71,6 +69,12 @@ export default defineSketch(async ({ scene }) => {
71
69
  });
72
70
  ```
73
71
 
72
+ This draws one point. For a cloud, put one square per point in the vertex arrays, or draw many copies of this shape with `scene.addFeatureInstances`, as [Many copies of one shape](#many-copies-of-one-shape) shows.
73
+
74
+ ![Two clouds of colored discs: small, firm discs behind and larger, soft discs in front.](../images/api/feature-draws/feature-draw-clouds.webp)
75
+
76
+ An opaque and a blended feature draw.
77
+
74
78
  ## The description
75
79
 
76
80
  `addFeatureDraw` reads these fields of the description. The [feature description page](features.md) gives the others: `name`, `reads`, `writes`, `outputs`, `provides` and the callbacks.
@@ -101,7 +105,7 @@ Geometries are shared, so the engine allocates the draw's buffers once and draws
101
105
 
102
106
  The uniforms that the add-on declares in `struct Uniforms` are the draw's payload. `uniforms` gives their first values, and `draw.setUniform(name, value)` or `draw.set(values)` changes them at any time without allocating. A uniform reaches the WGSL as `material.<name>`, in a surface function or a full shader. [Surface functions](../shaders/surface-functions.md#uniforms) gives the types and the 32-number limit.
103
107
 
104
- The draw also takes the material's values, such as `color`, `alphaMode`, `blending`, `depthWrite`, `doubleSided` and `map`, with the same names and meanings as `materials.shader`. A texture that its WGSL declares comes from `textures`, as `materials.shader` takes it.
108
+ The draw also takes the material's values, such as `color`, `alphaMode`, `blending`, `depthWrite`, `doubleSided`, `map` and `sceneInputs`, with the same names and meanings as `materials.shader`. A texture that its WGSL declares comes from `textures`, as `materials.shader` takes it. `sceneInputs: ['sceneDepth']` lets a blended draw read the opaque scene's depth behind it ([Materials](materials.md#the-scene-behind-a-surface)).
105
109
 
106
110
  ## Where it sorts
107
111
 
@@ -109,7 +113,8 @@ A draw's vertex data and material draw as one scene object. The engine culls it
109
113
 
110
114
  - `'opaque'` draws with the pass's other opaque objects, in the engine's own order, which the depth test decides.
111
115
  - `'transparent'` draws with the blended objects, back to front. The description's band and order place it among them, as `mesh.setRenderOrder` does: `draw.setRenderOrder(order)` changes the place later.
112
- - `'resolve'` blends after the camera's other blended objects. While the scene has more than one sample per pixel (MSAA), the camera draws such surfaces back to front into a layer of one sample per pixel, tested against a one-sample copy of the opaque depth, and blends the layer over the scene. Thousands of overlapping blended cards, such as Gaussian splats, then cost one blend per pixel instead of one per sample. Use it for a draw of soft, heavily overlapping surfaces. A glass or a particle in front of such a draw shows behind it, and a mesh's anti-aliased edge in front of it can show a faint fringe. With one sample, other views and frames before the layer's shaders are ready, the draw blends in the transparent pass, back to front with the other blended objects.
116
+ - `'resolve'` blends after the camera's other blended objects. While the scene has more than one sample per pixel (MSAA), the camera draws such surfaces back to front into a layer of one sample per pixel, tested against a one-sample copy of the opaque depth, and blends the layer over the scene. Thousands of overlapping blended cards, such as Gaussian splats, then cost one blend per pixel instead of one per sample.
117
+ - Use it for a draw of soft, heavily overlapping surfaces. A glass or a particle in front of such a draw shows behind it, and a mesh's anti-aliased edge in front of it can show a faint fringe. With one sample, other views and frames before the layer's shaders are ready, the draw blends in the transparent pass, back to front with the other blended objects.
113
118
 
114
119
  The draw's scene object, `draw.object`, takes the other object calls, such as `setPosition`, `setRotation`, `setScale` and `setLayers`. Its `setCastShadows(true)` makes the draw cast the shadows of every light that casts them, and its `setReceiveShadows(true)` makes the draw receive them. The draw's own `setVisible` shows and hides it. The draw's own `destroy()` frees its object, its material and its vertices, where `draw.object.destroy()` frees the object alone.
115
120
 
@@ -147,8 +152,8 @@ values.set([...]); // four numbers of yours for each row, read as `object.values
147
152
  ## Limits
148
153
 
149
154
  - The adapter places the main view alone. A scene pass and a reflection pass do not draw a feature draw, and a description that names one throws E1223.
150
- - A draw has one shape and one material, repeated once for each row. A scene that draws a different shape for each copy, or whose copies the GPU chooses, needs another hook.
151
- - A compact buffer of many copies that a shader expands, as a large splat scene needs, is not this hook: [compute instances](feature-instances.md) draw a capacity of instances whose live count a compute pass writes.
155
+ - A draw has one shape and one material, repeated once for each row. A scene that draws a different shape for each copy needs another hook.
156
+ - An opaque set whose live count a compute pass writes on the GPU, such as grass that the GPU culls, needs [compute instances](feature-instances.md). Those draw at the opaque point only, so a blended set such as splats stays with this hook.
152
157
  - The feature description's `reads`, `writes`, `outputs` and `provides` stay with the [feature registry](features.md): this draw reads and writes no scene resource and provides no lighting slot.
153
158
 
154
159
  ## Errors
@@ -166,6 +171,7 @@ values.set([...]); // four numbers of yours for each row, read as `object.values
166
171
  - [Custom shaders](../guides/custom-shaders.md): the WGSL that the plugin compiles, surface functions and full shaders.
167
172
  - [Surface functions](../shaders/surface-functions.md): the surface input, the surface record, uniforms and textures.
168
173
  - [Render graph API](render.md): the sketch's own passes, which draw into textures.
174
+ - [Many copies and the resolve point](https://github.com/null3d-engine/null3d/tree/main/examples/splats): the splats add-on makes the draw, with its instances at the resolve point.
169
175
 
170
176
  ## API reference
171
177
 
@@ -1,25 +1,25 @@
1
1
  ---
2
2
  id: api/feature-effects
3
3
  title: Add-on feature effects
4
- status: experimental
5
- since: "0.3"
6
4
  summary: "post.addFeatureEffect turns a full-screen feature description into a pass of your WGSL over the scene's color, at the resolve point, on both GPU paths and in every thread mode, and draws it only while the feature is ready."
7
5
  ---
8
6
 
9
7
  # Add-on feature effects
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. A full-screen effect records at the resolve point, in the main view alone.
9
+ > A full-screen effect records at the resolve point, in the main view alone.
12
10
 
13
11
  ```mermaid
14
12
  flowchart LR
15
- description["defineFeature<br/>frame 'resolve', kind 'fullscreen'"] --> call["post.addFeatureEffect"]
16
- shader["Your WGSL"] --> call
17
- uniforms["Your uniforms"] --> call
18
- call --> chain["The chain of custom effects<br/>HDR color, before bloom"]
13
+ description["defineFeature<br/>frame 'resolve', kind 'fullscreen'"] --> create["post.addFeatureEffect"]
14
+ shader["Your WGSL"] --> create
15
+ uniforms["Your uniforms"] --> create
16
+ create --> chain["The chain of custom effects<br/>HDR color, before bloom"]
19
17
  chain --> gpu["WebGPU or WebGL2"]
20
18
  ```
21
19
 
22
- `post.addFeatureEffect` runs an add-on's pass over the whole image. The add-on gives the WGSL, its uniforms and its textures, as it would to [`post.addEffect`](post.md). The description says where the pass records. It says what the pass reads and writes, and whether it draws at all. The engine places it in the chain of custom effects. That chain runs on the scene's high dynamic range color, after the exposure and before bloom and the tone curve. The pass therefore reaches WebGPU and WebGL2, in every thread mode, with the same picture.
20
+ `post.addFeatureEffect` runs an add-on's pass over the whole image. The add-on gives the WGSL, its uniforms and its textures, as it would to [`post.addEffect`](post.md). The description says where the pass records. It says what the pass reads and writes, and whether it draws at all.
21
+
22
+ The engine places it in the chain of custom effects. That chain runs on the scene's high dynamic range color, after the exposure and before bloom and the tone curve. The pass therefore reaches WebGPU and WebGL2, in every thread mode, with the same picture.
23
23
 
24
24
  This is the adapter for a [feature description](features.md) with `kind: 'fullscreen'`. The description carries the place, the resources and the readiness; the shader and its values are the pass's own declaration, which this call takes.
25
25
 
@@ -1,34 +1,36 @@
1
1
  ---
2
2
  id: api/feature-instances
3
3
  title: Add-on instance draws
4
- status: experimental
5
- since: "0.3"
6
4
  summary: "scene.addComputeInstances draws a capacity of instances from your own buffer, with a count that the GPU writes, on WebGPU, and an instance batch that the CPU fills on WebGL2."
7
5
  ---
8
6
 
9
7
  # Add-on instance draws
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. A draw records in the main view alone, at the opaque point.
9
+ > A draw records in the main view alone, at the opaque point.
12
10
 
13
11
  ```mermaid
14
12
  flowchart LR
15
- description["defineFeature<br/>frame 'opaque', kind 'draw'"] --> call["scene.addComputeInstances"]
16
- shader["Your WGSL"] --> call
17
- vertices["Your shape"] --> call
18
- call --> buffers["Your count and instance buffers"]
13
+ description["defineFeature<br/>frame 'opaque', kind 'draw'"] --> create["scene.addComputeInstances"]
14
+ shader["Your WGSL"] --> create
15
+ vertices["Your shape"] --> create
16
+ create --> buffers["Your count and instance buffers"]
19
17
  buffers --> compute["Your compute pass<br/>writes the count and the instances"]
20
18
  compute --> convert["The engine's conversion<br/>world rows to camera-relative rows"]
21
19
  convert --> list["The frame's draw list<br/>the count copied into the indirect draw"]
22
20
  list --> gpu["WebGPU<br/>the GPU's count drawn"]
23
- call --> batch["WebGL2<br/>an instance batch the CPU fills"]
21
+ create --> batch["WebGL2<br/>an instance batch the CPU fills"]
24
22
  ```
25
23
 
26
- `scene.addComputeInstances` draws one shape once for each live instance. On WebGPU the live count comes from GPU memory. On WebGL2 the page gives it. Use it for a large set whose count a compute pass writes each frame, such as foliage that the pass places and culls. The add-on's compute writes the count word and the per-instance rows, and the engine draws exactly that many instances.
24
+ `scene.addComputeInstances` draws one shape once for each live instance. On WebGPU the live count comes from GPU memory. On WebGL2 the sketch gives it, with `draw.setInstances` or `draw.setCount`. Use it for a large set whose count a compute pass writes each frame, such as foliage that the pass places and culls. The add-on's compute writes the count word and the per-instance rows, and the engine draws exactly that many instances.
27
25
 
28
26
  This is the adapter for a [feature description](features.md) with `kind: 'draw'` and `frame: 'opaque'`. The description places the draw; the options give the shape, the shader and the capacity.
29
27
 
30
28
  ## A draw of quads
31
29
 
30
+ ![Six rows of seven discs that a compute pass placed and counted.](../images/api/feature-instances/compute-instances.webp)
31
+
32
+ The GPU writes the rows and the count.
33
+
32
34
  ```ts
33
35
  import { defineFeature, defineSketch } from '@null3d/engine';
34
36
 
@@ -74,8 +76,12 @@ export default defineSketch(async ({ scene }) => {
74
76
  count: 0,
75
77
  });
76
78
  // The add-on's compute pass binds draw.instances and draw.counts, then writes them each frame.
77
- // A page without compute fills both on the CPU, which draws the same picture.
78
- draw.setInstances(rows, liveCount);
79
+ // On WebGL2, which has no compute, the sketch fills both on the CPU with setInstances.
80
+ const row = new Float32Array(16);
81
+ row[0] = 1; row[5] = 1; row[10] = 1; // an identity matrix, in the first three rows
82
+ row[3] = 0; row[7] = 0; row[11] = 0; // the translation, in each row's w
83
+ row[12] = draw.materialIndex; // the first id word names the draw's material
84
+ draw.setInstances(row, 1);
79
85
  });
80
86
  ```
81
87
 
@@ -111,6 +117,26 @@ The draw's material is opaque. The options take the material's other values, suc
111
117
 
112
118
  The engine's vertex shaders read an instance matrix relative to the camera. On WebGPU the engine converts the world rows to that space on the GPU, once for each draw in each frame, before the pass that draws them. The rows that you write stay world rows, so a camera that moves costs no upload. The engine keeps a second buffer of `capacity` rows for the converted rows, which doubles the memory that the draw's instances take.
113
119
 
120
+ <details>
121
+ <summary>Technical details: a fill shader that writes one row</summary>
122
+
123
+ ```wgsl
124
+ @group(0) @binding(0) var<storage, read_write> counts: atomic<u32>;
125
+ @group(0) @binding(1) var<storage, read_write> instances: array<vec4f>;
126
+
127
+ @compute @workgroup_size(1)
128
+ fn main() {
129
+ for (var i = 0u; i < 16u; i++) { instances[i] = vec4f(0.0); }
130
+ instances[0] = vec4f(1.0, 0.0, 0.0, 0.0);
131
+ instances[5] = vec4f(0.0, 1.0, 0.0, 0.0);
132
+ instances[10] = vec4f(0.0, 0.0, 1.0, 0.0);
133
+ instances[12] = vec4f(0.0, 0.0, 0.0, 0.0); // the draw's material index goes here
134
+ atomicStore(&counts, 1u);
135
+ }
136
+ ```
137
+
138
+ </details>
139
+
114
140
  ```ts
115
141
  render.addPass({
116
142
  kind: 'compute',
@@ -129,6 +155,10 @@ The add-on's compute writes the count each frame. The engine copies the word int
129
155
 
130
156
  WebGL2 has no compute shaders and no storage buffers. There the draw is an instance batch that the CPU fills, and the same shader reads the same instances:
131
157
 
158
+ ![Standing discs, counted on the GPU, cast shadows on the ground.](../images/api/feature-instances/instances-shadow.webp)
159
+
160
+ The page fills 64 rows but counts 42; only 42 cast shadows.
161
+
132
162
  ```ts
133
163
  draw.setInstances(rows, liveCount); // rows of 16 floats each, as draw.instances holds them
134
164
  draw.setCount(liveCount);
@@ -138,17 +168,38 @@ On WebGL2, each row's matrix is split into a position, a rotation and a scale th
138
168
 
139
169
  `draw.setCount(n)` works on both paths. On WebGPU it is the count of a frame that the add-on's compute has not written yet. The compute's word replaces it in the same frame. The camera's view and every shadow view draw the word's count. An instance that the GPU counts therefore casts its shadow by that same count.
140
170
 
171
+ ## Rules
172
+
173
+ - Run the add-on's compute in `band: 'before'`, as the example does.
174
+ - Create the draw in the sketch's setup, and await `addComputeInstances()` before the first frame. On a device that draws the scene directly, a draw that arrives later fails the frame with [E1506](../errors/E1506.md).
175
+ - Keep the add-on's count at or under `capacity`.
176
+
141
177
  ## Limits
142
178
 
143
179
  - The draw records at the opaque point, and its feature records in the main view alone. The engine still draws the object into the shadow views of the lights that it casts into. The adapter places no transparent instance draw, and none in a reflection or a scene pass.
144
180
  - The draw records only while the description's `ready` callback answers true. The sketch's thread asks it once each frame. While it answers false the engine records no draw, no count copy and no conversion for it, and draws none of its rows on WebGL2.
145
181
  - The engine does not cull the draw by the camera's frustum or layers. Your compute's cull, or your count, decides what draws. `draw.setVisible(false)` stops it, and so does a hidden parent.
146
- - The engine does not bound the count. Keep the add-on's count at or under `capacity`. Past it, the GPU reads past the end of the buffer.
147
- - The engine keeps two buffers of `capacity` rows: the world rows that you fill and the camera-relative rows that it converts them into each frame. A large capacity therefore takes twice the instance memory.
148
- - The conversion uses the main view's camera, so every view, the shadows included, reads the rows converted for that camera. A shadow view draws the add-on's count word too, so the instances that cast shadows are the instances that the GPU counts.
149
- - The shadow views cull the faces that point away from the light, as every caster does. A thin surface, such as a leaf or a standing disc, therefore casts nothing while the light reaches its back. Give such a draw `doubleSided` to cast from either side.
150
- - The add-on's compute pass must run before the scene draws: use `band: 'before'`, as the example does. Rows that it writes after the scene are too late for that frame's opaque pass.
151
- - Create the draw in the sketch's setup, and await `addComputeInstances()` before the first frame. A device that draws the scene directly fixes that choice at its first frame. Such a device cannot take a draw whose count the GPU writes later. The frame then fails with [E1506](../errors/E1506.md).
182
+ - The engine does not bound the count. Past `capacity`, the GPU reads past the end of the buffer.
183
+ - The conversion uses the main view's camera, so every view, the shadows included, reads the rows converted for that camera.
184
+ - The shadow views cull the faces that point away from the light. A thin surface, such as a leaf or a standing disc, therefore casts nothing while the light reaches its back. Give such a draw `doubleSided` to cast from either side.
185
+ - On an Apple GPU in Safari, or in any browser on iPhone and iPad, the engine can draw the scene directly, with no indirect draws. `engine.capabilities.directDraws` is then true (see [GPU tiers and backends](../concepts/backends.md)). Such a device sets its draw list at its first frame, and cannot take a draw whose count the GPU writes later. The frame then fails with E1506.
152
186
  - The feature description's `reads`, `writes`, `outputs` and `provides` stay with the [feature registry](features.md).
153
187
 
188
+ ## Errors
189
+
190
+ | Code | Cause |
191
+ | --- | --- |
192
+ | E1223 | A description that the adapter cannot take, such as a `kind` other than `'draw'`, a `frame` other than `'opaque'`, or a view other than `'main'`. |
193
+ | E1506 | A device that draws the scene directly took the draw at its first frame, and the count arrives later. |
194
+
195
+ ## Related pages
196
+
197
+ - [Feature descriptions](features.md): the description that places the draw.
198
+ - [Add-on draws](feature-draws.md): a draw over its own vertices, rather than a capacity of instances.
199
+ - [Compute passes](render.md#compute-passes): the pass that writes the count and the rows.
200
+ - [Grass](grass.md): an add-on that draws with instance draws.
201
+ - [Compute instances in use](https://github.com/null3d-engine/null3d/tree/main/examples/vegetation-wind): the grass add-on draws its blades this way in the Plants in wind demo.
202
+
203
+ ## API reference
204
+
154
205
  [The API reference](reference/feature-instances.md) lists every export of this page with its type and description. The engine's doc comments make it.