@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
@@ -1,14 +1,12 @@
1
1
  ---
2
2
  id: concepts/particle-buffer
3
3
  title: The particle buffer
4
- status: experimental
5
- since: "0.2"
6
4
  summary: "What a particle buffer holds: its 32-byte records, its values and its frame's values; how an emitter or sketch code writes births into it; and the limits that it meets."
7
5
  ---
8
6
 
9
7
  # The particle buffer
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. Use the [particles add-on](../api/particles.md), which fills this buffer for you, unless you write your own emitter. Coding agents must not use these calls.
9
+ > This is a low-level API. The [particles add-on](../api/particles.md) fills this buffer for you, and the null3D agent skills always use the add-on. Write records yourself only for an emitter that the add-on does not fit.
12
10
 
13
11
  ```mermaid
14
12
  flowchart LR
@@ -21,7 +19,7 @@ flowchart LR
21
19
 
22
20
  A particle buffer is a scene object and a flat table of particle records. A record is written once, when a particle is born. The GPU then works out where that particle is and how it looks at its age, in closed form. No pass moves the particles, so a frame at a given time looks the same whatever frames came before it, on WebGPU and on WebGL2.
23
21
 
24
- The `@null3d/particles` add-on builds its systems from buffers. Its emitters, bursts and sub-emitters decide where and when particles are born, then write the records in the engine's core. Use the add-on for most work. This page covers the buffer itself, for an emitter that the add-on does not fit.
22
+ The `@null3d/particles` add-on builds its systems from buffers. Its emitters, bursts and sub-emitters decide where and when particles are born, then write the records in the engine's core ([Architecture](architecture.md)). Use the add-on for most work. This page covers the buffer itself, for an emitter that the add-on does not fit.
25
23
 
26
24
  ## What the buffer holds
27
25
 
@@ -30,9 +28,26 @@ The `@null3d/particles` add-on builds its systems from buffers. Its emitters, bu
30
28
  | The object | one scene object | Its place, turn, scale, layers, visibility and bounds. Birth places are in its space, so moving the object moves every particle. |
31
29
  | The records | 32 bytes for each of `capacity` | One record for each particle that the buffer holds at once. |
32
30
  | The values | 608 bytes | The motion and the look of every particle of the buffer, and the wind field when it names one. It uploads when `set` or `setWind` changes it. |
33
- | The frame's values | 20 bytes | The time, the record count, the time shift and the wind texture's number. The sketch writes them, or the core's emitter does. |
31
+ | The frame's values | 20 bytes | The time, the record count, the time shift and the wind texture's number. The sketch or the core's emitter writes the time and count; `setWind` writes the wind texture's number. |
34
32
  | The emitter | a block of numbers | The settings and the frame's numbers of an emitter in the core, when the buffer has one. |
35
33
 
34
+ Each frame's values have a slot of their own. `buffer.frame` is a view of these five numbers.
35
+
36
+ | Slot | Meaning | Who writes it |
37
+ | --- | --- | --- |
38
+ | 0 | The buffer's time in seconds. | The sketch, or the core's emitter. |
39
+ | 1 | How many records from the first the draw reads. | The sketch, or the core's emitter. |
40
+ | 2 | The first record that still counts from the old time base. | The core's emitter, when it moves the time base. |
41
+ | 3 | The seconds to take off the birth times of those records. | The core's emitter, when it moves the time base. |
42
+ | 4 | The wind texture's number. | `setWind`. |
43
+
44
+ <details>
45
+ <summary>Technical details: how the time base moves</summary>
46
+
47
+ Birth times are 32-bit floats, so their precision falls as the buffer's clock grows. A buffer that runs for hours moves its time base. It rewrites the birth times at their new times and tells the shader how far that move has reached. The call `shiftRecords(from, to, seconds)` takes whole seconds off the birth times of rows `from` to `to`. That moves the time that they count from. An emitter does this after 1,024 seconds.
48
+
49
+ </details>
50
+
36
51
  The engine gives the object one material, with the particle shading. It blends and writes no depth. The material takes a `map` for the particles' texture, and without one each particle is a soft round dot. The `blending` option is additive or normal, and it defaults to additive. `layers` chooses the layers that the buffer draws on.
37
52
 
38
53
  ## A record
@@ -49,25 +64,6 @@ A record is eight 32-bit numbers, or 32 bytes.
49
64
 
50
65
  The seed picks the particle's random size, turn, spin, color and first flipbook frame. Two particles of one buffer get their own values from their own seeds. Call `write(index, record, seed)` with the eight numbers in that order: place, birth time, velocity, lifetime. The seed is the third argument.
51
66
 
52
- Call `writeRecords(block, count, first)` to write many births in one call. The block holds nine numbers for each birth: the eight above and the seed. Row `first` takes the first birth, and the rest follow, wrapping at the capacity. The engine packs the records and marks them, so the sketch's loop fills the block and the call writes it. Pass a block that stays the same size from frame to frame, which keeps the engine's room for it. Call `shiftRecords(from, to, seconds)` to take whole seconds off the birth times of rows `from` to `to`, which moves the time that they count from.
53
-
54
- ## Layout in practice
55
-
56
- The records are one table, with a row for each particle that the buffer holds at once. An index from 0 to `capacity - 1` names a row. The buffer keeps no list of live particles. The shader reads each record's birth time and lifetime, so a particle draws nothing before its birth and nothing after its death.
57
-
58
- `frame[1]` says how many records from the first the draw reads, at most the capacity. Set it to the number of rows that hold a record, so rows that the sketch never wrote do not draw. Rows past the count draw nothing even when they hold a live particle. Once the count reaches the capacity, every row runs the vertex shader in every frame. A record past its life leaves before it makes a quad.
59
-
60
- An emitter usually fills the table in order and then writes over the oldest rows:
61
-
62
- ```ts
63
- // The n-th birth goes into row n. After a full table, the rows start again.
64
- buffer.write(born % buffer.capacity, record, born & 0xffff);
65
- ```
66
-
67
- A capacity that fits the rate over the longest lifetime keeps that safe. A write over a row whose particle is still alive ends that particle early.
68
-
69
- A buffer draws as one blended object. Its particles keep the order of their records, and the engine does not sort them among themselves. Additive blending needs no order, which suits most effects. With normal blending, keep the particles faint and soft, as smoke is.
70
-
71
67
  ## Write into the buffer
72
68
 
73
69
  The sketch below writes a fountain straight into a buffer, and the GPU moves every particle.
@@ -123,7 +119,7 @@ export default defineSketch(async ({ scene, time }) => {
123
119
 
124
120
  Await the creation in the setup, because the first call downloads the particle code. If the code does not download, the promise rejects with [E1406](../errors/E1406.md).
125
121
 
126
- Make the record array once. Every birth is then a write into engine memory, so a frame allocates nothing. The frame array is a view into that memory: take it once and assign its numbers.
122
+ Make the record array once. Every birth is then a write into engine memory, so a frame allocates nothing. The frame array is a view into that memory: take it once and assign its numbers. The count in `frame[1]` stops the draw at the rows that hold a record ([Layout in practice](#layout-in-practice) explains).
127
123
 
128
124
  `commit()` marks the records written since the last call for the next frame's upload. A call in every frame is enough: writes that continue the run are marked there, and a write elsewhere marks its range at once.
129
125
 
@@ -135,6 +131,22 @@ The birth time counts from `frame[0]`, which must rise with the frame's time. Ke
135
131
 
136
132
  `buffer.destroy()` frees the records, the GPU buffers and the object.
137
133
 
134
+ ### Write many births in one call
135
+
136
+ Call `writeRecords(block, count, first)` to write many births in one call. The block holds nine numbers for each birth: the eight above and the seed. Row `first` takes the first birth, and the rest follow, wrapping at the capacity.
137
+
138
+ The engine packs the records and marks them, so the sketch's loop fills the block and the call writes it. Pass a block that stays the same size from frame to frame, which keeps the engine's room for it.
139
+
140
+ ## Layout in practice
141
+
142
+ The records are one table, with a row for each particle that the buffer holds at once. An index from 0 to `capacity - 1` names a row. The buffer keeps no list of live particles. The shader reads each record's birth time and lifetime, so a particle draws nothing before its birth and nothing after its death.
143
+
144
+ `frame[1]` says how many records from the first the draw reads, at most the capacity. Set it to the number of rows that hold a record, so rows that the sketch never wrote do not draw. Rows past the count draw nothing even when they hold a live particle. Once the count reaches the capacity, every row runs the vertex shader in every frame. A record past its life leaves before it makes a quad.
145
+
146
+ An emitter usually fills the table in order, as the fountain example does, and then writes over the oldest rows. A capacity that fits the rate over the longest lifetime keeps that safe. A write over a row whose particle is still alive ends that particle early.
147
+
148
+ A buffer draws as one blended object. Its particles keep the order of their records, and the engine does not sort them among themselves. Additive blending needs no order, which suits most effects. With normal blending, keep the particles faint and soft, as smoke is.
149
+
138
150
  ## An emitter in the core
139
151
 
140
152
  A buffer can also emit. Configure an emitter once, and the core writes a frame's records in one call. The particles add-on uses this path. The core makes every record of the frame. It plans and fires the sub-emitters, and moves the time base. The sketch runs no loop over the births.
@@ -152,14 +164,14 @@ buffer.configureEmitter({
152
164
  // In each frame, after the objects have their world places. The five numbers are the frame's
153
165
  // start and end, its rate, and 1 or 0 for whether it emits and whether it is a prewarmed first
154
166
  // frame. Make the array once: a fraction passed as a call argument is boxed.
155
- const frame = new Float64Array(5);
156
-
157
- frame[0] = time.now - dt;
158
- frame[1] = time.now;
159
- frame[2] = 200;
160
- frame[3] = 1;
161
- frame[4] = 0;
162
- buffer.emitFrame(frame);
167
+ const emitNumbers = new Float64Array(5);
168
+
169
+ emitNumbers[0] = time.now - dt;
170
+ emitNumbers[1] = time.now;
171
+ emitNumbers[2] = 200;
172
+ emitNumbers[3] = 1;
173
+ emitNumbers[4] = 0;
174
+ buffer.emitFrame(emitNumbers);
163
175
  ```
164
176
 
165
177
  `configureEmitter` takes the seed and the shape: point, sphere, cone, box or disc. It also takes the direction and its spread, with the speed and lifetime ranges. A velocity, the bursts, the duration, the loop, the followed object and the sub-emitters follow. The engine keeps the motion and the values, so the core's events follow the same closed form as the shader.
@@ -187,15 +199,16 @@ A frame's upload therefore grows with the births it writes. The number of partic
187
199
  - The engine's memory holds 32 bytes for each record, and the GPU holds a copy of the same bytes. A buffer that cannot get its memory throws [E1109](../errors/E1109.md).
188
200
  - The count is rounded down to a whole number, at most the capacity. A count that is not finite, or that is 0 or less, draws nothing.
189
201
  - The lifetime is a 16-bit float with about three digits of precision, rounded down. One above 65,504 seconds stores as 65,504. One below about 0.00003 seconds stores as zero, so the particle never draws.
190
- - Birth times are 32-bit floats, so their precision falls as the buffer's clock grows. A buffer that runs for hours moves its time base. It rewrites the birth times at their new times and tells the shader how far that move has reached. The value in `frame[2]` is the first record that still counts from the old base, and `frame[3]` holds the seconds to take off it. An emitter does this after 1,024 seconds.
202
+ - Birth times are 32-bit floats, so their precision falls as the buffer's clock grows. A buffer that runs for hours moves its time base ([technical details](#what-the-buffer-holds)).
191
203
  - A buffer with a map draws nothing in a frame where the map's image is not yet on the GPU.
192
- - A softness above 0 makes the camera copy its opaque depth in each frame, which is one full-screen pass. The Low preset turns soft particles off.
204
+ - The `softness` value fades particles out over that distance, in meters, where they near the surfaces behind them ([Soft particles](../api/particles.md#soft-particles)). A value above 0 makes the camera copy its opaque depth in each frame, which is one full-screen pass. The Low preset turns soft particles off. The [particles demo](https://github.com/null3d-engine/null3d/tree/main/examples/particles) sets a softness of 0.25 on its campfire flames, so they meet the ground softly.
193
205
  - The particles cast no shadow and lights do not light them. A raycast against the object tests its one triangle at the origin, which has no area, so it never hits a particle.
194
206
  - After `destroy()`, the buffer's calls and arrays throw.
195
207
 
196
208
  ## Related pages
197
209
 
198
210
  - [Particles](../api/particles.md): the add-on that makes systems from this buffer, with emitters and sub-emitters.
211
+ - [The particles demo](https://github.com/null3d-engine/null3d/tree/main/examples/particles): the campfire glade draws its flames, embers and smoke from particle buffers.
199
212
  - [Instances and batching](instances.md): typed arrays that sketch code writes, row by row.
200
213
  - [Culling](culling.md): how the engine culls the buffer by its object's bounds.
201
214
  - [GPU tiers and backends](backends.md): the two paths that draw the same particles.
@@ -1,21 +1,25 @@
1
1
  ---
2
2
  id: concepts/post-processing
3
3
  title: The post-processing chain
4
- status: experimental
5
- since: "0.2"
6
4
  summary: "HDR scene color, ambient occlusion and screen-space reflections at half size, custom effects, depth of field with near and far fields, bloom through a chain of mip levels, automatic exposure from a meter on the GPU, an outline mask, and the final pass for the vignette, tone mapping, FXAA, outlines, color grading and dithering, in two steps once the render scale can drop below the whole canvas; still views that blend and then rest the GPU."
7
5
  ---
8
6
 
9
7
  # The post-processing chain
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. The chain has HDR scene color, ambient occlusion, screen-space reflections, custom effects, depth of field, bloom, automatic exposure and outlines. The final pass adds color grading, the vignette, sharpening and custom tone curves. A still view blends and then rests the GPU.
9
+ ![Crates in a neon alley at night, with glowing neon, reflections in the wet ground and a yellow outline round one crate.](../images/concepts/post-processing/post-effects-alley.webp)
10
+
11
+ The post effects demo: built-in bloom, reflections and outline, and the lens kit's custom effect.
12
+
13
+ > The chain has HDR scene color, ambient occlusion, screen-space reflections, screen-space bounce light, custom effects, depth of field, bloom, automatic exposure and outlines. The final pass adds color grading, the vignette, sharpening and custom tone curves. A still view blends and then rests the GPU.
12
14
 
13
15
  ```mermaid
14
16
  flowchart LR
15
17
  prepass["Depth prepass"] --> ao["Ambient occlusion:<br/>three steps at half size"]
16
18
  prepass --> ssr["Screen-space reflections:<br/>a depth pyramid and a trace<br/>at half size"]
19
+ prepass --> bounce["Bounce light:<br/>a trace and a denoise<br/>at half size"]
17
20
  ao --> scene
18
21
  ssr --> scene
22
+ bounce --> scene
19
23
  copy["The frame before's<br/>opaque colors"] --> scene
20
24
  scene["Scene passes:<br/>linear HDR color"] --> fog["Volumetric fog:<br/>adds the light in the fog"]
21
25
  fog --> custom["Custom effects:<br/>joined into few passes"]
@@ -24,7 +28,7 @@ flowchart LR
24
28
  down --> up["Bloom's steps up:<br/>each level blends in<br/>the one below"]
25
29
  dof --> meter["Exposure meter:<br/>a histogram or a downsample<br/>into one texel"]
26
30
  up --> meter
27
- meter --> final["Final pass: blends in bloom,<br/>applies the adapted exposure,<br/>then the vignette,<br/>FXAA and tone mapping"]
31
+ meter --> final["Final pass: applies the adapted exposure,<br/>smooths edges with FXAA,<br/>blends in bloom, then<br/>the vignette and tone mapping"]
28
32
  dof --> final
29
33
  up --> final
30
34
  mask["Outline mask:<br/>outlined objects"] --> line
@@ -34,7 +38,15 @@ flowchart LR
34
38
  scaled --> canvas
35
39
  ```
36
40
 
37
- Ambient occlusion and screen-space reflections run before the scene's opaque objects shade. They read the depth that the depth prepass draws first, and the opaque pass darkens its ambient light with the occlusion and reflects the frame before's colors where the reflections' rays hit. The scene passes draw linear color with no upper limit into a float target, the scene color. The exposure scales each light and each color as it enters the scene, so the scene color holds exposed color. Effects that need that range, such as the volumetric fog's light, the sketch's custom effects, depth of field and bloom, read it before the final pass, in that order. [Lighting and environment](lighting.md#volumetric-fog) describes the volumetric fog. The final pass then does all of its work for each pixel in one pass, while the render scale cannot drop below the whole canvas. It smooths edges with FXAA, adds the effects' results, darkens the edges with the vignette and applies the tone mapping curve: AgX with a punchy look by default, which keeps the hues of bright colors. [Color management](color-management.md#exposure-and-tone-mapping) lists the curves. Then it encodes sRGB, draws the outline's line, and grades the display color with a color grading table, when the sketch sets one. Last, it dithers. [Below the whole canvas's render scale](#below-the-whole-canvass-render-scale) describes how that work splits in two when the scale can drop.
41
+ Each frame draws the scene into a linear HDR target, runs the effects that need that range, then turns the result into the canvas's colors in a final pass. The steps, in order:
42
+
43
+ 1. Before the opaque objects shade, the depth prepass draws depth. Ambient occlusion and screen-space reflections read it.
44
+ 2. The scene passes draw linear color with no upper limit into a float target, the scene color. The exposure scales each light and color as it enters, so the scene color holds exposed color. The opaque pass darkens its ambient light with the occlusion and reflects the frame before's colors where the reflections' rays hit.
45
+ 3. The HDR effects read the scene color in this order: the volumetric fog's light ([Lighting and environment](lighting.md#volumetric-fog)), custom effects, depth of field, then bloom. The [light shafts demo](https://github.com/null3d-engine/null3d/tree/main/examples/light-shafts) shows that stage at dusk, with sun rays between the trunks.
46
+ 4. The final pass smooths edges with FXAA, adds the effects' results, darkens the edges with the vignette and applies the tone curve: AgX with a punchy look by default, which keeps the hues of bright colors ([Color management](color-management.md#exposure-and-tone-mapping)). Then it encodes sRGB.
47
+ 5. In the same pass, it draws the outline's line, applies the color grading table when the sketch sets one, and dithers last.
48
+
49
+ Steps 4 and 5 run as one pass only while the render scale cannot drop below the whole canvas. Low, Medium and High let it drop, and then the work splits in two ([Below the whole canvas's render scale](#below-the-whole-canvass-render-scale)).
38
50
 
39
51
  Every full-screen pass reads and writes the whole screen once more. On a phone at its full resolution that is tens of megabytes per frame, so the engine keeps such passes few. Bloom's passes draw small levels of a fixed size. The outline draws only a mask of the outlined meshes. The final pass reads their results without a pass of its own.
40
52
 
@@ -57,10 +69,21 @@ export default defineSketch(({ scene, geometry, materials, post }) => {
57
69
 
58
70
  ## Below the whole canvas's render scale
59
71
 
60
- The engine can draw the scene at a lower scale than the canvas, then scale the image up, to hold a frame rate on a slow GPU ([Dynamic resolution](quality-presets.md#dynamic-resolution)). Below the whole canvas's scale, the final pass runs in two steps, while the render scale can drop below 1, which the default presets allow. At the whole canvas's scale, and while the scale cannot drop below 1, one pass does that work, exactly as before the split.
72
+ The engine can draw the scene at a lower scale than the canvas, then scale the image up, to hold a frame rate on a slow GPU ([Dynamic resolution](quality-presets.md#dynamic-resolution)). While the render scale can drop below 1, as it can on the Low, Medium and High presets, the final pass runs in two steps.
73
+
74
+ The first step tone maps the image at the render size into an 8-bit target. The second step scales that target up to the canvas with an upscaler that keeps edges sharp, then draws the outline's line, applies the color grading table and dithers. While the scale cannot drop below 1, one pass does all of this work.
75
+
76
+ <details>
77
+ <summary>Technical details: the two steps and the upscaler</summary>
78
+
79
+ 1. The first step draws at the render size, one pixel for each render pixel. It adds bloom's light and darkens the edges with the vignette. It runs the output transform, which is the tone curve and the sRGB encode. It smooths edges with FXAA too.
61
80
 
62
- 1. The first step draws at the render size, one pixel for each render pixel. It adds bloom's light, darkens the edges with the vignette, and runs the output transform, which is the tone curve and the sRGB encode. It smooths edges with FXAA too. It writes an 8-bit target the size of the canvas, with the image in its corner at the render scale. The second step reads that target as display color. The first step leaves the dither to the second step: that step draws canvas pixels, so the noise lands at the canvas's size.
63
- 2. The second step is the plain final pass. It reads the 8-bit target and scales it up to the whole canvas with GSR 1, Qualcomm's spatial upscaler, which keeps edges sharper than a bilinear filter. The pass blends the four nearest texels as a bilinear filter does, then votes on their green channel to find an edge. Where an edge passes, it weighs twelve texels around the pixel and adds a bounded correction to the blend; a flat area keeps the blend alone. The work runs only where a pixel reads a smaller corner on the canvas, so an image at the whole canvas's scale pays nothing for it. Then the pass sharpens the display color while the sketch asks for it ([Sharpening](#sharpening)), darkens the edges with the vignette, draws the outline's line, applies the color grading table, when the sketch sets one, and dithers.
81
+ It writes an 8-bit target the size of the canvas, with the image in its corner at the render scale. The second step reads that target as display color. The first step leaves the dither to the second step: that step draws canvas pixels, so the noise lands at the canvas's size.
82
+ 2. The second step is the plain final pass. It reads the 8-bit target and scales it up to the whole canvas with GSR 1, Qualcomm's spatial upscaler, which keeps edges sharper than a bilinear filter. The pass blends the four nearest texels as a bilinear filter does, then votes on their green channel to find an edge.
83
+
84
+ Where an edge passes, it weighs twelve texels around the pixel and adds a bounded correction to the blend. A flat area keeps the blend alone. The work runs only where a pixel reads a smaller corner on the canvas, so an image at the whole canvas's scale pays nothing for it. Then the pass sharpens the display color while the sketch asks for it ([Sharpening](#sharpening)). It draws the outline's line, applies the color grading table when the sketch sets one, and dithers.
85
+
86
+ </details>
64
87
 
65
88
  The two steps also draw at the whole canvas's scale while the sketch sets `sharpen`, since the sharpening reads display color. Without it, one pass does the work there, as the sections below describe.
66
89
 
@@ -88,7 +111,7 @@ Bloom spreads light from the bright parts of the scene into their surroundings,
88
111
  | `blend` | `'mix'`, `'add'` or `'screen'`. | `'mix'` |
89
112
  | `weights` | Up to 10 numbers of 0 or more: each level's share of the glow, from the narrowest level to the widest. Not all 0. | Shares for 8 levels |
90
113
 
91
- - The `'mix'` blend moves each pixel's color toward the glow by the intensity, so the image keeps its total light. A lit wall keeps its brightness and turns softer. `'add'` adds the glow, as three.js's `UnrealBloomPass` does, and `'screen'` screens it, as pmndrs's `BloomEffect` does.
114
+ - The `'mix'` blend moves each pixel's color toward the glow by the intensity, so the image keeps its total light. A lit wall keeps its brightness and turns softer. The `'add'` blend adds the glow, so the image gains light. The `'screen'` blend screens it, so the glow adds less where the scene is already bright.
92
115
  - At a threshold of 0, all light glows a little, as in a real lens. At 1, only light brighter than white glows, such as an emissive material with an `emissiveIntensity` above 1.
93
116
  - The levels have the canvas's shape and a fixed number of texels on its shorter side. So the glow keeps its size as a share of the screen at any pixel ratio, render scale and screen orientation.
94
117
  - Each level spreads light twice as far as the one before. The eighth spreads it over about a quarter of the canvas's shorter side, and the tenth over all of it. The engine divides the weights by their sum. The default gives eight levels a share, most to the narrow ones, for a soft glow that keeps the shape of the light.
@@ -121,6 +144,10 @@ With the default weights, bloom draws 15 small passes: 8 steps down and 7 steps
121
144
 
122
145
  Depth of field blurs what lies in front of and behind the focus distance, as a camera lens does. Each pixel's blur is the circle of confusion of a thin lens, from the pixel's depth, the focal length, the aperture and the focus distance. The near field, what lies in front of the focus, and the far field, what lies behind it, blur apart:
123
146
 
147
+ ![A low view across a chess board: the far king is sharp, and the near pawns and the string lights are blurred.](../images/concepts/post-processing/depth-of-field.webp)
148
+
149
+ Depth of field in the camera lens demo.
150
+
124
151
  1. The setup step reads four pixels of the scene's color and depth for each texel of a target at half the render size. It finds each pixel's blur, and writes their color with the smallest blur. In-focus color counts less in the average, so sharp detail does not bleed into the blur.
125
152
  2. The gather reads a spiral of taps over a disk around each texel, or over a polygon when the aperture has blades. A tap adds to the far field only where both its own blur and the texel's reach it. It adds to the near field wherever its own blur reaches the texel.
126
153
  3. A small tent filter smooths the gather.
@@ -163,6 +190,10 @@ Depth of field adds three passes at half the render size and one at the render s
163
190
 
164
191
  Automatic exposure adapts the picture to the scene's brightness, as an eye or a camera does. A meter on the GPU reads the color that the final pass reads, in the same frame. It writes the adapted exposure into one texel, and the final pass multiplies the color by it before FXAA, the vignette and the tone curve.
165
192
 
193
+ ![A stone hall and a pool under a blue sky, lit after automatic exposure adapted to the scene.](../images/concepts/post-processing/auto-exposure.webp)
194
+
195
+ The stone hall with automatic exposure on.
196
+
166
197
  ```ts
167
198
  post.set({ autoExposure: { minEv: -6, speedDown: 0.7 } });
168
199
  ```
@@ -212,7 +243,9 @@ post.addEffect({ wgsl: warm });
212
243
  - Effects run after the scene passes and before depth of field and bloom, on linear HDR color after the exposure. Light that an effect adds can glow, and the tone curve maps it with the rest.
213
244
  - Each effect reads the color that the effect before it wrote. It can read any pixel, and the scene's depth on every GPU path.
214
245
  - Effects run from the lowest `order` to the highest, at most 8 at once.
215
- - An effect that calls `effectBloom(input.uv)` reads a level of bloom's chain, and `bloomLevel` names which level, from 0 for the narrowest glow. The chain then draws before the effects, from the scene color rather than from their output, and the final pass still blends its glow into the picture after them. A streak, a glare or a halo reads the level that suits its width instead of blurring the picture again. Such an effect draws in a pass of its own, as an effect with textures does, and a level that the chain does not draw reads black.
246
+ - An effect that calls `effectBloom(input.uv)` reads a level of bloom's chain, and `bloomLevel` names which level, from 0 for the narrowest glow. The chain then draws before the effects, from the scene color rather than from their output, and the final pass still blends its glow into the picture after them.
247
+
248
+ A streak, a glare or a halo reads the level that suits its width instead of blurring the picture again. Such an effect draws in a pass of its own, as an effect with textures does, and a level that the chain does not draw reads black.
216
249
  - Two targets of the render size serve all the effects. The render graph lets them share memory, because each effect's target lives only until the next effect has read it.
217
250
  - A full-screen pass reads and writes 8 bytes per pixel. The engine joins an effect that reads only its own pixel into the pass of the effect before it, while the render scale cannot drop below the whole canvas. With bloom and FXAA off, the last of these passes folds into the final pass then too. While the scale can drop, each effect draws a pass of its own, at every scale ([below the whole canvas's render scale](#below-the-whole-canvass-render-scale)). [Custom passes](../guides/custom-passes.md#cost) gives the rules.
218
251
 
@@ -220,7 +253,7 @@ A custom tone curve replaces the built-in curves. Its WGSL declares `fn toneCurv
220
253
 
221
254
  ## Ambient occlusion
222
255
 
223
- Ambient occlusion darkens the light that comes from all around where nearby surfaces hide a surface from it. That happens in corners, in creases and under objects that rest on the ground. It follows three.js's `GTAOPass` step by step, at half the render size:
256
+ Ambient occlusion darkens the light that comes from all around where nearby surfaces hide a surface from it. That happens in corners, in creases and under objects that rest on the ground. It uses ground-truth ambient occlusion (GTAO), at half the render size:
224
257
 
225
258
  1. The depth prepass draws the opaque objects' depth. Ambient occlusion turns the prepass on while it draws.
226
259
  2. A first step copies the depth of one pixel under each texel.
@@ -242,8 +275,7 @@ post.set({ ao: { radius: 0.5, intensity: 1 } });
242
275
  | `samples` | The depth samples of each pixel's search, a whole number from 1 to 64: 3 directions below 30, and 5 from 30. | 16 |
243
276
  | `intensity` | From 0 to 1: how much of the occlusion reaches the ambient light. | 1 |
244
277
 
245
- - The settings mean what `GTAOPass`'s settings mean, with the same search and blur. In the engine's parity tests, with `GTAOPass`'s defaults, null3D's image differs from three.js's in under 0.1% of the pixels on every GPU path. With a wider, darker search, under 1% differ, along the soft edges of the darkened areas.
246
- - `GTAOPass` darkens the whole image, direct light and highlights included. null3D darkens only the ambient light, and the light that light maps add. A surface in the sun keeps its sunlight in a corner, as it would in the real world. In a scene that only ambient light lights, the two give the same image.
278
+ - It darkens only the ambient light, and the light that light maps add. Direct light and highlights keep their strength, so a surface in the sun keeps its sunlight in a corner, as in the real world.
247
279
  - Blended objects draw over the surfaces that ambient occlusion saw, so they take none.
248
280
  - The depth prepass leaves out masked surfaces and levels of detail while they fade, so ambient occlusion may see only what lies behind them. Such a surface takes the occlusion only where ambient occlusion saw a surface at its own depth, such as a leaf on the ground. A petal in front of grass takes none of the grass's occlusion.
249
281
  - `post.set({ ao: false })` turns ambient occlusion off. The settings keep their values, so `post.set({ ao: {} })` turns it on again with them.
@@ -261,7 +293,7 @@ Ambient occlusion needs no HDR color, so it draws on the 8-bit path too. Its tar
261
293
 
262
294
  ### Cost
263
295
 
264
- Ambient occlusion adds the depth prepass and three small passes at half the render size. It also adds four texture reads to each pixel that the opaque pass shades. The engine's ambient occlusion scene ran on a MacBook Pro in Chrome, at 3,024 x 1,518 pixels. There it added 2.42 ms of GPU time per frame. three.js's `GTAOPass` added about 5.3 ms to the same scene and canvas. At a render scale of 0.5 it added 1.18 ms.
296
+ Ambient occlusion adds the depth prepass and three small passes at half the render size. It also adds four texture reads to each pixel that the opaque pass shades. The engine's ambient occlusion scene ran on a MacBook Pro in Chrome, at 3,024 x 1,518 pixels. There it added 2.42 ms of GPU time per frame, and 1.18 ms at a render scale of 0.5. three.js's `GTAOPass` added about 5.3 ms to the same scene and canvas, more than twice as much.
265
297
 
266
298
  - Its targets follow the render scale, so a lower scale costs less, and a new scale makes no new target. They take 20 bytes per texel at half size, 5 bytes per pixel of the canvas. They exist only while ambient occlusion draws.
267
299
  - The depth prepass costs a second pass over the opaque objects' vertices. In a scene with many vertices it adds time of its own. [Quality presets](quality-presets.md#the-depth-prepass) says when the prepass pays.
@@ -272,6 +304,10 @@ Ambient occlusion adds the depth prepass and three small passes at half the rend
272
304
 
273
305
  Screen-space reflections make shiny opaque surfaces reflect what the screen shows along their mirror direction. A wet street shows the lamps and windows above it, a polished floor the furniture on it, and a metal pipe the wall beside it. They work in four steps, the first three at the size of ambient occlusion's grid:
274
306
 
307
+ ![Puddles that mirror lit windows and neon signs.](../images/concepts/post-processing/ssr-wet-street.webp)
308
+
309
+ Screen-space reflections in the wet street demo.
310
+
275
311
  1. The depth prepass draws the opaque objects' depth, and a first step copies the depth of one pixel under each texel, as for ambient occlusion.
276
312
  2. Six small steps build a depth pyramid. Each texel of a level keeps the nearest depth of the four texels under it, so a level shows where nothing stands in front of a ray.
277
313
  3. The trace rebuilds each surface's normal from the depth, and marches its mirror ray through the pyramid. Where a cell holds nothing nearer than the ray, the ray crosses the whole cell and climbs to a larger one. Where it does, the ray drops to a smaller cell, until it meets a surface. A hit counts only where the ray passes no further behind that surface than `thickness`. The trace keeps the ray's length.
@@ -303,7 +339,9 @@ Screen-space reflections and ambient occlusion share one grid, at the larger of
303
339
 
304
340
  ### Cost
305
341
 
306
- The reflections add the depth prepass, the depth copy, six small steps for the pyramid, the trace and the copy of the opaque colors with its mip levels. Transmission shares that copy. The opaque pass reads four texels of the screen texture at each pixel, the same reads that ambient occlusion and contact shadows use. It adds one filtered read to each pixel of a smooth enough surface. While the reflections are off, the frame has none of these passes or targets, and the shaders download only when a sketch first turns them on.
342
+ The reflections add the depth prepass, the depth copy, six small steps for the pyramid, the trace and the copy of the opaque colors with its mip levels. Transmission shares that copy.
343
+
344
+ The opaque pass reads four texels of the screen texture at each pixel, the same reads that ambient occlusion and contact shadows use. It adds one filtered read to each pixel of a smooth enough surface. While the reflections are off, the frame has none of these passes or targets, and the shaders download only when a sketch first turns them on.
307
345
 
308
346
  The engine's benchmark scene of 100,000 boxes over a polished floor ran on a MacBook Pro in Chrome. With WebGPU, the reflections added about 0.7 ms of GPU time per frame on Medium, at a quarter of the render size. On High, at half the size, they added about 1.8 ms. On WebGL2 they added between 0.25 and 1.24 ms. They added no CPU time beyond the noise.
309
347
 
@@ -315,6 +353,12 @@ The engine's benchmark scene of 100,000 boxes over a polished floor ran on a Mac
315
353
 
316
354
  Screen-space bounce light adds one bounce of the indirect light that the camera's view shows. A red wall throws red light onto the floor beside it. A green wall throws green light onto the other side. The environment's light is one color for every direction, so it cannot show that.
317
355
 
356
+ ![A room without and with bounce light: with it, the floor turns red and green near the walls.](../images/concepts/post-processing/bounce-light.webp)
357
+
358
+ Bounce light off and on.
359
+
360
+ Bounce light needs no `post.set` call. The High and Ultra presets draw it, and so does Medium on WebGL2. While it draws, the depth prepass runs too. `quality.set({ bounceRays: 0 })` turns it off.
361
+
318
362
  A mirror's color holds what it shows this view, not light that its surface sends every way, so the gather leaves out what lies on the plane of a mirror view: the first two mirrors of a scene, and water's reflection among them. A glossy surface with no mirror view, such as a floor that screen-space reflections draw, still sends its color. No buffer holds a surface's roughness for the gather to read.
319
363
 
320
364
  The light draws on ambient occlusion's grid, at half the render size, and it reuses that feature's depth copy and normals:
@@ -327,7 +371,7 @@ The light draws on ambient occlusion's grid, at half the render size, and it reu
327
371
  quality.set({ bounceRays: 8 });
328
372
  ```
329
373
 
330
- - The quality setting `bounceRays` is the number of rays each texel casts: 0 draws none. High sets 4 and Ultra 8. Low and Medium set 0, and WebGL2, which ends at Medium, sets 4 there. A change takes effect during play and makes no GPU object. At 1920 by 1080 the light costs 2.475 ms at High and 1.326 at Ultra on WebGPU, and 0.825 ms at WebGL2's Medium.
374
+ - The quality setting `bounceRays` is the number of rays each texel casts: 0 draws none. High sets 4 and Ultra 8. Low and Medium set 0, and WebGL2, which ends at Medium, sets 4 there. A change takes effect during play and makes no GPU object.
331
375
  - The light is one frame behind the scene, as screen-space reflections are. The first frame after it turns on shows none.
332
376
  - The light draws nothing on the 8-bit path, whose copy holds display color. Compatibility mode draws that path, so it draws no bounce light.
333
377
  - A scene with a [light probe grid](lighting.md#light-probe-grid) draws no bounce light. The grid already holds one bounce, with the validity and sky-occlusion terms that the screen cannot supply.
@@ -335,7 +379,7 @@ quality.set({ bounceRays: 8 });
335
379
 
336
380
  ### Cost
337
381
 
338
- The light costs two passes at half the render size and a few texture reads in the opaque pass. At 1920 x 1080 on the Mac it added 2.5 ms at High and 1.3 ms at Ultra on WebGPU. It added 0.8 ms at WebGL2's Medium. At half the render scale it adds about a millisecond.
382
+ The light costs two passes at half the render size and a few texture reads in the opaque pass. At 1920 x 1080 on the Mac it added 2.5 ms at High and 1.3 ms at Ultra on WebGPU. It added 0.8 ms at WebGL2's Medium. At half the render scale it adds about a millisecond. Ultra's eight rays measured a little less than High's four. The gap is within the spread between runs, so expect about the same cost on both.
339
383
 
340
384
 
341
385
  ## Outlines
@@ -350,7 +394,7 @@ Outlines draw a crisp line around the meshes that `setOutlined(true)` marks:
350
394
 
351
395
  - The line has no blur, so it ends as sharply as the meshes' own edges. Its width counts pixels of the canvas, so it stays sharp at every pixel ratio and render scale.
352
396
  - The mask pass culls the outlined meshes with the camera's view on its own, so outlined meshes out of view cost nothing.
353
- - three.js draws every other object's depth again for its hidden parts. The mask pass reads the depth that the scene passes drew instead.
397
+ - The mask pass finds the hidden parts from the depth that the scene passes drew, so it draws no other object again.
354
398
  - The 8-bit path draws the same line as the HDR path.
355
399
  - While nothing is outlined, the mask pass and the mask are off, so turning outlines on costs nothing until a mesh is outlined.
356
400
 
@@ -360,20 +404,25 @@ Outlines draw the outlined meshes twice into the mask, which takes 4 bytes per p
360
404
 
361
405
  ## Color grading and the vignette
362
406
 
363
- A color grading table, from a `.cube` or a `.3dl` file through `assets.loadLut` or from numbers through `assets.lutFromData`, maps each display color to a graded color, as three.js's `LUTPass` does after its `OutputPass`. The vignette darkens the picture toward its edges. [The post-processing API](../api/post.md#color-grading) lists their settings.
407
+ A color grading table, from a `.cube` or a `.3dl` file through `assets.loadLut` or from numbers through `assets.lutFromData`, maps each display color to a graded color. The vignette darkens the picture toward its edges. [The post-processing API](../api/post.md#color-grading) lists their settings.
364
408
 
365
- - The vignette multiplies HDR color before the tone mapping, as Filament, Unity's URP, Bevy and Babylon.js do. Bright corners then darken as dark corners do. three.js's `VignetteShader` blends display color toward a gray after the tone mapping, which turns bright corners gray.
409
+ - The vignette multiplies HDR color before the tone mapping, as Filament, Unity's URP, Bevy and Babylon.js do. Bright corners then darken as dark corners do, and never turn gray.
366
410
  - The grading controls work on display color, after the tone mapping, as most grading tools do. A `.cube` or `.3dl` table works there too: grading tools make tables for display color, so they look as their authors made them.
367
411
  - Both draw on every GPU path, with HDR color or without it, as [Post-processing API](../api/post.md#vignette) says.
368
412
  - They are settings of the final pass, not passes of their own. Turning one on builds no pipeline, so the picture changes in the next frame with no pause.
369
413
  - Each table is a 3D texture, read with one filtered texture read per pixel. The vignette costs a few operations per pixel.
370
- - The grading controls' table holds 32 texels a side, and the final pass takes the square root of a color before it reads the table, which places the texels closer together toward black where a grade's curve is steepest. A job worker computes the table's texels, so a value that changes stalls no frame. The frame that lands a bake uploads the table, 256 KB. The table keeps the worker's whole range, past white, and the canvas clips it, so a color that crosses white inside a texel's cell still matches the grade.
371
- - The engine's parity test compares a `.cube` table alone with three.js's composer. It matches in all but under 0.1% of the pixels on every GPU path. With the vignette too, mapped from `VignetteShader`'s settings for AgX, it matches as closely.
414
+ - The grading controls' table holds 32 texels a side, and the final pass takes the square root of a color before it reads the table, which places the texels closer together toward black where a grade's curve is steepest.
415
+
416
+ A job worker computes the table's texels, so a value that changes stalls no frame. The frame that lands a bake uploads the table, 256 KB. The table keeps the worker's whole range, past white, and the canvas clips it, so a color that crosses white inside a texel's cell still matches the grade.
372
417
 
373
418
  ## Sharpening
374
419
 
375
420
  Sharpening makes edges and fine detail crisper, as a lens that is stopped down does. `post.set({ sharpen: 0.5 })` turns it on with half its strength, and it is off by default. [The post-processing API](../api/post.md#sharpening) lists its setting.
376
421
 
422
+ ![A small patch of fine detail before and after sharpening, enlarged.](../images/concepts/post-processing/sharpen.webp)
423
+
424
+ Sharpening, enlarged 4 times.
425
+
377
426
  - It works on display color, after the tone mapping and the sRGB encoding, as FSR 1's RCAS does at the end of its chain. Sharpening light before the tone curve lets a bright edge gain colored rings, so the engine sharpens what the canvas shows.
378
427
  - RCAS is robust contrast-adaptive sharpening. Each pixel reads the four neighbors that cross it. The pass takes a share of them that grows where they form an edge, and shrinks it where the ring around the pixel is noise. Flat areas and grain therefore stay as they are. It also limits the result to the colors' own range, so no channel clips and no dark or bright halo appears.
379
428
  - It draws at the whole canvas's render scale. A render scale below 1 sharpens its own upscale, so the value adds nothing there.
@@ -391,7 +440,12 @@ An 8-bit canvas holds 256 steps of each color, and a smooth gradient between two
391
440
 
392
441
  ## Still-camera accumulation
393
442
 
394
- When nothing in the view changes, the engine sharpens the picture and then stops drawing. Each frame draws the scene with the camera moved by a fraction of a pixel, and blends into a kept 16-bit history. After 63 blended frames, about a second at 60 frames per second, the history holds their average. Its edges and fine detail are smoother than any one frame's. The thread that draws then takes frames without drawing them, so the GPU rests, and the canvas keeps the sharp picture. The first frame that changes draws at once, as a moving view does, and the blending starts again.
443
+ A still view goes through these steps:
444
+
445
+ 1. Each frame draws the scene with the camera moved by a fraction of a pixel, and blends it into a kept 16-bit history.
446
+ 2. After 63 blended frames, about a second at 60 frames per second, the history holds their average. Its edges and fine detail are smoother than any one frame's.
447
+ 3. The thread that draws then takes frames without drawing them, so the GPU rests, and the canvas keeps the sharp picture.
448
+ 4. The first frame that changes draws at once, as a moving view does, and the blending starts again.
395
449
 
396
450
  The engine finds a still view by comparing each frame's draw commands and uploaded values with those of the frame two frames before. It leaves out only the values that change on their own in every frame: the clock, the sub-pixel offset and the blend's weight. Anything else that changes counts as a change, so the picture never freezes while something moves. The sketch keeps running while the view rests, so `onUpdate` sees input and time as before.
397
451
 
@@ -410,26 +464,6 @@ Bloom, depth of field, automatic exposure, custom effects and custom tone curves
410
464
 
411
465
  The devices that the engine was tested on all draw HDR color with WebGL2, and with core WebGPU.
412
466
 
413
- ## Porting from three.js
414
-
415
- - Delete `EffectComposer`, `RenderPass` and `OutputPass`. The scene pass and the final pass are built in.
416
- - `new UnrealBloomPass(resolution, strength, radius, threshold)` becomes `post.set({ bloom })` with `blend: 'add'`, the same `threshold` and a `knee` of 0.01. The intensity is about 8.8 times `strength`, and `radius` becomes the `weights`. The `null3d-port-threejs` skill holds a table of weights by radius, and a script that maps the settings for a canvas size. The resolution is the canvas's, so it needs no setting.
417
- - three.js's glow spans a number of pixels, and null3D's a share of the screen. So a mapping matches at one canvas size, 1080 pixels on the shorter side by default. On a larger screen null3D's glow looks wider than three.js's.
418
- - A strong bloom spreads a little wider at the edges of the frame than three.js's. three.js's faint haze fades toward the corners, and null3D's keeps its light there. To soften it, lower `strength` or `radius` before you map the settings, or lower `intensity`.
419
- - pmndrs's `BloomEffect` maps the same way, with `blend: 'screen'`: its `intensity` stays, `luminanceThreshold` becomes `threshold`, and `luminanceSmoothing` becomes `knee`. three.js's `bloom()` node maps as `UnrealBloomPass` does, at a third of the intensity.
420
- - `new BokehPass(scene, camera, { focus, aperture, maxblur })` becomes `post.set({ dof: { focusDistance: focus, maxBlur } })`, with the lens's `aperture` as an f-number. `BokehPass`'s aperture scales its blur with the distance from the focus. null3D's lens blurs as a camera does, so set `camera.setFocalLength` and pick an f-number by eye, such as 2.8.
421
- - The `maxblur` of `BokehPass` is a share of the canvas's width, and `maxBlur` is a share of its height. Multiply it by the aspect ratio. In one pass, `BokehPass` blurs each pixel by its own depth, so a sharp object spreads a halo into a blurred background. null3D's near and far fields spread no halo.
422
- - `new GTAOPass(scene, camera, width, height)` becomes `post.set({ ao: {} })`. Its `updateGtaoMaterial({ radius, thickness, distanceExponent, distanceFallOff, scale, samples })` settings keep their names, with `distanceFalloff` spelled so, and `blendIntensity` becomes `intensity`. Set `quality.set({ aoScale: 0.5 })` too where phones and tablets should draw it.
423
- - `SSAOPass`, `SAOPass` and the N8AO library also become `post.set({ ao })`. Their settings have other meanings, so start from the defaults and tune `radius` and `scale` by eye.
424
- - `new OutlinePass(resolution, scene, camera, selectedObjects)` becomes `post.set({ outline: { color, hiddenColor, width } })`, from `visibleEdgeColor` and `hiddenEdgeColor`. `OutlinePass` draws its edge at half size, so a `width` of twice its `edgeThickness` gives about the same line. three.js draws a dark brown line around hidden parts by default, and null3D draws none until `hiddenColor` is set. Each selected mesh calls `setOutlined(true)`. A selected model's copy from `scene.instantiate` calls it once for all of its meshes.
425
- - A port that needs `OutlinePass`'s soft edge, its glow or its pulse installs `@null3d/three-compat` and calls `createOutlinePass(ctx, { color, hiddenColor, strength, thickness, glow, pulsePeriod })`. Its settings keep `edgeStrength`, `edgeThickness`, `edgeGlow` and `pulsePeriod`, and `visibleEdgeColor` and `hiddenEdgeColor` become `color` and `hiddenColor`. The add-on turns the core's crisp line off, and it costs five full-screen passes and one effect ([three.js compatibility](../api/three-compat.md)).
426
- - three.js has no automatic exposure. pmndrs's `ToneMappingEffect` with `mode: ToneMappingMode.REINHARD2_ADAPTIVE` adapts, and becomes `post.set({ autoExposure: { metering: 'mean' } })`. Its `adaptationRate` becomes about `speedUp` and `speedDown`, and its `middleGrey` the `compensation`: `log2(middleGrey / 0.18)` stops. Its Reinhard curve becomes a custom tone curve. pmndrs meters a mip chain of the whole frame. null3D meters on the GPU with center weighting, so the result differs a little.
427
- - `renderer.toneMapping` and `toneMappingExposure` become `post.set({ toneMapping, exposure })`. three.js applies no tone mapping by default, and null3D applies punchy AgX. A port that set `AgXToneMapping` sets `'agx'`, and one that set `ACESFilmicToneMapping` sets `'aces'`. `ReinhardToneMapping` and `CineonToneMapping` become the `reinhard` and `cineon` curves of `@null3d/three-compat`. The exposure gives the same picture: null3D applies it to each light rather than at the end, and bloom's threshold keeps its meaning.
428
- - `new LUTPass({ lut: result.texture3D, intensity })` after a `LUTCubeLoader` or `LUT3dlLoader` becomes `post.set({ lut: await assets.loadLut(url), lutIntensity: intensity })`. A `Data3DTexture` that code fills becomes `await assets.lutFromData({ size, data })`.
429
- - A `ShaderPass(VignetteShader)` with its `offset` and `darkness` uniforms becomes `post.set({ vignette: { size: offset, intensity: darkness } })`. Under ACES the default falloff gives a close match. Under AgX, keep `intensity` at 1 or less and set `falloff` to 3. With a `darkness` below 1, three.js also lifts dark corners toward a gray, and null3D does not.
430
- - `new SharpenNode(target, sharpness, denoise)` becomes `post.set({ sharpen })`. Both sharpen display color with FSR 1's RCAS over the same five texels. null3D draws it in the final pass, so the port needs no render target and no pass of its own. The two settings count the other way round. three.js scales the sharpening by `2^-sharpness`, where 0 sharpens the most and 2 does nothing. So `sharpen` takes that factor: three.js's default of 0.2 is `sharpen: 0.87`, and `sharpen: 0.5` is stronger than three.js's default. null3D always damps the sharpening where the ring around a pixel is noise, which three.js does only with `denoise: true`.
431
- - Any other `ShaderPass` becomes `post.addEffect` with the shader rewritten in WGSL. A pass after `OutputPass` saw display color, and an effect sees linear HDR color. Numbers that assume colors from 0 to 1 may need changes. `CustomToneMapping` becomes a custom tone curve, and `ReinhardToneMapping` and `CineonToneMapping` take the curves of `@null3d/three-compat`. [Porting post-processing](../porting/threejs-postprocessing.md) shows both.
432
-
433
467
  ## Related pages
434
468
 
435
469
  - [Post-processing API](../api/post.md): `post.set` and its settings, and `post.addEffect`.
@@ -440,3 +474,10 @@ The devices that the engine was tested on all draw HDR color with WebGL2, and wi
440
474
  - [Color management](color-management.md): HDR color, the final pass and the 8-bit path.
441
475
  - [The render graph](render-graph.md): how the passes of a frame are declared and ordered.
442
476
  - [Quality presets](quality-presets.md): `bloomSize`, `aoScale`, `dofSamples`, the depth prepass and the frame-budget governor.
477
+ - [The whole chain](https://github.com/null3d-engine/null3d/tree/main/examples/post-effects): bloom, ambient occlusion, an outline, depth of field, a vignette, sharpening and color grading in one neon alley.
478
+ - [Depth of field](https://github.com/null3d-engine/null3d/tree/main/examples/camera-lens): the focus racks across a chess board during a dolly zoom.
479
+ - [Automatic exposure](https://github.com/null3d-engine/null3d/tree/main/examples/auto-exposure): a walk from a sunny courtyard into a dark hall.
480
+ - [Screen-space reflections](https://github.com/null3d-engine/null3d/tree/main/examples/wet-street): puddles that mirror the lit windows, the neon signs and a passing taxi.
481
+ - [Screen-space bounce light](https://github.com/null3d-engine/null3d/tree/main/examples/bounce-light): red and green walls that tint a gray floor and back wall.
482
+ - [Outlines](https://github.com/null3d-engine/null3d/tree/main/examples/picking): a click outlines the selected piece, and the hidden parts keep their own line.
483
+ - [Color grading tables](https://github.com/null3d-engine/null3d/tree/main/examples/compare/night-town): a city block whose color grade comes from a table, in both engines.