@null3d/engine 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) 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 +39 -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 +65 -25
  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/E1401.md +11 -3
  146. package/docs/errors/E1402.md +13 -5
  147. package/docs/errors/E1403.md +11 -3
  148. package/docs/errors/E1404.md +13 -3
  149. package/docs/errors/E1405.md +15 -4
  150. package/docs/errors/E1406.md +31 -5
  151. package/docs/errors/E1407.md +11 -3
  152. package/docs/errors/E1408.md +11 -3
  153. package/docs/errors/E1409.md +11 -3
  154. package/docs/errors/E1410.md +13 -5
  155. package/docs/errors/E1411.md +11 -3
  156. package/docs/errors/E1412.md +29 -6
  157. package/docs/errors/E1413.md +11 -3
  158. package/docs/errors/E1414.md +11 -3
  159. package/docs/errors/E1415.md +11 -3
  160. package/docs/errors/E1416.md +27 -6
  161. package/docs/errors/E1417.md +11 -3
  162. package/docs/errors/E1418.md +12 -3
  163. package/docs/errors/E1419.md +13 -5
  164. package/docs/errors/E1420.md +11 -3
  165. package/docs/errors/E1421.md +11 -3
  166. package/docs/errors/E1422.md +12 -3
  167. package/docs/errors/E1423.md +12 -3
  168. package/docs/errors/E1424.md +24 -5
  169. package/docs/errors/E1425.md +11 -3
  170. package/docs/errors/E1426.md +11 -3
  171. package/docs/errors/E1430.md +11 -3
  172. package/docs/errors/E1431.md +11 -3
  173. package/docs/errors/E1432.md +11 -3
  174. package/docs/errors/E1433.md +11 -3
  175. package/docs/errors/E1434.md +15 -6
  176. package/docs/errors/E1435.md +11 -3
  177. package/docs/errors/E1436.md +11 -3
  178. package/docs/errors/E1437.md +14 -6
  179. package/docs/errors/E1501.md +41 -6
  180. package/docs/errors/E1502.md +13 -3
  181. package/docs/errors/E1503.md +11 -3
  182. package/docs/errors/E1504.md +11 -3
  183. package/docs/errors/E1505.md +23 -5
  184. package/docs/errors/E1506.md +11 -3
  185. package/docs/errors/index.md +52 -29
  186. package/docs/getting-started/cdn.md +15 -9
  187. package/docs/getting-started/first-scene.md +20 -12
  188. package/docs/getting-started/hosting.md +111 -63
  189. package/docs/getting-started/install.md +39 -24
  190. package/docs/getting-started/network-use.md +31 -21
  191. package/docs/getting-started/project-structure.md +20 -8
  192. package/docs/getting-started/third-party-notices.md +6 -10
  193. package/docs/guides/accessibility.md +4 -4
  194. package/docs/guides/add-ons.md +83 -13
  195. package/docs/guides/agents.md +2 -6
  196. package/docs/guides/assets-pipeline.md +248 -72
  197. package/docs/guides/audio.md +17 -15
  198. package/docs/guides/baked-light-data.md +44 -23
  199. package/docs/guides/car-paint.md +37 -31
  200. package/docs/guides/content-pages.md +53 -29
  201. package/docs/guides/custom-passes.md +59 -17
  202. package/docs/guides/custom-shaders.md +54 -37
  203. package/docs/guides/debugging.md +31 -41
  204. package/docs/guides/deploying.md +6 -27
  205. package/docs/guides/deterministic-simulation.md +23 -16
  206. package/docs/guides/first-use-shaders.md +83 -45
  207. package/docs/guides/lens-kit.md +29 -26
  208. package/docs/guides/loading-screens.md +70 -30
  209. package/docs/guides/multiple-views.md +22 -11
  210. package/docs/guides/performance.md +188 -37
  211. package/docs/guides/phones.md +71 -19
  212. package/docs/guides/physics.md +6 -10
  213. package/docs/guides/screens.md +41 -29
  214. package/docs/guides/start-time.md +120 -85
  215. package/docs/guides/testing.md +137 -98
  216. package/docs/guides/ui-overlays.md +17 -12
  217. package/docs/guides/video-textures.md +14 -13
  218. package/docs/images/api/animation/character.webp +0 -0
  219. package/docs/images/api/animation/look-at-ring.webp +0 -0
  220. package/docs/images/api/animation/morph-tulips.webp +0 -0
  221. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  222. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  223. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  224. package/docs/images/api/debug/debug-shapes.webp +0 -0
  225. package/docs/images/api/debug/levels-view.webp +0 -0
  226. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  227. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  228. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  229. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  230. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  231. package/docs/images/api/geometry/generators.webp +0 -0
  232. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  233. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  234. package/docs/images/api/grass/grass-grove.webp +0 -0
  235. package/docs/images/api/grass/grass-presets.webp +0 -0
  236. package/docs/images/api/grass/grass-shadow.webp +0 -0
  237. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  238. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  239. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  240. package/docs/images/api/lights/spot-cookies.webp +0 -0
  241. package/docs/images/api/lines/lines-lit.webp +0 -0
  242. package/docs/images/api/lines/lines-widths.webp +0 -0
  243. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  244. package/docs/images/api/materials/decals.webp +0 -0
  245. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  246. package/docs/images/api/materials/relief.webp +0 -0
  247. package/docs/images/api/materials/shader-inputs.webp +0 -0
  248. package/docs/images/api/materials/standard-grid.webp +0 -0
  249. package/docs/images/api/materials/subsurface.webp +0 -0
  250. package/docs/images/api/materials/translucency.webp +0 -0
  251. package/docs/images/api/objects/objects-turntable.webp +0 -0
  252. package/docs/images/api/particles/campfire.webp +0 -0
  253. package/docs/images/api/points/galaxy.webp +0 -0
  254. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  255. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  256. package/docs/images/api/render/reflection-mirror.webp +0 -0
  257. package/docs/images/api/render/security-camera.webp +0 -0
  258. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  259. package/docs/images/api/sound/sound-demo.webp +0 -0
  260. package/docs/images/api/splats/splats-demo.webp +0 -0
  261. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  262. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  263. package/docs/images/api/textures/canvas-screen.webp +0 -0
  264. package/docs/images/api/textures/mipmaps.webp +0 -0
  265. package/docs/images/api/vertex-draws/rain.webp +0 -0
  266. package/docs/images/api/water/ocean.webp +0 -0
  267. package/docs/images/api/water/water-demo.webp +0 -0
  268. package/docs/images/api/water/water-rain.webp +0 -0
  269. package/docs/images/api/water/waterfall.webp +0 -0
  270. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  271. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  272. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  273. package/docs/images/concepts/instances/instances.webp +0 -0
  274. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  275. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  276. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  277. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  278. package/docs/images/concepts/lighting/environment.webp +0 -0
  279. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  280. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  281. package/docs/images/concepts/lod/forest.webp +0 -0
  282. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  283. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  284. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  285. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  286. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  287. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  288. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  289. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  290. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  291. package/docs/images/cookbook/index/picking.webp +0 -0
  292. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  293. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  294. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  295. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  296. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  297. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  298. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  299. package/docs/images/index/showcase-island.webp +0 -0
  300. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  301. package/docs/images/shaders/builtins/builtins.webp +0 -0
  302. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  303. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  304. package/docs/images/shots.json +2231 -0
  305. package/docs/index.md +14 -23
  306. package/docs/moves.json +1 -0
  307. package/docs/nav.json +300 -0
  308. package/docs/pages.md +230 -212
  309. package/docs/porting/react-three-fiber.md +2 -6
  310. package/docs/porting/threejs-loop-and-threads.md +1 -5
  311. package/docs/porting/threejs-mapping.md +1248 -234
  312. package/docs/porting/threejs-materials.md +10 -5
  313. package/docs/porting/threejs-overview.md +26 -6
  314. package/docs/porting/threejs-postprocessing.md +2 -6
  315. package/docs/porting/threejs-shaders.md +16 -14
  316. package/docs/porting/threejs-unsupported.md +6 -6
  317. package/docs/porting/verification.md +0 -4
  318. package/docs/shaders/builtins.md +15 -4
  319. package/docs/shaders/library.md +9 -6
  320. package/docs/shaders/surface-functions.md +51 -16
  321. package/docs/shaders/wgsl-rules.md +12 -5
  322. package/lib/debug/debug.d.ts +2 -2
  323. package/lib/debug/draw.d.ts +2 -2
  324. package/lib/debug/draw.js +8 -4
  325. package/lib/debug/overlay-look.d.ts +6 -0
  326. package/lib/debug/overlay-look.js +29 -7
  327. package/lib/debug/overlay.js +15 -11
  328. package/lib/debug/stats-options.d.ts +13 -0
  329. package/lib/debug/stats-panel.d.ts +21 -6
  330. package/lib/debug/stats-panel.js +80 -13
  331. package/lib/errors/codes.d.ts +17 -3
  332. package/lib/errors/codes.js +111 -105
  333. package/lib/errors/fixes.js +18 -18
  334. package/lib/gpu/variants.d.ts +8 -2
  335. package/lib/gpu/variants.js +39 -7
  336. package/lib/gpu/webgl2/programs.js +1 -1
  337. package/lib/gpu/webgpu/pipelines.js +13 -13
  338. package/lib/index.d.ts +1 -1
  339. package/lib/page/capabilities.d.ts +1 -1
  340. package/lib/page/engine.d.ts +14 -5
  341. package/lib/page/engine.js +18 -2
  342. package/lib/page/label-loop.js +9 -4
  343. package/lib/page/stats-switch.js +2 -0
  344. package/lib/page/switches.d.ts +6 -4
  345. package/lib/page/switches.js +20 -4
  346. package/lib/scene/baked-light.d.ts +2 -2
  347. package/lib/scene/fake-call-values.js +2 -2
  348. package/lib/scene/frame-cameras.d.ts +16 -4
  349. package/lib/scene/frame-cameras.js +28 -10
  350. package/lib/scene/gltf.d.ts +1 -1
  351. package/lib/scene/level-rule.d.ts +6 -5
  352. package/lib/scene/level-rule.js +2 -2
  353. package/lib/scene/particles.d.ts +7 -3
  354. package/lib/scene/particles.js +3 -1
  355. package/lib/scene/post.d.ts +3 -2
  356. package/lib/scene/resources.d.ts +15 -9
  357. package/lib/scene/scene.d.ts +18 -2
  358. package/lib/scene/scene.js +47 -5
  359. package/lib/scene/time-of-day.d.ts +10 -5
  360. package/lib/scene/time-of-day.js +11 -7
  361. package/lib/shader-artifact.json +1 -1
  362. package/lib/shared/labels.d.ts +5 -2
  363. package/lib/shared/labels.js +5 -2
  364. package/lib/shared/permutation-words.d.ts +2 -0
  365. package/lib/shared/permutation-words.js +8 -0
  366. package/lib/shared/recording.d.ts +13 -5
  367. package/lib/shared/recording.js +31 -10
  368. package/lib/shared/sketch-data.d.ts +9 -0
  369. package/lib/shared/sketch-data.js +57 -0
  370. package/lib/shared/version.d.ts +1 -1
  371. package/lib/shared/version.js +1 -1
  372. package/lib/sketch/define-sketch.d.ts +16 -7
  373. package/lib/sketch/define-sketch.js +2 -1
  374. package/lib/sketch/runner.d.ts +4 -0
  375. package/lib/sketch/runner.js +5 -0
  376. package/lib/sketch/ui.js +4 -2
  377. package/lib/stats.d.ts +1 -0
  378. package/lib/workers/protocol.d.ts +10 -0
  379. package/lib/workers/render-worker.js +4 -1
  380. package/lib/workers/sketch-worker.js +4 -1
  381. package/package.json +1 -1
@@ -1,15 +1,11 @@
1
1
  ---
2
2
  id: concepts/instances
3
3
  title: Instances and batching
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "createInstances; typed-array views; markDirty; automatic batching; per-row colors and values."
7
5
  ---
8
6
 
9
7
  # Instances and batching
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
  code["Sketch code writes rows<br/>into typed arrays"] --> rows[("Batch rows<br/>positions, rotations, scales")]
@@ -23,6 +19,10 @@ An instance batch draws one mesh with one material many times. Each copy is a ro
23
19
 
24
20
  Use a batch for many copies that you move in loops, such as particles, bullets, crowds, trees and rocks. Use separate objects from `scene.createMesh` when each copy needs a name, a parent or its own setters.
25
21
 
22
+ ![A field of about 100,000 columns in one instance batch at golden hour, with hover cars streaming above it.](../images/concepts/instances/instances.webp)
23
+
24
+ One dynamic batch: the sketch writes every column's height in every frame.
25
+
26
26
  ## Create a batch
27
27
 
28
28
  ```ts
@@ -54,6 +54,10 @@ export default defineSketch(({ scene, geometry, materials }) => {
54
54
  | `values` | `false` | `true` adds a `values` array: four numbers for each row, which a custom material reads |
55
55
  | `layers` | `1`, layer 0 | The [layers](render-layers.md) of every row, as a 32-bit mask |
56
56
  | `origin` | `[0, 0, 0]` | The point that every row's position is relative to, kept at full precision: [Batch origins](large-worlds.md#batch-origins) |
57
+ | `castShadows` | `false` | `true` makes every row cast shadows: [Shadows](shadows.md) |
58
+ | `receiveShadows` | `false` | `true` makes shadows fall on every row |
59
+ | `occluder` | `true` | `false` keeps rows from hiding what lies behind them in GPU occlusion culling on WebGPU: [Which objects hide others](culling.md#which-objects-hide-others) |
60
+ | `ranges` | `false` | `true` adds a `ranges` array: a start and an end distance for each row, so each row draws in a band of its own: [Distance bands](lod.md#distance-bands) |
57
61
 
58
62
  `count` is the batch's capacity, which never changes. All rows draw at first. A new batch computes every row in its first frame, so rows that you write before that frame need no mark.
59
63
 
@@ -66,12 +70,13 @@ export default defineSketch(({ scene, geometry, materials }) => {
66
70
  | `scales` | 3 | The scale on each axis | 1, 1, 1 |
67
71
  | `colors` | 4 | A linear color (r, g, b, a), with `colors: true` only | 1, 1, 1, 1 |
68
72
  | `values` | 4 | Four numbers of your own, with `values: true` only | 0, 0, 0, 0 |
73
+ | `ranges` | 2 | A start and an end distance, with `ranges: true` only | 0 and infinity |
69
74
 
70
75
  Row `i` starts at index `i * 3` in an array of 3 floats per row, and at `i * 4` in an array of 4. Rows have no parent, so each position is in world space, relative to the batch's `origin`. Far from the world's origin, give the batch an origin near its rows, so their 32-bit positions stay small and precise.
71
76
 
72
77
  The arrays are `Float32Array` views of engine memory. The engine's memory can grow when the scene grows: new meshes, batches, materials and lights, and textures made or updated from data. In the single-threaded build, growth empties every older view, and a write to an empty view does nothing. So read the arrays from the batch each time you use them, such as at the start of `onUpdate`. Do not keep them from the setup. A read allocates nothing while the memory keeps its size.
73
78
 
74
- To turn rows, write quaternions. The engine scales a rotation whose length is more than about one per cent from unit length. A quaternion inside that band is used exactly as written, so a rounded rotation is not moved, but one that is wrong all the same can shear its row by up to about four per cent. Well outside the band, a mistyped quaternion is scaled and only turns its row. The [math helpers](../api/math.md) make them without allocating:
79
+ To turn rows, write unit quaternions, whose length is 1. The engine uses a quaternion within about one per cent of unit length exactly as written, so a rounded rotation such as `[0, 0.38, 0, 0.92]` does not move. The engine does not correct an error inside that band: it can stretch or shear the row by up to about four per cent. The engine scales a quaternion further from unit length to unit length, so a mistyped one turns its row without stretching it. The [math helpers](../api/math.md) make unit quaternions without allocating:
75
80
 
76
81
  ```ts
77
82
  import { defineSketch, quat } from '@null3d/engine';
@@ -127,19 +132,14 @@ trees.rotations.set(q, 42 * 4);
127
132
  trees.markDirty(42, 1); // recompute and upload row 42 only
128
133
  ```
129
134
 
130
- A mark past the batch's capacity throws [E1108](../errors/E1108.md). Development builds check the rule. Before each batch update, they note the marked rows, and compare up to 4,096 drawn rows a frame, over all static batches, with the values they read before. The next frame takes the next rows, so the check finds a write within a few frames, and costs a bounded time per frame. A row that changed without a mark raises [E1110](../errors/E1110.md), which names the row. Sprite and point batches get the same check. Release builds leave it out. A dynamic batch needs no marks, because it recomputes every row in use in every frame. [Static and dynamic objects](static-dynamic.md) compares what each kind uploads.
135
+ A mark past the batch's capacity throws [E1108](../errors/E1108.md). Development builds also find rows that changed without a mark and raise [E1110](../errors/E1110.md), which names the row. Sprite and point batches get the same check, and release builds leave it out. A dynamic batch needs no marks, because it recomputes every row in use in every frame. [Static and dynamic objects](static-dynamic.md) compares what each kind uploads. The [terrain demo](https://github.com/null3d-engine/null3d/tree/main/examples/terrain) writes its boulders into a static batch and marks them once. The [custom shader inputs demo](https://github.com/null3d-engine/null3d/tree/main/examples/shader-inputs) does the same for its crystal spiral.
131
136
 
132
- ## Rows that arrive in chunks
137
+ <details>
138
+ <summary>Technical details: how the unmarked-write check works</summary>
139
+
140
+ Before each batch update the check notes the marked rows. It then compares up to 4,096 drawn rows a frame, over all static batches, with the values it read before. The next frame takes the next rows, so a write is found within a few frames at a bounded cost per frame.
133
141
 
134
- An add-on can hand the engine rows that arrive in pieces. A cloud of Gaussian splats is one such
135
- add-on. Call `batch.createChunkRows()` to make a writer. The writer stores a chunk's arrays in the
136
- engine's memory once, at load. Call `writer.reserve(count)` with the number of chunks. Then call
137
- `writer.write(slot, chunk)` for each chunk as it arrives. In each frame that the chosen rows
138
- change, call `writer.pack(counts)` with one chosen count for each slot. The writer writes the first
139
- `counts[slot]` rows of each chunk into the batch, in slot order, and sets the batch's active count.
140
- The pack runs in the engine's core, so the sketch copies no rows and runs no loop over them. The
141
- batch must own its rows' transforms: a part of a model, or a sprite or line batch, takes no chunked
142
- rows. The writer's code loads on first use. `writer.destroy()` frees its chunks.
142
+ </details>
143
143
 
144
144
  ## Pools: draw only the rows in use
145
145
 
@@ -171,17 +171,36 @@ function remove(row: number): void {
171
171
  }
172
172
  ```
173
173
 
174
- Keep each row's own data, such as a velocity, in your own typed arrays in the same row order, and move it the same way. An active count past the capacity throws [E1108](../errors/E1108.md).
174
+ Keep each row's own data, such as a velocity, in your own typed arrays in the same row order, and move it the same way. An active count past the capacity throws [E1108](../errors/E1108.md). The [instancing demo](https://github.com/null3d-engine/null3d/tree/main/examples/instances) sets its active count from the quality preset and fills the rows from the middle out.
175
175
 
176
176
  `destroy()` removes a batch at once and frees its rows. After it, stop using the batch and every array that you read from it. Its calls throw [E1101](../errors/E1101.md), and so do its array getters, such as `positions`, in every build. An array that you read before the destroy can point at memory that the engine gives to another batch.
177
177
 
178
178
  ## Culling
179
179
 
180
- Each row has its own bounding sphere. The sphere's center is the row's position, and its radius is the mesh's radius times the row's largest scale. `setBoundingRadius(r)` gives one batch's rows a radius of their own. Use it for a vertex shader that moves rows far from their origins, as traffic along a lane does. Without it, the engine culls rows that are still on the screen. A call builds the engine's draw tables again, so make it at setup. The engine culls row by row in each view, and skips the rows outside the view. On WebGPU a compute pass on the GPU culls. On a device that draws directly, the job workers cull on the CPU there too. The rows of a batch whose material blends are the exception. On both paths, the job workers cull them one by one and sort them back to front. On WebGL2 the job workers cull. They test a static batch at rest in groups of 64 nearby rows, each group inside one grid cell. A group that is partly in view draws whole, and the GPU clips the rows outside. In a scene over several grid cells, both paths skip the rows of static batches in the cells out of view ([Culling](culling.md)). On WebGL2, a frame where you mark a static batch's rows tests the batch row by row, with no cell skipped. So does the frame after it.
180
+ Each row has its own bounding sphere: its center is the row's position, and its radius is the mesh's radius times the row's largest scale. A vertex shader that moves rows far from their origins, as traffic along a lane does, needs `setBoundingRadius(r)`. Without it, the engine culls rows that are still on the screen. The call rebuilds the engine's draw tables, so make it at setup. [Culling](culling.md#how-each-path-culls) explains how each GPU path culls.
181
+
182
+ <details>
183
+ <summary>Technical details: how rows are culled</summary>
184
+
185
+ - Each view culls row by row.
186
+ - On WebGPU a compute pass culls, and on direct-draw devices the job workers cull.
187
+ - The rows of a blended material are culled one by one on the job workers, on both paths, and sorted back to front.
188
+ - On WebGL2 a static batch at rest is tested in groups of 64 nearby rows inside one grid cell. A group that is partly in view draws whole, and the GPU clips the rows outside.
189
+ - Both paths skip the rows of static batches in grid cells out of view.
190
+ - On WebGL2, a frame that marks a static batch, and the frame after it, test that batch row by row with no cell skipped.
191
+
192
+ </details>
181
193
 
182
194
  ## Automatic batching
183
195
 
184
- The engine groups what it draws by mesh and material. Objects from `scene.createMesh` and batch rows that share a mesh and a material draw together. They share instanced or indirect draws. So 500 crates from `createMesh` with one mesh and one material draw as cheaply as a batch of 500 rows. Some groups split. On WebGPU, an object with bounds of its own from `setBounds` draws apart from the others. Objects that are never culled draw apart from the culled ones, in a group of their own for each mesh and material. Objects and rows that receive shadows draw with other pipelines than those that do not, so they draw apart from them. On WebGL2, the rows of a dynamic batch and of a static batch at rest draw apart from objects with the same mesh and material. Blended objects and rows draw in the transparent pass, sorted back to front.
196
+ The engine groups what it draws by mesh and material. Objects from `scene.createMesh` and batch rows that share a mesh and a material draw together. They share instanced or indirect draws. So 500 crates from `createMesh` with one mesh and one material draw as cheaply as a batch of 500 rows. Some groups split:
197
+
198
+ - On WebGPU, an object with bounds of its own from `setBounds` draws apart from the others.
199
+ - Objects that are never culled draw apart from the culled ones, in a group of their own for each mesh and material.
200
+ - Objects and rows that receive shadows draw with other pipelines than those that do not, so they draw apart from them.
201
+ - On WebGL2, the rows of a dynamic batch and of a static batch at rest draw apart from objects with the same mesh and material.
202
+
203
+ Blended objects and rows draw in the transparent pass, sorted back to front. The [factory comparison](https://github.com/null3d-engine/null3d/tree/main/examples/compare/factory) builds each robot arm from separate meshes, and tells how null3D draws parts that share a mesh and a material together.
185
204
 
186
205
  The difference is the sketch's own work on the CPU:
187
206
 
@@ -191,7 +210,21 @@ The difference is the sketch's own work on the CPU:
191
210
  | Hierarchy | Parents and children | None: each row is in world space |
192
211
  | Identity | A name and a handle each | A row number |
193
212
 
194
- Some calls change the scene's structure: creating or destroying a batch or an object of any kind, lights included, and `setMaterial`, `setMesh`, `setParent`, `setDynamic`, `setBounds`, `setFrustumCulled`, `setCastShadows` and `setReceiveShadows`, on an object or a batch. So do `texture.destroy()`, and `texture.update()` with an image of another size. So does turning shadows on or off, and in development builds a new [debug view](../api/debug.md). The next frame then rebuilds the engine's draw tables, which costs more than a normal frame. These calls rebuild even when the value does not change, apart from a batch's `setCastShadows` and `setReceiveShadows`. Transform setters, row writes, `setVisible`, `setLayers`, `setActiveCount` and `setRenderOrder` never rebuild the tables. Neither do the other setters of lights and cameras, or `material.set`. So create batches in the setup, and pool rows during play instead of creating batches.
213
+ Some calls change the scene's structure. The next frame then rebuilds the engine's draw tables, which costs more than a normal frame. These calls rebuild:
214
+
215
+ - creating or destroying a batch or an object of any kind, lights included
216
+ - `setMaterial`, `setMesh`, `setParent`, `setDynamic`, `setBounds`, `setFrustumCulled`, `setCastShadows` and `setReceiveShadows`, on an object or a batch
217
+ - `texture.destroy()`, and `texture.update()` with an image of another size
218
+ - turning shadows on or off
219
+ - in development builds, a new [debug view](../api/debug.md)
220
+
221
+ They rebuild even when the value does not change, apart from a batch's `setCastShadows` and `setReceiveShadows`. These never rebuild the tables:
222
+
223
+ - transform setters and row writes
224
+ - `setVisible`, `setLayers`, `setActiveCount` and `setRenderOrder`
225
+ - the other setters of lights and cameras, and `material.set`
226
+
227
+ So create batches in the setup, and pool rows during play instead of creating batches.
195
228
 
196
229
  ## Limits
197
230
 
@@ -201,12 +234,16 @@ Some calls change the scene's structure: creating or destroying a batch or an ob
201
234
  - Each row takes about 210 bytes of engine memory, or about 300 with colors or values. When the engine cannot get more memory, `createInstances` throws [E1109](../errors/E1109.md). Rows with colors or values also take 32 bytes each of GPU memory.
202
235
  - On WebGL2 the limit follows the largest texture the device allows. A device whose textures reach only 2,048 pixels, the least that WebGL2 allows, draws 1,048,576. That leaves 1,047,552 rows for batches beside a scene of up to 1,023 objects. [GPU tiers and backends](backends.md#the-portable-budget) gives the numbers.
203
236
  - Development builds warn once in the console when a scene passes the number that every device of its GPU path draws. On WebGPU that is 2,097,152, the most that devices with WebGPU's default limits draw. On WebGL2 it is 1,048,576. The engine picks the GPU path for each device, so test a scene past 1,048,576 on both paths.
204
- - A row costs the mesh's vertices in every pass that draws it. Many rows of a detailed mesh therefore cost more than their pixels suggest. A hull of 72 vertices drawn 30,000 times is 2,165,760 vertex shader runs for one pass, and a depth prepass draws the rows again: the reflections and ambient occlusion turn one on. Share each vertex between the faces that meet at it where the shading allows a smooth surface: the same mesh with 24 vertices does a third of that work.
237
+ - A row costs the mesh's vertices in every pass that draws it. Many rows of a detailed mesh therefore cost more than their pixels suggest. A hull of 72 vertices drawn 30,000 times is 2,160,000 vertex shader runs for one pass. A depth prepass draws the rows again, because the reflections and ambient occlusion turn one on. Share each vertex between the faces that meet at it where the shading allows a smooth surface. The same mesh with 24 vertices does a third of that work.
205
238
 
206
239
  ## Per-row colors
207
240
 
208
241
  `colors: true` adds a `colors` array, with a linear RGBA color for each row, white at first. The color multiplies the material's base color and opacity, as a mesh's vertex colors do. So a white material shows each row's color, and a row's alpha below a masked material's cutoff hides the row. Convert an sRGB color, such as a hex string, with the color helpers in [Math helpers](../api/math.md).
209
242
 
243
+ ![Five instance batches of eight rows each, every row in its own color, beside one gray row of the same material without colors.](../images/concepts/instances/per-row-colors.webp)
244
+
245
+ Row colors multiply the material's color.
246
+
210
247
  ```ts
211
248
  import { color, defineSketch } from '@null3d/engine';
212
249
 
@@ -230,7 +267,7 @@ A static batch draws a new color after `markDirty`, as it draws a new position.
230
267
 
231
268
  ## Per-row values
232
269
 
233
- `values: true` adds a `values` array, with four numbers for each row, 0 at first. A [custom material](../guides/custom-shaders.md) reads its row's numbers as `object.values`, a `vec4f`, in its `vertexOffset` and `surface` functions. Use them for whatever changes from row to row: a phase of the wind, an age, a tint or a size. Objects from `scene.createMesh`, and batches without values, read zeros.
270
+ `values: true` adds a `values` array, with four numbers for each row, 0 at first. A [custom material](../guides/custom-shaders.md) reads its row's numbers as `object.values`, a `vec4f`, in its `vertexOffset` and `surface` functions. Use them for whatever changes from row to row: a phase of the wind, an age, a tint or a size. Objects from `scene.createMesh`, and batches without values, read zeros. The [instancing demo](https://github.com/null3d-engine/null3d/tree/main/examples/instances) draws its hover cars with the traffic lanes add-on, whose batches use values and whose shader moves each car.
234
271
 
235
272
  ```ts
236
273
  import { defineSketch } from '@null3d/engine';
@@ -273,11 +310,23 @@ Rows with colors or values draw with shader builds of their own, which a page do
273
310
 
274
311
  A custom material also reads each row's place in its batch as `input.instance`, from 0, in its `vertexOffset` and `surface` functions. It needs no `values` array: a hue, a phase or a size that follows from the row's place costs the sketch nothing. Every row reads its batch's id as `object.id`, which is `batch.shaderId` in the sketch. [Built-in shader inputs](../shaders/builtins.md#object) describes both.
275
312
 
313
+ ## Rows that arrive in chunks
314
+
315
+ An add-on can give the engine rows that arrive in pieces, such as the chunks of a Gaussian splat cloud. A chunk row writer stores each chunk in the engine's memory once. In each frame it then packs the rows that you choose into the batch, in the engine's core. So the sketch copies no rows and runs no loop over them.
316
+
317
+ 1. `const writer = await batch.createChunkRows()` makes the writer. Its code loads on first use.
318
+ 2. `writer.reserve(count)` makes room for `count` chunks. Call it again when the cloud gets more chunks.
319
+ 3. `writer.write(slot, chunk)` stores one chunk when it arrives. Do not call it in a frame.
320
+ 4. `writer.pack(counts)`, in each frame where the chosen rows change, takes one count for each slot. It writes the first `counts[slot]` rows of each chunk into the batch, in slot order, sets the batch's active count and returns that count.
321
+ 5. `writer.destroy()` frees the chunks.
322
+
323
+ The batch must own its rows' transforms. A part of a model, or a sprite or line batch, takes no chunked rows.
324
+
276
325
  ## Related pages
277
326
 
278
327
  - [Static and dynamic objects](static-dynamic.md): what each kind recomputes and uploads.
279
328
  - [Handles and objects](handles.md): separate objects, and per-object data in your own arrays.
280
- - [Scene](../api/scene.md): `createInstances` and the reference of instance batches.
329
+ - [Scene](../api/scene.md): `createInstances`. [The API reference of instance batches](../api/reference/scene.md#instancebatch) lists every member of `InstanceBatch` and every option of `createInstances`.
281
330
  - [Math helpers](../api/math.md): vectors, quaternions and colors for rows.
282
331
  - [Sprites](../api/sprites.md): batches of quads that face the camera, with the same rows, marks and limits.
283
332
  - [Points](../api/points.md): batches of squares of one size that face the camera, made of sprite rows.
@@ -1,15 +1,11 @@
1
1
  ---
2
2
  id: concepts/large-worlds
3
3
  title: Large worlds and precision
4
- status: experimental
5
- since: "0.2"
6
4
  summary: "Cell-relative positions and per-frame camera-to-cell offsets; reversed depth; largeWorld mode; batch origins; floating-origin geometry."
7
5
  ---
8
6
 
9
7
  # Large worlds and precision
10
8
 
11
- > Roadmap step 0.2, 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
  setters["Positions you set:<br/>JavaScript's 64-bit numbers"] -->|"largeWorld: true"| split["Whole cells and<br/>a small 32-bit rest"]
@@ -39,6 +35,10 @@ Lights, shadow cascades, raycasts, overlap queries, `screenToRay`, `worldToScree
39
35
 
40
36
  Cells keep world matrices precise, but a position that you set is a 32-bit float by default. At the Earth's radius it moves in steps of 0.5 m before it reaches a cell. Start the engine with `largeWorld: true`, and the setters keep each position exact:
41
37
 
38
+ ![A road at golden hour with dashed lane marks, trees and hazy hills.](../images/concepts/large-worlds/large-world.webp)
39
+
40
+ A road 6,378 km from the origin, in large-world mode.
41
+
42
42
  ```ts
43
43
  // page.ts
44
44
  const engine = await createEngine({ canvas, sketch, largeWorld: true });
@@ -94,9 +94,16 @@ Sprite, point and line batches take the same `origin` option. Batch origins work
94
94
 
95
95
  A camera that moves far from the origin stays as smooth as one near it. Each frame, the engine computes the camera's offset to each cell in 64-bit numbers, so the offsets stay small and exact near the camera.
96
96
 
97
- A test checks this with a flight. A camera flies sideways past six squares, 4 m to 35 m away, 12 cm per frame for 16 frames. It flies at the origin, 1,000 km out and at the Earth's radius, in large-world mode. Each square's image moves from frame to frame as it does at the origin, within 0.0001 pixels. This holds on WebGPU, its compatibility mode and WebGL2.
97
+ In large-world mode, a camera that flies past objects 1,000 km out or at the Earth's radius moves them on screen smoothly. It is as smooth as at the origin, on WebGPU, its compatibility mode and WebGL2. Without large-world mode, or when all 512 cells are in use ([Limits](#limits)), the same camera jitters. Positions then move in the coarse steps given at the top of this page.
98
+
99
+ <details>
100
+ <summary>Technical details: how the engine tests a moving camera</summary>
101
+
102
+ A test flies a camera sideways past six squares, 4 m to 35 m away, 12 cm per frame for 16 frames. It flies at the origin, 1,000 km out and at the Earth's radius, in large-world mode. Each square's image moves from frame to frame as it does at the origin, within 0.0001 pixels.
103
+
104
+ The same flight without large-world mode jitters. The camera's position moves in steps of about 6 cm at 1,000 km and 0.5 m at the Earth's radius. So the squares jump by up to 3.5 pixels at 1,000 km and 7.8 pixels at the Earth's radius.
98
105
 
99
- The same flight without large-world mode, or with no free cell, jitters. The camera's position then moves in steps of about 6 cm at 1,000 km and 0.5 m at the Earth's radius. So the squares jump by up to 3.5 pixels at 1,000 km and 7.8 pixels at the Earth's radius.
106
+ </details>
100
107
 
101
108
  ## Floating-origin geometry
102
109
 
@@ -113,8 +120,10 @@ The engine does not use logarithmic depth, which writes depth from the fragment
113
120
  ## Limits
114
121
 
115
122
  - At most 512 cells are in use at once, the origin's cell included. A cell is in use while an object or a row lies in it, and frees when the last one leaves. When all 512 are in use, an object or a row that enters a new cell goes into the origin's cell instead. There it has the precision of a 32-bit position. The engine then warns once in the console, as such content jitters far from the origin.
116
- - Dense content fills the most objects and rows that a scene can draw before it fills the cells. A city of 20,000 objects per square kilometer reaches that most at about 420 km² of flat ground: about 420 cells. Content spread thin can reach it, such as one marker in each of 1,000 towns. Keep such content in fewer cells. Put far objects under a few parent objects, as children share their root's cell. Or create and destroy them as the camera moves.
123
+ - Dense content fills the most objects and rows that a scene can draw before it fills the cells. A city of 20,000 objects per square kilometer reaches that most at about 105 km² of flat ground. That needs a device with WebGPU's default limits, and it takes about 100 cells. On a device that allows the most, it reaches the limit at about 420 km², or about 400 cells. The property `engine.capabilities.maxInstances` gives the number for the device ([The portable budget](backends.md#the-portable-budget)).
124
+ - Content spread thin can reach it, such as one marker in each of 1,000 towns. Keep such content in fewer cells. Put far objects under a few parent objects, as children share their root's cell. Or create and destroy them as the camera moves.
117
125
  - In large-world mode, positions reach about 2 × 10¹² m from the origin, the most whole cells that a 32-bit integer counts.
126
+ - `getWorldPosition` and `getWorldMatrix` return 64-bit positions, so pass a plain array or a `Float64Array`.
118
127
 
119
128
  ## Related pages
120
129
 
@@ -124,3 +133,4 @@ The engine does not use logarithmic depth, which writes depth from the fragment
124
133
  - [Engine](../api/engine.md): the `largeWorld` option of `createEngine`.
125
134
  - [GPU tiers and backends](backends.md#depth-on-each-tier): depth on each tier.
126
135
  - [The large world demo](https://github.com/null3d-engine/null3d/tree/main/examples/large-world): a drive along a road on the Earth's surface, in large-world mode with batch origins.
136
+ - [No `largeWorld` flag](https://github.com/null3d-engine/null3d/tree/main/examples/far-from-origin): 2 cm keys and a brass wheel, 1,000 km from the origin, seen from 40 cm.