@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: concepts/backends
3
3
  title: GPU tiers and backends
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "WebGPU core, compatibility mode and WebGL2; color, anti-aliasing and depth on each tier; capability flags; the portable budget; never branching on GPU names."
7
5
  ---
8
6
 
9
7
  # GPU tiers and backends
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 TD
15
11
  start["Page loads: the engine runs feature tests"] --> adapter{"Does the browser give<br/>a WebGPU adapter?"}
@@ -18,7 +14,11 @@ flowchart TD
18
14
  adapter -- "no" --> gl["WebGL2"]
19
15
  ```
20
16
 
21
- null3D draws with WebGPU where the browser offers it, and with WebGL2 everywhere else. The same sketch code runs on both, with no backend checks in it. So one sketch works in every current browser on computers, tablets and phones. The engine picks the tier once, at startup, from feature tests. It tests the thread that will draw: where a worker draws, the engine picks the best tier that the worker can use. Where no worker can draw, the page draws in pipelined mode, even when the page asks for low latency ([Architecture](architecture.md#where-the-sketch-runs)). After two starts in a row that crashed the tab on WebGPU, the engine starts on WebGL2. A page that names a GPU path keeps it ([Quality presets](quality-presets.md#starts-that-crashed-the-tab)).
17
+ null3D draws with WebGPU where the browser offers it, and with WebGL2 everywhere else. The same sketch code runs on both, with no backend checks in it. So one sketch works in every current browser on computers, tablets and phones.
18
+
19
+ The engine picks the tier once, at startup, from feature tests. It tests the thread that will draw: where a worker draws, the engine picks the best tier that the worker can use. Where no worker can draw, the page draws in pipelined mode, even when the page asks for low latency ([Architecture](architecture.md#where-the-sketch-runs)). After two starts in a row that crashed the tab on WebGPU, the engine starts on WebGL2. A page that names a GPU path keeps it ([Quality presets](quality-presets.md#starts-that-crashed-the-tab)).
20
+
21
+ Other pages call the tier the GPU path. `engine.capabilities.tier` says which one the engine started on.
22
22
 
23
23
  ## The three tiers
24
24
 
@@ -32,9 +32,18 @@ Browser support changes often, so this table can go out of date. At run time, th
32
32
 
33
33
  ## How each path draws
34
34
 
35
- On WebGPU, the GPU culls the scene itself. The engine records one draw for each group of objects that share a pipeline, a mesh and a material, and replays these draws every frame. The GPU fills in each draw's count. The CPU's cost per frame grows with the number of those groups, and stays almost flat as the object count grows. A start-up measurement can pick a direct-draw path instead, where the job workers cull on the CPU and each bucket draws directly ([Culling](culling.md#how-each-path-culls)).
35
+ On WebGPU, the GPU culls the scene itself. The engine records one draw for each group of objects that share a pipeline, a mesh and a material, and replays these draws every frame. The GPU fills in each draw's count. The CPU's cost per frame grows with the number of those groups, and stays almost flat as the object count grows. A start-up measurement can pick a direct-draw path instead. There the job workers cull on the CPU, and each group draws with the count they found ([Culling](culling.md#how-each-path-culls)).
36
+
37
+ On WebGL2 there are no compute shaders, so the job workers cull on the CPU ([Culling](culling.md#how-each-path-culls)). Where the browser has the `WEBGL_multi_draw` extension, one call draws each group with the same shading, texture maps and mesh buffer. Firefox lacks the extension, so there each group takes one call.
38
+
39
+ <details>
40
+ <summary>Technical details: how WebGL2 uploads a frame</summary>
41
+
42
+ The job workers group the visible objects the same way as on WebGPU. Each object's matrix sits in a data texture on the GPU, which a frame updates only where matrices changed. Dynamic instance batches write theirs each frame into the next of three textures. So a frame never writes a texture that the GPU may still read.
36
43
 
37
- On WebGL2 there are no compute shaders, so the job workers cull in parallel on the CPU and group the visible objects the same way. Each object's matrix sits in a data texture on the GPU, which a frame updates only where matrices changed. Dynamic instance batches write theirs each frame into the next of three textures. A frame then never writes a texture that the GPU may still read. Each frame lists the visible objects, 4 bytes each, and uploads the list only when it changed. The `visibleEntries` figure of `engine.measure` counts the entries of each frame's list. A static instance batch that has stopped changing is culled in groups of 64 nearby rows, with one test and one list entry per group. A group partly in view draws all its rows, and the GPU clips the ones outside. On both paths, a scene spread over several grid cells skips the still objects of the cells out of view first ([Culling](culling.md)). Where the browser has the `WEBGL_multi_draw` extension, one call draws every group with the same shading, the same texture maps and the same mesh buffer. Firefox lacks the extension, so there each group takes one call.
44
+ Each frame lists the visible objects, 4 bytes each, and uploads the list only when it changed. The `visibleEntries` figure of `engine.measure` counts the entries of each frame's list. A static instance batch that has stopped changing is culled in groups of 64 nearby rows, with one test and one list entry per group. A group partly in view draws all its rows, and the GPU clips the ones outside. On both paths, a scene spread over several grid cells skips the still objects of the cells out of view first ([Culling](culling.md)).
45
+
46
+ </details>
38
47
 
39
48
  Every feature works on both paths, or its page describes its WebGL2 fallback. The page downloads only the renderers and the shaders of the path that it draws with. Other work differs by path too:
40
49
 
@@ -46,7 +55,7 @@ Every feature works on both paths, or its page describes its WebGL2 fallback. Th
46
55
  | [Skinning](../api/animation.md#skinned-meshes) | The vertex shader of each pass that draws the mesh, with copies of one mesh and material in one instanced draw | The same |
47
56
  | [Morph targets](../api/animation.md#morph-targets) | The skinning pass, once per frame, with every weight | The vertex shader of each pass, with the preset's count of each object's largest weights. Its shaders load with the first morphed mesh |
48
57
  | The [depth prepass](quality-presets.md#the-depth-prepass) | Off on every preset. Drawn when `depthPrepass` is on, with a shader that computes positions only | On for every preset, as it restores early rejection of hidden pixels on Apple GPUs. Drawn with each material's own vertex shader |
49
- | [Occlusion culling](culling.md#gpu-occlusion-culling-on-webgpu) | On the GPU, in two phases, when `gpuOcclusion` is on | Not on the GPU |
58
+ | [Occlusion culling](culling.md#gpu-occlusion-culling-on-webgpu) | On the GPU, in two phases, when `gpuOcclusion` is on | On the job workers, against marked blockers, when `softwareOcclusion` is on ([Culling](culling.md#software-occlusion-culling-on-webgl2)) |
50
59
  | GPU time in `engine.measure` | Where the device has timestamp queries | Not measured |
51
60
 
52
61
  Shadows, skinned and morphed meshes, debug views and custom materials draw the same on both paths. The one exception: on WebGL2, a custom material draws a morphed mesh in its shape at rest. A debug view's wireframe draws an edge list of each mesh, because neither API fills triangles as lines.
@@ -57,7 +66,9 @@ WebGL2 and WebGPU's compatibility mode run at most the Medium [quality preset](q
57
66
 
58
67
  ## Color and anti-aliasing on each tier
59
68
 
60
- The anti-aliasing mode smooths the jagged edges of objects. The quality preset picks it: FXAA on Low, and MSAA from Medium up. The `antialias` option of `createEngine` replaces the preset's mode. The mode stays fixed while the engine runs, because the scene's targets and pipelines depend on it. One exception: when the start-up preset check lowers the preset, the demo draws with the lower preset's mode. The engine moves the canvas to a lighter mode for that, and never under the viewer's own preset change.
69
+ The anti-aliasing mode smooths the jagged edges of objects. The quality preset picks it: FXAA on Low, and MSAA from Medium up. The `antialias` option of `createEngine` replaces the preset's mode. The mode stays fixed while the engine runs, because the scene's targets and pipelines depend on it.
70
+
71
+ Two cases move it. When the start-up preset check lowers the preset, the engine draws with the lower preset's mode. In compatibility mode with MSAA, the first effect that needs HDR color moves the engine to FXAA ([The post-processing chain](post-processing.md#effects-on-devices-without-hdr-color)). A sketch's own preset change never moves it.
61
72
 
62
73
  | Mode | How the frame draws it |
63
74
  | --- | --- |
@@ -65,7 +76,7 @@ The anti-aliasing mode smooths the jagged edges of objects. The quality preset p
65
76
  | `fxaa` | The opaque pass draws one sample per pixel. The final pass finds edges by their contrast, and blends each pixel on an edge with its neighbors along the edge. It needs less memory and bandwidth than MSAA, and blurs thin lines a little. |
66
77
  | `none` | The opaque pass draws one sample per pixel, and nothing smooths the edges. |
67
78
 
68
- The moment transparency layer draws its surfaces at one sample per pixel, whatever the mode. While a sketch turns `momentTransparency` on, SMAA 1x smooths the layer's edges under the share that its moments cover, and MSAA's samples keep smoothing the opaque geometry around them. SMAA reads the color, so it works on every tier and replaces no other mode. It runs only under that share, so it does not soften edges that MSAA already smoothed.
79
+ The moment transparency layer draws its surfaces at one sample per pixel, whatever the mode. While a sketch turns `momentTransparency` on, SMAA 1x smooths the layer's edges under the share that its moments cover. MSAA's samples keep smoothing the opaque geometry around them. SMAA reads the color, so it works on every tier and replaces no other mode. It runs only under that share, so it does not soften edges that MSAA already smoothed.
69
80
 
70
81
  The scene's color target differs from tier to tier:
71
82
 
@@ -75,11 +86,18 @@ The scene's color target differs from tier to tier:
75
86
  | WebGPU compatibility mode | With MSAA, 8 bits per channel. With FXAA or none, as on core WebGPU. | With MSAA, each shader tone maps and encodes its own result. The render pass averages the samples into the canvas, or into a texture that the final pass copies while the render scale can drop below 1 or an effect needs the final pass. With FXAA or none, as on core WebGPU. |
76
87
  | WebGL2 | `RGBA16F` where the float target test passes; 8 bits per channel elsewhere. With `?scene-format=rg11b10`, `R11F_G11F_B10F` where the canvas is opaque and that format passes the test too | As on core WebGPU with the float target. Without it, each shader tone maps its own result. MSAA then averages the samples as in compatibility mode. With FXAA or none, the final pass reads the color as it is, and FXAA smooths its edges. |
77
88
 
78
- On every tier, the final pass also scales the image up to the canvas when the [render scale](quality-presets.md#dynamic-resolution) is below 1. It then runs in two steps. The first applies FXAA, the tone curve and the sRGB encode at the render size. The second scales the image up to the canvas with GSR 1, an upscaler that keeps edges sharp ([The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale)). WebGL2 and compatibility mode run Low or Medium, whose lowest render scale is below 1, so there the final pass usually runs.
89
+ Where the render scale can drop below 1, the final pass runs in two steps. It scales the image up with GSR 1 ([The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale)). WebGL2 and compatibility mode run Low or Medium, whose render scale can drop below 1, so there the final pass usually runs.
90
+
91
+ High dynamic range (HDR) color keeps light brighter than white until the tone mapping. It needs a float target that the GPU can draw into, with 4 samples for MSAA. Compatibility mode allows no MSAA on 16-bit float targets, so there MSAA takes the 8-bit path, and FXAA and none keep HDR color.
79
92
 
80
- High dynamic range (HDR) color keeps light brighter than white until the tone mapping. It needs a float target that the GPU can draw into, with 4 samples for MSAA. Compatibility mode allows no MSAA on 16-bit float targets, so there MSAA takes the 8-bit path, and FXAA and none keep HDR color. Some WebGL2 devices draw into no float target at all. On WebGL2, `engine.report.webgl2.floatRenderTargets` gives the result of the engine's test for `RGBA16F`, `RGBA32F` and `R11F_G11F_B10F`. The target must be complete and keep values above 1. For MSAA it must also take 4 samples.
93
+ <details>
94
+ <summary>Technical details: the float target test on WebGL2</summary>
81
95
 
82
- `engine.capabilities.hdr` says which path the engine started on. Bloom moves compatibility mode to HDR color with FXAA when a sketch turns it on ([the post-processing chain](post-processing.md#effects-on-devices-without-hdr-color)). Both paths show the same colors. Edges differ a little, because the 8-bit path averages MSAA's samples after the tone mapping. FXAA compares and blends colors as the tone mapping would show them on both paths, so bright edges stay smooth. [Color management](color-management.md) describes the conversions and the tone mapping.
96
+ Some WebGL2 devices draw into no float target at all. On WebGL2, `engine.report.webgl2.floatRenderTargets` gives the result of the engine's test for `RGBA16F`, `RGBA32F` and `R11F_G11F_B10F`. The target must be complete and keep values above 1. For MSAA it must also take 4 samples.
97
+
98
+ </details>
99
+
100
+ Both paths show the same colors. Edges differ a little, because the 8-bit path averages MSAA's samples after the tone mapping. FXAA compares and blends colors as the tone mapping would show them on both paths, so bright edges stay smooth ([Color management](color-management.md#the-8-bit-path)).
83
101
 
84
102
  Phone GPUs draw in tiles, and each write of a tile back to memory costs time and power. So each render pass discards the targets that no later pass reads: the depth, and with MSAA the samples once they are averaged. Chrome 146 and later also offer transient attachments. Where the browser has them, those targets take that usage, so they can stay in the GPU's tile memory. `engine.report.webgpu.transientAttachments` says whether the browser has them. On WebGL2 the engine tells the driver the same with `invalidateFramebuffer`.
85
103
 
@@ -93,7 +111,9 @@ The engine draws reversed depth: the near plane stores 1 and the far plane store
93
111
  | WebGL2 with the `EXT_clip_control` extension | Reversed, in a 32-bit float buffer | Out to 10 km |
94
112
  | WebGL2 without it | Reversed, in WebGL2's range from -1 to 1 | Out to about 250 m |
95
113
 
96
- WebGL2 maps depth into a range from -1 to 1, which loses most of the precision that reversed depth gives. The `EXT_clip_control` extension sets the range from 0 to 1, as on WebGPU. In the engine's tests, Chrome, Safari and Brave have it on a MacBook Pro. So do Chrome on a Galaxy S24+, and Safari and Brave on an iPad Pro. Firefox on macOS does not. Without the extension, the engine keeps reversed depth in the range from -1 to 1. In every browser tested, that fought in fewer pixels than standard depth.
114
+ WebGL2 maps depth into a range from -1 to 1, which loses most of the precision that reversed depth gives. The `EXT_clip_control` extension sets the range from 0 to 1, as on WebGPU.
115
+
116
+ In the engine's tests, Chrome, Safari and Brave have it on a MacBook Pro. So do Chrome on a Galaxy S24+, and Safari and Brave on an iPad Pro. Firefox on macOS does not. Without the extension, the engine keeps reversed depth in the range from -1 to 1. In every browser tested, that fought in fewer pixels than standard depth.
97
117
 
98
118
  The distances come from the engine's depth precision test on a MacBook Pro, with the camera's near plane at 0.1 m. The field `engine.capabilities.depth` says which depth the device draws: `reversed`, or `reversed-gl` on WebGL2 without the extension. In both, depth textures such as [shadow maps](shadows.md) hold the same values as on WebGPU. Shaders that read depth then work the same on every tier. The `?depth=standard` switch below gives a third value, `standard`.
99
119
 
@@ -115,9 +135,11 @@ The `features` field lists the WebGPU adapter's optional features. On WebGL2 it
115
135
  - rendering into 16-bit and 32-bit float textures, and into the packed `R11F_G11F_B10F` format, on WebGL2 (`engine.report.webgl2.floatRenderTargets`)
116
136
  - transient attachments on WebGPU (`engine.report.webgpu.transientAttachments`)
117
137
 
118
- On an Apple GPU in WebKit, the engine also measures whether direct draws are faster than its indirect draws. WebKit is the engine of Safari and of every browser on iPhone and iPad. It checks each indirect draw at a fixed cost, which direct draws do not pay. That is not a capability flag. The `directDraws` field reports the choice, and it is false on WebGL2, which always draws directly. The `drawPath` field says why the engine took its path. On other devices it is `not-apple-gpu-in-webkit`, since they skip the measurement.
138
+ On an Apple GPU in WebKit, the engine also measures whether direct draws are faster than its indirect draws. WebKit is the engine of Safari and of every browser on iPhone and iPad. It checks each indirect draw at a fixed cost, which direct draws do not pay.
119
139
 
120
- Where float targets take the anti-aliasing mode, the scene draws high dynamic range color, and the final pass tone maps it. That holds on core WebGPU and on WebGL2 devices that pass the float target test. It holds in compatibility mode with FXAA or none too. `hdr` says whether the engine took that path. [Color management](color-management.md) covers the 8-bit path of the other devices.
140
+ That is not a capability flag. The `directDraws` field reports the choice, and it is false on WebGL2, which always draws directly. The `drawPath` field says why the engine took its path. On other devices it is `not-apple-gpu-in-webkit`, since they skip the measurement.
141
+
142
+ `hdr` says whether the engine took the HDR path ([Color and anti-aliasing on each tier](#color-and-anti-aliasing-on-each-tier)).
121
143
 
122
144
  Code that uses an optional feature checks this object first. A sketch reads the same values in its context, as `ctx.engine.capabilities`.
123
145
 
@@ -141,7 +163,9 @@ The storage binding is the one limit the engine raises past this budget. When a
141
163
 
142
164
  On WebGPU, development builds warn once when a scene passes 2,097,152, because a device with the default limits refuses that scene.
143
165
 
144
- On WebGL2 the limit follows the largest texture the device allows. Each object's matrix takes 3 texels of a data texture, 512 matrices to a texel row. That is 2,097,152 objects and instance rows at 4,096 pixels, and 8,388,608 at 16,384. Larger textures hold no more, because the list of visible objects can name at most 8,388,608. WebGL2 promises at least 2,048 pixels, which holds 1,048,576. `engine.capabilities.maxInstances` gives the number on WebGL2 too. On WebGL2, development builds warn once when a scene passes 1,048,576, because a device with the smallest textures refuses that scene.
166
+ On WebGL2 the limit follows the largest texture the device allows. Each object's matrix takes 3 texels of a data texture, 512 matrices to a texel row. That is 2,097,152 objects and instance rows at 4,096 pixels, and 8,388,608 at 16,384. Larger textures hold no more, because the list of visible objects can name at most 8,388,608. WebGL2 promises at least 2,048 pixels, which holds 1,048,576.
167
+
168
+ `engine.capabilities.maxInstances` gives the number on WebGL2 too. On WebGL2, development builds warn once when a scene passes 1,048,576, because a device with the smallest textures refuses that scene.
145
169
 
146
170
  Engine memory holds the rows too. A page with worker threads gives the engine 1 GiB by default, which holds about 5 million instance rows. The `memory` option of `createEngine` raises the maximum to as much as 4 GiB ([Page API](../api/engine.md#memory)). A call that needs more memory than the engine can get fails with E1109.
147
171
 
@@ -159,21 +183,32 @@ Some laptops have a separate graphics chip next to the one built into the proces
159
183
 
160
184
  ## Choosing a tier for testing
161
185
 
162
- `createEngine({ gpu: 'webgl2' })` forces a tier, and so do the URL switches `?gpu=webgpu`, `?gpu=compat` and `?gpu=webgl2`. A device can then test every path it supports. Use them for testing only; in production, let the engine choose.
186
+ `createEngine({ gpu: 'webgl2' })` forces a tier, and so do the URL switches `?gpu=webgpu`, `?gpu=compat` and `?gpu=webgl2`. A device can then test every path it supports. Use them for testing only; in production, let the engine choose. The [Testing guide](../guides/testing.md#switches-for-tests) lists many of the switches.
187
+
188
+ Other switches make one device test the paths of other devices. They cover copied uploads, shader compiles without the parallel compile extension, the 8-bit color path, each WebGL2 depth mode and each compressed texture family. The engine reads them in development builds, or in a production build with the Vite plugin's `urlSwitches` option on.
163
189
 
164
- On WebGL2, uploads read straight from the engine's shared memory. A browser that refuses to read shared memory gets a copy of each upload instead. The switch `?uploads=copy` makes the engine copy everywhere, so one device can test both routes.
190
+ A production build can ship the shaders of one path alone. It suits a deployment whose browser always offers that path. The engine then refuses a tier that the build lacks, with [E1308](../errors/E1308.md), even where the browser offers it.
165
191
 
166
- On WebGL2, the engine compiles shader programs in the background where the browser has the `KHR_parallel_shader_compile` extension. The switch `?compile=wait` makes it wait for each compile at the program's first draw instead, as a browser without the extension does.
192
+ `engine.report` still describes the browser, and `engine.capabilities.tier` still names the path that the page draws with. The Vite plugin's `shaders.gpuPaths` option makes such a build, and the build is smaller than one of both paths ([Ship a subset of the GPU paths](../guides/assets-pipeline.md#ship-a-subset-of-the-gpu-paths)).
167
193
 
168
- The switch `?half=on` makes the scene shaders do their color math at half precision, where the device can. It is off by default, and serves measurements. The switch `?hdr=off` makes the engine draw the 8-bit color path on a device that draws HDR color, so one device can test both. The switch `?scene-format=` picks the HDR scene color's format where the device can draw it. The value `rg11b10` takes the packed small float format of 4 bytes a pixel, and `rgba16f` takes 16-bit floats of 8 bytes. The small format keeps 6 bits of mantissa in red and green and 5 in blue, against 10 in a 16-bit float. On WebGL2 it serves measurements of its cost and of banding in dark gradients. Without the switch, WebGL2 keeps `RGBA16F`: on the phones measured, the small format drew no faster. The switch `?prepass=on` or `?prepass=off` turns the depth prepass on or off, and `?occlusion=on` or `?occlusion=off` turns GPU occlusion culling on or off.
194
+ On WebGL2, uploads read straight from the engine's shared memory. A browser that refuses to read shared memory gets a copy of each upload instead.
169
195
 
170
196
  The switch `?depth=` forces a WebGL2 depth mode: `reversed`, `reversed-gl` or `standard`, where the near plane stores 0 and the far plane 1. A browser without `EXT_clip_control` cannot draw `reversed`, so it draws its own mode instead. Shadow maps hold the same depth values as on WebGPU in `reversed` and `reversed-gl`. In `standard` they would hold them the other way around, so WebGL2 draws no shadows in that mode.
171
197
 
172
- KTX2 textures take the compressed format of the first family that the device has: ASTC, BC7 or ETC2 by the file's data ([Textures](../api/textures.md#ktx2-files)). The switch `?compression=` keeps them to the families that it lists, such as `?compression=bc`, or to none with `?compression=none`. One device can then test the format of each kind of device.
198
+ <details>
199
+ <summary>Technical details: the packed scene color format</summary>
200
+
201
+ The switch `?scene-format=` picks the HDR scene color's format where the device can draw it. The value `rg11b10` takes the packed small float format of 4 bytes a pixel, and `rgba16f` takes 16-bit floats of 8 bytes. The small format keeps 6 bits of mantissa in red and green and 5 in blue, against 10 in a 16-bit float. On WebGL2 it serves measurements of its cost and of banding in dark gradients. Without the switch, WebGL2 keeps `RGBA16F`: on the phones measured, the small format drew no faster.
202
+
203
+ </details>
173
204
 
174
205
  ## When the GPU goes away
175
206
 
176
- A WebGPU device can be lost, for example after a driver reset, and so can a WebGL2 context. The thread that draws then makes a new device, or waits for the context to come back. It draws the whole scene again from data the engine kept. A texture from a file loads its file again. On a phone or a tablet the engine also keeps a copy of each texture's texels after their upload, so those maps come back too. The `keepTextureCopies` option of `createEngine` turns that on or off on any device ([Page API](../api/engine.md#options)). Keeping the copies costs about one more copy of each image in memory. Where no copy is kept, such a texture draws without its map until the sketch gives it texels again ([Textures](../api/textures.md#when-the-browser-takes-the-gpu-away)). The sketch worker keeps running, so your sketch's state survives. If the GPU is lost more than twice within one minute, or no new device starts, the engine stops drawing and reports E1302.
207
+ A WebGPU device can be lost, for example after a driver reset, and so can a WebGL2 context. The thread that draws then makes a new device, or waits for the context to come back. It draws the whole scene again from data the engine kept. A texture from a file loads its file again.
208
+
209
+ On a phone or a tablet the engine also keeps a copy of each texture's texels after their upload, so those maps come back too. The `keepTextureCopies` option of `createEngine` turns that on or off on any device ([Page API](../api/engine.md#options)). Keeping the copies costs about one more copy of each image in memory. Where no copy is kept, such a texture draws without its map until the sketch gives it texels again ([Textures](../api/textures.md#when-the-browser-takes-the-gpu-away)).
210
+
211
+ The sketch worker keeps running, so your sketch's state survives. If the GPU is lost more than twice within one minute, or no new device starts, the engine stops drawing and reports E1302.
177
212
 
178
213
  The engine also gives the GPU away itself while the browser keeps the page in its back-forward cache, where it keeps texture copies. A cached page would otherwise hold all its GPU memory, and on a phone with little memory the next page could lack it. When the page shows again, the thread that draws makes a new device and draws the scene again, as after a loss. This counts as no loss.
179
214
 
@@ -187,7 +222,16 @@ The engine also gives the GPU away itself while the browser keeps the page in it
187
222
 
188
223
  WebAssembly SIMD sets the minimums of Chrome, Edge and Firefox. In an older browser, and in Safari before 16.4, `createEngine` fails with [E1303](../errors/E1303.md) instead of taking a slow path. The page can then show its own message.
189
224
 
190
- Safari 16.4 and 17 have WebAssembly SIMD and pass the engine's feature tests. The engine still meets faults there that no test finds in advance. On a phone with 4 GB of memory, Safari 17 refused the engine's shared memory. Its WebGL2 compiler also rejected a shader of the standard material. So null3D does not support Safari before 18, and `createEngine` fails there with [E1306](../errors/E1306.md) before it starts a worker or asks for memory. A page that the null3D Vite plugin builds still starts the core's download as its HTML arrives, and leaves it unread. Every browser on iPhone and iPad runs Safari's WebKit engine, so the same check covers Chrome, Edge and Firefox on iOS and iPadOS before 18. The check reads the browser's user agent. An `AppleWebKit/` number of 600 or more marks Apple's WebKit, and the check then reads Safari's `Version/` part, or else the iOS or iPadOS version. Chrome, Edge, Samsung Internet and Firefox on other systems give no such number, so the check passes them.
225
+ Safari 16.4 and 17 pass the engine's feature tests, but the engine meets faults there that no test finds in advance. So null3D does not support Safari before 18, and `createEngine` fails there with [E1306](../errors/E1306.md) before it starts a worker or asks for memory. Every browser on iPhone and iPad runs Safari's WebKit engine, so Chrome, Edge and Firefox on iOS and iPadOS before 18 fail the same way.
226
+
227
+ <details>
228
+ <summary>Technical details: how the engine detects old Safari</summary>
229
+
230
+ On a phone with 4 GB of memory, Safari 17 refused the engine's shared memory. Its WebGL2 compiler also rejected a shader of the standard material. A page that the null3D Vite plugin builds still starts the core's download as its HTML arrives, and leaves it unread.
231
+
232
+ The check reads the browser's user agent. An `AppleWebKit/` number of 600 or more marks Apple's WebKit, and the check then reads Safari's `Version/` part, or else the iOS or iPadOS version. Chrome, Edge, Samsung Internet and Firefox on other systems give no such number, so the check passes them.
233
+
234
+ </details>
191
235
 
192
236
  On a cross-origin isolated page, the engine runs worker threads, which wait for each other with `Atomics.waitAsync`. Firefox has it from version 145. In older versions, the threads wake each other with messages instead. The switch `?wake=message` does the same in any browser, for tests.
193
237
 
@@ -1,15 +1,11 @@
1
1
  ---
2
2
  id: concepts/color-management
3
3
  title: Color management
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "Linear working space; sRGB hex colors and linear arrays; texture color spaces; HDR color; exposure and tone mapping; transparent canvases."
7
5
  ---
8
6
 
9
7
  # Color management
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
  hex["'#4a8cff' or 0x4a8cff<br/>sRGB"] --> linear
@@ -22,7 +18,9 @@ flowchart LR
22
18
 
23
19
  null3D works in linear color. A color that you give as a hex string or a number is sRGB, the way CSS writes colors. The engine converts it to linear once, when the call receives it. A color that you give as three numbers is linear already.
24
20
 
25
- Lighting adds and scales light in linear color, so a lit surface can be brighter than white. The scene therefore draws into a high dynamic range (HDR) target. Each light and each color of the scene comes in scaled by the exposure. At the end of each frame, a tone mapping curve maps it into the display's range. The final pass then encodes it as sRGB for the canvas.
21
+ Lighting adds and scales light in linear color, so a lit surface can be brighter than white. The scene therefore draws into a high dynamic range (HDR) target. Where the device cannot draw a float target in the anti-aliasing mode, the scene takes an 8-bit path. Each shader then tone maps its own color ([The 8-bit path](#the-8-bit-path)).
22
+
23
+ Each light and each color of the scene comes in scaled by the exposure. At the end of each frame, a tone mapping curve maps it into the display's range. The final pass then encodes it as sRGB for the canvas.
26
24
 
27
25
  ## Colors in the API
28
26
 
@@ -60,11 +58,33 @@ A strong light can make a surface many times brighter than white. The scene keep
60
58
  - `rgba16float` on WebGPU. Where the device can draw into `rg11b10ufloat` and the canvas is opaque, the scene color takes that format instead, which needs half the memory.
61
59
  - `RGBA16F` on WebGL2, where the device can draw float targets in the anti-aliasing mode.
62
60
 
63
- The final pass reads each pixel of the scene color. In the FXAA anti-aliasing mode it first smooths the edges. It darkens the edges with the vignette, when the sketch sets one, and applies the tone mapping to the exposed color. It then encodes the result as sRGB. Last, after any color grading table, it adds a little noise, called dithering, so smooth gradients show no bands. The final pass is one triangle over the canvas, with no scene work in it. Below the whole canvas's render scale it runs in two steps, while the render scale can drop. The first step does the FXAA, the tone curve and the sRGB encode at the render size. The second scales the image up ([The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale)).
61
+ The final pass reads each pixel of the scene color. In the order the shader runs them:
62
+
63
+ 1. In the FXAA mode, smooth the edges.
64
+ 2. Darken the edges by the vignette, when the sketch sets one.
65
+ 3. Apply the tone mapping to the exposed color (with automatic exposure, the adapted exposure first).
66
+ 4. Encode as sRGB.
67
+ 5. Apply any color grading table.
68
+ 6. Add the dither, so smooth gradients show no bands.
69
+
70
+ The final pass is one triangle over the canvas, with no scene work in it. Below the whole canvas's render scale it runs in two steps, while the render scale can drop ([The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale)).
64
71
 
65
72
  ### The 8-bit path
66
73
 
67
- Some devices cannot draw a float target in the anti-aliasing mode. These are WebGPU in compatibility mode with MSAA, and WebGL2 devices whose float targets fail the engine's test. There, each shader applies the tone mapping itself, and writes into an 8-bit target. With MSAA that target can resolve straight into the canvas, with no final pass. That holds while the render scale cannot drop below 1 and no effect needs the final pass. Such effects are color grading, sharpening, outlines, transmission, screen-space reflections and the bounce light. So are soft particles, a material that reads the scene's depth, the moment transparency layer, and a full-screen pass that reads the scene color. The scene's shaders apply the vignette themselves there. Low and Medium let the render scale drop below 1, so there the final pass usually runs. With FXAA or no anti-aliasing, the final pass reads the target and keeps its colors.
74
+ Some devices cannot draw a float target in the anti-aliasing mode. These are WebGPU in compatibility mode with MSAA, and WebGL2 devices whose float targets fail the engine's test. There, each shader applies the tone mapping itself, and writes into an 8-bit target. With MSAA that target can resolve straight into the canvas, with no final pass. That holds while the render scale cannot drop below 1 and no effect needs the final pass. These effects need it:
75
+
76
+ - color grading
77
+ - sharpening
78
+ - outlines
79
+ - transmission
80
+ - screen-space reflections
81
+ - bounce light
82
+ - soft particles
83
+ - a material that reads the scene's depth
84
+ - the moment transparency layer
85
+ - a full-screen pass that reads the scene color
86
+
87
+ The scene's shaders apply the vignette themselves there. Low and Medium let the render scale drop below 1, so there the final pass usually runs. With FXAA or no anti-aliasing, the final pass reads the target and keeps its colors.
68
88
 
69
89
  Effects that need HDR color, such as bloom, move compatibility mode to HDR color with FXAA when a sketch turns them on. On a WebGL2 device with no float target they stay off. [The post-processing chain](post-processing.md#effects-on-devices-without-hdr-color) explains both.
70
90
 
@@ -74,7 +94,18 @@ Effects that need HDR color, such as bloom, move compatibility mode to HDR color
74
94
 
75
95
  A material with `toneMapped: false` keeps its color as the display shows it. Use it for a panel, a sign or another object whose colors are set for the screen, such as a heads-up display in the world.
76
96
 
77
- The 8-bit path honours it in each material's own shader, which tone maps there: the shader encodes the color without the curve. The HDR path tone maps the whole image once, in its final pass. While a material keeps its display color, that pass also reads a mask of the surfaces whose material does so, and it skips the curve for those pixels. A blended surface keeps the curve on the HDR path, because a blended pixel mixes two surfaces and the mask cannot say which one owns it. Draw such a surface on the 8-bit path with `createEngine({ hdr: false })` if it needs the exact color. [The post-processing chain](post-processing.md) explains what else that path changes.
97
+ ![Two rows of the same seven bright colors: the top row keeps its display color, the bottom row takes the tone curve.](../images/concepts/color-management/tone-mapped.webp)
98
+
99
+ toneMapped: false on the top row.
100
+
101
+ The 8-bit path honors it in each material's own shader. The HDR path honors it in its final pass, for surfaces that do not blend. A blended surface still takes the tone curve on the HDR path. If it needs the exact color, use the 8-bit path with `createEngine({ hdr: false })` ([The post-processing chain](post-processing.md) explains what else that path changes).
102
+
103
+ <details>
104
+ <summary>Technical details: how each path keeps the display color</summary>
105
+
106
+ On the 8-bit path the shader encodes the color without the curve. The HDR path's final pass reads a mask of the marked surfaces and skips the curve there. A blended pixel mixes two surfaces, so the mask cannot say which one owns it.
107
+
108
+ </details>
78
109
 
79
110
  The vignette and the sRGB encoding still apply to such a material. The exposure scales its colors before them, as it scales every other color.
80
111
 
@@ -103,17 +134,15 @@ Punchy AgX suits most scenes: bright lights and colors keep their hue, and the p
103
134
 
104
135
  The exposure multiplies the scene's color before the tone mapping. An exposure of 2 is one stop brighter, and 0.5 is one stop darker. The engine applies it to each light and each color as they enter the scene. That gives the same picture as scaling the finished color, and keeps scenes in real units inside the range of the HDR target. [Lighting and environment](lighting.md#units-and-exposure) explains it.
105
136
 
106
- Automatic exposure adapts the picture to the scene's brightness over time, as an eye does. The scene still draws at the exposure that `exposure` and `ev100` set. A meter on the GPU then reads each frame, and the final pass multiplies the HDR color by the adapted exposure before the tone mapping. [The post-processing chain](post-processing.md#automatic-exposure) explains the meter.
137
+ Automatic exposure adapts the picture to the scene's brightness over time, as an eye does. The scene still draws at the exposure that `exposure` and `ev100` set. A meter on the GPU then reads each frame, and the final pass multiplies the HDR color by the adapted exposure before the tone mapping. [The post-processing chain](post-processing.md#automatic-exposure) explains the meter. The [automatic exposure demo](https://github.com/null3d-engine/null3d/tree/main/examples/auto-exposure) walks from a sunny courtyard into a dark hall, so the eye opens and closes.
107
138
 
108
139
  ## The background
109
140
 
110
- The background color is part of the scene. Exposure and tone mapping change it as they change the objects. The curves, for example, make dark colors a little darker. To show an exact page color behind the scene, use `toneMapping: 'none'` at an exposure of 1. You can also use a transparent canvas over a CSS background.
111
-
112
- A [background texture](../api/scene.md#the-camera-and-the-background) draws into the scene color too, so exposure and tone mapping change it in the same way. To show the texture's own colors, use `toneMapping: 'none'` at an exposure of 1.
141
+ The background color and a [background texture](../api/scene.md#the-camera-and-the-background) are part of the scene. Exposure and tone mapping change them as they change the objects, so the curves, for example, make dark colors a little darker. To show either one with its own colors, use `toneMapping: 'none'` at an exposure of 1. A transparent canvas over a CSS background gives an exact page color behind the scene instead.
113
142
 
114
143
  ## Transparent canvases
115
144
 
116
- `createEngine({ transparent: true })` makes a see-through canvas. The page shows through wherever no object draws, until the sketch calls `scene.setBackground`. The canvas holds premultiplied alpha, the form that browsers composite, so a partly covered edge pixel keeps its color scaled by its coverage.
145
+ `createEngine({ transparent: true })` makes a see-through canvas. The page shows through wherever no object draws, until the sketch calls `scene.setBackground`. The canvas holds premultiplied alpha, the form that browsers composite, so a partly covered edge pixel keeps its color scaled by its coverage. The [depth-only holdout demo](https://github.com/null3d-engine/null3d/tree/main/examples/depth-only) starts on a see-through canvas over a page backdrop.
117
146
 
118
147
  ```ts
119
148
  const engine = await createEngine({
@@ -1,15 +1,11 @@
1
1
  ---
2
2
  id: concepts/culling
3
3
  title: Culling
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "Frustum culling on the GPU on WebGPU, or on the job workers there when the device draws directly, and on the job workers on WebGL2; grid cells, whole cells out of view skipped first, positions relative to the camera, and occlusion culling: behind large opaque objects that the GPU picks on WebGPU, and behind marked blockers on WebGL2."
7
5
  ---
8
6
 
9
7
  # Culling
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
  subgraph core["Engine core, each frame"]
@@ -29,15 +25,32 @@ flowchart LR
29
25
  occlude --> draw["Draw the visible<br/>objects and rows"]
30
26
  ```
31
27
 
32
- Culling finds the objects and instance rows in the camera's view, so the GPU draws only those. Occlusion culling also skips the objects that others hide. The engine tests each bounding sphere against the six planes of the view. Every position in the test is relative to the camera, so a scene far from the origin culls and draws as it does near it. When a scene spreads over several grid cells, the engine first skips every still object of the cells out of view. The engine culls each [view](render-graph.md) separately, against that view's camera. A view is the camera's, a shadow cascade's, a shadow tile's, a [scene pass](../api/render.md)'s, or one that [`scene.createView`](../api/scene.md#multiple-views) draws into a rectangle of the canvas.
28
+ Culling finds the objects and instance rows in the camera's view, so the GPU draws only those. Occlusion culling also skips the objects that others hide. The engine tests each bounding sphere against the six planes of the view. The engine culls each [view](render-graph.md) separately, against that view's camera. A view is one of:
29
+
30
+ - the camera's view
31
+ - a shadow cascade's
32
+ - a shadow tile's
33
+ - a [scene pass](../api/render.md)'s
34
+ - one that [`scene.createView`](../api/scene.md#multiple-views) draws into a rectangle of the canvas
33
35
 
34
36
  ## How each path culls
35
37
 
36
- On WebGPU the GPU culls the scene itself. A compute pass runs one GPU thread per object or instance row. Each thread adds its cell's offset to its bounding sphere and tests the sphere. An object in view joins its group: the objects that share a mesh and a material. The prerecorded draws read how many each group holds. The CPU's cost per frame stays almost flat as the scene grows. When the scene spreads over several grid cells, the pass runs only over the objects of the cells in view and over the moving objects.
38
+ On WebGPU the GPU culls the scene itself. A compute pass runs one GPU thread per object or instance row. Each thread adds its cell's offset to its bounding sphere and tests the sphere.
39
+
40
+ An object in view joins its group: the objects that share a mesh and a material. The prerecorded draws read how many each group holds. The CPU's cost per frame stays almost flat as the scene grows. When the scene spreads over several grid cells, the pass runs only over the objects of the cells in view and over the moving objects.
41
+
42
+ On an Apple GPU in Safari, or in any browser on iPhone and iPad, a start-up measurement can find direct draws clearly faster. The job workers then cull on the CPU instead. They use the WebGL2 culling on the WebGPU path's own groups. Each group then draws with its known count. `engine.capabilities.directDraws` says which path the device took, and `engine.capabilities.drawPath` says why. The [Performance guide](../guides/performance.md#how-the-engine-batches-builds-pipelines-and-times-frames) explains how the engine batches.
43
+
44
+ <details>
45
+ <summary>Technical details: how the device picks a path</summary>
46
+
47
+ The start-up measurement takes the direct path only when that path measures at least 25% faster and at least 0.15 ms a frame faster. Other devices skip the measurement and cull on the GPU.
48
+
49
+ </details>
37
50
 
38
- On an Apple GPU in Safari, or in any browser on iPhone and iPad, a start-up measurement can find direct draws clearly faster. The job workers then cull on the CPU instead. They use the WebGL2 culling on the WebGPU layout's own buckets. Each bucket then draws with its known count. The probe takes the direct path only when that path measures at least 25% faster and at least 0.15 ms a frame faster. Other devices skip the measurement and cull on the GPU. `engine.capabilities.directDraws` says which path the device took, and `engine.capabilities.drawPath` says why. The [Performance guide](../guides/performance.md#how-the-engine-batches-builds-pipelines-and-times-frames) explains how the engine batches.
51
+ On WebGL2 there are no compute shaders, so the job workers cull on the CPU. They test four spheres per SIMD instruction and list the visible objects, 4 bytes each.
39
52
 
40
- On WebGL2 there are no compute shaders, so the job workers cull on the CPU. They test four spheres per SIMD instruction and list the visible objects, 4 bytes each. They test a static instance batch that has stopped changing in groups of 64 nearby rows, one test per group. Each group lies inside one grid cell. The job workers skip the objects and groups of the cells out of view.
53
+ They test a static instance batch that has stopped changing in groups of 64 nearby rows, one test per group. Each group lies inside one grid cell. A group that is partly in view draws whole, and the GPU clips the rows outside. The job workers skip the objects and groups of the cells out of view.
41
54
 
42
55
  [GPU tiers and backends](backends.md) describes each path's draw calls and uploads.
43
56
 
@@ -48,6 +61,24 @@ On WebGL2 there are no compute shaders, so the job workers cull on the CPU. They
48
61
  - A morphed mesh culls with a sphere that its weights grow: each target's longest move, times its weight.
49
62
  - Sprites, points and line segments cull as instance rows do, one sphere each. Sprites and points sized in CSS pixels, with `sizeAttenuation: false`, never cull, because their size in the world grows with their distance.
50
63
 
64
+ ## Bounds that you set
65
+
66
+ By default, culling tests an object's mesh sphere. That sphere is around the center of the box that holds every vertex of its mesh. `mesh.center` and `mesh.radius` give it in the mesh's own space. The object's scale grows it, and its rotation turns it.
67
+
68
+ A shader that moves vertices, such as waves on water, can move them outside that sphere. Culling then hides the object while parts of it are still in view. Two mesh calls change what culling tests:
69
+
70
+ - `setBounds(center, radius)` gives the object a sphere of its own, with its center relative to the object's origin. Bounds that cover the moved vertices keep culling at work.
71
+ - `setFrustumCulled(false)` turns culling off for the object, so the engine draws it wherever it is.
72
+
73
+ ```ts
74
+ // Waves lift the water's vertices by up to 2 m. A sphere 1 m higher and 1 m wider than the
75
+ // mesh's sphere holds every lifted vertex.
76
+ const [x, y, z] = waterMesh.center;
77
+ water.setBounds([x, y + 1, z], waterMesh.radius + 1);
78
+ ```
79
+
80
+ Both calls rebuild the draw tables, so make them at setup. On WebGPU, each object with a sphere of its own draws from a group of its own, as the GPU tests one sphere per group. Skinned objects without morph targets are the exception: copies of one mesh and material share a group, whose sphere holds every copy's. On WebGL2, the job workers test each object's own sphere and the cost stays the same.
81
+
51
82
  ## GPU occlusion culling on WebGPU
52
83
 
53
84
  The frustum test keeps every object in view, even one that a wall hides. On WebGPU, large opaque objects hide the objects behind them, and the GPU skips those. You mark nothing: the GPU picks the objects that hide others itself, among every opaque object and instance row. The GPU works in two phases in each frame, for each camera:
@@ -76,15 +107,22 @@ The pyramid holds the depth of objects drawn in this frame, at the detail that t
76
107
 
77
108
  ### The check during play
78
109
 
79
- The extra passes cost GPU time: a depth draw of the occluders, a depth pyramid and a second culling pass. Another program's work on the GPU can also run in the gaps between them, so a frame with them can take longer although it draws less. So the engine checks during play whether they pay:
110
+ The extra passes cost GPU time: a depth draw of the occluders, a depth pyramid and a second culling pass. So the engine checks during play whether they pay. About every 120 frames it runs a few frames the other way and compares.
111
+
112
+ The passes stay on while they hide at least a tenth of the objects that would draw. The frame must also take no longer with them, within 2%. Otherwise they stay off until a later check finds that they pay. While the view holds still, the check pauses, so the still-camera accumulation can finish.
113
+
114
+ `engine.measure` reports the objects that the culling hid as `occludedEntries`. That is the count of the newest frame whose counts came back, and 0 while the check keeps the passes off. The `?occlusion-check=off` switch keeps the passes on in every frame, for a test that compares the image with culling and without it.
115
+
116
+ <details>
117
+ <summary>Technical details: how the engine checks that occlusion culling pays</summary>
80
118
 
119
+ - Another program's work on the GPU can run in the gaps between the extra passes. So a frame with them can take longer although it draws less.
81
120
  - The second phase counts the objects in view that would draw and those that the pyramid hid. A frame copies the counts, and the GPU sends them back a few frames later. Nothing waits for them.
82
- - About every 120 frames, the engine runs a few frames the other way: without the passes while they run, or with them while they do not. It compares the GPU's frame times, from each frame's submit to its completion, with the frames just before.
83
- - The passes stay on while they hide at least a tenth of the objects that would draw, and a frame with them takes no longer than one without, within 2%. Otherwise they stay off until a later check finds that they pay.
121
+ - A trial runs without the passes while they run, or with them while they do not. It compares the GPU's frame times, from each frame's submit to its completion, with the frames just before.
84
122
  - The occluders' pass draws only the groups of objects that held occluders in the last few checks, so it draws nothing for the rest.
85
- - While the view holds still, the check pauses: the passes stay as they are and nothing is copied, so the still-camera accumulation finishes and the view rests. It starts again a little after the view moves.
123
+ - While the view holds still, nothing is copied and the passes stay as they are. The check starts again a little after the view moves.
86
124
 
87
- `engine.measure` reports the objects that the culling hid as `occludedEntries`: the count of the newest frame whose counts came back, and 0 while the check keeps the passes off. The `?occlusion-check=off` switch keeps the passes on in every frame, for a test that compares the image with culling and without it.
125
+ </details>
88
126
 
89
127
  ### Where it runs
90
128
 
@@ -100,22 +138,6 @@ The extra passes cost GPU time: a depth draw of the occluders, a depth pyramid a
100
138
  scene.createMesh({ mesh: sculpture, material: bronze, position: [0, 0, -8], occluder: false });
101
139
  ```
102
140
 
103
- ## Bounds that you set
104
-
105
- By default, culling tests an object's mesh sphere: the sphere around the center of the box that holds every vertex of its mesh. `mesh.center` and `mesh.radius` give it in the mesh's own space. The object's scale grows it, and its rotation turns it. A shader that moves vertices, such as waves on water, can move them outside that sphere. Culling then hides the object while parts of it are still in view. Two mesh calls change what culling tests:
106
-
107
- - `setBounds(center, radius)` gives the object a sphere of its own, with its center relative to the object's origin. Bounds that cover the moved vertices keep culling at work.
108
- - `setFrustumCulled(false)` turns culling off for the object, so the engine draws it wherever it is.
109
-
110
- ```ts
111
- // Waves lift the water's vertices by up to 2 m. A sphere 1 m higher and 1 m wider than the
112
- // mesh's sphere holds every lifted vertex.
113
- const [x, y, z] = waterMesh.center;
114
- water.setBounds([x, y + 1, z], waterMesh.radius + 1);
115
- ```
116
-
117
- Both calls rebuild the draw tables, so make them at setup. On WebGPU, each object with a sphere of its own draws from a group of its own, as the GPU tests one sphere per group. Skinned objects without morph targets are the exception: copies of one mesh and material share a group, whose sphere holds every copy's. On WebGL2, the job workers test each object's own sphere and the cost stays the same.
118
-
119
141
  ## Software occlusion culling on WebGL2
120
142
 
121
143
  Frustum culling keeps everything in the view, even what a building hides. On WebGL2, objects that you mark as blockers hide the objects behind them, so the GPU skips those too:
@@ -156,7 +178,14 @@ scene.instantiate(city, { occluder: false });
156
178
 
157
179
  ### Turn it on where it pays
158
180
 
159
- Every quality preset leaves software occlusion culling off. The engine measured it in S6, its benchmark city, on three Android phones and an iPad, all on WebGL2. It hid 23% to 39% of the entries in view, but removed fewer than 3% of the draw calls. Most hidden entries were rows of instance batches whose other rows still showed, so the batch still drew. The job workers spent 7 to 22 ms more per frame, and the render worker saved 2.3 ms at most. On every device, it cost at least 3.5 times what it saved.
181
+ Every quality preset leaves software occlusion culling off. In S6, the engine's benchmark city, on three Android phones and an iPad, all on WebGL2, it cost at least 3.5 times what it saved. Most hidden entries were rows of instance batches whose other rows still showed, so the batch still drew.
182
+
183
+ <details>
184
+ <summary>Technical details: the S6 measurements</summary>
185
+
186
+ It hid 23% to 39% of the entries in view, but removed fewer than 3% of the draw calls. The job workers spent 7 to 22 ms more per frame, and the render worker saved 2.3 ms at most.
187
+
188
+ </details>
160
189
 
161
190
  A scene whose few large blockers hide many separate meshes, each its own draw call, can gain where the city lost. So turn it on only when your scene measures a gain:
162
191
 
@@ -173,14 +202,7 @@ WebGPU picks its occluders itself for its own [occlusion culling on the GPU](#gp
173
202
 
174
203
  ## Grid cells
175
204
 
176
- The engine divides space into cells 1,024 m wide. The origin cell spans 512 m on each side of the origin, so a scene within 512 m of it uses one cell.
177
-
178
- - A root object takes the cell that holds its position. Its children take its cell.
179
- - An instance row takes the cell that holds its position.
180
-
181
- The engine keeps each world matrix relative to its cell's center, where 32-bit floats are precise to a fraction of a millimeter. Each frame it computes the offset from the camera to each cell in use, in 64-bit floats, and uploads one vector per cell. Each view gets the offsets from its own camera. The GPU adds an object's offset to its position, so every position it sees is relative to the camera. Positions near the camera keep the most precision.
182
-
183
- When only the camera moves, static objects keep their data on the GPU, and only the offsets change. A scene inside one cell uploads one vector per frame.
205
+ The engine divides space into cells, cubes 1,024 m wide. A root object takes the cell that holds its position, and its children share it. An instance row takes the cell that holds its own position. [Large worlds and precision](large-worlds.md#grid-cells) explains how the cells keep positions precise.
184
206
 
185
207
  ## Skipping cells out of view
186
208
 
@@ -193,12 +215,16 @@ Most frames of a large world show a few of its cells. The engine then tests each
193
215
  - A still object that changes grows its cell's box. One that moves into another cell rebuilds the cell order, as creating or destroying an object does. Keep objects that cross cells often dynamic.
194
216
  - On WebGL2, a static batch whose rows change is tested row by row until it rests again. So is a static batch whose rows are spread so thinly over cells that its groups of 64 rows would be mostly empty.
195
217
 
196
- A scene inside one cell has nothing to skip, and culls as it would without cells. The benchmark scene S1-cells spreads 100,000 still boxes over 8 x 8 cells and flies the camera low over them.
218
+ A scene inside one cell has nothing to skip, and culls as it would without cells. The benchmark scene S1-cells spreads 100,000 still boxes over 8 x 8 cells and flies the camera low over them. The [Performance guide](../guides/performance.md#large-worlds) gives what the cells saved in it.
197
219
 
198
220
  ## What this means for your sketch
199
221
 
200
222
  Write world positions as usual, and the engine picks the cells:
201
223
 
224
+ ![A tray of small keys and a brass wheel, drawn sharp.](../images/concepts/culling/far-from-origin.webp)
225
+
226
+ 2 cm keys 1,000 km from the origin, drawn without jitter.
227
+
202
228
  ```ts
203
229
  const base = [250_000, 0, -80_000] as const;
204
230
  const camera = scene.createPerspectiveCamera({
@@ -209,14 +235,7 @@ scene.setActiveCamera(camera);
209
235
  scene.createMesh({ mesh: geometry.box(), material: stone, position: base });
210
236
  ```
211
237
 
212
- The cells have these limits:
213
-
214
- - The engine stores positions as 32-bit floats. It places an object 100 km from the origin to within about 4 mm, and 1,000 km out to within about 3 cm. What it computes from those positions, such as a child's place under its parent, keeps its precision.
215
- - A mesh's vertices are offsets from its object's origin, and they stay 32-bit. Put large coordinates in object positions, never in vertices.
216
- - `getWorldPosition` and `getWorldMatrix` give 64-bit positions. Pass them a plain array or a `Float64Array`, because a `Float32Array` rounds them to 32 bits.
217
- - At most 512 cells hold objects at once. An object in a cell past that stays in the origin cell, where its position keeps only 32-bit precision. The engine then warns once in the console.
218
-
219
- For a world the size of a planet, `createEngine`'s `largeWorld` option keeps every position that you set exact. A batch's `origin` option keeps its rows precise far from the origin. [Large worlds and precision](large-worlds.md) explains both.
238
+ [Large worlds and precision](large-worlds.md) gives the precision figures and the limits, including the 512-cell cap. [Floating-origin geometry](large-worlds.md#floating-origin-geometry) says why vertices stay 32-bit, and [Objects and transforms](../api/objects.md) covers the world getters. For a world the size of a planet, `createEngine`'s `largeWorld` option keeps every position that you set exact, and a batch's `origin` option keeps its rows precise.
220
239
 
221
240
  ## Related pages
222
241
 
@@ -225,3 +244,5 @@ For a world the size of a planet, `createEngine`'s `largeWorld` option keeps eve
225
244
  - [Static and dynamic objects](static-dynamic.md): which objects upload their data each frame.
226
245
  - [Large worlds and precision](large-worlds.md): `largeWorld` mode and batch origins.
227
246
  - [The demo far from the origin](https://github.com/null3d-engine/null3d/tree/main/examples/far-from-origin): keys 2 cm wide, 1,000 km from the origin, seen from 40 cm.
247
+ - [Row-by-row culling of a large batch](https://github.com/null3d-engine/null3d/tree/main/examples/instances): a dynamic batch of 100,000 rows, each culled on its own.
248
+ - [Bounds that follow the waves](https://github.com/null3d-engine/null3d/tree/main/examples/vertex-updates): `setBounds` on a pool whose waves lift its corners past the flat mesh's sphere.
@@ -1,15 +1,11 @@
1
1
  ---
2
2
  id: concepts/handles
3
3
  title: Handles and objects
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "30-bit handles; wrapper objects; stale-handle errors; keeping per-object data in your own arrays."
7
5
  ---
8
6
 
9
7
  # Handles and objects
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
  handle["Handle<br/>a 30-bit integer"] --> slot["Slot index<br/>20 bits"]
@@ -72,7 +68,18 @@ crate.setPosition(0, 0, 0); // development build: throws E1101
72
68
 
73
69
  In development builds, every call on an object apart from `describe` checks that the object still lives. A call on a destroyed object throws an `EngineError` with the code [E1101](../errors/E1101.md), which names the object and the frame it was destroyed in. Release builds leave this check out, so a transform setter costs only its memory writes.
74
70
 
75
- A call on a destroyed object never changes the object that takes its slot, in any build. When you destroy an object, its wrapper stops pointing at the slot. In a release build, its setters then write to a row that no object uses, and its light setters reach no light. A second `destroy()` frees nothing. The engine core checks the generation of each change that waits for the next frame. It logs E1101 for a change to a destroyed object. An instance batch's arrays throw E1101 in every build once the batch is gone. The world getters throw it in every build from the frame after the destroy, and at once in development builds. The call is still a bug in your sketch, so find it in a development build.
71
+ A call on a destroyed object never changes the object that takes its slot, in any build. The call is still a bug in your sketch, so find it in a development build.
72
+
73
+ <details>
74
+ <summary>Technical details: what each build does with a destroyed object</summary>
75
+
76
+ Slot 0 is never used, so handle 0 means no object. When you destroy an object, its wrapper's setters switch to row 0. Its handle gets a generation that no live object gets, so it never matches a later object in its slot. In a release build, its setters then write to that unused row, and its light setters reach no light. A second `destroy()` frees nothing.
77
+
78
+ The engine core checks the generation of each change that waits for the next frame, and logs E1101 for a change to a destroyed object.
79
+
80
+ </details>
81
+
82
+ An instance batch's arrays throw [E1101](../errors/E1101.md) in every build once the batch is gone. The world getters throw it in every build from the frame after the destroy, and at once in development builds.
76
83
 
77
84
  ## Keep per-object data in your own arrays
78
85
 
@@ -91,3 +98,5 @@ Your loops then read your arrays and write the engine's arrays, and neither side
91
98
  - [Static and dynamic objects](static-dynamic.md): when a write reaches the GPU.
92
99
  - [Instances and batching](instances.md): rows instead of handles, for many copies of one mesh.
93
100
  - [Architecture: threads and the frame](architecture.md): where the shared arrays live.
101
+ - [Wrapper objects and setters](https://github.com/null3d-engine/null3d/tree/main/examples/objects): crates move with setters between a turntable and the stage.
102
+ - [Per-object data in your own arrays](https://github.com/null3d-engine/null3d/tree/main/examples/math): a drone swarm keeps a weight for each of its 300 rows.