@null3d/engine 0.0.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 (517) hide show
  1. package/README.md +109 -0
  2. package/THIRD-PARTY-NOTICES.txt +0 -1
  3. package/dist/wasm/single/null3d.js +25 -10
  4. package/dist/wasm/single/null3d_bg.wasm +0 -0
  5. package/dist/wasm/threaded/null3d.js +25 -10
  6. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  7. package/docs/api/animation.md +114 -86
  8. package/docs/api/assets.md +135 -49
  9. package/docs/api/cameras.md +45 -12
  10. package/docs/api/controls.md +88 -62
  11. package/docs/api/debug.md +116 -41
  12. package/docs/api/engine.md +117 -35
  13. package/docs/api/feature-draws.md +23 -17
  14. package/docs/api/feature-effects.md +11 -11
  15. package/docs/api/feature-instances.md +70 -19
  16. package/docs/api/features.md +77 -47
  17. package/docs/api/geometry.md +132 -82
  18. package/docs/api/grass.md +55 -13
  19. package/docs/api/impostors.md +175 -22
  20. package/docs/api/input.md +24 -18
  21. package/docs/api/lights.md +78 -51
  22. package/docs/api/lines.md +41 -33
  23. package/docs/api/materials.md +248 -121
  24. package/docs/api/math.md +12 -13
  25. package/docs/api/objects.md +47 -22
  26. package/docs/api/page.md +58 -7
  27. package/docs/api/particles.md +33 -20
  28. package/docs/api/points.md +19 -31
  29. package/docs/api/post.md +75 -42
  30. package/docs/api/quality.md +42 -17
  31. package/docs/api/raycast.md +65 -51
  32. package/docs/api/reference/animation.md +10 -11
  33. package/docs/api/reference/assets.md +25 -22
  34. package/docs/api/reference/cameras.md +8 -4
  35. package/docs/api/reference/controls.md +134 -25
  36. package/docs/api/reference/debug.md +81 -14
  37. package/docs/api/reference/engine.md +58 -17
  38. package/docs/api/reference/feature-draws.md +3 -4
  39. package/docs/api/reference/feature-effects.md +2 -3
  40. package/docs/api/reference/feature-instances.md +5 -4
  41. package/docs/api/reference/features.md +7 -4
  42. package/docs/api/reference/geometry.md +287 -97
  43. package/docs/api/reference/grass.md +63 -3
  44. package/docs/api/reference/impostors.md +208 -13
  45. package/docs/api/reference/input.md +4 -5
  46. package/docs/api/reference/lights.md +13 -12
  47. package/docs/api/reference/lines.md +10 -11
  48. package/docs/api/reference/materials.md +54 -53
  49. package/docs/api/reference/math.md +35 -24
  50. package/docs/api/reference/objects.md +11 -12
  51. package/docs/api/reference/particles.md +31 -6
  52. package/docs/api/reference/points.md +6 -7
  53. package/docs/api/reference/post.md +21 -20
  54. package/docs/api/reference/quality.md +8 -5
  55. package/docs/api/reference/raycast.md +7 -8
  56. package/docs/api/reference/render.md +5 -4
  57. package/docs/api/reference/scene.md +52 -30
  58. package/docs/api/reference/sketch.md +15 -11
  59. package/docs/api/reference/sound.md +234 -0
  60. package/docs/api/reference/splats.md +42 -3
  61. package/docs/api/reference/sprites.md +7 -8
  62. package/docs/api/reference/tasks.md +16 -3
  63. package/docs/api/reference/terrain.md +27 -5
  64. package/docs/api/reference/textures.md +5 -6
  65. package/docs/api/reference/three-compat.md +18 -7
  66. package/docs/api/reference/time.md +1 -2
  67. package/docs/api/reference/ui.md +12 -9
  68. package/docs/api/reference/vertex-draws.md +5 -6
  69. package/docs/api/reference/water.md +153 -9
  70. package/docs/api/reference/wind.md +17 -4
  71. package/docs/api/render.md +73 -29
  72. package/docs/api/scene.md +164 -60
  73. package/docs/api/sketch.md +102 -15
  74. package/docs/api/sound.md +205 -0
  75. package/docs/api/splats.md +46 -12
  76. package/docs/api/sprites.md +10 -24
  77. package/docs/api/tasks.md +33 -24
  78. package/docs/api/terrain.md +42 -22
  79. package/docs/api/textures.md +68 -19
  80. package/docs/api/three-compat.md +15 -7
  81. package/docs/api/time.md +3 -5
  82. package/docs/api/ui.md +19 -23
  83. package/docs/api/vertex-draws.md +13 -12
  84. package/docs/api/water.md +262 -35
  85. package/docs/api/wind.md +63 -17
  86. package/docs/cli/null3d.md +177 -27
  87. package/docs/concepts/architecture.md +73 -27
  88. package/docs/concepts/assets.md +57 -33
  89. package/docs/concepts/backends.md +69 -27
  90. package/docs/concepts/color-management.md +54 -36
  91. package/docs/concepts/culling.md +68 -47
  92. package/docs/concepts/handles.md +14 -5
  93. package/docs/concepts/instances.md +74 -25
  94. package/docs/concepts/large-worlds.md +18 -8
  95. package/docs/concepts/lighting.md +155 -87
  96. package/docs/concepts/lod.md +126 -44
  97. package/docs/concepts/materials.md +58 -27
  98. package/docs/concepts/particle-buffer.md +48 -35
  99. package/docs/concepts/post-processing.md +84 -43
  100. package/docs/concepts/quality-preset-tables.md +56 -52
  101. package/docs/concepts/quality-presets.md +164 -52
  102. package/docs/concepts/render-graph.md +69 -29
  103. package/docs/concepts/render-layers.md +11 -21
  104. package/docs/concepts/shadows.md +105 -52
  105. package/docs/concepts/static-dynamic.md +22 -7
  106. package/docs/cookbook/index.md +164 -120
  107. package/docs/data/threejs-mapping.json +362 -367
  108. package/docs/errors/E1101.md +23 -5
  109. package/docs/errors/E1102.md +11 -3
  110. package/docs/errors/E1103.md +11 -3
  111. package/docs/errors/E1104.md +11 -3
  112. package/docs/errors/E1105.md +13 -5
  113. package/docs/errors/E1106.md +11 -3
  114. package/docs/errors/E1107.md +15 -5
  115. package/docs/errors/E1108.md +11 -3
  116. package/docs/errors/E1109.md +32 -6
  117. package/docs/errors/E1110.md +23 -5
  118. package/docs/errors/E1111.md +11 -3
  119. package/docs/errors/E1112.md +11 -3
  120. package/docs/errors/E1203.md +12 -4
  121. package/docs/errors/E1204.md +11 -3
  122. package/docs/errors/E1205.md +11 -3
  123. package/docs/errors/E1206.md +28 -6
  124. package/docs/errors/E1207.md +11 -3
  125. package/docs/errors/E1208.md +12 -3
  126. package/docs/errors/E1209.md +11 -3
  127. package/docs/errors/E1213.md +27 -5
  128. package/docs/errors/E1214.md +14 -6
  129. package/docs/errors/E1215.md +31 -6
  130. package/docs/errors/E1216.md +31 -6
  131. package/docs/errors/E1217.md +29 -6
  132. package/docs/errors/E1218.md +22 -6
  133. package/docs/errors/E1219.md +11 -3
  134. package/docs/errors/E1220.md +24 -5
  135. package/docs/errors/E1221.md +24 -5
  136. package/docs/errors/E1222.md +11 -3
  137. package/docs/errors/E1223.md +39 -6
  138. package/docs/errors/E1224.md +11 -3
  139. package/docs/errors/E1225.md +11 -3
  140. package/docs/errors/E1301.md +11 -3
  141. package/docs/errors/E1302.md +11 -3
  142. package/docs/errors/E1303.md +11 -3
  143. package/docs/errors/E1304.md +11 -3
  144. package/docs/errors/E1305.md +13 -3
  145. package/docs/errors/E1306.md +11 -3
  146. package/docs/errors/E1307.md +40 -0
  147. package/docs/errors/E1401.md +11 -3
  148. package/docs/errors/E1402.md +13 -5
  149. package/docs/errors/E1403.md +11 -3
  150. package/docs/errors/E1404.md +13 -3
  151. package/docs/errors/E1405.md +15 -4
  152. package/docs/errors/E1406.md +31 -5
  153. package/docs/errors/E1407.md +11 -3
  154. package/docs/errors/E1408.md +11 -3
  155. package/docs/errors/E1409.md +11 -3
  156. package/docs/errors/E1410.md +13 -5
  157. package/docs/errors/E1411.md +11 -3
  158. package/docs/errors/E1412.md +29 -6
  159. package/docs/errors/E1413.md +11 -3
  160. package/docs/errors/E1414.md +11 -3
  161. package/docs/errors/E1415.md +11 -3
  162. package/docs/errors/E1416.md +27 -6
  163. package/docs/errors/E1417.md +11 -3
  164. package/docs/errors/E1418.md +12 -3
  165. package/docs/errors/E1419.md +13 -5
  166. package/docs/errors/E1420.md +14 -6
  167. package/docs/errors/E1421.md +11 -3
  168. package/docs/errors/E1422.md +12 -3
  169. package/docs/errors/E1423.md +12 -3
  170. package/docs/errors/E1424.md +24 -5
  171. package/docs/errors/E1425.md +11 -3
  172. package/docs/errors/E1426.md +11 -3
  173. package/docs/errors/E1430.md +11 -3
  174. package/docs/errors/E1431.md +11 -3
  175. package/docs/errors/E1432.md +11 -3
  176. package/docs/errors/E1433.md +11 -3
  177. package/docs/errors/E1434.md +15 -6
  178. package/docs/errors/E1435.md +11 -3
  179. package/docs/errors/E1436.md +11 -3
  180. package/docs/errors/E1437.md +14 -6
  181. package/docs/errors/E1501.md +41 -6
  182. package/docs/errors/E1502.md +13 -3
  183. package/docs/errors/E1503.md +11 -3
  184. package/docs/errors/E1504.md +11 -3
  185. package/docs/errors/E1505.md +23 -5
  186. package/docs/errors/E1506.md +11 -3
  187. package/docs/errors/index.md +54 -30
  188. package/docs/getting-started/cdn.md +32 -10
  189. package/docs/getting-started/first-scene.md +21 -13
  190. package/docs/getting-started/hosting.md +152 -63
  191. package/docs/getting-started/install.md +44 -28
  192. package/docs/getting-started/network-use.md +33 -15
  193. package/docs/getting-started/project-structure.md +33 -12
  194. package/docs/getting-started/third-party-notices.md +12 -14
  195. package/docs/guides/accessibility.md +5 -5
  196. package/docs/guides/add-ons.md +86 -15
  197. package/docs/guides/agents.md +16 -9
  198. package/docs/guides/assets-pipeline.md +259 -82
  199. package/docs/guides/audio.md +115 -128
  200. package/docs/guides/baked-light-data.md +44 -23
  201. package/docs/guides/car-paint.md +38 -32
  202. package/docs/guides/content-pages.md +63 -35
  203. package/docs/guides/custom-passes.md +65 -22
  204. package/docs/guides/custom-shaders.md +59 -39
  205. package/docs/guides/debugging.md +74 -10
  206. package/docs/guides/deploying.md +85 -6
  207. package/docs/guides/deterministic-simulation.md +24 -17
  208. package/docs/guides/first-use-shaders.md +83 -45
  209. package/docs/guides/lens-kit.md +29 -26
  210. package/docs/guides/loading-screens.md +132 -47
  211. package/docs/guides/multiple-views.md +63 -13
  212. package/docs/guides/performance.md +192 -38
  213. package/docs/guides/phones.md +78 -15
  214. package/docs/guides/physics.md +7 -11
  215. package/docs/guides/screens.md +47 -33
  216. package/docs/guides/start-time.md +363 -0
  217. package/docs/guides/testing.md +152 -95
  218. package/docs/guides/ui-overlays.md +19 -14
  219. package/docs/guides/video-textures.md +14 -13
  220. package/docs/images/api/animation/character.webp +0 -0
  221. package/docs/images/api/animation/look-at-ring.webp +0 -0
  222. package/docs/images/api/animation/morph-tulips.webp +0 -0
  223. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  224. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  225. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  226. package/docs/images/api/debug/debug-shapes.webp +0 -0
  227. package/docs/images/api/debug/levels-view.webp +0 -0
  228. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  229. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  230. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  231. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  232. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  233. package/docs/images/api/geometry/generators.webp +0 -0
  234. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  235. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  236. package/docs/images/api/grass/grass-grove.webp +0 -0
  237. package/docs/images/api/grass/grass-presets.webp +0 -0
  238. package/docs/images/api/grass/grass-shadow.webp +0 -0
  239. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  240. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  241. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  242. package/docs/images/api/lights/spot-cookies.webp +0 -0
  243. package/docs/images/api/lines/lines-lit.webp +0 -0
  244. package/docs/images/api/lines/lines-widths.webp +0 -0
  245. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  246. package/docs/images/api/materials/decals.webp +0 -0
  247. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  248. package/docs/images/api/materials/relief.webp +0 -0
  249. package/docs/images/api/materials/shader-inputs.webp +0 -0
  250. package/docs/images/api/materials/standard-grid.webp +0 -0
  251. package/docs/images/api/materials/subsurface.webp +0 -0
  252. package/docs/images/api/materials/translucency.webp +0 -0
  253. package/docs/images/api/objects/objects-turntable.webp +0 -0
  254. package/docs/images/api/particles/campfire.webp +0 -0
  255. package/docs/images/api/points/galaxy.webp +0 -0
  256. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  257. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  258. package/docs/images/api/render/reflection-mirror.webp +0 -0
  259. package/docs/images/api/render/security-camera.webp +0 -0
  260. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  261. package/docs/images/api/sound/sound-demo.webp +0 -0
  262. package/docs/images/api/splats/splats-demo.webp +0 -0
  263. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  264. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  265. package/docs/images/api/textures/canvas-screen.webp +0 -0
  266. package/docs/images/api/textures/mipmaps.webp +0 -0
  267. package/docs/images/api/vertex-draws/rain.webp +0 -0
  268. package/docs/images/api/water/ocean.webp +0 -0
  269. package/docs/images/api/water/water-demo.webp +0 -0
  270. package/docs/images/api/water/water-rain.webp +0 -0
  271. package/docs/images/api/water/waterfall.webp +0 -0
  272. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  273. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  274. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  275. package/docs/images/concepts/instances/instances.webp +0 -0
  276. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  277. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  278. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  279. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  280. package/docs/images/concepts/lighting/environment.webp +0 -0
  281. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  282. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  283. package/docs/images/concepts/lod/forest.webp +0 -0
  284. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  285. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  286. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  287. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  288. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  289. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  290. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  291. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  292. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  293. package/docs/images/cookbook/index/picking.webp +0 -0
  294. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  295. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  296. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  297. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  298. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  299. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  300. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  301. package/docs/images/index/showcase-island.webp +0 -0
  302. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  303. package/docs/images/shaders/builtins/builtins.webp +0 -0
  304. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  305. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  306. package/docs/images/shots.json +2231 -0
  307. package/docs/index.md +18 -23
  308. package/docs/moves.json +1 -0
  309. package/docs/nav.json +300 -0
  310. package/docs/pages.md +230 -209
  311. package/docs/porting/react-three-fiber.md +225 -6
  312. package/docs/porting/threejs-loop-and-threads.md +217 -7
  313. package/docs/porting/threejs-mapping.md +1249 -233
  314. package/docs/porting/threejs-materials.md +218 -6
  315. package/docs/porting/threejs-overview.md +240 -7
  316. package/docs/porting/threejs-postprocessing.md +4 -8
  317. package/docs/porting/threejs-shaders.md +301 -6
  318. package/docs/porting/threejs-unsupported.md +83 -7
  319. package/docs/porting/verification.md +178 -6
  320. package/docs/shaders/builtins.md +15 -4
  321. package/docs/shaders/library.md +72 -45
  322. package/docs/shaders/surface-functions.md +59 -23
  323. package/docs/shaders/wgsl-rules.md +12 -5
  324. package/lib/debug/channel.d.ts +103 -0
  325. package/lib/debug/channel.js +269 -0
  326. package/lib/debug/debug.d.ts +11 -9
  327. package/lib/debug/draw.d.ts +11 -2
  328. package/lib/debug/draw.js +57 -6
  329. package/lib/debug/inspector.d.ts +60 -0
  330. package/lib/debug/inspector.js +475 -0
  331. package/lib/debug/overlay-look.d.ts +6 -0
  332. package/lib/debug/overlay-look.js +29 -7
  333. package/lib/debug/overlay.js +15 -11
  334. package/lib/debug/stats-options.d.ts +13 -0
  335. package/lib/debug/stats-panel.d.ts +22 -7
  336. package/lib/debug/stats-panel.js +80 -13
  337. package/lib/debug/stats.d.ts +2 -3
  338. package/lib/errors/codes.d.ts +17 -3
  339. package/lib/errors/codes.js +117 -105
  340. package/lib/errors/engine-error.js +25 -10
  341. package/lib/errors/fixes.d.ts +1 -0
  342. package/lib/errors/fixes.js +20 -19
  343. package/lib/generated/core.d.ts +1 -1
  344. package/lib/generated/core.js +1 -1
  345. package/lib/gpu/early-builds.d.ts +68 -0
  346. package/lib/gpu/early-builds.js +158 -0
  347. package/lib/gpu/pipeline-name.d.ts +6 -0
  348. package/lib/gpu/pipeline-name.js +23 -0
  349. package/lib/gpu/variants.d.ts +8 -2
  350. package/lib/gpu/variants.js +39 -7
  351. package/lib/gpu/webgl2/backend.d.ts +63 -2
  352. package/lib/gpu/webgl2/backend.js +226 -8
  353. package/lib/gpu/webgl2/programs.d.ts +18 -0
  354. package/lib/gpu/webgl2/programs.js +5 -2
  355. package/lib/gpu/webgpu/backend.d.ts +89 -2
  356. package/lib/gpu/webgpu/backend.js +255 -8
  357. package/lib/gpu/webgpu/pipelines.d.ts +13 -0
  358. package/lib/gpu/webgpu/pipelines.js +28 -14
  359. package/lib/index.d.ts +7 -5
  360. package/lib/index.js +3 -2
  361. package/lib/math/color.d.ts +5 -5
  362. package/lib/math/color.js +5 -5
  363. package/lib/math/mat4.d.ts +6 -12
  364. package/lib/math/mat4.js +6 -12
  365. package/lib/math/namespaces/quat.d.ts +3 -3
  366. package/lib/math/namespaces/quat.js +3 -3
  367. package/lib/math/quat.d.ts +8 -12
  368. package/lib/math/quat.js +8 -12
  369. package/lib/math/random.d.ts +2 -3
  370. package/lib/math/random.js +2 -3
  371. package/lib/math/types.d.ts +4 -4
  372. package/lib/math/vec3.d.ts +3 -6
  373. package/lib/math/vec3.js +3 -6
  374. package/lib/page/capabilities.d.ts +8 -8
  375. package/lib/page/capabilities.js +39 -25
  376. package/lib/page/check-store.d.ts +14 -2
  377. package/lib/page/check-store.js +34 -11
  378. package/lib/page/engine.d.ts +117 -31
  379. package/lib/page/engine.js +438 -99
  380. package/lib/page/first-frame.d.ts +16 -0
  381. package/lib/page/first-frame.js +35 -0
  382. package/lib/page/frame-stats.d.ts +34 -1
  383. package/lib/page/frame-stats.js +15 -0
  384. package/lib/page/label-loop.d.ts +7 -3
  385. package/lib/page/label-loop.js +26 -14
  386. package/lib/page/labels.d.ts +3 -3
  387. package/lib/page/pipeline-store.d.ts +25 -0
  388. package/lib/page/pipeline-store.js +84 -0
  389. package/lib/page/start-marker.d.ts +4 -1
  390. package/lib/page/start-marker.js +5 -2
  391. package/lib/page/stats-switch.js +2 -0
  392. package/lib/page/switches.d.ts +38 -6
  393. package/lib/page/switches.js +29 -5
  394. package/lib/quality/check.d.ts +24 -3
  395. package/lib/quality/check.js +21 -7
  396. package/lib/quality/chooser.d.ts +6 -0
  397. package/lib/quality/chooser.js +8 -0
  398. package/lib/quality/governor.d.ts +98 -6
  399. package/lib/quality/governor.js +250 -20
  400. package/lib/quality/preset-docs.d.ts +16 -1
  401. package/lib/quality/preset-docs.js +3 -0
  402. package/lib/quality/presets.d.ts +84 -7
  403. package/lib/quality/presets.js +94 -2
  404. package/lib/render/draw.d.ts +3 -2
  405. package/lib/render/draw.js +15 -5
  406. package/lib/render/load-draw.d.ts +7 -5
  407. package/lib/render/load-draw.js +7 -5
  408. package/lib/render/loss.d.ts +28 -10
  409. package/lib/render/loss.js +50 -22
  410. package/lib/render/recovery.d.ts +20 -0
  411. package/lib/render/recovery.js +44 -4
  412. package/lib/render/renderer.d.ts +85 -9
  413. package/lib/render/renderer.js +181 -42
  414. package/lib/render/scene-renderer.d.ts +19 -1
  415. package/lib/render/scene-renderer.js +25 -1
  416. package/lib/render/webgl2-renderers.js +8 -5
  417. package/lib/render/webgpu-renderers.js +5 -4
  418. package/lib/scene/animation.d.ts +28 -32
  419. package/lib/scene/animation.js +12 -15
  420. package/lib/scene/assets.d.ts +61 -86
  421. package/lib/scene/assets.js +103 -236
  422. package/lib/scene/background.d.ts +14 -18
  423. package/lib/scene/background.js +5 -2
  424. package/lib/scene/baked-light.d.ts +2 -2
  425. package/lib/scene/color.d.ts +3 -3
  426. package/lib/scene/downloads.d.ts +2 -0
  427. package/lib/scene/downloads.js +371 -0
  428. package/lib/scene/environment.d.ts +7 -7
  429. package/lib/scene/environment.js +1 -1
  430. package/lib/scene/fake-call-values.js +3 -3
  431. package/lib/scene/fog.d.ts +11 -4
  432. package/lib/scene/fog.js +8 -2
  433. package/lib/scene/frame-cameras.d.ts +35 -4
  434. package/lib/scene/frame-cameras.js +86 -10
  435. package/lib/scene/gltf.d.ts +33 -3
  436. package/lib/scene/gltf.js +78 -49
  437. package/lib/scene/grading.d.ts +2 -2
  438. package/lib/scene/grading.js +3 -3
  439. package/lib/scene/ktx2.d.ts +9 -1
  440. package/lib/scene/ktx2.js +3 -2
  441. package/lib/scene/level-rule.d.ts +121 -0
  442. package/lib/scene/level-rule.js +130 -0
  443. package/lib/scene/lines.d.ts +13 -17
  444. package/lib/scene/lines.js +3 -3
  445. package/lib/scene/lut.d.ts +1 -2
  446. package/lib/scene/lut.js +1 -2
  447. package/lib/scene/particles.d.ts +7 -3
  448. package/lib/scene/particles.js +3 -1
  449. package/lib/scene/picks.d.ts +2 -2
  450. package/lib/scene/pointer-events.d.ts +4 -7
  451. package/lib/scene/post.d.ts +39 -43
  452. package/lib/scene/post.js +4 -1
  453. package/lib/scene/prefab.d.ts +7 -8
  454. package/lib/scene/prefab.js +7 -8
  455. package/lib/scene/property-animation.d.ts +1 -1
  456. package/lib/scene/property-animation.js +1 -1
  457. package/lib/scene/queries.d.ts +7 -13
  458. package/lib/scene/resources.d.ts +238 -261
  459. package/lib/scene/resources.js +179 -81
  460. package/lib/scene/scene.d.ts +167 -120
  461. package/lib/scene/scene.js +243 -103
  462. package/lib/scene/serial-loads.d.ts +29 -0
  463. package/lib/scene/serial-loads.js +68 -0
  464. package/lib/scene/shader-preloads.d.ts +34 -0
  465. package/lib/scene/shader-preloads.js +38 -0
  466. package/lib/scene/sprites.d.ts +14 -17
  467. package/lib/scene/sprites.js +5 -6
  468. package/lib/scene/textures.d.ts +11 -12
  469. package/lib/scene/textures.js +9 -10
  470. package/lib/scene/time-of-day.d.ts +11 -7
  471. package/lib/scene/time-of-day.js +11 -8
  472. package/lib/scene/vertex-draws.d.ts +5 -4
  473. package/lib/scene/vertex-draws.js +7 -5
  474. package/lib/shader-artifact.json +1 -0
  475. package/lib/shared/core.d.ts +5 -0
  476. package/lib/shared/core.js +1 -0
  477. package/lib/shared/import-once.d.ts +6 -0
  478. package/lib/shared/import-once.js +19 -0
  479. package/lib/shared/labels.d.ts +5 -2
  480. package/lib/shared/labels.js +5 -2
  481. package/lib/shared/metrics.d.ts +38 -0
  482. package/lib/shared/metrics.js +62 -1
  483. package/lib/shared/permutation-words.d.ts +2 -0
  484. package/lib/shared/permutation-words.js +8 -0
  485. package/lib/shared/recording.d.ts +13 -5
  486. package/lib/shared/recording.js +31 -10
  487. package/lib/shared/run-task.js +7 -1
  488. package/lib/shared/sketch-data.d.ts +9 -0
  489. package/lib/shared/sketch-data.js +57 -0
  490. package/lib/shared/task-pending.d.ts +12 -0
  491. package/lib/shared/task-pending.js +61 -1
  492. package/lib/shared/tasks.js +79 -32
  493. package/lib/shared/version.d.ts +17 -1
  494. package/lib/shared/version.js +19 -1
  495. package/lib/shared/wasm.d.ts +12 -4
  496. package/lib/shared/wasm.js +50 -27
  497. package/lib/shared/worker-start.d.ts +7 -0
  498. package/lib/shared/worker-start.js +27 -0
  499. package/lib/sketch/define-sketch.d.ts +51 -7
  500. package/lib/sketch/define-sketch.js +2 -1
  501. package/lib/sketch/input.d.ts +2 -2
  502. package/lib/sketch/preset-check.d.ts +20 -6
  503. package/lib/sketch/preset-check.js +42 -17
  504. package/lib/sketch/quality.d.ts +69 -11
  505. package/lib/sketch/quality.js +54 -13
  506. package/lib/sketch/runner.d.ts +80 -9
  507. package/lib/sketch/runner.js +390 -52
  508. package/lib/sketch/ui.d.ts +5 -8
  509. package/lib/sketch/ui.js +4 -2
  510. package/lib/stats.d.ts +1 -0
  511. package/lib/workers/probe-worker.d.ts +5 -0
  512. package/lib/workers/probe-worker.js +13 -4
  513. package/lib/workers/protocol.d.ts +71 -13
  514. package/lib/workers/protocol.js +4 -0
  515. package/lib/workers/render-worker.js +29 -5
  516. package/lib/workers/sketch-worker.js +108 -16
  517. package/package.json +2 -2
package/docs/api/scene.md CHANGED
@@ -1,16 +1,12 @@
1
1
  ---
2
2
  id: api/scene
3
3
  title: Scene
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "Creating objects; models and copies; find; multiple views of one scene; background, environment, reflection probes, fog, sky; the light probe grid; the material override; warmUp."
7
5
  ---
8
6
 
9
7
  # Scene
10
8
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds the environment, the sky and environment backgrounds, the sky's environment, the light probe grid, `timeOfDay` and volumetric fog. The API is experimental, so it can still change between versions.
12
-
13
- The scene holds everything the engine draws: the objects, the camera that the canvas shows, the lights and the background. A sketch gets it as `scene` in its setup function, and creates everything through it.
9
+ The scene holds everything the engine draws: the objects, the camera that the canvas shows, the lights and the background. A sketch gets it as `scene` in its setup function, and creates everything through it. Wrong options throw one of the codes in [Errors](#errors).
14
10
 
15
11
  ```ts
16
12
  import { defineSketch } from '@null3d/engine';
@@ -50,21 +46,35 @@ export default defineSketch(({ scene, geometry, materials }) => {
50
46
  | `clone(object)` | A copy of an object and of every object below it |
51
47
  | `createPerspectiveCamera(options)` | A `PerspectiveCamera` that the scene can draw from |
52
48
  | `createOrthographicCamera(options)` | An `OrthographicCamera`, whose view is a box, that the scene can draw from |
49
+ | `createView({ camera, rect })` | A `SceneView` that draws the scene again from another camera, into a rectangle of the canvas: [Multiple views](#multiple-views) |
53
50
  | `createDirectionalLight(options)` | A `DirectionalLight`: light from one direction, like sunlight |
54
51
  | `createPointLight(options)` | A `PointLight`: light from a point in every direction, out to its range |
55
52
  | `createSpotLight(options)` | A `SpotLight`: light from a point in a cone, out to its range |
53
+ | `createRectAreaLight(options)` | A `RectAreaLight`: light from a glowing rectangle, out to its range: [Lights](lights.md) |
54
+ | `createTubeLight(options)` | A `TubeLight`: light from a glowing tube, out to its range: [Lights](lights.md) |
56
55
  | `createHemisphereLight(options)` | A `HemisphereLight`: light from the sky above and the ground below |
57
56
  | `createAmbientLight(options)` | An `AmbientLight`: the same light on every surface |
57
+ | `createReflectionProbe(options)` | A `ReflectionProbe` that lights the surfaces inside its box with the scene around a point: [Reflection probes](#reflection-probes) |
58
58
  | `createSprites(options)` | A batch of camera-facing quads, after an `await`: [Sprites](sprites.md) |
59
59
  | `createPoints(options)` | A batch of points, after an `await`: [Points](points.md) |
60
60
  | `createLines(options)` | A batch of wide lines, after an `await`: [Lines](lines.md) |
61
+ | `createParticleBuffer(options)` | A `ParticleBuffer`, a table of particles that the GPU moves, after an `await`. The [particles add-on](particles.md)'s emitters fill it: [The particle buffer](../concepts/particle-buffer.md) |
61
62
  | `addFeatureDraw(description, options)` | A draw that an add-on's feature description declares, after an `await`: [Add-on feature draws](feature-draws.md) |
63
+ | `addFeatureInstances(description, options)` | A draw of many copies of one shape that an add-on's feature description declares, after an `await`: [Add-on feature draws](feature-draws.md#many-copies-of-one-shape) |
64
+ | `addComputeInstances(description, options)` | A draw of instances from the add-on's own GPU buffer, after an `await`: [Add-on instance draws](feature-instances.md) |
65
+ | `createVertexDraw(options)` | A draw of a custom material over a vertex count, with no mesh data: [Draws from a vertex count](vertex-draws.md) |
66
+
67
+ Groups, meshes, cameras and lights take the same object options: `name`, `position`, `rotation`, `scale`, `parent`, `dynamic` and `layers`. [Objects and transforms](objects.md) describes them.
68
+
69
+ `createMesh` also takes `castShadows` and `receiveShadows`, which [Shadows](../concepts/shadows.md) explains. It takes `occluder` too, which [Culling](../concepts/culling.md) explains. `createInstances` takes `colors: true` and `values: true` for a color and four values per row: [Instances and batching](../concepts/instances.md).
62
70
 
63
- Groups, meshes, cameras and lights take the same object options: `name`, `position`, `rotation`, `scale`, `parent`, `dynamic` and `layers`. [Objects and transforms](objects.md) describes them. `createMesh` also takes `castShadows` and `receiveShadows`, which [Shadows](../concepts/shadows.md) explains. It takes `occluder` too, which [Culling](../concepts/culling.md) explains. `createInstances` takes `colors: true` and `values: true` for a color and four values per row: [Instances and batching](../concepts/instances.md). Meshes come from `geometry` and materials from `materials` in the sketch context. One mesh and one material can serve any number of objects.
71
+ Meshes come from `geometry` and materials from `materials` in the sketch context. One mesh and one material can serve any number of objects.
64
72
 
65
73
  ## Models and copies
66
74
 
67
- `scene.instantiate(prefab, options)` creates the objects of a model that [`assets.loadGltf`](assets.md#gltf-models) loaded. It returns a `PrefabInstance`: a group that holds the copy of the file's nodes. The `options` place that group as they place any object. Every copy shares the model's meshes, materials and textures, so a second copy costs only its objects. `castShadows` and `receiveShadows` apply to every mesh of the copy, and to every row of the instance batches of nodes with instancing of their own. The engine reserves the places of all the copy's objects with one call, and queues their changes as one batch. So no frame shows part of a copy.
75
+ `scene.instantiate(prefab, options)` creates the objects of a model that [`assets.loadGltf`](assets.md#gltf-models) loaded. It returns a `PrefabInstance`: a group that holds the copy of the file's nodes. The `options` place that group as they place any object. Every copy shares the model's meshes, materials and textures, so a second copy costs only its objects.
76
+
77
+ `castShadows` and `receiveShadows` apply to every mesh of the copy, and to every row of the instance batches of nodes with instancing of their own. The engine reserves the places of all the copy's objects with one call, and queues their changes as one batch. So no frame shows part of a copy.
68
78
 
69
79
  ```ts
70
80
  const ship = await assets.loadGltf('/models/ship.glb');
@@ -75,9 +85,11 @@ turret?.rotateY(0.5);
75
85
 
76
86
  `instance.find(name)` gives the copy's object of a node, by the node's name in the file. `scene.find` searches every object. When several copies share a name, it gives the first copy's object.
77
87
 
78
- `scene.clone(object)` copies an object and every object below it, with their meshes, materials, lights, cameras and settings, as three.js's `clone` does. The copy goes under the same parent, so it starts in the same place. It uses the same path as `instantiate`: one call and one batch of changes for the whole tree. Instance batches are not objects, so `clone` leaves them out.
88
+ `scene.clone(object)` copies an object and every object below it, with their meshes, materials, lights, cameras and settings. The copy goes under the same parent, so it starts in the same place. It uses the same path as `instantiate`: one call and one batch of changes for the whole tree. Instance batches are not objects, so `clone` leaves them out.
89
+
90
+ `scene.createInstances(prefab, count, options)` draws many copies of a model with instance batches, one for each mesh of the model. The batches share one set of rows, so each row places a whole copy. Write the returned batch's `positions`, `rotations` and `scales` as for a batch of one mesh.
79
91
 
80
- `scene.createInstances(prefab, count, options)` draws many copies of a model with instance batches, one for each mesh of the model. The batches share one set of rows, so each row places a whole copy. Write the returned batch's `positions`, `rotations` and `scales` as for a batch of one mesh. Each mesh keeps its place in the model. The model's lights are left out. A model with no meshes, or with instancing of its own, throws E1417. Give `createInstances` one of its meshes and a material instead, from `prefab.find(name)`.
92
+ Each mesh keeps its place in the model. The model's lights are left out. A model with no meshes, or with instancing of its own, throws [E1417](../errors/E1417.md). Give `createInstances` one of its meshes and a material instead, from `prefab.find(name)`.
81
93
 
82
94
  ```ts
83
95
  const tree = await assets.loadGltf('/models/tree.glb');
@@ -100,11 +112,13 @@ door?.setVisible(false);
100
112
 
101
113
  `find` returns the general `Object3D` type. When you know which kind of object has the name, cast the result to its class, such as `Mesh`, to use its own calls. Look objects up at setup and keep them, rather than calling `find` in every frame.
102
114
 
115
+ `scene.listObjects()` returns every object of the scene that is not destroyed, in the order of their slots, as a new array. It walks the whole scene and allocates, so call it from tools and setup code, never in every frame.
116
+
103
117
  ## The camera and the background
104
118
 
105
119
  The canvas shows the scene from the active camera, which `setActiveCamera` picks. It can be either kind of camera, and [Cameras](cameras.md) covers both lenses. Until you pick a camera, the canvas shows only the background. `setBackground` takes a color. The default background is black, or the page behind a transparent canvas. Exposure and tone mapping change the background as they change the objects: [Color management](../concepts/color-management.md#the-background).
106
120
 
107
- `setBackground` also takes a [texture](textures.md). The texture fills the camera's view behind every object, as a texture in three.js's `scene.background` does. It stretches to the shape of the view. A texture that loads with the default `flipY` stands upright. The engine samples it with the texture's own filter and ignores its alpha. The texture draws behind every object, in the pixels that no object covers.
121
+ `setBackground` also takes a [texture](textures.md). The texture fills the camera's view behind every object. It stretches to the shape of the view. A texture that loads with the default `flipY` stands upright. The engine samples it with the texture's own filter and ignores its alpha. The texture draws behind every object, in the pixels that no object covers.
108
122
 
109
123
  ```ts
110
124
  import { defineSketch } from '@null3d/engine';
@@ -120,11 +134,11 @@ The color set before a texture shows until the texture's texels are on the GPU,
120
134
 
121
135
  ### Environments, cube maps and the sky
122
136
 
123
- `setBackground` also takes four backgrounds that surround the scene, as three.js's `scene.background` does with a cube texture and its `Sky` object:
137
+ `setBackground` also takes four backgrounds that surround the scene:
124
138
 
125
- - An environment from [`assets.loadEnvironment` or `assets.builtinEnvironment`](assets.md#environments). It can blur, as three.js's `backgroundBlurriness` blurs a PMREM texture.
139
+ - An environment from [`assets.loadEnvironment` or `assets.builtinEnvironment`](assets.md#environments). It can blur.
126
140
  - A cube map of six images from [`assets.loadCubemap`](assets.md#cube-maps), a sky box.
127
- - three.js's analytic sky: `{ sky: { sunPosition } }`, with the settings of three.js's `Sky` object.
141
+ - The analytic sky: `{ sky: { sunPosition } }`, the Preetham daylight model with a sun disc and drifting clouds.
128
142
  - The physical sky: `{ atmosphere: { sunPosition } }`, the earth's air lit by the sun and the moon. The same air hazes distant objects ([The physical sky](#the-physical-sky)).
129
143
 
130
144
  ```ts
@@ -141,17 +155,17 @@ export default defineSketch(async ({ scene, assets }) => {
141
155
 
142
156
  | Option | Takes | Default | What it sets |
143
157
  | --- | --- | --- | --- |
144
- | `intensity` | Every background but a color | 1 | The factor of the background's light, 0 or more, as three.js's `scene.backgroundIntensity` |
145
- | `blur` | Environments | 0 | How much the background blurs, from 0 (sharp) to 1, as `scene.backgroundBlurriness` |
146
- | `rotation` | Environments and cube maps | `[0, 0, 0]` | The background's turn, as Euler angles in radians in the order X, Y, Z, as `scene.backgroundRotation` |
158
+ | `intensity` | Every background but a color | 1 | The factor of the background's light, 0 or more |
159
+ | `blur` | Environments | 0 | How much the background blurs, from 0 (sharp) to 1 |
160
+ | `rotation` | Environments and cube maps | `[0, 0, 0]` | The background's turn, as Euler angles in radians in the order X, Y, Z |
147
161
 
148
- An environment's map holds its light blurred for each roughness. So the background reads the level of the blur's roughness, as three.js reads its PMREM texture. A blurred background costs no more than a sharp one. The background and `setEnvironment` are separate: a scene can show one environment and take its light from another. A cube map shows its six images as three.js's `CubeTextureLoader` shows them, and does not light the scene.
162
+ An environment's map holds its light blurred for each roughness. So the background reads the level of the blur's roughness. A blurred background costs no more than a sharp one. The background and `setEnvironment` are separate: a scene can show one environment and take its light from another. A cube map shows its six images without blur, and it does not light the scene.
149
163
 
150
- The sky takes the names and the defaults of three.js's `Sky` uniforms:
164
+ The analytic sky takes these settings:
151
165
 
152
166
  | Setting | Default | What it sets |
153
167
  | --- | --- | --- |
154
- | `sunPosition` | `[0, 0.0349, -0.9994]` | A point toward the sun, as `sunPosition`. The default puts the sun 2 degrees over the horizon, as three.js's sky example does |
168
+ | `sunPosition` | `[0, 0.0349, -0.9994]` | A point toward the sun. Its direction places the sun. The default puts the sun 2 degrees over the horizon, toward -Z |
155
169
  | `turbidity` | 2 | The haze in the air |
156
170
  | `rayleigh` | 1 | The scattering by the air's molecules, which makes the sky blue |
157
171
  | `mieCoefficient` | 0.005 | The scattering by haze |
@@ -164,9 +178,13 @@ The sky takes the names and the defaults of three.js's `Sky` uniforms:
164
178
  | `time` | 0 | The time in seconds that moves the clouds, such as the sketch's time |
165
179
  | `showSunDisc` | true | Whether the sky shows the sun's disc |
166
180
 
167
- The quality preset's [`cloudSteps`](../concepts/quality-preset-tables.md#settings-of-each-preset) chooses which layer draws: Low and Medium draw the flat layer, and High and Ultra draw volumetric clouds, ray marched through a noise volume. Both read the same settings above, so a setting keeps its meaning when the preset changes. WebGL2 and compatibility mode stop at Medium, so a page there draws the tier with `quality.set({ cloudSteps })` or the `cloudSteps` option of `createEngine`. The tier's noise and shaders load at its first use, and a page on the flat presets downloads neither. The sky's environment map takes the clouds too, with two limits. A map marches at most 16 steps. It draws them only when the page starts with `cloudSteps` above 0, because the map picks the tier's shaders at the page's start.
181
+ The quality preset's [`cloudSteps`](../concepts/quality-preset-tables.md#settings-of-each-preset) chooses which layer draws: Low and Medium draw the flat layer, and High and Ultra draw volumetric clouds, ray marched through a noise volume. Both read the same settings above, so a setting keeps its meaning when the preset changes. A `cloudSteps` of 0 draws the flat layer.
168
182
 
169
- Two more settings are null3D's own. They add a second sky, which `timeOfDay` uses to fade the moon's sky in as night falls:
183
+ WebGL2 and compatibility mode stop at Medium, so they draw the flat layer unless the page sets `cloudSteps` above 0, with `quality.set({ cloudSteps: 32 })` or the `cloudSteps` option of `createEngine`. The tier's noise and shaders load at its first use, and a page on the flat presets downloads neither.
184
+
185
+ The sky's environment map takes the clouds too, with two limits. A map marches at most 16 steps. It draws them only when the page starts with `cloudSteps` above 0, because the map picks the tier's shaders at the page's start. To show clouds in reflections on WebGL2, give the `cloudSteps` option of `createEngine`.
186
+
187
+ Two more settings add a second sky, which `timeOfDay` uses to fade the moon's sky in as night falls:
170
188
 
171
189
  | Setting | Default | What it sets |
172
190
  | --- | --- | --- |
@@ -229,23 +247,35 @@ export default defineSketch(async ({ scene, assets }) => {
229
247
  | `moonIntensity` | 0 | The moon's light above the air. It lights the air as the sun does, and the sky shows its disc, lit from the sun's side. 0 draws no moon |
230
248
  | `stars` | 0 | The stars' brightness. They show only where the sky is dark enough. 0 draws no stars |
231
249
 
232
- The sky's light is in the units of a directional light's intensity, so the exposure that suits the scene's lights suits the sky. It does not move a light: set the main light's direction and color with it, or take them from [`timeOfDay`](#time-of-day). The quality setting [`physicalSky`](../concepts/quality-presets.md) is off on Low. There three.js's analytic sky stands in, with the same sun, moon, air and clouds, matched to the physical sky's brightness, and the haze on objects stays. The first physical sky downloads its shaders, `'physical_sky'`, and the view shows the background color until its tables are drawn.
250
+ The sky's light is in the units of a directional light's intensity, so the exposure that suits the scene's lights suits the sky. It does not move a light: set the main light's direction and color with it, or take them from [`timeOfDay`](#time-of-day).
251
+
252
+ The quality setting [`physicalSky`](../concepts/quality-presets.md) is off on Low. There the analytic sky stands in, with the same sun, moon, air and clouds, matched to the physical sky's brightness. The haze on objects stays. The first physical sky downloads its shaders, `'physical_sky'`, and the view shows the background color until its tables are drawn.
233
253
 
234
254
  The sky lights nothing by itself. [`assets.skyEnvironment()`](assets.md#environments) makes an environment of it, which follows the sky's settings as they change: [Lighting and environment](../concepts/lighting.md#sky-and-backgrounds) shows how.
235
255
 
236
- The first background of each kind downloads its shaders, `'background'`, `'sky'` or `'physical_sky'`, and the view shows the background color until they are built. [Loading screens](../guides/loading-screens.md#loading-everything-up-front) shows how to load them before the first frame. Each call sets every option and every setting, and one left out takes its default. The settings are values, not shader builds, and the call allocates nothing. So a sketch can move the sun or turn a cube map in every frame. `bun run bench:allocation --sky` and `--atmosphere` check it. Each background draws behind every object, in the pixels that no object covers, and exposure and tone mapping change it with the rest of the scene. An orthographic camera's view rays are parallel, so an environment, a cube map or the sky fills its view with one color. The color set before an environment or a cube map shows until its texels are on the GPU, and again after you destroy it.
256
+ The first background of each kind downloads its shaders, `'background'`, `'sky'` or `'physical_sky'`, and the view shows the background color until they are built. [Loading screens](../guides/loading-screens.md#loading-everything-up-front) shows how to load them before the first frame.
257
+
258
+ Each call sets every option and every setting, and one left out takes its default. The settings are values, not shader builds, and the call allocates nothing. So a sketch can move the sun or turn a cube map in every frame. The engine's allocation benchmark checks it.
259
+
260
+ Each background draws behind every object, in the pixels that no object covers, and exposure and tone mapping change it with the rest of the scene. An orthographic camera's view rays are parallel, so an environment, a cube map or the sky fills its view with one color. The color set before an environment or a cube map shows until its texels are on the GPU, and again after you destroy it.
237
261
 
238
- Development builds throw E1203 for a number that is not finite, and E1108 for a number out of its range. They throw E1213 for `blur` on a background that is not an environment, and for `rotation` on a texture or the sky. Every build throws E1101 for a background that was destroyed. [Lighting and environment](../concepts/lighting.md#sky-and-backgrounds) says how each background draws, and what it costs.
262
+ A value out of its range, `blur` on a background that is not an environment, `rotation` on a texture or the sky, or a background that was destroyed throws one of the codes in [Errors](#errors). [Lighting and environment](../concepts/lighting.md#sky-and-backgrounds) says how each background draws, and what it costs.
239
263
 
240
264
  ### Sky layers
241
265
 
242
- `scene.setSkyLayer(description, { wgsl })` draws an add-on's own layer over the sky: the top of the sky, a second layer of clouds, an aurora or a space backdrop. The description is a [feature description](features.md): it names the feature and records at the `'background'` point, as a `'draw'`, provides `'sky'`, and draws in the `'main'`, `'scenePass'` and `'reflection'` views. The layer's WGSL declares `fn skyLayer(input: SkyLayerInput) -> SkyLayer` and the null3D Vite plugin builds it into the engine's sky-layer template, which owns the box around the camera, the bindings, the depth state and the blend. The layer draws right after the background, in the pixels that no object covers, on WebGPU, WebGL2 and in compatibility mode.
266
+ `scene.setSkyLayer(description, { wgsl })` draws an add-on's own layer over the sky: the top of the sky, a second layer of clouds, an aurora or a space backdrop. The description is a [feature description](features.md): it names the feature and records at the `'background'` point, as a `'draw'`, provides `'sky'`, and draws in the `'main'`, `'scenePass'` and `'reflection'` views.
267
+
268
+ ![Green aurora curtains over dark pines, mirrored in a frozen lake.](../images/api/scene/aurora-sky-layer.webp)
269
+
270
+ A sky layer from the aurora add-on.
271
+
272
+ The layer's WGSL declares `fn skyLayer(input: SkyLayerInput) -> SkyLayer` and the null3D Vite plugin builds it into the engine's sky-layer template, which owns the box around the camera, the bindings, the depth state and the blend. The layer draws right after the background, in the pixels that no object covers, on WebGPU, WebGL2 and in compatibility mode.
243
273
 
244
274
  ```ts
245
275
  import { defineFeature, defineSketch } from '@null3d/engine';
246
276
  import curtain from './curtain.wgsl';
247
277
 
248
- export default defineSketch(({ scene }) => {
278
+ export default defineSketch(({ scene, time }) => {
249
279
  scene.setBackground({ sky: { cloudCoverage: 0.1 } });
250
280
  const description = defineFeature({
251
281
  name: 'curtain',
@@ -256,7 +286,7 @@ export default defineSketch(({ scene }) => {
256
286
  });
257
287
  const layer = scene.setSkyLayer(description, { wgsl: curtain, sun: 0.2 });
258
288
  return {
259
- onUpdate(time) {
289
+ onUpdate() {
260
290
  layer.set({ opacity: 0.8 + 0.2 * Math.sin(time.now) });
261
291
  },
262
292
  };
@@ -283,9 +313,15 @@ The layer's function reads one input and returns one value:
283
313
 
284
314
  A layer declares no uniforms, textures or bindings of its own: the engine binds the frame and the layer's values, and the add-on's numbers are constants in its WGSL. It draws in the camera's view, in scene passes and in reflections, and it draws nothing where the background draws nothing, as in a debug view. A second call replaces the layer, `set` changes its values, and `scene.clearSkyLayer()` removes it and gives the core sky its full sun back.
285
315
 
286
- The layer reaches the sky's environment map as well as the background, so every place that a sky is seen shows it: a lake or a window reflects the layer, and the diffuse light that the sky gives the scene carries its color, so it lights the ground under it. The engine builds the layer's WGSL a second time into the shader that fills the map's cube faces, and finds the map's light in the map itself: a small pass sums a level of the map onto the nine coefficients of its diffuse light, and the engine reads them back once for each fill, never in a frame and with nothing waiting: the read is asynchronous, and a fill that cannot start while another runs starts on a later frame. None of this is the add-on's work, and the light matches the reflections because it comes from them.
316
+ The layer reaches the sky's environment map as well as the background, so every place that a sky is seen shows it. A lake or a window reflects the layer, and the diffuse light that the sky gives the scene carries its color. So the layer lights the ground under it.
317
+
318
+ The engine builds the layer's WGSL a second time into the shader that fills the map's cube faces. A small pass sums a level of the map onto the nine coefficients of its diffuse light. The engine reads them back once for each fill. The read is asynchronous and runs in no frame, so nothing waits. A fill that cannot start while another runs starts on a later frame.
319
+
320
+ None of this is the add-on's work, and the light matches the reflections because it comes from them.
287
321
 
288
- A fill spreads over some twenty frames, one stage a frame, so a layer that its clock moves tells the map how often to capture it with `refresh`, in seconds. A shorter time follows a faster layer, at a rate of one fill each `refresh` seconds: at the default of a second that is 15 stage draws a second, and a page that asks for less waits for none of it. A layer of 0 stands still and costs one fill per change. Until the first capture of a new layer lands, the scene keeps the core sky's own light, and a frame or two passes before the map's light follows its texels. The aurora example add-on in `examples/addons/aurora/` draws one, over a frozen lake that reflects it.
322
+ A fill spreads over some twenty frames, one stage a frame. A layer that its clock moves sets `refresh`, in seconds, to tell the map how often to capture it again. The map starts one fill each `refresh` seconds, so a shorter time follows a faster layer. At the default of one second, that is about 20 stage draws a second. A layer with `refresh: 0` stands still and costs one fill for each change.
323
+
324
+ Until the first capture of a new layer lands, the scene keeps the core sky's own light, and a frame or two passes before the map's light follows its texels. The aurora example add-on in `examples/addons/aurora/` draws one, over a frozen lake that reflects it.
289
325
 
290
326
  ## Multiple views
291
327
 
@@ -306,17 +342,23 @@ export default defineSketch(({ scene }) => {
306
342
 
307
343
  The view's camera gives its layer mask, as the active camera's does, and the view follows the camera's layers when they change. The rectangle's shape sets the camera's aspect ratio, so objects keep their proportions in a half-width view. `setCamera` changes the view's camera, `setRect` changes its rectangle, and `destroy` removes the view.
308
344
 
309
- Each view culls the scene on its own, and draws it at its rectangle's pixels with its own depth. The sun's and the spot lights' shadows, the environment's light and the fog cost nothing more than the camera's view. On every GPU path and in every thread mode the view draws in the same frame as the camera's view, and the final image takes the tone mapping, the effects and bloom once. On the 8-bit path the view writes display color into the camera's image, and the resolve pass or the final pass draws it to the canvas.
345
+ Each view culls the scene on its own, and draws it at its rectangle's pixels with its own depth. The sun's and the spot lights' shadows, the environment's light and the fog cost nothing more than the camera's view.
346
+
347
+ On every GPU path and in every thread mode the view draws in the same frame as the camera's view. The final image takes the tone mapping, the effects and bloom once. On the 8-bit path the view writes display color into the camera's image. The resolve pass or the final pass draws it to the canvas.
310
348
 
311
- A view costs one more cull and one more scene draw. The camera's view still draws the whole canvas first, with the canvas's aspect ratio, so a split screen of two half-width views draws the scene three times: once across the canvas underneath and once for each half. A picture in picture draws it twice. The rectangle follows the render scale, as the camera's view does, so a lower scale lowers a view's cost too. A small rectangle costs little on a phone. Bloom's threshold and the tone curve see the whole image once.
349
+ A view costs one more cull and one more scene draw. The camera's view still draws the whole canvas first, with the canvas's aspect ratio, so a split screen of two half-width views draws the scene three times: once across the canvas underneath and once for each half. A picture in picture draws it twice. The rectangle follows the render scale, as the camera's view does, so a lower scale lowers a view's cost too.
312
350
 
313
- A view's objects take no ambient occlusion or screen-space reflections, which shade the camera's view. The camera's volumetric fog and outline are added to the whole image after the views draw, so they also reach a view's rectangle. An object whose material shows a render pass's texture does not draw in a view, as it does not draw in another pass. `screenToRay` and `worldToScreen` map the whole canvas, so they do not follow a view's rectangle. A scene and its passes share 32 views, the camera's included; `scene.createView` throws E1501 when none is free. Development builds throw E1213 for a camera or a rectangle that a view does not take, and E1203 for a number that is not finite.
351
+ A small rectangle costs little on a phone. Bloom's threshold and the tone curve see the whole image once.
352
+
353
+ A view's objects take no ambient occlusion or screen-space reflections, which shade the camera's view. The camera's volumetric fog and outline are added to the whole image after the views draw, so they also reach a view's rectangle. An object whose material shows a render pass's texture does not draw in a view, as it does not draw in another pass.
354
+
355
+ `camera.screenToRay` and `camera.worldToScreen` map the whole canvas. `view.screenToRay` and `view.worldToScreen` map the view's image, and `scene.viewAt(x, y)` finds the view under a point ([Multiple views](../guides/multiple-views.md#picking-in-a-view)). A scene and its passes share 32 views, the camera's included; `scene.createView` throws [E1501](../errors/E1501.md) when none is free.
314
356
 
315
357
  [Multiple views](../guides/multiple-views.md) covers split screens, picture in picture and their cost.
316
358
 
317
359
  ## The environment
318
360
 
319
- `setEnvironment` lights the scene with an environment map from [`assets.loadEnvironment`, `assets.builtinEnvironment` or `assets.skyEnvironment`](assets.md#environments), as three.js's `scene.environment` does with a texture from `PMREMGenerator`. Standard materials reflect it, sharply when smooth and blurred when rough, and take its diffuse light. `setEnvironment(null)` removes it. The background stays as `setBackground` set it.
361
+ `setEnvironment` lights the scene with an environment map from [`assets.loadEnvironment`, `assets.builtinEnvironment` or `assets.skyEnvironment`](assets.md#environments). Standard materials reflect it, sharply when smooth and blurred when rough, and take its diffuse light. `setEnvironment(null)` removes it. The background stays as `setBackground` set it.
320
362
 
321
363
  ```ts
322
364
  const sunset = await assets.loadEnvironment('/env/sunset.ktx2');
@@ -325,16 +367,22 @@ scene.setEnvironment(sunset, { intensity: 0.8, rotation: [0, Math.PI / 2, 0] });
325
367
 
326
368
  | Option | Default | What it sets |
327
369
  | --- | --- | --- |
328
- | `intensity` | 1 | The factor of the environment's light, 0 or more, as three.js's `scene.environmentIntensity` |
329
- | `rotation` | `[0, 0, 0]` | The environment's turn, as Euler angles in radians in the order X, Y, Z, as `scene.environmentRotation` |
370
+ | `intensity` | 1 | The factor of the environment's light, 0 or more |
371
+ | `rotation` | `[0, 0, 0]` | The environment's turn, as Euler angles in radians in the order X, Y, Z |
372
+
373
+ Each call sets both options, and an option left out takes its default. The call allocates nothing, so a sketch can turn the environment in every frame. The engine's allocation benchmark checks it. A material's `envIntensity` scales the light on that material.
330
374
 
331
- Each call sets both options, and an option left out takes its default. The call allocates nothing, so a sketch can turn the environment in every frame. `bun run bench:allocation --environment` checks it. A material's `envIntensity` scales the light on that material. The scene draws without a file's environment until its map is on the GPU. The built-in room's map and the sky's map are whole in the first frame that uses them. The sky's map follows the sky background: after a change that shows, the scene takes the new light up to 19 frames later, and a smaller change waits for its next step. The scene draws without the environment again after `environment.destroy()`. Development builds throw E1203 for a number that is not finite and E1108 for a negative intensity. They throw E1213 for a value that is not an environment. Every build throws E1101 for an environment that was destroyed. [Lighting and environment](../concepts/lighting.md#environment-maps) says how the environment lights a surface, and what it costs.
375
+ The scene draws without a file's environment until its map is on the GPU. The built-in room's map and the sky's map are whole in the first frame that uses them. The sky's map follows the sky background: after a change that shows, the scene takes the new light up to 19 frames later, and a smaller change waits for its next step. The scene draws without the environment again after `environment.destroy()`.
376
+
377
+ Development builds throw E1203, E1108 and E1213 for values that they refuse, and every build throws E1101 for an environment that was destroyed ([Errors](#errors)). [Lighting and environment](../concepts/lighting.md#environment-maps) says how the environment lights a surface, and what it costs.
332
378
 
333
379
  ## The light probe grid
334
380
 
335
381
  `setLightProbeGrid` lights the scene with a grid of irradiance probes, so light that changes with a surface's place, bounced from colored walls or sky, reaches it. Each probe holds L1 spherical harmonics of the light that its surroundings bounce back. Standard materials read the grid per pixel, with four filtered reads each. Its light takes the place of the environment's diffuse light, and the environment keeps its reflections.
336
382
 
337
- A grid baked elsewhere passes in through `LightProbeGridData`, which packs its coefficients and its two masks into the texture. Each probe holds four RGB coefficients, 12 numbers: L0, then L1 along y, z and x. It also holds a validity and a sky visibility. The validity is 1 where the probe stands in open space and 0 where geometry encloses it, which stops its light leaking through the wall around it. The sky visibility is the share of the sky that its rays reached. A grid that a tool outside the engine baked can also come from a file: [`assets.loadLightProbeGrid`](assets.md#baked-light) reads the [baked light file](../guides/baked-light-data.md) format and gives the options below, with the texture already made. `assets.lightProbeGridFile` writes that format from a grid that `bakeProbes` made.
383
+ A grid baked elsewhere passes in through `LightProbeGridData`, which packs its coefficients and its two masks into the texture. Each probe holds four RGB coefficients, 12 numbers: L0, then L1 along y, z and x. It also holds a validity and a sky visibility. The validity is 1 where the probe stands in open space and 0 where geometry encloses it, which stops its light leaking through the wall around it. The sky visibility is the share of the sky that its rays reached.
384
+
385
+ A grid that a tool outside the engine baked can also come from a file: [`assets.loadLightProbeGrid`](assets.md#baked-light) reads the [baked light file](../guides/baked-light-data.md) format and gives the options below, with the texture already made. `assets.lightProbeGridFile` writes that format from a grid that `bakeProbes` made.
338
386
 
339
387
  ```ts
340
388
  const grid = new LightProbeGridData(
@@ -362,9 +410,21 @@ scene.setLightProbeGrid({
362
410
  | `intensity` | 1 | The factor of the grid's light, 0 or more. A factor of 0 gives none of it |
363
411
  | `environmentWeight` | 1 | The share of the environment's diffuse light that the grid takes over, 0 to 1 |
364
412
 
365
- `bakeProbes` bakes a grid in the browser. It casts directions from each probe with `scene.raycastBatch`, testing both faces of every triangle. A ray that reaches the sky counts toward the probe's sky visibility, which the live environment's light multiplies at draw time, weighted by how much the surface faces the sky above the horizon, so a change of the hour needs no new bake. A ray that meets a surface's back means geometry encloses the probe: the probe takes no validity, and the bake fills it from the probes around it. Where a ray hits a surface's front, `albedo` gives the surface's color for one colored bounce: the surface sends back that share of the environment's light at its normal, as a matte surface does. The bake counts no lamps, so the grid holds one colored bounce, its occlusion of the sky and which probes are enclosed. Bake a few probes a frame so a loading screen can show progress.
413
+ `bakeProbes` bakes a grid in the browser. It casts directions from each probe with `scene.raycastBatch`, testing both faces of every triangle. A ray that reaches the sky counts toward the probe's sky visibility, which the live environment's light multiplies at draw time, weighted by how much the surface faces the sky above the horizon, so a change of the hour needs no new bake.
366
414
 
367
- `spacing` sets the distance between probes along each axis, in meters, or one number for every axis. The default is 2. The grid starts at the box's least corner and takes as many probes as fit the box, at least two along each axis.
415
+ A ray that meets a surface's back means geometry encloses the probe: the probe takes no validity, and the bake fills it from the probes around it. Where a ray hits a surface's front, `albedo` gives the surface's color for one colored bounce: the surface sends back that share of the environment's light at its normal, as a matte surface does. The bake counts no lamps, so the grid holds one colored bounce, its occlusion of the sky and which probes are enclosed.
416
+
417
+ | Option | Default | What it sets |
418
+ | --- | --- | --- |
419
+ | `box` | required | The box the probes cover, in the world, as `min` and `max` corners |
420
+ | `spacing` | 2 | The distance between probes along each axis, in meters, or one number for every axis. The grid starts at the box's least corner and takes as many probes as fit, at least two along each axis |
421
+ | `samples` | 64 | The directions cast from each probe, 8 to 1024 |
422
+ | `distance` | the box's diagonal | How far a ray reaches before it counts as the sky, in meters |
423
+ | `environment` | none | The environment whose light a hit surface sends back. Without one, the bake counts no bounce light |
424
+ | `environmentOptions` | those of `scene.setEnvironment` | The intensity and rotation that `scene.setEnvironment` got, so the bounce matches the scene |
425
+ | `albedo` | none | A function that gives a hit surface's color. Without it, the bake holds sky visibility and validity alone |
426
+
427
+ `bake.step(n)` bakes up to n probes, 4 by default, and returns true once every probe is baked. `bake.done` counts the probes baked so far. `bake.grid` holds the result. `bake.finish()` bakes the rest at once and returns the grid. Bake a few probes a frame so a loading screen can show progress.
368
428
 
369
429
  ```ts
370
430
  import { bakeProbes, defineSketch } from '@null3d/engine';
@@ -374,13 +434,13 @@ export default defineSketch(async ({ scene, assets, textures }) => {
374
434
  const environmentOptions = { intensity: 0.8 };
375
435
  scene.setEnvironment(environment, environmentOptions);
376
436
  // ... build the room here ...
377
- const grey = [0.8, 0.8, 0.8] as const; // every surface a light grey
437
+ const gray = [0.8, 0.8, 0.8] as const; // every surface a light gray
378
438
  const bake = bakeProbes(scene, {
379
439
  box: { min: [-12, 0, -12], max: [12, 8, 12] },
380
440
  spacing: [1, 2, 1],
381
441
  environment,
382
442
  environmentOptions,
383
- albedo: () => grey,
443
+ albedo: () => gray,
384
444
  });
385
445
  let baking = true;
386
446
  return {
@@ -399,7 +459,7 @@ export default defineSketch(async ({ scene, assets, textures }) => {
399
459
  });
400
460
  ```
401
461
 
402
- Development builds throw E1203 for a number that is not finite, E1108 for a value out of range, and E1213 for something that is not a texture. Every build throws E1101 for a texture that was destroyed, and E1222 for a texture that is not a 3D texture: make the grid's texture with `LightProbeGridData.toTexture()`. The grid takes 32 bytes of GPU memory per probe, plus a padding slice at either end of each sub-volume, and each lit pixel reads it four times. [Lighting and environment](../concepts/lighting.md#light-probe-grid) gives the grid's limits, what takes its light, and how its shaders load.
462
+ A texture that is not a 3D texture throws [E1222](../errors/E1222.md): make the grid's texture with `LightProbeGridData.toTexture()`. The grid takes 32 bytes of GPU memory per probe, plus a padding slice at either end of each sub-volume, and each lit pixel reads it four times. [Lighting and environment](../concepts/lighting.md#light-probe-grid) gives the grid's limits, what takes its light, and how its shaders load.
403
463
 
404
464
  ## Reflection probes
405
465
 
@@ -437,19 +497,21 @@ export default defineSketch(async ({ scene, assets, input }) => {
437
497
  | `layers` | The default layer | The layers of the objects that the captures draw |
438
498
  | `priority` | 0 | Where boxes overlap, the higher priority wins, then the smaller box |
439
499
 
440
- `probe.set(options)` sets every option again. A new position or new layers capture again. `probe.capture()` captures again in a frame soon after the call, as after an object around the probe moved. The surfaces in its box read the new map from that frame. Without a call, a probe that refreshes once keeps its last map. `probe.destroy()` removes the probe. Its box takes the light of other probes or of the environment from the next frame.
500
+ `probe.set(options)` sets every option again. A new position or new layers capture again. `probe.capture()` captures again in a frame soon after the call, as after an object around the probe moved. The surfaces in its box read the new map from that frame. Without a call, a probe that refreshes once keeps its last map.
501
+
502
+ `probe.destroy()` removes the probe. Its box takes the light of other probes or of the environment from the next frame.
441
503
 
442
- A scene has at most 16 probes, and their captures take 6 of the 32 views that the scene and its [passes](render.md) share. Each throws E1430 past its limit. Development builds throw E1213 for an option that probes do not take, E1203 for a number that is not finite, and E1108 for a negative blend or intensity, or a box whose `min` does not lie below its `max`. They also throw E1101 for a call on a probe that was destroyed.
504
+ A scene has at most 16 probes, and their captures take 6 of the 32 views that the scene and its [passes](render.md) share. Each throws [E1430](../errors/E1430.md) past its limit. An option that probes do not take, or a call on a probe that was destroyed, throws one of the codes in [Errors](#errors).
443
505
 
444
506
  ## Fog
445
507
 
446
508
  `setFog` covers every object in fog that thickens with its distance from the camera. The distance is the straight line from the camera to the point, so an object keeps its fog as the camera turns. A curve sets how the fog thickens:
447
509
 
448
510
  - `'exponential'`, the default: an even haze. An object at distance d takes the fog color by a factor of 1 - exp(-density × d).
449
- - `'exp2'`: thicker with the square of the distance, 1 - exp(-(density × d)²), as three.js's `FogExp2`.
450
- - `'linear'`: clear up to `near`, and hides objects from `far`, with a smooth change between them, as three.js's `Fog`.
511
+ - `'exp2'`: thicker with the square of the distance, 1 - exp(-(density × d)²).
512
+ - `'linear'`: clear up to `near`, and hides objects from `far`, with a smooth change between them.
451
513
 
452
- The fog can also thin with height, as mist lies in a valley, and glow toward the main directional light. `setFog(null)` removes the fog. The call allocates nothing, so a sketch can change the fog in every frame; `bun run bench:allocation --fog` checks it, the volumetric fog included.
514
+ The fog can also thin with height, as mist lies in a valley, and glow toward the main directional light. `setFog(null)` removes the fog. The call allocates nothing, so a sketch can change the fog in every frame. The engine's allocation benchmark checks it, the volumetric fog included.
453
515
 
454
516
  ```ts
455
517
  scene.setBackground('#b8c4d0');
@@ -471,10 +533,15 @@ scene.setFog({ color: '#b8c4d0', density: 0.04, sunGlow: 1.5 });
471
533
  | `heightFalloff` | All | 0 | How fast the fog thins with height, 0 or more. The fog's density falls to about a third every 1 / `heightFalloff` units up, and grows below `height`. 0 keeps the fog the same at every height |
472
534
  | `sunGlow` | All | 0 | How much of the main directional light the fog scatters toward the camera, 0 or more. Fog toward that light glows in its color |
473
535
  | `sunGlowExponent` | All | 8 | How tightly the glow gathers around the light's direction, above 0. Higher values make a smaller glow |
536
+ | `background` | All | 0 | How much of the fog the sky and the background take, from 0 to 1. At 1 they take the fog of a surface at the camera's far plane, so the haze over the land continues over the sky it meets; 0 leaves them unfogged |
474
537
 
475
538
  Height fog sums the fog along each line of sight. A view down into the mist then sees thick fog, and a view up sees clear air. The sun glow takes the color and the intensity of the scene's main directional light, so it follows the light as it moves. Shadows do not block the glow.
476
539
 
477
- The fog does not cover the background, so give the background the fog's color to fade far objects into it. Past the edge of an outdoor scene's land, the background shows with no fog at all. [Where the land ends](../concepts/lighting.md#where-the-land-ends) says how to hide that edge. A material created with `fog: false` keeps its color at every distance, as [Materials](materials.md#options-fixed-at-creation) says. The engine mixes the fog into each pixel as it shades the pixel, before the tone mapping, so fog adds almost no work. The fog applies from the next frame. Development builds throw E1108 for an unknown curve, a `far` that is not above `near`, a negative `density`, `heightFalloff` or `sunGlow`, and a `sunGlowExponent` that is not above 0. They throw E1203 for a value that is not a finite number. The `null3d::fog` module of the [shader library](../shaders/library.md#null3dfog) holds the same formulas for WGSL shaders.
540
+ `background` mixes the scene's fog into the sky and the background, as if they stood at the camera's far plane. The haze over the land then runs on over the sky it meets, so a scene needs no haze sheet. It runs from 0 to 1 and defaults to 0.
541
+
542
+ At 0 the background takes no fog, and the background's color or the scene's own sheets must blend the edge; [Where the land ends](../concepts/lighting.md#where-the-land-ends) says how. A material created with `fog: false` keeps its color at every distance, as [Materials](materials.md#options-fixed-at-creation) says.
543
+
544
+ The engine mixes the fog into each pixel as it shades the pixel, before the tone mapping, so fog adds almost no work. The fog applies from the next frame. The `null3d::fog` module of the [shader library](../shaders/library.md#null3dfog) holds the same formulas for WGSL shaders.
478
545
 
479
546
  ### Volumetric fog
480
547
 
@@ -498,13 +565,19 @@ scene.setFog({
498
565
 
499
566
  The lit fog takes the fog's `density` and `heightFalloff`, so it lights the same air that dims the objects. It takes `density` with every curve, the linear one too. While it draws, its own light of the sun replaces `sunGlow`, with the shadows. Past its `distance`, the fog still scatters the sun's light, without shadows, so no edge shows.
500
567
 
501
- The lit fog needs HDR color. In WebGPU's compatibility mode with MSAA, turning it on moves the engine to HDR color with FXAA, as bloom does, once `fogSlices` is above 0. On a device with no HDR target, the fog keeps its sun glow. The quality setting `fogSlices` sets its detail: 32 slices on Medium, 64 on High and 96 on Ultra. On Low it is 0, so phones draw the fog with its sun glow at no cost. Surfaces that blend or let light through, such as water and glass, take the lit fog of the whole line of sight to the opaque surface behind them. [Lighting and environment](../concepts/lighting.md#volumetric-fog) says how it works and what it costs.
568
+ The lit fog needs HDR color. In WebGPU's compatibility mode with MSAA, turning it on moves the engine to HDR color with FXAA, as bloom does, once `fogSlices` is above 0. On a device with no HDR target, the fog keeps its sun glow. The quality setting `fogSlices` sets its detail: 32 slices on Medium, 64 on High and 96 on Ultra. On Low it is 0, so phones draw the fog with its sun glow at no cost.
502
569
 
503
- Development builds throw E1108 for a negative `intensity`, an `anisotropy` outside -0.95 to 0.95, a `distance` that is not above 0, and a `density` inside `volumetric`. They throw E1203 for a value that is not a finite number.
570
+ Surfaces that blend or let light through, such as water and glass, take the lit fog of the whole line of sight to the opaque surface behind them. [Lighting and environment](../concepts/lighting.md#volumetric-fog) says how it works and what it costs.
504
571
 
505
572
  ## Time of day
506
573
 
507
- `timeOfDay(hours)` works out the settings of a time of day. They are the sky, the main light (the sun, or the moon at night), the fog's color and glow, an ambient light, the sky's intensity and the exposure. It takes an hour from 0 to 24, or a preset: `'afternoon'`, `'goldenHour'`, `'blueHour'` or `'night'`. It returns plain values, which the sketch applies to its own objects. Pass its exposure to `post.set({ exposure })`, or set one of your own. At dusk and at night the default exposure shows the scene several times too dark. A second argument takes `heading` and `noonElevation`. `heading` turns the sun's path about the up axis. `noonElevation` is the noon sun's height in radians, π/3 by default. At night the sky is lit from the moon's place, a navy blue, and the sky's sun disc draws the moon. As night falls the sunset's sky fades straight into the moon's sky.
574
+ `timeOfDay(hours)` works out the settings of a time of day. They are the sky, the main light (the sun, or the moon at night), the fog's color and glow, an ambient light, the sky's intensity and the exposure. It takes an hour from 0 to 24, or a preset: `'afternoon'`, `'goldenHour'`, `'blueHour'` or `'night'`.
575
+
576
+ It returns plain values, which the sketch applies to its own objects. Pass its exposure to `post.set({ exposure })`, or set one of your own. At dusk and at night the default exposure shows the scene several times too dark.
577
+
578
+ A second argument takes `heading` and `noonElevation`. `heading` turns the sun's path about the up axis. `noonElevation` is the noon sun's height in radians, π/3 by default.
579
+
580
+ At night the sky is lit from the moon's place, a navy blue, and the sky's sun disc draws the moon. As night falls the sunset's sky fades straight into the moon's sky.
508
581
 
509
582
  ```ts
510
583
  import { defineSketch, timeOfDay } from '@null3d/engine';
@@ -535,13 +608,15 @@ export default defineSketch(async ({ scene, assets, post }) => {
535
608
  });
536
609
  ```
537
610
 
538
- A third argument is an object that the call fills, in place of making one: `timeOfDay(hour, {}, day)` writes the new settings into `day`, so a day cycle that moves the time in every frame makes no settings object and no arrays of its own. The browser still makes an object of each fraction that one step of the sky model hands to another step that it has not inlined, as it does in any code of this size. `bun run bench:allocation --time-of-day` measures both. `emptyTimeOfDay()` makes the first such object. The [atmosphere demo](https://github.com/null3d-engine/null3d/tree/main/examples/atmosphere) passes one and moves the hour with the pointer.
611
+ A third argument is an object that the call fills, in place of making one: `timeOfDay(hour, {}, day)` writes the new settings into `day`, so a day cycle that moves the time in every frame makes no settings object and no arrays of its own. The browser still makes an object of each fraction that one step of the sky model hands to another step that it has not inlined, as it does in any code of this size. The engine's allocation benchmark measures both.
612
+
613
+ `emptyTimeOfDay()` makes the first such object. The [atmosphere demo](https://github.com/null3d-engine/null3d/tree/main/examples/atmosphere) passes one and moves the hour with the pointer.
539
614
 
540
615
  [Lighting and environment](../concepts/lighting.md#time-of-day) explains each value, the presets and the sun's path. A value that is not a finite number, or an unknown preset, throws a `RangeError`. The [time of day demo](https://github.com/null3d-engine/null3d/tree/main/examples/time-of-day) passes a whole day over a lighthouse in 40 seconds, and lights its windows and its lamp at dusk.
541
616
 
542
617
  ## Lights
543
618
 
544
- Each light is an object, so a scene can hold many, and each call creates another. Without lights, standard materials draw black. [Lights](lights.md) covers each kind, and which of them light surfaces in this version.
619
+ Each light is an object, so a scene can hold many, and each call creates another. Without lights, standard materials draw black. [Lights](lights.md) covers each kind, and which of them light surfaces.
545
620
 
546
621
  ## Decals
547
622
 
@@ -549,17 +624,17 @@ A decal is a mesh of `geometry.box()` with a `materials.decal` material, which p
549
624
 
550
625
  ## Drawing every mesh with one material
551
626
 
552
- `scene.overrideMaterial = material` draws every mesh and instance batch of the main pass with that material, in place of each object's own. This matches three.js's `scene.overrideMaterial`. Each object keeps its mesh, its place and its instances. A batch draws all of its rows with the override. Set the property to `null` to draw each object with its own material again.
627
+ `scene.overrideMaterial = material` draws every mesh and instance batch of the main pass with that material, in place of each object's own. Each object keeps its mesh, its place and its instances. A batch draws all of its rows with the override. Set the property to `null` to draw each object with its own material again.
553
628
 
554
- Sprites, points, lines and particle systems keep their own materials. The shadow maps also keep each object's material, as three.js's shadow maps do, so a masked object still cuts its shadow. A sprite, point or line material throws E1224.
629
+ Sprites, points, lines and particle systems keep their own materials. The shadow maps also keep each object's material, so a masked object still cuts its shadow. A sprite, point or line material throws E1224.
555
630
 
556
631
  The change reaches the frame after the call, and that frame rebuilds the engine's draw tables. After that the override adds no draw call and no pipeline beyond the materials it replaces. For the built-in debug views, use `debug.view` instead.
557
632
 
558
633
  ## When changes take effect
559
634
 
560
- Creating an object, `destroy`, `setParent`, `setVisible`, `setLayers` and `setDynamic` change the structure of the scene, and so do the mesh calls: `setMaterial`, `setMesh`, `setCastShadows`, `setReceiveShadows`, `setRenderOrder`, `setFrustumCulled` and `setBounds`. The engine queues these changes and applies them after `onUpdate` returns, before it updates transforms and draws. The frame drawn after the call shows the change. Some of them make the engine rebuild its draw tables, as the [performance guide](../guides/performance.md#objects-during-play) lists.
635
+ Creating an object, `destroy`, `setParent`, `setVisible`, `setLayers` and `setDynamic` change the structure of the scene, and so do the mesh calls: `setMaterial`, `setMesh`, `setCastShadows`, `setReceiveShadows`, `setRenderOrder` and `setFrustumCulled`, and so does `setBounds`. The engine queues these changes and applies them after `onUpdate` returns, before it updates transforms and draws. The frame drawn after the call shows the change. Some of them make the engine rebuild its draw tables, as the [performance guide](../guides/performance.md#objects-during-play) lists.
561
636
 
562
- Values that the engine computes, such as the result of `getWorldPosition`, come from the engine's last transform update. In `onUpdate` they come from the previous frame. In `onLateUpdate` they already hold the frame's changes, because the engine updates transforms before it calls `onLateUpdate`. Setters that `onLateUpdate` calls show in the same frame, and structural changes that it makes wait for the next frame ([Sketch API](sketch.md#when-changes-show)).
637
+ Values that the engine computes, such as the result of `getWorldPosition`, come from the engine's last transform update. In `onUpdate` they come from the previous frame. `onLateUpdate` sees this frame's values; [Sketch API](sketch.md#when-changes-show) gives its timing rules.
563
638
 
564
639
  When the engine cannot apply a change, such as a parent loop (E1104), it skips that change and logs the error to the console. The rest of the queue still applies.
565
640
 
@@ -569,16 +644,36 @@ The GPU draws each kind of object with a pipeline, which takes time to build. Th
569
644
 
570
645
  ## Instance batches
571
646
 
572
- An instance batch is one object that draws many copies of one mesh with one material. Its rows live in typed arrays that sketch code writes directly, with no call per row. A static batch, the default, uploads the rows you mark with `markDirty`. A batch created with `dynamic: true` uploads every row in every frame. Every row of a batch shares the batch's layers, which the `layers` option and `setLayers(mask)` set, as [Render layers](../concepts/render-layers.md) explains. Rows are relative to the batch's `origin`, which keeps rows precise far from the world's origin: [Batch origins](../concepts/large-worlds.md#batch-origins). An add-on whose rows arrive in chunks stores each chunk once with `batch.createChunkRows()`, which packs the chosen rows in the engine's core: [Rows that arrive in chunks](../concepts/instances.md#rows-that-arrive-in-chunks). [Instances and batching](../concepts/instances.md) explains batches in full.
647
+ An instance batch is one object that draws many copies of one mesh with one material. Its rows live in typed arrays that sketch code writes directly, with no call per row. A static batch, the default, uploads the rows you mark with `markDirty`. A batch created with `dynamic: true` uploads every row in every frame.
648
+
649
+ Every row of a batch shares the batch's layers, which the `layers` option and `setLayers(mask)` set, as [Render layers](../concepts/render-layers.md) explains. Rows are relative to the batch's `origin`, which keeps rows precise far from the world's origin: [Batch origins](../concepts/large-worlds.md#batch-origins). An add-on whose rows arrive in chunks stores each chunk once with `batch.createChunkRows()`, which packs the chosen rows in the engine's core: [Rows that arrive in chunks](../concepts/instances.md#rows-that-arrive-in-chunks). [Instances and batching](../concepts/instances.md) explains batches in full.
573
650
 
574
651
  ## Limits
575
652
 
576
653
  - A scene starts with room for 1,023 objects: groups, meshes, cameras and lights together. When it needs more, it grows on its own. It doubles its room at the start of a frame once it is three quarters full. A create call that finds it full doubles it at once. A destroyed object frees its place when the frame applies the change.
577
654
  - Each growth copies the scene's tables, about 267 bytes per object, in one short pause. A scene that knows its size can start with room for every object, with the `expectedObjects` option of [`createEngine`](engine.md#options), and never grows during play.
578
655
  - A scene holds up to 1,048,575 objects, the most that a handle can name. Past that, a create call throws E1102. A growth that the engine's memory cannot hold throws E1109. Each place counts toward the objects and instance rows that the GPU draws (`engine.capabilities.maxInstances`), and a growth past that limit throws E1501.
579
- - The rows of an instance batch take none of those places. One engine holds up to 256 batches, and `createInstances(prefab, ...)` takes one for each mesh of the model.
656
+ - The rows of an instance batch take none of those places. One engine holds up to 512 batches, and `createInstances(prefab, ...)` takes one for each mesh of the model.
580
657
  - The queue holds up to 65,536 changes between two frames. One more throws E1102.
581
- - Each copy of a model with clips or skins takes a place in the animation table, and its joints take places too. The table starts with room for 1,024 animated objects and 65,536 joints. When a copy does not fit, it doubles what it lacks, in one short pause that copies the table. It holds up to 1,048,576 joints in all. That is the most that the joint texture holds on every WebGL2 device: about 24,000 copies of a character of 43 joints. A copy past that throws E1102, and a growth that the engine's memory cannot hold throws E1109. Either way, `instantiate` or `clone` then creates no part of the copy.
658
+ - Each copy of a model with clips or skins takes a place in the animation table, and its joints take places too. The table starts with room for 1,024 animated objects and 65,536 joints. When a copy does not fit, it doubles what it lacks, in one short pause that copies the table. It holds up to 1,048,576 joints in all.
659
+ - That is the most that the joint texture holds on every WebGL2 device: about 24,000 copies of a character of 43 joints. A copy past that throws E1102, and a growth that the engine's memory cannot hold throws E1109. Either way, `instantiate` or `clone` then creates no part of the copy.
660
+
661
+ ## Errors
662
+
663
+ | Code | Cause |
664
+ | --- | --- |
665
+ | [E1101](../errors/E1101.md) | A call on an object, background, environment or probe that was destroyed. |
666
+ | [E1102](../errors/E1102.md) | A scene past its object, change-queue or animation-table limit, or a copy that does not fit. |
667
+ | [E1104](../errors/E1104.md) | A parent loop: `setParent` given the object itself or one of its descendants. A self-parent throws; a queued loop is skipped and logged. |
668
+ | [E1108](../errors/E1108.md) | A number out of its range, such as a negative blend or intensity, or a box whose `min` is not below its `max`. Development builds throw it. |
669
+ | [E1109](../errors/E1109.md) | The engine's memory cannot hold a growth. |
670
+ | [E1203](../errors/E1203.md) | A number that is not finite. Development builds throw it. |
671
+ | [E1213](../errors/E1213.md) | A value that a call does not take, such as a background option on the wrong kind of background, a value that is not an environment, a camera or rectangle that a view does not take, or a probe option that probes do not take. Development builds throw it. |
672
+ | [E1222](../errors/E1222.md) | A light-probe texture that is not a 3D texture. |
673
+ | [E1224](../errors/E1224.md) | The material override set to a sprite, point or line material. |
674
+ | [E1417](../errors/E1417.md) | `createInstances(prefab, ...)` on a model with no meshes or with instancing of its own. |
675
+ | [E1430](../errors/E1430.md) | Past the scene's limit of 16 reflection probes. |
676
+ | [E1501](../errors/E1501.md) | Past the scene's limit of objects and instance rows, or of views. |
582
677
 
583
678
  ## Related pages
584
679
 
@@ -589,6 +684,15 @@ An instance batch is one object that draws many copies of one mesh with one mate
589
684
  - [Loading screens and warm-up](../guides/loading-screens.md): waiting for the scene's pipelines.
590
685
  - [Assets and prefabs](../concepts/assets.md): models from glTF files, and what a prefab shares.
591
686
  - [Lighting and environment](../concepts/lighting.md#environment-maps): how an environment lights the scene.
687
+ - [The physical sky](https://github.com/null3d-engine/null3d/tree/main/examples/atmosphere): a day over a valley of ridges under the physical sky.
688
+ - [Sky layers](https://github.com/null3d-engine/null3d/tree/main/examples/aurora): curtains of green and violet light over a frozen lake.
689
+ - [Multiple views](https://github.com/null3d-engine/null3d/tree/main/examples/multiple-views): one scene drawn from two cameras in the same frame.
690
+ - [Reflection probes](https://github.com/null3d-engine/null3d/tree/main/examples/reflection-probes): two rooms over one polished floor, each with a probe.
691
+ - [Volumetric fog](https://github.com/null3d-engine/null3d/tree/main/examples/light-shafts): sun rays and lantern cones in a pine wood at dusk.
692
+ - [The environment](https://github.com/null3d-engine/null3d/tree/main/examples/environment): spheres lit by an HDR file, an EXR file and the built-in room.
693
+ - [Instance batches](https://github.com/null3d-engine/null3d/tree/main/examples/instances): 100,000 columns in one batch at golden hour.
694
+ - [Decals](https://github.com/null3d-engine/null3d/tree/main/examples/decals): road paint, posters and stains projected onto a street.
695
+ - [The material override](https://github.com/null3d-engine/null3d/tree/main/examples/objects): the Look button draws the whole stage in one material.
592
696
 
593
697
  ## API reference
594
698