@null3d/engine 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. package/dist/wasm/single/null3d.js +10 -8
  2. package/dist/wasm/single/null3d_bg.wasm +0 -0
  3. package/dist/wasm/threaded/null3d.js +10 -8
  4. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  5. package/docs/api/animation.md +96 -24
  6. package/docs/api/assets.md +99 -29
  7. package/docs/api/cameras.md +38 -7
  8. package/docs/api/controls.md +47 -23
  9. package/docs/api/debug.md +105 -35
  10. package/docs/api/engine.md +108 -32
  11. package/docs/api/feature-draws.md +21 -15
  12. package/docs/api/feature-effects.md +8 -8
  13. package/docs/api/feature-instances.md +68 -17
  14. package/docs/api/features.md +68 -37
  15. package/docs/api/geometry.md +83 -14
  16. package/docs/api/grass.md +55 -13
  17. package/docs/api/impostors.md +92 -50
  18. package/docs/api/input.md +22 -9
  19. package/docs/api/lights.md +67 -16
  20. package/docs/api/lines.md +38 -13
  21. package/docs/api/materials.md +187 -59
  22. package/docs/api/math.md +6 -6
  23. package/docs/api/objects.md +40 -15
  24. package/docs/api/page.md +58 -7
  25. package/docs/api/particles.md +36 -11
  26. package/docs/api/points.md +18 -8
  27. package/docs/api/post.md +57 -23
  28. package/docs/api/quality.md +36 -16
  29. package/docs/api/raycast.md +57 -24
  30. package/docs/api/reference/animation.md +1 -2
  31. package/docs/api/reference/assets.md +7 -4
  32. package/docs/api/reference/cameras.md +3 -2
  33. package/docs/api/reference/controls.md +59 -2
  34. package/docs/api/reference/debug.md +58 -6
  35. package/docs/api/reference/engine.md +39 -10
  36. package/docs/api/reference/feature-draws.md +3 -4
  37. package/docs/api/reference/feature-effects.md +2 -3
  38. package/docs/api/reference/feature-instances.md +5 -4
  39. package/docs/api/reference/features.md +7 -4
  40. package/docs/api/reference/geometry.md +132 -21
  41. package/docs/api/reference/grass.md +62 -2
  42. package/docs/api/reference/impostors.md +120 -16
  43. package/docs/api/reference/input.md +1 -2
  44. package/docs/api/reference/lights.md +4 -3
  45. package/docs/api/reference/lines.md +3 -4
  46. package/docs/api/reference/materials.md +7 -6
  47. package/docs/api/reference/math.md +13 -2
  48. package/docs/api/reference/objects.md +2 -3
  49. package/docs/api/reference/particles.md +31 -6
  50. package/docs/api/reference/points.md +2 -3
  51. package/docs/api/reference/post.md +4 -3
  52. package/docs/api/reference/quality.md +1 -2
  53. package/docs/api/reference/raycast.md +1 -2
  54. package/docs/api/reference/render.md +4 -3
  55. package/docs/api/reference/scene.md +24 -5
  56. package/docs/api/reference/sketch.md +11 -11
  57. package/docs/api/reference/sound.md +33 -2
  58. package/docs/api/reference/splats.md +42 -3
  59. package/docs/api/reference/sprites.md +2 -3
  60. package/docs/api/reference/tasks.md +16 -3
  61. package/docs/api/reference/terrain.md +26 -5
  62. package/docs/api/reference/textures.md +1 -2
  63. package/docs/api/reference/three-compat.md +18 -7
  64. package/docs/api/reference/time.md +1 -2
  65. package/docs/api/reference/ui.md +10 -7
  66. package/docs/api/reference/vertex-draws.md +2 -3
  67. package/docs/api/reference/water.md +78 -5
  68. package/docs/api/reference/wind.md +15 -2
  69. package/docs/api/render.md +67 -25
  70. package/docs/api/scene.md +129 -36
  71. package/docs/api/sketch.md +45 -19
  72. package/docs/api/sound.md +48 -12
  73. package/docs/api/splats.md +42 -15
  74. package/docs/api/sprites.md +8 -6
  75. package/docs/api/tasks.md +31 -22
  76. package/docs/api/terrain.md +44 -12
  77. package/docs/api/textures.md +61 -12
  78. package/docs/api/three-compat.md +15 -7
  79. package/docs/api/time.md +3 -5
  80. package/docs/api/ui.md +18 -10
  81. package/docs/api/vertex-draws.md +13 -12
  82. package/docs/api/water.md +111 -67
  83. package/docs/api/wind.md +61 -15
  84. package/docs/cli/null3d.md +90 -15
  85. package/docs/concepts/architecture.md +69 -23
  86. package/docs/concepts/assets.md +57 -16
  87. package/docs/concepts/backends.md +65 -25
  88. package/docs/concepts/color-management.md +42 -13
  89. package/docs/concepts/culling.md +68 -47
  90. package/docs/concepts/handles.md +14 -5
  91. package/docs/concepts/instances.md +72 -23
  92. package/docs/concepts/large-worlds.md +17 -7
  93. package/docs/concepts/lighting.md +117 -44
  94. package/docs/concepts/lod.md +128 -33
  95. package/docs/concepts/materials.md +43 -12
  96. package/docs/concepts/particle-buffer.md +48 -35
  97. package/docs/concepts/post-processing.md +77 -14
  98. package/docs/concepts/quality-preset-tables.md +3 -2
  99. package/docs/concepts/quality-presets.md +122 -39
  100. package/docs/concepts/render-graph.md +56 -21
  101. package/docs/concepts/render-layers.md +9 -5
  102. package/docs/concepts/shadows.md +96 -25
  103. package/docs/concepts/static-dynamic.md +22 -7
  104. package/docs/cookbook/index.md +163 -119
  105. package/docs/data/threejs-mapping.json +301 -340
  106. package/docs/errors/E1101.md +23 -5
  107. package/docs/errors/E1102.md +11 -3
  108. package/docs/errors/E1103.md +11 -3
  109. package/docs/errors/E1104.md +11 -3
  110. package/docs/errors/E1105.md +13 -5
  111. package/docs/errors/E1106.md +11 -3
  112. package/docs/errors/E1107.md +15 -5
  113. package/docs/errors/E1108.md +11 -3
  114. package/docs/errors/E1109.md +32 -6
  115. package/docs/errors/E1110.md +23 -5
  116. package/docs/errors/E1111.md +11 -3
  117. package/docs/errors/E1112.md +11 -3
  118. package/docs/errors/E1203.md +12 -4
  119. package/docs/errors/E1204.md +11 -3
  120. package/docs/errors/E1205.md +11 -3
  121. package/docs/errors/E1206.md +28 -6
  122. package/docs/errors/E1207.md +11 -3
  123. package/docs/errors/E1208.md +12 -3
  124. package/docs/errors/E1209.md +11 -3
  125. package/docs/errors/E1213.md +27 -5
  126. package/docs/errors/E1214.md +11 -3
  127. package/docs/errors/E1215.md +31 -6
  128. package/docs/errors/E1216.md +31 -6
  129. package/docs/errors/E1217.md +29 -6
  130. package/docs/errors/E1218.md +22 -6
  131. package/docs/errors/E1219.md +11 -3
  132. package/docs/errors/E1220.md +24 -5
  133. package/docs/errors/E1221.md +24 -5
  134. package/docs/errors/E1222.md +11 -3
  135. package/docs/errors/E1223.md +39 -6
  136. package/docs/errors/E1224.md +11 -3
  137. package/docs/errors/E1225.md +11 -3
  138. package/docs/errors/E1301.md +11 -3
  139. package/docs/errors/E1302.md +11 -3
  140. package/docs/errors/E1303.md +11 -3
  141. package/docs/errors/E1304.md +11 -3
  142. package/docs/errors/E1305.md +13 -3
  143. package/docs/errors/E1306.md +11 -3
  144. package/docs/errors/E1307.md +23 -6
  145. package/docs/errors/E1401.md +11 -3
  146. package/docs/errors/E1402.md +13 -5
  147. package/docs/errors/E1403.md +11 -3
  148. package/docs/errors/E1404.md +13 -3
  149. package/docs/errors/E1405.md +15 -4
  150. package/docs/errors/E1406.md +31 -5
  151. package/docs/errors/E1407.md +11 -3
  152. package/docs/errors/E1408.md +11 -3
  153. package/docs/errors/E1409.md +11 -3
  154. package/docs/errors/E1410.md +13 -5
  155. package/docs/errors/E1411.md +11 -3
  156. package/docs/errors/E1412.md +29 -6
  157. package/docs/errors/E1413.md +11 -3
  158. package/docs/errors/E1414.md +11 -3
  159. package/docs/errors/E1415.md +11 -3
  160. package/docs/errors/E1416.md +27 -6
  161. package/docs/errors/E1417.md +11 -3
  162. package/docs/errors/E1418.md +12 -3
  163. package/docs/errors/E1419.md +13 -5
  164. package/docs/errors/E1420.md +11 -3
  165. package/docs/errors/E1421.md +11 -3
  166. package/docs/errors/E1422.md +12 -3
  167. package/docs/errors/E1423.md +12 -3
  168. package/docs/errors/E1424.md +24 -5
  169. package/docs/errors/E1425.md +11 -3
  170. package/docs/errors/E1426.md +11 -3
  171. package/docs/errors/E1430.md +11 -3
  172. package/docs/errors/E1431.md +11 -3
  173. package/docs/errors/E1432.md +11 -3
  174. package/docs/errors/E1433.md +11 -3
  175. package/docs/errors/E1434.md +15 -6
  176. package/docs/errors/E1435.md +11 -3
  177. package/docs/errors/E1436.md +11 -3
  178. package/docs/errors/E1437.md +14 -6
  179. package/docs/errors/E1501.md +41 -6
  180. package/docs/errors/E1502.md +13 -3
  181. package/docs/errors/E1503.md +11 -3
  182. package/docs/errors/E1504.md +11 -3
  183. package/docs/errors/E1505.md +23 -5
  184. package/docs/errors/E1506.md +11 -3
  185. package/docs/errors/index.md +52 -29
  186. package/docs/getting-started/cdn.md +15 -9
  187. package/docs/getting-started/first-scene.md +20 -12
  188. package/docs/getting-started/hosting.md +111 -63
  189. package/docs/getting-started/install.md +39 -24
  190. package/docs/getting-started/network-use.md +31 -21
  191. package/docs/getting-started/project-structure.md +20 -8
  192. package/docs/getting-started/third-party-notices.md +6 -10
  193. package/docs/guides/accessibility.md +4 -4
  194. package/docs/guides/add-ons.md +83 -13
  195. package/docs/guides/agents.md +2 -6
  196. package/docs/guides/assets-pipeline.md +248 -72
  197. package/docs/guides/audio.md +17 -15
  198. package/docs/guides/baked-light-data.md +44 -23
  199. package/docs/guides/car-paint.md +37 -31
  200. package/docs/guides/content-pages.md +53 -29
  201. package/docs/guides/custom-passes.md +59 -17
  202. package/docs/guides/custom-shaders.md +54 -37
  203. package/docs/guides/debugging.md +31 -41
  204. package/docs/guides/deploying.md +6 -27
  205. package/docs/guides/deterministic-simulation.md +23 -16
  206. package/docs/guides/first-use-shaders.md +83 -45
  207. package/docs/guides/lens-kit.md +29 -26
  208. package/docs/guides/loading-screens.md +70 -30
  209. package/docs/guides/multiple-views.md +22 -11
  210. package/docs/guides/performance.md +188 -37
  211. package/docs/guides/phones.md +71 -19
  212. package/docs/guides/physics.md +6 -10
  213. package/docs/guides/screens.md +41 -29
  214. package/docs/guides/start-time.md +120 -85
  215. package/docs/guides/testing.md +137 -98
  216. package/docs/guides/ui-overlays.md +17 -12
  217. package/docs/guides/video-textures.md +14 -13
  218. package/docs/images/api/animation/character.webp +0 -0
  219. package/docs/images/api/animation/look-at-ring.webp +0 -0
  220. package/docs/images/api/animation/morph-tulips.webp +0 -0
  221. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  222. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  223. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  224. package/docs/images/api/debug/debug-shapes.webp +0 -0
  225. package/docs/images/api/debug/levels-view.webp +0 -0
  226. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  227. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  228. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  229. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  230. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  231. package/docs/images/api/geometry/generators.webp +0 -0
  232. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  233. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  234. package/docs/images/api/grass/grass-grove.webp +0 -0
  235. package/docs/images/api/grass/grass-presets.webp +0 -0
  236. package/docs/images/api/grass/grass-shadow.webp +0 -0
  237. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  238. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  239. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  240. package/docs/images/api/lights/spot-cookies.webp +0 -0
  241. package/docs/images/api/lines/lines-lit.webp +0 -0
  242. package/docs/images/api/lines/lines-widths.webp +0 -0
  243. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  244. package/docs/images/api/materials/decals.webp +0 -0
  245. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  246. package/docs/images/api/materials/relief.webp +0 -0
  247. package/docs/images/api/materials/shader-inputs.webp +0 -0
  248. package/docs/images/api/materials/standard-grid.webp +0 -0
  249. package/docs/images/api/materials/subsurface.webp +0 -0
  250. package/docs/images/api/materials/translucency.webp +0 -0
  251. package/docs/images/api/objects/objects-turntable.webp +0 -0
  252. package/docs/images/api/particles/campfire.webp +0 -0
  253. package/docs/images/api/points/galaxy.webp +0 -0
  254. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  255. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  256. package/docs/images/api/render/reflection-mirror.webp +0 -0
  257. package/docs/images/api/render/security-camera.webp +0 -0
  258. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  259. package/docs/images/api/sound/sound-demo.webp +0 -0
  260. package/docs/images/api/splats/splats-demo.webp +0 -0
  261. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  262. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  263. package/docs/images/api/textures/canvas-screen.webp +0 -0
  264. package/docs/images/api/textures/mipmaps.webp +0 -0
  265. package/docs/images/api/vertex-draws/rain.webp +0 -0
  266. package/docs/images/api/water/ocean.webp +0 -0
  267. package/docs/images/api/water/water-demo.webp +0 -0
  268. package/docs/images/api/water/water-rain.webp +0 -0
  269. package/docs/images/api/water/waterfall.webp +0 -0
  270. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  271. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  272. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  273. package/docs/images/concepts/instances/instances.webp +0 -0
  274. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  275. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  276. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  277. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  278. package/docs/images/concepts/lighting/environment.webp +0 -0
  279. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  280. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  281. package/docs/images/concepts/lod/forest.webp +0 -0
  282. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  283. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  284. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  285. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  286. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  287. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  288. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  289. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  290. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  291. package/docs/images/cookbook/index/picking.webp +0 -0
  292. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  293. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  294. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  295. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  296. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  297. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  298. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  299. package/docs/images/index/showcase-island.webp +0 -0
  300. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  301. package/docs/images/shaders/builtins/builtins.webp +0 -0
  302. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  303. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  304. package/docs/images/shots.json +2231 -0
  305. package/docs/index.md +14 -23
  306. package/docs/moves.json +1 -0
  307. package/docs/nav.json +300 -0
  308. package/docs/pages.md +230 -212
  309. package/docs/porting/react-three-fiber.md +2 -6
  310. package/docs/porting/threejs-loop-and-threads.md +1 -5
  311. package/docs/porting/threejs-mapping.md +1248 -234
  312. package/docs/porting/threejs-materials.md +10 -5
  313. package/docs/porting/threejs-overview.md +26 -6
  314. package/docs/porting/threejs-postprocessing.md +2 -6
  315. package/docs/porting/threejs-shaders.md +16 -14
  316. package/docs/porting/threejs-unsupported.md +6 -6
  317. package/docs/porting/verification.md +0 -4
  318. package/docs/shaders/builtins.md +15 -4
  319. package/docs/shaders/library.md +9 -6
  320. package/docs/shaders/surface-functions.md +51 -16
  321. package/docs/shaders/wgsl-rules.md +12 -5
  322. package/lib/debug/debug.d.ts +2 -2
  323. package/lib/debug/draw.d.ts +2 -2
  324. package/lib/debug/draw.js +8 -4
  325. package/lib/debug/overlay-look.d.ts +6 -0
  326. package/lib/debug/overlay-look.js +29 -7
  327. package/lib/debug/overlay.js +15 -11
  328. package/lib/debug/stats-options.d.ts +13 -0
  329. package/lib/debug/stats-panel.d.ts +21 -6
  330. package/lib/debug/stats-panel.js +80 -13
  331. package/lib/errors/codes.d.ts +17 -3
  332. package/lib/errors/codes.js +111 -105
  333. package/lib/errors/fixes.js +18 -18
  334. package/lib/gpu/variants.d.ts +8 -2
  335. package/lib/gpu/variants.js +39 -7
  336. package/lib/gpu/webgl2/programs.js +1 -1
  337. package/lib/gpu/webgpu/pipelines.js +13 -13
  338. package/lib/index.d.ts +1 -1
  339. package/lib/page/capabilities.d.ts +1 -1
  340. package/lib/page/engine.d.ts +14 -5
  341. package/lib/page/engine.js +18 -2
  342. package/lib/page/label-loop.js +9 -4
  343. package/lib/page/stats-switch.js +2 -0
  344. package/lib/page/switches.d.ts +6 -4
  345. package/lib/page/switches.js +20 -4
  346. package/lib/scene/baked-light.d.ts +2 -2
  347. package/lib/scene/fake-call-values.js +2 -2
  348. package/lib/scene/frame-cameras.d.ts +16 -4
  349. package/lib/scene/frame-cameras.js +28 -10
  350. package/lib/scene/gltf.d.ts +1 -1
  351. package/lib/scene/level-rule.d.ts +6 -5
  352. package/lib/scene/level-rule.js +2 -2
  353. package/lib/scene/particles.d.ts +7 -3
  354. package/lib/scene/particles.js +3 -1
  355. package/lib/scene/post.d.ts +3 -2
  356. package/lib/scene/resources.d.ts +15 -9
  357. package/lib/scene/scene.d.ts +18 -2
  358. package/lib/scene/scene.js +47 -5
  359. package/lib/scene/time-of-day.d.ts +10 -5
  360. package/lib/scene/time-of-day.js +11 -7
  361. package/lib/shader-artifact.json +1 -1
  362. package/lib/shared/labels.d.ts +5 -2
  363. package/lib/shared/labels.js +5 -2
  364. package/lib/shared/permutation-words.d.ts +2 -0
  365. package/lib/shared/permutation-words.js +8 -0
  366. package/lib/shared/recording.d.ts +13 -5
  367. package/lib/shared/recording.js +31 -10
  368. package/lib/shared/sketch-data.d.ts +9 -0
  369. package/lib/shared/sketch-data.js +57 -0
  370. package/lib/shared/version.d.ts +1 -1
  371. package/lib/shared/version.js +1 -1
  372. package/lib/sketch/define-sketch.d.ts +16 -7
  373. package/lib/sketch/define-sketch.js +2 -1
  374. package/lib/sketch/runner.d.ts +4 -0
  375. package/lib/sketch/runner.js +5 -0
  376. package/lib/sketch/ui.js +4 -2
  377. package/lib/stats.d.ts +1 -0
  378. package/lib/workers/protocol.d.ts +10 -0
  379. package/lib/workers/render-worker.js +4 -1
  380. package/lib/workers/sketch-worker.js +4 -1
  381. package/package.json +1 -1
package/docs/api/post.md CHANGED
@@ -1,17 +1,28 @@
1
1
  ---
2
2
  id: api/post
3
3
  title: Post-processing API
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "post.set for tone mapping, exposure and a camera's EV100, automatic exposure, bloom, ambient occlusion, screen-space reflections, depth of field, outlines, color grading tables and controls, the vignette and sharpening; custom effects with post.addEffect, custom tone curves, and still views."
7
5
  ---
8
6
 
9
7
  # Post-processing API
10
8
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
-
13
9
  `ctx.post` holds the settings that the engine applies to the scene's color on its way to the canvas. They are the tone mapping, the exposure, automatic exposure, bloom, ambient occlusion, screen-space reflections, depth of field, outlines, a color grading table, the vignette, the sharpening and the sketch's own effects. [Color management](../concepts/color-management.md) explains how the first two fit into the frame. [The post-processing chain](../concepts/post-processing.md) explains how bloom, ambient occlusion, screen-space reflections, depth of field and sharpening do.
14
10
 
11
+ Every effect is off until `post.set` turns it on. The tone mapping (AgX punchy) and an exposure of 1 always apply.
12
+
13
+ | Effect | `post.set` key | [Quality setting that turns it off](../concepts/quality-presets.md) | [Without HDR color](../concepts/post-processing.md#effects-on-devices-without-hdr-color) |
14
+ | --- | --- | --- | --- |
15
+ | Automatic exposure | `autoExposure` | None (`exposureMeter` picks the meter) | Stays off |
16
+ | Bloom | `bloom` | None (`bloomSize` sets the detail) | Stays off |
17
+ | Ambient occlusion | `ao` | `aoScale` 0: Low, Medium | Stays off with no float targets |
18
+ | Screen-space reflections | `ssr` | `ssrScale` 0: Low | Stays off with no float targets |
19
+ | Depth of field | `dof` | `dofSamples` 0: Low | Stays off |
20
+ | Outlines | `outline` | None | Draws |
21
+ | Color grading | `lut`, `grading` | None | Draws |
22
+ | Vignette | `vignette` | None | Draws |
23
+ | Sharpening | `sharpen` | None (adds nothing below a render scale of 1) | Draws |
24
+ | Custom effects and tone curves | `post.addEffect`, `toneMapping` | None | Stay off |
25
+
15
26
  ## Tone mapping and exposure
16
27
 
17
28
  ```ts
@@ -38,7 +49,16 @@ export default defineSketch(({ post }) => {
38
49
 
39
50
  ## Lights in real units
40
51
 
41
- Most scenes need no camera setting: their lights have small intensities, such as a sun of 3, and the exposure stays at 1. Lights in real units, such as a sun of 100,000 lux, need `ev100`: the exposure value of a camera at ISO 100. The units are on the [Lights](lights.md#color-intensity-and-units) page. Typical values are 15 for a sunny day, 12 for an overcast day and 7 for a lit room. Each step up is one stop darker. The engine scales the scene by 1 / (1.2 × 2^ev100), the formula of Filament, Bevy and Unity's HDRP. The `exposure` setting then scales that, as exposure compensation does. Setting `ev100: false` turns the camera off again.
52
+ Most scenes need no camera setting: their lights have small intensities, such as a sun of 3, and the exposure stays at 1. Lights in real units, such as a sun of 100,000 lux, need `ev100`: the exposure value of a camera at ISO 100. The units are on the [Lights](lights.md#color-intensity-and-units) page. Typical values are 15 for a sunny day, 12 for an overcast day and 7 for a lit room. Each step up is one stop darker.
53
+
54
+ The `exposure` setting then scales that, as exposure compensation does. Setting `ev100: false` turns the camera off again.
55
+
56
+ <details>
57
+ <summary>Technical details: the exposure formula</summary>
58
+
59
+ The engine scales the scene by 1 / (1.2 × 2^ev100), the formula of Filament, Bevy and Unity's HDRP. [Lighting and environment](../concepts/lighting.md) covers the units in full.
60
+
61
+ </details>
42
62
 
43
63
  ```ts
44
64
  import { defineSketch } from '@null3d/engine';
@@ -51,11 +71,21 @@ export default defineSketch(({ scene, post }) => {
51
71
  });
52
72
  ```
53
73
 
54
- The engine multiplies the exposure into each light, the environment's light, the background color and the fog color. The shaders multiply it into emissive light and unlit colors. The tone mapping then works on values near 1, even with a sun of 100,000 lux. Otherwise its highlights would pass the largest value of the 16-bit float scene color. The picture is the one that an exposure at the end gives. Background and unlit colors take the exposure too. At EV100 15 they draw black unless their own values are in real units.
74
+ Background and unlit colors take the exposure too. At EV100 15 they draw black unless their own values are in real units.
75
+
76
+ <details>
77
+ <summary>Technical details: where the engine applies the exposure</summary>
55
78
 
56
- ## Changing the exposure during play
79
+ The engine multiplies the exposure into each light, the environment's light, the background color and the fog color. The shaders multiply it into emissive light and unlit colors. The tone mapping then works on values near 1, even with a sun of 100,000 lux. Otherwise its highlights would pass the largest value of the 16-bit float scene color. The picture is the one that an exposure at the end gives.
57
80
 
58
- `post.set` allocates nothing, so a sketch can change the exposure every frame. Keep one settings object and change its field, so your own code allocates nothing either:
81
+ </details>
82
+
83
+ ## Changing settings during play
84
+
85
+ `post.set` allocates nothing, so a sketch can change settings every frame. Keep one settings object and change its field, so your own code allocates nothing either.
86
+
87
+ - A setting that a call leaves out keeps its value, also while its effect is off. `post.set({ effect: {} })` turns an effect on with the values it had.
88
+ - Turning an effect on or off can cost more. Each effect's section says how much.
59
89
 
60
90
  ```ts
61
91
  export default defineSketch(({ post, time }) => {
@@ -106,11 +136,9 @@ export default defineSketch(({ scene, geometry, materials, post }) => {
106
136
  - The scene draws at the camera's exposure, the `exposure` and `ev100` settings, and the eye adapts from there. A brightness of 0 stops is a scene that the camera's exposure shows as middle gray. With `ev100: 15`, `minEv: -8` lets the eye adapt down to a scene of about EV100 7.
107
137
  - Within one stop of its target, the eye slows down, so it settles smoothly. Eyes adapt to the dark more slowly than to the light, so `speedDown` is lower by default.
108
138
  - The first frame that meters takes its target at once, so a scene starts adapted. Hold mode draws one frame, so its image is the adapted image, the same in every run.
109
- - The final pass multiplies the scene's color, bloom's glow and folded effects by the adapted exposure, before FXAA, the vignette and the tone curve. Custom effects and depth of field see the camera's exposure. Bloom's `threshold` keeps its meaning in the scene's units.
139
+ - The final pass multiplies the color it reads by the adapted exposure: the scene's color, with the result of any custom effects, and bloom's glow. It does this before FXAA, the vignette and the tone curve. Custom effects and depth of field read the color at the camera's exposure. This is also true when the engine joins an effect into the final pass. Bloom's `threshold` keeps its meaning in the scene's units.
110
140
  - The quality setting `exposureMeter` picks the meter. `'histogram'` bins a grid of samples in compute shaders on WebGPU, on Medium and above. `'downsample'` averages 16 x 16 cells of the image, on Low and on WebGL2. Both take the same settings.
111
141
  - It needs HDR color, as bloom does. In WebGPU's compatibility mode with MSAA, turning it on moves the engine to HDR color with FXAA. On a device with no HDR target it stays off, and development builds warn once.
112
- - A setting that a call leaves out keeps its value, also while it is off. `post.set({ autoExposure: {} })` turns it on with the values it had.
113
- - `post.set` allocates nothing, and a meter costs nothing while it is off. Its shaders download the first time it turns on.
114
142
 
115
143
  ## Bloom
116
144
 
@@ -325,15 +353,11 @@ export default defineSketch(async ({ assets, post }) => {
325
353
  - The table grades each pixel after the tone mapping and the sRGB encoding. Tables made for sRGB display color, as most are, look as their authors made them.
326
354
  - The final pass reads the table with a linear filter between its texel centers. It maps the colors of a `.cube` file's domain onto the table.
327
355
  - The table grades the picture from the first frame after its texels reach the GPU, usually the next one.
328
- - `lutIntensity` keeps its value while the table is off, and `post.set` allocates nothing, so a sketch can fade a grade in every frame.
356
+ - `lutIntensity` keeps its value while the table is off.
329
357
 
330
358
  ### Grading controls
331
359
 
332
- The grading controls set a look from a few numbers, without a table file. A job worker bakes them
333
- into a table of its own. The final pass applies that table to the display color that the tone curve
334
- leaves, before a `lut`. A change stalls no frame. The picture shows the new grade once the
335
- worker's bake reaches the GPU, usually within a few frames. The frame that lands a bake uploads the
336
- table, 256 KB.
360
+ The grading controls set a look from a few numbers, without a table file. A [job worker](../concepts/architecture.md#the-kinds-of-thread) bakes them into a table of its own, so a change stalls no frame. The final pass applies that table to the display color that the tone curve leaves. The picture shows the new grade once the bake reaches the GPU, usually within a few frames.
337
361
 
338
362
  ```ts
339
363
  post.set({
@@ -366,11 +390,20 @@ post.set({
366
390
  - White balance corrects the light of the given temperature to the neutral white of daylight at 6500 kelvin. It keeps the picture's brightness.
367
391
  - The table holds 32 texels along each side. The final pass takes the square root of the color before it reads the table. Its texels therefore lie closer together toward black, where a grade's curve is steepest.
368
392
  - The table holds the grade alone, and the tone curve stays a calculation in the pass. A custom tone curve therefore still works with the controls.
393
+
394
+ The [Creek showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/creek) sets its own WGSL tone curve in the scene's look.
369
395
  - The final pass applies the built-in grade first and a `lut` after it, so a look from a file can sit over a grade from the controls.
370
396
  - The final pass draws on every GPU path, with HDR color or without it, so both paths grade alike.
371
- - The bake runs in a job worker, so a value that changes in a frame loop does not stall the frames. The frame that lands a bake uploads the table, 256 KB. Where no worker can run tasks, the picture keeps its colors and development builds warn once.
397
+ - The bake runs in a job worker, so a value that changes in a frame loop does not stall the frames. Where no worker can run tasks, the picture keeps its colors and development builds warn once.
372
398
  - The values are designed for the null3D grading controls. To match a grade that a colorist made in another tool, load its `.cube` file instead.
373
399
 
400
+ <details>
401
+ <summary>Technical details: the grading table</summary>
402
+
403
+ Each table costs the final pass a few operations per pixel and one texture read. On a device that resolves its multisampled picture straight into the canvas, the table makes the final pass run, which reads the picture once more. The frame that lands a bake uploads the table, 256 KB.
404
+
405
+ </details>
406
+
374
407
  ## Vignette
375
408
 
376
409
  The vignette darkens the picture toward its edges:
@@ -389,9 +422,8 @@ post.set({ vignette: { intensity: 0.8, size: 1.2 } });
389
422
 
390
423
  - The vignette multiplies each pixel's light before the tone mapping. [The post-processing chain](../concepts/post-processing.md#color-grading-and-the-vignette) gives the rule and the engines it follows.
391
424
  - At a distance `d` from the center, in canvas widths and heights times `size`, the light is multiplied by `1 - intensity × (1 - (1 - d²)^falloff)`, and never by less than 0.
392
- - A setting that a call leaves out keeps its value, also while the vignette is off. `post.set({ vignette: {} })` turns it on with the values it had.
393
425
 
394
- Grading and the vignette draw on every GPU path, with HDR color or without it. Without HDR color, the scene's shaders darken their light by the vignette before their tone mapping. A plain background color then draws as a background, so the vignette darkens it too. Each table costs the final pass a few operations per pixel and one texture read. On a device that resolves its multisampled picture straight into the canvas, the table makes the final pass run, which reads the picture once more.
426
+ Grading and the vignette draw on every GPU path, with HDR color or without it. Without HDR color, the vignette still draws: the scene's shaders darken their light before their tone mapping, and a plain background color darkens too.
395
427
 
396
428
  The final pass dithers last, after the table and the vignette. It adds noise of up to one step of the 8-bit canvas, so smooth gradients show no bands. The noise is the same in every frame.
397
429
 
@@ -412,7 +444,7 @@ post.set({ sharpen: 0.5 });
412
444
  - It draws at the whole canvas's render scale. A render scale below 1 sharpens its own upscale, so the value adds nothing there ([quality presets](../concepts/quality-presets.md#dynamic-resolution)).
413
445
  - While it is on, the frame draws in two steps at the whole render scale. The first step tone maps the scene into an 8-bit target, and the second sharpens that display color. A sketch whose render scale can drop already keeps that target, so sharpening adds no memory there. One that holds the render scale at 1 keeps a target of the canvas's size while sharpening is on.
414
446
  - While it is on, a still view keeps drawing instead of blending its frames and resting, because the sharpening draws in the moving frame's second step. [The post-processing chain](../concepts/post-processing.md#still-camera-accumulation) says what a still view does.
415
- - A setting that a call leaves out keeps its value. `post.set({ sharpen: false })` turns it off, and 0 does the same.
447
+ - `post.set({ sharpen: false })` turns it off, and 0 does the same.
416
448
 
417
449
  ## Custom effects
418
450
 
@@ -463,13 +495,13 @@ post.set({ toneMapping: reinhard });
463
495
 
464
496
  ## Still views
465
497
 
466
- A view that holds still blends its frames into a sharper picture, then stops drawing until something changes. It needs no setting: `post.set` turns nothing on for it. Bloom, outlines and automatic exposure keep a view drawing every frame, as [the post-processing chain](../concepts/post-processing.md#still-camera-accumulation) explains. `createEngine({ still: false })` and the page switch `?still-camera=off` turn it off.
498
+ A view that holds still blends its frames into a sharper picture, then stops drawing until something changes. It needs no setting: `post.set` turns nothing on for it. Bloom, outlines, automatic exposure, screen-space reflections, sharpening and custom effects keep a view drawing every frame. [The post-processing chain](../concepts/post-processing.md#still-camera-accumulation) lists every feature that does. `createEngine({ still: false })` and the page switch `?still-camera=off` turn it off.
467
499
 
468
500
  ## Errors
469
501
 
470
502
  | Code | Cause |
471
503
  | --- | --- |
472
- | [E1213](../errors/E1213.md) | A ninth effect. A setting that this version does not have, a tone mapping that the engine does not know, or a bloom, ambient occlusion, depth of field, automatic exposure, outline, vignette or sharpening value other than settings, a number or `false`, or an `ssr` value other than settings or `false`. An automatic exposure `metering` other than `'mean'` or `'percentile'`, `percentiles` that are not two numbers from 0 to 1 with the lower first, a `centerWeight` outside 0 to 1, a speed below 0, a `minEv`, `maxEv` or `compensation` outside -20 to 20, or a `minEv` above `maxEv`. A depth of field `focusDistance`, `aperture` or `focalLength` that is not above 0, a `maxBlur` outside 0 to 0.1, `blades` other than 0 or a whole number from 3 to 12, or a `focusPoint` that is not three finite numbers or `false`. Also a `lut` that is not a table from `assets.loadLut` or `assets.lutFromData`, a `grading` value out of its range, such as a white balance outside 1667 to 25000 kelvin, a lift channel outside -1 to 1, a gamma channel of 0 or below, a negative gain or saturation, or a split toning balance outside -1 to 1 or strength outside 0 to 1, or a value out of its range. These are an exposure, bloom intensity, threshold or knee, vignette intensity or size, or outline width below 0, a vignette falloff of 0 or below or a roundness above 1, a bloom blend other than `'mix'`, `'add'` or `'screen'`, bloom weights that are not 1 to 10 numbers of 0 or more, or that are all 0, a `lutIntensity` outside 0 to 1, a sharpening strength outside 0 to 1, an ambient occlusion value below 0 or its `distanceFalloff` or `intensity` above 1, a `distanceExponent` of 0, `samples` that are not a whole number from 1 to 64, a screen-space reflection value below 0 or its `intensity` or `maxRoughness` above 1, an `ssr.maxDistance` of 0, or an `ev100` outside -20 to 30. |
504
+ | [E1213](../errors/E1213.md) | A ninth effect, because at most 8 run at once. A setting that this version does not have, or a value that a setting does not take, such as a tone mapping that the engine does not know or a number outside its range. Each section's settings table gives the values that a setting takes. |
473
505
  | [E1203](../errors/E1203.md) | A value that is not a finite number, such as NaN, or an effect's `order` that is not one. |
474
506
  | [E1204](../errors/E1204.md) | An outline color that is not a hex string, a hex number or three linear components from 0 to 1. |
475
507
  | [E1215](../errors/E1215.md) | An effect or a tone curve as WGSL that the null3D Vite plugin did not compile, or compiled WGSL of another kind. |
@@ -488,6 +520,8 @@ A view that holds still blends its frames into a sharper picture, then stops dra
488
520
  - [Assets](assets.md): `assets.loadLut`, which loads color grading tables, and `assets.lutFromData`, which makes them from numbers.
489
521
  - [The post effects demo](https://github.com/null3d-engine/null3d/tree/main/examples/post-effects): bloom, ambient occlusion, an outline, a vignette, sharpening and color grading tables in one scene. It makes its warm and cool tables from lift, gamma and gain in code.
490
522
  - [The depth of field demo](https://github.com/null3d-engine/null3d/tree/main/examples/camera-lens): the focus racks across a chess board with `focusPoint`, while a dolly zoom changes the camera's focal length in every frame.
523
+ - [The automatic exposure demo](https://github.com/null3d-engine/null3d/tree/main/examples/auto-exposure): a walk from a sunny courtyard into a dark hall, where the eye opens and closes.
524
+ - [The screen-space reflections demo](https://github.com/null3d-engine/null3d/tree/main/examples/wet-street): puddles that mirror lit windows, neon signs and a passing taxi.
491
525
 
492
526
  ## API reference
493
527
 
@@ -1,16 +1,14 @@
1
1
  ---
2
2
  id: api/quality
3
3
  title: Quality API
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "quality.preset, quality.set, quality.setPreset, the preset check, the frame-budget governor, budgets for a sketch's own systems, quality events."
7
5
  ---
8
6
 
9
7
  # Quality API
10
8
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. `quality.set` takes every setting that changes during play, as [Settings](#settings) says. The others stay fixed while the engine runs.
9
+ > `quality.set` takes every setting that changes during play, as [Changing settings during play](#changing-settings-during-play) says. The others stay fixed while the engine runs.
12
10
 
13
- `ctx.quality` gives a sketch the quality preset that the engine runs and its settings. The sketch can change the settings that change during play, switch to another preset, and hear when either changes. [Quality presets](../concepts/quality-presets.md) explains how the engine chooses and checks the preset, and lists each preset's values.
11
+ `ctx.quality` gives a sketch the quality preset that the engine runs and its settings. The sketch can change the settings that change during play, switch to another preset, and hear when either changes ([Quality events](#quality-events)). [Quality presets](../concepts/quality-presets.md) explains how the engine chooses and checks the preset, and lists each preset's values.
14
12
 
15
13
  ```ts
16
14
  import { defineSketch } from '@null3d/engine';
@@ -46,12 +44,12 @@ console.log(engine.mode.presetCheck); // { from: 'high', targetFps: 60, rounds:
46
44
  | `presetCheck: 'during-play'` or `'before-play'` | When the preset check measures: in the first frames of play, the default, or before play, with `createEngine` waiting for it: [The preset check](../concepts/quality-presets.md#the-preset-check). |
47
45
  | `targetFps: 'display'` or a whole number | The frame rate that the preset check and the governor defend. Without it, the display's refresh rate, at most 60. `'display'` defends the display's full rate, and a number caps the target at that rate: [The target frame rate](../concepts/quality-presets.md#the-target-frame-rate). |
48
46
  | `maxPixelRatio` | Replaces the preset's pixel ratio cap. |
49
- | `antialias: 'msaa'`, `'fxaa'` or `'none'` | Replaces the preset's anti-aliasing mode. |
50
- | `shadowCascades`, `shadowMapSize`, `shadowTiles`, `shadowTileSize`, `heroTileSize`, `pointLightShadows`, `momentTransparency`, `gpuOcclusion`, `morphTargets` | Replace the preset's values of these settings, which stay fixed while the engine runs. |
47
+ | `antialias: 'msaa'`, `'fxaa'` or `'none'` | Replaces the preset's anti-aliasing mode: [GPU tiers and backends](../concepts/backends.md#color-and-anti-aliasing-on-each-tier). |
48
+ | `shadowCascades`, `shadowMapSize`, `shadowTiles`, `shadowTileSize`, `heroTileSize`, `pointLightShadows`, `momentTransparency`, `gpuOcclusion`, `morphTargets` | Replace the preset's values of these settings, which stay fixed while the engine runs. [Quality presets](../concepts/quality-presets.md#moment-transparency) explains `momentTransparency` and its `?moments=` switch. |
51
49
  | `depthPrepass`, `cloudSteps`, `softwareOcclusion`, `textureMemoryMiB` | Replace the preset's values of these settings. A sketch can change them during play. |
52
50
  | `memory: { maximumMiB }` | Replaces the preset's memory maximum: [Page API](engine.md#memory). |
53
- | `?preset=low` to `?preset=ultra` | Fixes the preset for tests. It wins over the option, and the engine ignores earlier crashes and checks no preset. |
54
- | `?tier=lowest` | Starts in the lowest quality tier for tests and devices. The render scale fixes at a third, and the sun's cast shadows and bloom go off. A reflection that names no scale of its own draws at a quarter of the render size, and WebGL2 also drops its depth prepass. The four presets keep their looks, and the governor enters the same tier when frames still miss at the preset's floor. |
51
+ | `?preset=low` to `?preset=ultra` | Fixes the preset for tests. It wins over the option, skips the preset check and starts outside the lowest tier. A crashed start still lowers the preset by one. |
52
+ | `?tier=lowest` | Starts in the [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier), for tests and weak devices. |
55
53
  | `?tier=off` | Keeps the governor out of the lowest quality tier, so a test reads the presets' own settings and looks on a slow machine. |
56
54
  | `?target-fps=display` or `?target-fps=90` | Sets the target frame rate. It wins over the `targetFps` option. |
57
55
  | `?preset-check=during-play` or `?preset-check=before-play` | Sets when the preset check measures. It wins over the `presetCheck` option. |
@@ -62,17 +60,24 @@ console.log(engine.mode.presetCheck); // { from: 'high', targetFps: 60, rounds:
62
60
 
63
61
  Most settings change during play. The preset tables' "Changes" column names the ones that stay fixed from the start, which the page's `createEngine` options set.
64
62
 
65
- ### Moment transparency
63
+ ## Changing settings during play
66
64
 
67
- `momentTransparency` blends the blended surfaces in a layer that needs no sort, and it keeps more of each surface's own color than `blending: 'weighted'` does. The setting is fixed at the start, so it goes in `createEngine`'s options or in the `?moments=` switch. Every preset leaves it off. Its cost is in [Quality presets](../concepts/quality-presets.md#moment-transparency). [Moment transparency](materials.md#moment-transparency) describes the layer and the surfaces that it draws.
65
+ `quality.set(settings)` changes the settings it gets and keeps the others. It takes the settings that change during play, applies them from the next frame on, and returns a promise that resolves at once. Another setting, or a value outside the setting's range, throws [E1213](../errors/E1213.md) and changes nothing. E1213 is also thrown for a `minRenderScale` above `maxRenderScale`, for a `createEngine` option with a value that its setting does not take, and for a preset name that `createEngine` does not know. [Quality presets](../concepts/quality-presets.md#moment-transparency) describes the moment transparency layer and the surfaces that it draws.
68
66
 
69
- [GPU tiers and backends](../concepts/backends.md#color-and-anti-aliasing-on-each-tier) compares the anti-aliasing modes on each GPU path.
67
+ <details>
68
+ <summary>Technical details: other calls that throw, and the render scale's range</summary>
70
69
 
71
- `quality.set(settings)` changes the settings it gets and keeps the others. It takes the settings that change during play, applies them from the next frame on, and returns a promise that resolves at once. Another setting, or a value outside the setting's range, throws [E1213](../errors/E1213.md) and changes nothing. So does a `minRenderScale` above `maxRenderScale`, an option of `createEngine` with a value that its setting does not take, and a preset name that `createEngine` does not know. To move both ends of the render scale's range past each other, give both in one call. In the [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier), a `minRenderScale` above the tier's cap of the scale raises the cap to it instead. Only a `maxRenderScale` that the sketch set itself throws.
70
+ To move both ends of the render scale's range past each other, give both in one call. In the [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier), a `minRenderScale` above the tier's cap on the scale raises the cap to it instead. Only a `maxRenderScale` that the sketch set itself throws.
71
+
72
+ </details>
72
73
 
73
74
  ## Switching presets
74
75
 
75
- `quality.setPreset(preset)` switches to another preset at a point that the sketch picks, such as a menu or a loading screen. Every setting that changes during play takes the new preset's value, apart from those that the page's options give. The values that `set` gave end with the switch too. The settings fixed at the start, such as `antialias`, keep their values. The preset check is different: when it lowers the preset after the setup, the settings that the setup changed with `set` keep their values. The GPU path caps the preset: `setPreset('ultra')` on WebGL2 runs Medium. `quality.highest` names that cap, so a menu shows the presets above it as unavailable.
76
+ `quality.setPreset(preset)` switches to another preset at a point that the sketch picks, such as a menu or a loading screen. Every setting that changes during play takes the new preset's value, apart from those that the page's options give. The values that `set` gave end with the switch too. The settings fixed at the start, such as `antialias`, keep their values.
77
+
78
+ The preset check is different: when it lowers the preset after the setup, the settings that the setup changed with `set` keep their values.
79
+
80
+ The GPU path caps the preset: `setPreset('ultra')` on WebGL2 runs Medium. `quality.highest` names that cap, so a menu shows the presets above it as unavailable.
76
81
 
77
82
  ```ts
78
83
  export default defineSketch(({ quality, page }) => {
@@ -99,7 +104,16 @@ console.log(quality.renderScale); // 0.75
99
104
 
100
105
  ## The frame-budget governor
101
106
 
102
- When frames take too long, the engine lowers a sketch's budgets and the render scale in turn, a budget's step first, until the render scale reaches its lowest. Then it lowers the levels of detail, the live shadow settings, bloom's size, ambient occlusion's scale and the scale of screen-space reflections. Then it lowers the steps of contact shadows, the far characters' update interval and the slices of volumetric fog. It raises them again once frames have time to spare. When the frames still miss at the render scale's floor, it enters the [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier). [Quality presets](../concepts/quality-presets.md#the-frame-budget-governor) gives the order of the steps and the rules that drive them. `quality.settings` keeps the values that the preset and the sketch gave. `quality.governor` reports what the engine draws with now. [`QualityGovernor`](reference/quality.md#qualitygovernor) lists each of its members with the step that changes it.
107
+ When frames take too long, the engine lowers the sketch's budgets and the render scale first, then detail, shadow and effect settings, one step at a time. It raises them again once frames have time to spare. When frames still miss at the lowest render scale, it enters the [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier). [Quality presets](../concepts/quality-presets.md#the-frame-budget-governor) lists every step in order.
108
+
109
+ `quality.settings` keeps the values that the preset and the sketch gave. `quality.governor` reports what the engine draws with now. [`QualityGovernor`](reference/quality.md#qualitygovernor) lists each of its members with the step that changes it.
110
+
111
+ <details>
112
+ <summary>Technical details: the order of the steps</summary>
113
+
114
+ After the budgets and the render scale, the governor lowers the levels of detail, the live shadow settings, bloom's size, ambient occlusion's scale and the scale of screen-space reflections. It then lowers the steps of contact shadows, the far characters' update interval and the slices of volumetric fog.
115
+
116
+ </details>
103
117
 
104
118
  The `quality.onChange` handlers run after each of these steps. So a sketch can lighten its own work with the engine's:
105
119
 
@@ -174,7 +188,7 @@ Each budget step adds a step before a step of the render scale. So with budgets,
174
188
 
175
189
  ## Texture memory
176
190
 
177
- The `quality.textureMemory` object reports the GPU memory of textures against their budget, the `textureMemoryMiB` setting. Its `bytes` are the GPU bytes that every texture takes, with the free layers of texture arrays. Its `budgetBytes` give the budget in bytes. Its `droppedLevels` count the mip levels that the engine dropped from every texture to stay under the budget. Its `droppedTextures` count the textures that hold fewer levels than their own. Each texture's `droppedLevels` gives its own count. [Quality presets](../concepts/quality-presets.md#texture-memory) explains which levels drop and how they come back.
191
+ The `quality.textureMemory` object reports the GPU memory of textures against the `textureMemoryMiB` budget, and how many mip levels the engine dropped to stay under it. [`TextureMemory`](reference/quality.md#texturememory) lists its fields, and each texture's own `droppedLevels` gives its count. [Quality presets](../concepts/quality-presets.md#texture-memory) explains which levels drop and how they come back.
178
192
 
179
193
  ```ts
180
194
  quality.onChange(({ textureMemory }) => {
@@ -187,7 +201,13 @@ Some textures never drop levels: those that the sketch made from images or data,
187
201
 
188
202
  ## Quality events
189
203
 
190
- `quality.onChange(handler)` calls the handler at the start of the first frame after the settings or the preset change. It also calls it after each shadow step of the frame-budget governor, and after the texture memory budget drops levels or asks for them again. A step of the budgets calls their `onScale` functions, not these handlers. It returns a function that removes the handler. Keep handlers cheap: they run when quality changes, not every frame. After a change of preset, the handler's frame waits for its pipelines too. So objects that a handler creates for the new preset appear with it.
204
+ `quality.onChange(handler)` returns a function that removes the handler. The engine calls the handler:
205
+
206
+ - At the start of the first frame after `quality.set` or `quality.setPreset` changes the settings or the preset. After a preset change, that frame waits for its pipelines, so objects that the handler makes for the new preset appear with it.
207
+ - After each step of [the frame-budget governor](#the-frame-budget-governor), apart from a step of the render scale.
208
+ - After the [texture memory](#texture-memory) budget drops mip levels or asks for them again.
209
+
210
+ A step of the [budgets](#budgets-for-the-sketchs-own-systems) calls their `onScale` functions, not these handlers. Keep handlers cheap: they run when quality changes, not every frame.
191
211
 
192
212
  ## Related pages
193
213
 
@@ -1,15 +1,11 @@
1
1
  ---
2
2
  id: api/raycast
3
3
  title: Raycasting and spatial queries
4
- status: experimental
5
- since: "0.2"
6
4
  summary: "raycast, raycastAny, raycastAll, raycastBatch, overlap queries, pointer events on objects."
7
5
  ---
8
6
 
9
7
  # Raycasting and spatial queries
10
8
 
11
- > Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Queries test a skinned character in its bind pose, not in its animated pose. Pixel-exact picking draws each character as it is posed.
12
-
13
9
  ```mermaid
14
10
  flowchart LR
15
11
  query["A ray, a sphere<br/>or a box"] --> scene["The scene's trees:<br/>static and dynamic objects"]
@@ -20,7 +16,7 @@ flowchart LR
20
16
 
21
17
  A raycast finds where a ray meets the scene's objects. An overlap query finds the objects inside a sphere or a box. Every query tests the triangles of objects and instance rows. Raycasts also hit [sprites, points and lines](#sprites-points-and-lines) where they draw. The engine keeps a tree over the scene's objects and a tree over each mesh's triangles. So a query tests only the few triangles near it.
22
18
 
23
- Queries run in the sketch, on the scene. They write their results into objects and arrays that you create once, so a query in every frame allocates nothing. `bun run bench:allocation --calls` checks it.
19
+ Queries run in the sketch, on the scene. They write their results into objects and arrays that you create once, so a query in every frame allocates nothing. The engine's allocation benchmark checks it in every frame. The [picking demo](https://github.com/null3d-engine/null3d/tree/main/examples/picking) casts rays from the pointer, and its `object.on` events report the hit point.
24
20
 
25
21
  ```ts
26
22
  import { defineSketch, type RaycastHit, vec3 } from '@null3d/engine';
@@ -103,7 +99,9 @@ in-world screen turns a click into a pixel of its image.
103
99
 
104
100
  ## Rays from the pointer
105
101
 
106
- For clicks and hover on objects, `object.on('click', handler)` casts the ray itself. [Pointer events on objects](input.md#pointer-events-on-objects) describes it. For a ray of your own, such as one that tests only some layers, `camera.screenToRay(x, y, ray)` writes the ray through a point on the canvas. Pass `input.pointer.x` and `input.pointer.y`, and the ray comes from the frame that was on screen at the pointer's event. Over a view from `scene.createView`, cast the ray with `view.screenToRay` instead, and `scene.viewAt(x, y)` finds that view ([Multiple views](../guides/multiple-views.md#picking-in-a-view)).
102
+ For clicks and hover on objects, `object.on('click', handler)` casts the ray itself. [Pointer events on objects](input.md#pointer-events-on-objects) describes it.
103
+
104
+ For a ray of your own, such as one that tests only some layers, `camera.screenToRay(x, y, ray)` writes the ray through a point on the canvas. Pass `input.pointer.x` and `input.pointer.y`, and the ray comes from the frame that was on screen at the pointer's event. Over a view from `scene.createView`, cast the ray with `view.screenToRay` instead, and `scene.viewAt(x, y)` finds that view ([Multiple views](../guides/multiple-views.md#picking-in-a-view)).
107
105
 
108
106
  ```ts
109
107
  const ray = { origin: vec3.create(), direction: vec3.create() }; // made once
@@ -116,7 +114,9 @@ if (input.wasPressed('Mouse0')) {
116
114
 
117
115
  ## Batches of rays
118
116
 
119
- The call `scene.raycastBatch(rays, options, out)` casts many rays at once, on the job workers. Its `rays` array holds six numbers per ray: its origin, then its direction. Its `out` object holds typed arrays with one entry per ray, or three numbers per ray for points and normals. Only `distances` is required, and the call fills each other array that you give. It returns how many rays hit something.
117
+ The call `scene.raycastBatch(rays, options, out)` casts many rays at once, on the job workers. Its `rays` array holds six numbers per ray: its origin, then its direction. Its `out` object holds typed arrays with one entry per ray, or three numbers per ray for points and normals.
118
+
119
+ Only `distances` is required, and the call fills each other array that you give. It returns how many rays hit something.
120
120
 
121
121
  ```ts
122
122
  const COUNT = 1000;
@@ -146,26 +146,48 @@ scene.pick(240, 180).then((hit) => {
146
146
  });
147
147
  ```
148
148
 
149
- A hit carries `uv` and `hasUv`, as a raycast's hit does. `uv` holds where on the surface the pixel landed, in the mesh's first texture coordinates. It blends them across the hit triangle's three corners. `hasUv` says whether the surface has such coordinates. Read `hasUv` first: `uv` holds nothing to read when it is false.
149
+ The pick draws each object's id into a small image around the point, then reads the id back. So a pick is exact to the pixel only when every source in the scene can draw into that image.
150
150
 
151
- The coordinates stay the mesh's own. A repeated texture reports values past 1, and a material's `uvTransform` does not move them. A ray through the same point finds them, from the camera of the frame that recorded the pick. So a pick and a raycast on one point give one answer. A ray that names another object than the pixel did leaves `hasUv` false. The pick then keeps the object that the pixel showed.
151
+ One sprite, point or line in the scene, one material that blends, uses `transmission` or uses `alphaMode: 'hash'`, or one custom material that masks or has no vertex offset, makes every pick a raycast. That raycast tests triangles: it ignores masks, tests skinned characters in their bind pose, and uses the camera of the frame that last ran. In [hold mode](../guides/testing.md), which runs no frame loop, a pick is a raycast too.
152
152
 
153
- A skinned or morphed character draws a different shape than the mesh that the ray tests. So does a custom material that moves its vertices in its shader. Their coordinates can therefore differ from the pose that the frame drew.
154
-
155
- The point is tested at the pixel that the camera draws, not at a projected triangle. A surface thinner than a pixel picks where its pixels are. An engine material with `alphaMode: 'mask'` picks by its mask. So a ray through a cut-out hole finds what lies behind the hole. The frame that records the pick draws it, so the camera of that frame answers. A camera that moves meanwhile can differ from the frame that the click saw.
156
-
157
- A pick finds these sources:
153
+ ### What a pick finds
158
154
 
159
155
  - Meshes of the engine's materials, on the camera's layers, where they draw opaque.
160
156
  - Custom materials with a vertex offset, whose pick builds move each vertex as the surface draws.
161
157
  - Each row of an instance batch, named by `object` and `instance`.
162
158
  - Skinned and morphed characters, as their last frame's pose places them.
163
159
 
164
- A scene with a source that the pick's id target cannot hold answers the whole pick with a raycast instead. Such a source is a custom material without a vertex offset, a masked custom material, or a material with `alphaMode: 'hash'`, `blending` or `transmission`. A sprite, point or line is one too. The raycast tests triangles, so it ignores masks, and it uses the camera of the frame that last ran.
160
+ ### Texture coordinates
161
+
162
+ A hit carries `uv` and `hasUv`, as a raycast's hit does. `uv` holds where on the surface the pixel landed, in the mesh's first texture coordinates. It blends them across the hit triangle's three corners. `hasUv` says whether the surface has such coordinates. Read `hasUv` first: `uv` holds nothing to read when it is false.
163
+
164
+ The coordinates stay the mesh's own. A repeated texture reports values past 1, and a material's `uvTransform` does not move them.
165
+
166
+ <details>
167
+ <summary>Technical details: how a pick finds its texture coordinates</summary>
168
+
169
+ A ray through the same point finds them, from the camera of the frame that recorded the pick. So a pick and a raycast on one point give one answer. A ray that names another object than the pixel did leaves `hasUv` false. The pick then keeps the object that the pixel showed.
165
170
 
166
- A pick before the first frame answers `null`. The engine has not drawn the camera yet, so no pixel of a frame shows anything.
171
+ </details>
167
172
 
168
- A pick costs one more draw of the camera's opaque objects, one read of four bytes, and one raycast for the texture coordinates. Picks wait in a queue of their own. Each answers in a frame after the one that records it. A hidden object, an object off the camera's layers, and a pixel that no object covers answer `null`.
173
+ The point is tested at the pixel that the camera draws, not at a projected triangle. A surface thinner than a pixel picks where its pixels are. An engine material with `alphaMode: 'mask'` picks by its mask. So a ray through a cut-out hole finds what lies behind the hole. The frame that records the pick draws it, so the camera of that frame answers. A camera that moves meanwhile can differ from the frame that the click saw.
174
+
175
+ A skinned or morphed character draws a different shape than the mesh that the ray tests. So does a custom material that moves its vertices in its shader. Their coordinates can therefore differ from the pose that the frame drew.
176
+
177
+ ### Timing and cost
178
+
179
+ A pick costs one more draw of the camera's opaque objects, one read of four bytes, and one raycast for the texture coordinates. A pick answers in a frame after the one that records it.
180
+
181
+ <details>
182
+ <summary>Technical details: what a pick costs</summary>
183
+
184
+ Picks wait in a queue of their own, because a frame records one read.
185
+
186
+ </details>
187
+
188
+ ### When a pick answers null or fails
189
+
190
+ A pick before the first frame answers `null`. A hidden object, an object off the camera's layers, and a pixel that no object covers answer `null` too.
169
191
 
170
192
  A pick that waits for its read when the browser takes the GPU away is rejected with [E1436](../errors/E1436.md). The engine starts a new device, but the frame that recorded the pick drew on the lost one, so the read never lands. Ask for the pick again: the new device answers a new pick. A pick still queued behind it goes to the new device in its turn.
171
193
 
@@ -203,7 +225,9 @@ A ray hits [sprites](sprites.md), [points](points.md) and [lines](lines.md) wher
203
225
 
204
226
  A hit's `instance` is the row: the sprite, the point, or the segment. Segment `i` of a strip or a loop joins points `i` and `i + 1`, and the last segment of a loop joins the last point to the first. Segment `i` of a batch of segments joins points `2i` and `2i + 1`. A hit's `triangle` is -1.
205
227
 
206
- Sprites face the camera, and sizes in pixels depend on it. So these raycasts need a camera. `scene.raycast` and the other raycasts use the active camera. A pointer event's ray uses the camera of the frame on screen at the event. Without an active camera, rays miss sprites, points without `pointThreshold` and lines sized in pixels. A row sized in pixels is hit only between the camera's near and far planes, where the camera draws it.
228
+ Sprites face the camera, and sizes in pixels depend on it. So these raycasts need a camera. `scene.raycast` and the other raycasts use the active camera. A pointer event's ray uses the camera of the frame on screen at the event.
229
+
230
+ Without an active camera, rays miss sprites, points without `pointThreshold` and lines sized in pixels. A row sized in pixels is hit only between the camera's near and far planes, where the camera draws it.
207
231
 
208
232
  The hit on a sprite or a point's square is the point where the ray crosses it, and its normal faces the camera. A hit near a line, or near a point within a threshold, is the ray's closest point to it. Its distance is that point's distance along the ray, and its normal points back along the ray. A ray hits a dashed line in its gaps too, and a sprite or a point where its map is clear.
209
233
 
@@ -251,18 +275,27 @@ A direction can have any length above 0, from 10^-300 to 10^300. The engine make
251
275
 
252
276
  ## How queries find objects
253
277
 
254
- The engine keeps two levels of trees, in its WebAssembly core.
278
+ - The first query after a mesh is created builds that mesh's tree. A large mesh can make that first query slow.
279
+ - Static objects are cheap to move. Creating or destroying objects rebuilds the static tree at the next query.
280
+ - Dynamic objects, dynamic batches, sprites, points and lines are rebuilt in each frame that runs a query. A large dynamic batch of particles adds to each such frame. A frame without queries builds nothing.
281
+ - A raycast on layers that hold pixel-sized sprites, points or lines costs more. Keep them on their own layers to keep other raycasts fast.
282
+ - A ray costs about the same in a large scene as in a small one.
283
+ - Objects thousands of kilometers from the origin get the same precision as objects near it.
284
+
285
+ <details>
286
+ <summary>Technical details: the query trees</summary>
287
+
288
+ The engine keeps two levels of trees, in its WebAssembly core. One tree per mesh, over its triangles. Two trees sit over the scene's objects and instance rows. The tree over static objects is built once, and again only after objects are created or destroyed. When a static object moves, the engine adjusts the boxes of its tree instead.
255
289
 
256
- - One tree per mesh, over its triangles. The first query after a mesh is created builds the mesh's tree, on the job workers. A large mesh can make that first query slow.
257
- - Two trees over the scene's objects and instance rows. The tree over static objects is built once, and again only after objects are created or destroyed. When a static object moves, the engine adjusts the boxes of its tree instead. The tree over dynamic objects is built again in each frame that runs a query, from all their positions at once. It holds the rows of dynamic batches too, also sprites, points and lines, on every layer. So a large dynamic batch of particles adds to each frame that runs a query. A frame without queries builds nothing.
290
+ The tree over dynamic objects is built again in each frame that runs a query, from all their positions at once. It holds the rows of dynamic batches too, also sprites, points and lines, on every layer.
258
291
 
259
292
  Each node of a tree has four children, so one SIMD instruction tests a ray against four boxes. A query walks the scene's trees to the objects whose boxes it meets. Then it moves the ray into each object's own space and walks that object's mesh tree. Each object's box comes from its mesh's box, so it holds every triangle.
260
293
 
261
- Because a query walks these trees, a ray costs about the same in a large scene as in a small one. A three.js `Raycaster` tests each object's bounding sphere in turn, so its rays cost more as the scene grows.
294
+ A three.js `Raycaster` tests each object's bounding sphere in turn, so its rays cost more as the scene grows. The trees hold sprites, points and line segments too. A row sized in pixels takes more room in the world the farther it lies from the camera. A threshold reaches past what a row draws. So when the query's layers hold such rows, the raycast grows each box of the trees as it walks them. A raycast on layers without them costs no more.
262
295
 
263
- The trees hold sprites, points and line segments too. A row sized in pixels takes more room in the world the farther it lies from the camera. A threshold reaches past what a row draws. So when the query's layers hold such rows, the raycast grows each box of the trees as it walks them. A raycast on layers without them costs no more.
296
+ The trees give the same hits as testing every triangle of every object in turn. The engine stores positions relative to grid cells, and each query moves its origin into each cell's frame in 64-bit numbers.
264
297
 
265
- The trees give the same hits as testing every triangle of every object in turn. Objects far from the origin, thousands of kilometers out, get the same precision as objects near it. The engine stores positions relative to grid cells, and each query moves its origin into each cell's frame in 64-bit numbers.
298
+ </details>
266
299
 
267
300
  ## API reference
268
301
 
@@ -1,8 +1,7 @@
1
1
  ---
2
2
  id: api/reference/animation
3
3
  title: "Animation: API reference"
4
- status: generated
5
- since: "0.2"
4
+ generated: true
6
5
  summary: "Every export of the Animation API, from the engine's doc comments."
7
6
  ---
8
7
 
@@ -1,8 +1,7 @@
1
1
  ---
2
2
  id: api/reference/assets
3
3
  title: "Assets: API reference"
4
- status: generated
5
- since: "0.1"
4
+ generated: true
6
5
  summary: "Every export of the Assets API, from the engine's doc comments."
7
6
  ---
8
7
 
@@ -176,7 +175,7 @@ A light map from `assets.loadLightMap`: its radiance texture, ready for a materi
176
175
  | `readonly width: number` | The texels across. |
177
176
  | `readonly height: number` | The texels down. |
178
177
  | `readonly texture: Texture` | The radiance, as a texture that a material takes as `lightMap`. |
179
- | `readonly direction: Int8Array \| undefined` | Three signed bytes per texel, from -127 to 127, each axis a direction divided by 127. It runs from the same first texel as the radiance, and it is undefined for a light map without a direction. |
178
+ | `readonly direction: Int8Array \| undefined` | Three signed bytes per texel, from -127 to 127: each axis of the direction times 127. It runs from the same first texel as the radiance, and it is undefined for a light map without a direction. |
180
179
  | `readonly directionTexture: Texture \| undefined` | The direction at each texel, in linear color: its red, green and blue map the direction's x, y and z from -1 to 1. It has the radiance's size, format and color space, so the engine reads it through the light map's own texture binding; give it to a material beside the radiance as `lightMapDirection`. It is undefined for a light map without a direction. |
181
180
 
182
181
  ## `LightMapEncoding`
@@ -332,4 +331,8 @@ Called as a download's bytes arrive and when one finishes or fails. It gets the
332
331
  function registerGltfExtension(handler: GltfExtensionHandler): () => void
333
332
  ```
334
333
 
335
- Registers a handler for the glTF extensions that an add-on reads, for every sketch of this thread. An add-on calls it once as its module loads, so a page that imports the add-on loads the add-on's files with no other call. Returns a function that unregisters the handler. A later handler for an extension replaces the earlier one, which a development reload of the add-on's module needs. Two add-ons that read one extension therefore give it to the one that loaded last. A sketch that reads one extension in one scene alone uses `assets.registerGltfExtension` instead. Throws E1213 for a handler without a list of extension names or a `load` function.
334
+ Registers a handler for the glTF extensions that an add-on reads, for every sketch of this thread. An add-on calls it once as its module loads, so a page that imports the add-on loads the add-on's files with no other call. Returns a function that unregisters the handler.
335
+
336
+ A later handler for an extension replaces the earlier one, which a development reload of the add-on's module needs. Two add-ons that read one extension therefore give it to the one that loaded last. A sketch that reads one extension in one scene alone uses `assets.registerGltfExtension` instead.
337
+
338
+ Throws E1213 for a handler without a list of extension names or a `load` function.
@@ -1,8 +1,7 @@
1
1
  ---
2
2
  id: api/reference/cameras
3
3
  title: "Cameras: API reference"
4
- status: generated
5
- since: "0.1"
4
+ generated: true
6
5
  summary: "Every export of the Cameras API, from the engine's doc comments."
7
6
  ---
8
7
 
@@ -23,6 +22,8 @@ An object that the scene can be drawn from. `scene.setActiveCamera` picks the ca
23
22
  | `readonly far: number` | The distance to the far clipping plane. |
24
23
  | `setLayers(mask: number): void` | Sets the layers the camera draws, as a 32-bit mask: it draws the objects whose masks share a layer with it. The default, 1, draws layer 0, where every object starts. |
25
24
  | `setNearFar(near: number, far: number): void` | Sets the distances to the near and far clipping planes. |
25
+ | `readonly lensShift: readonly [number, number]` | The lens shift: how far the view sits right of and above the camera's axis, as fractions of the view's width and height. The array is the camera's own and changes with `setLensShift`, so copy it to keep a value. |
26
+ | `setLensShift(x: number, y: number): void` | Moves the view off the camera's axis, as a shift lens on a real camera does: right by `x` times the view's width, and up by `y` times its height. The perspective stays as it is, so the image is a crop of a wider view from the same place. A shift of 0.25 across puts the camera's axis, and a `target` it looks at, a quarter of the width left of the middle. Culling, shadows, picking, `screenToRay`, `worldToScreen`, views and labels all follow the shifted view. The default is no shift. It allocates nothing. |
26
27
  | `screenToRay(x: number, y: number, out: Ray): void` | Writes the ray from the camera through a point on the canvas into `out`: `x` and `y` are CSS pixels from the canvas's top-left corner, as `input.pointer` gives them. A perspective ray starts at the camera, and an orthographic ray on the near plane. The direction has length 1. When the point is the position of the pointer or a finger from `input`, the ray uses the camera of the frame that was on screen at that event, if the engine still keeps it. It keeps the last four views, and frames in a row with the same view count as one. So a click during a fast pan picks what the user saw. Any other point uses the camera of the frame that last ran, with its lens as it is now. Objects stay where they are now, so a moving object can be up to a frame of its motion away from where the user saw it. |
27
28
  | `worldToScreen(point: Vec3Like, out: Vec3Like): void` | Writes where a point in the world lies on the canvas into `out`: x and y in CSS pixels from the canvas's top-left corner, then the point's depth, its distance in front of the camera along the view. A depth below 0 puts the point behind the camera, where x and y have no meaning. It uses the camera of the frame that last ran, with its lens as it is now, so in `onLateUpdate` it places points where the frame draws them. |
28
29