@null3d/engine 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. package/dist/wasm/single/null3d.js +10 -8
  2. package/dist/wasm/single/null3d_bg.wasm +0 -0
  3. package/dist/wasm/threaded/null3d.js +10 -8
  4. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  5. package/docs/api/animation.md +96 -24
  6. package/docs/api/assets.md +99 -29
  7. package/docs/api/cameras.md +38 -7
  8. package/docs/api/controls.md +47 -23
  9. package/docs/api/debug.md +105 -35
  10. package/docs/api/engine.md +108 -32
  11. package/docs/api/feature-draws.md +21 -15
  12. package/docs/api/feature-effects.md +8 -8
  13. package/docs/api/feature-instances.md +68 -17
  14. package/docs/api/features.md +68 -37
  15. package/docs/api/geometry.md +83 -14
  16. package/docs/api/grass.md +55 -13
  17. package/docs/api/impostors.md +92 -50
  18. package/docs/api/input.md +22 -9
  19. package/docs/api/lights.md +67 -16
  20. package/docs/api/lines.md +38 -13
  21. package/docs/api/materials.md +187 -59
  22. package/docs/api/math.md +6 -6
  23. package/docs/api/objects.md +40 -15
  24. package/docs/api/page.md +58 -7
  25. package/docs/api/particles.md +36 -11
  26. package/docs/api/points.md +18 -8
  27. package/docs/api/post.md +57 -23
  28. package/docs/api/quality.md +36 -16
  29. package/docs/api/raycast.md +57 -24
  30. package/docs/api/reference/animation.md +1 -2
  31. package/docs/api/reference/assets.md +7 -4
  32. package/docs/api/reference/cameras.md +3 -2
  33. package/docs/api/reference/controls.md +59 -2
  34. package/docs/api/reference/debug.md +58 -6
  35. package/docs/api/reference/engine.md +39 -10
  36. package/docs/api/reference/feature-draws.md +3 -4
  37. package/docs/api/reference/feature-effects.md +2 -3
  38. package/docs/api/reference/feature-instances.md +5 -4
  39. package/docs/api/reference/features.md +7 -4
  40. package/docs/api/reference/geometry.md +132 -21
  41. package/docs/api/reference/grass.md +62 -2
  42. package/docs/api/reference/impostors.md +120 -16
  43. package/docs/api/reference/input.md +1 -2
  44. package/docs/api/reference/lights.md +4 -3
  45. package/docs/api/reference/lines.md +3 -4
  46. package/docs/api/reference/materials.md +7 -6
  47. package/docs/api/reference/math.md +13 -2
  48. package/docs/api/reference/objects.md +2 -3
  49. package/docs/api/reference/particles.md +31 -6
  50. package/docs/api/reference/points.md +2 -3
  51. package/docs/api/reference/post.md +4 -3
  52. package/docs/api/reference/quality.md +1 -2
  53. package/docs/api/reference/raycast.md +1 -2
  54. package/docs/api/reference/render.md +4 -3
  55. package/docs/api/reference/scene.md +24 -5
  56. package/docs/api/reference/sketch.md +11 -11
  57. package/docs/api/reference/sound.md +33 -2
  58. package/docs/api/reference/splats.md +42 -3
  59. package/docs/api/reference/sprites.md +2 -3
  60. package/docs/api/reference/tasks.md +16 -3
  61. package/docs/api/reference/terrain.md +26 -5
  62. package/docs/api/reference/textures.md +1 -2
  63. package/docs/api/reference/three-compat.md +18 -7
  64. package/docs/api/reference/time.md +1 -2
  65. package/docs/api/reference/ui.md +10 -7
  66. package/docs/api/reference/vertex-draws.md +2 -3
  67. package/docs/api/reference/water.md +78 -5
  68. package/docs/api/reference/wind.md +15 -2
  69. package/docs/api/render.md +67 -25
  70. package/docs/api/scene.md +129 -36
  71. package/docs/api/sketch.md +45 -19
  72. package/docs/api/sound.md +48 -12
  73. package/docs/api/splats.md +42 -15
  74. package/docs/api/sprites.md +8 -6
  75. package/docs/api/tasks.md +31 -22
  76. package/docs/api/terrain.md +44 -12
  77. package/docs/api/textures.md +61 -12
  78. package/docs/api/three-compat.md +15 -7
  79. package/docs/api/time.md +3 -5
  80. package/docs/api/ui.md +18 -10
  81. package/docs/api/vertex-draws.md +13 -12
  82. package/docs/api/water.md +111 -67
  83. package/docs/api/wind.md +61 -15
  84. package/docs/cli/null3d.md +90 -15
  85. package/docs/concepts/architecture.md +69 -23
  86. package/docs/concepts/assets.md +57 -16
  87. package/docs/concepts/backends.md +65 -25
  88. package/docs/concepts/color-management.md +42 -13
  89. package/docs/concepts/culling.md +68 -47
  90. package/docs/concepts/handles.md +14 -5
  91. package/docs/concepts/instances.md +72 -23
  92. package/docs/concepts/large-worlds.md +17 -7
  93. package/docs/concepts/lighting.md +117 -44
  94. package/docs/concepts/lod.md +128 -33
  95. package/docs/concepts/materials.md +43 -12
  96. package/docs/concepts/particle-buffer.md +48 -35
  97. package/docs/concepts/post-processing.md +77 -14
  98. package/docs/concepts/quality-preset-tables.md +3 -2
  99. package/docs/concepts/quality-presets.md +122 -39
  100. package/docs/concepts/render-graph.md +56 -21
  101. package/docs/concepts/render-layers.md +9 -5
  102. package/docs/concepts/shadows.md +96 -25
  103. package/docs/concepts/static-dynamic.md +22 -7
  104. package/docs/cookbook/index.md +163 -119
  105. package/docs/data/threejs-mapping.json +301 -340
  106. package/docs/errors/E1101.md +23 -5
  107. package/docs/errors/E1102.md +11 -3
  108. package/docs/errors/E1103.md +11 -3
  109. package/docs/errors/E1104.md +11 -3
  110. package/docs/errors/E1105.md +13 -5
  111. package/docs/errors/E1106.md +11 -3
  112. package/docs/errors/E1107.md +15 -5
  113. package/docs/errors/E1108.md +11 -3
  114. package/docs/errors/E1109.md +32 -6
  115. package/docs/errors/E1110.md +23 -5
  116. package/docs/errors/E1111.md +11 -3
  117. package/docs/errors/E1112.md +11 -3
  118. package/docs/errors/E1203.md +12 -4
  119. package/docs/errors/E1204.md +11 -3
  120. package/docs/errors/E1205.md +11 -3
  121. package/docs/errors/E1206.md +28 -6
  122. package/docs/errors/E1207.md +11 -3
  123. package/docs/errors/E1208.md +12 -3
  124. package/docs/errors/E1209.md +11 -3
  125. package/docs/errors/E1213.md +27 -5
  126. package/docs/errors/E1214.md +11 -3
  127. package/docs/errors/E1215.md +31 -6
  128. package/docs/errors/E1216.md +31 -6
  129. package/docs/errors/E1217.md +29 -6
  130. package/docs/errors/E1218.md +22 -6
  131. package/docs/errors/E1219.md +11 -3
  132. package/docs/errors/E1220.md +24 -5
  133. package/docs/errors/E1221.md +24 -5
  134. package/docs/errors/E1222.md +11 -3
  135. package/docs/errors/E1223.md +39 -6
  136. package/docs/errors/E1224.md +11 -3
  137. package/docs/errors/E1225.md +11 -3
  138. package/docs/errors/E1301.md +11 -3
  139. package/docs/errors/E1302.md +11 -3
  140. package/docs/errors/E1303.md +11 -3
  141. package/docs/errors/E1304.md +11 -3
  142. package/docs/errors/E1305.md +13 -3
  143. package/docs/errors/E1306.md +11 -3
  144. package/docs/errors/E1307.md +23 -6
  145. package/docs/errors/E1401.md +11 -3
  146. package/docs/errors/E1402.md +13 -5
  147. package/docs/errors/E1403.md +11 -3
  148. package/docs/errors/E1404.md +13 -3
  149. package/docs/errors/E1405.md +15 -4
  150. package/docs/errors/E1406.md +31 -5
  151. package/docs/errors/E1407.md +11 -3
  152. package/docs/errors/E1408.md +11 -3
  153. package/docs/errors/E1409.md +11 -3
  154. package/docs/errors/E1410.md +13 -5
  155. package/docs/errors/E1411.md +11 -3
  156. package/docs/errors/E1412.md +29 -6
  157. package/docs/errors/E1413.md +11 -3
  158. package/docs/errors/E1414.md +11 -3
  159. package/docs/errors/E1415.md +11 -3
  160. package/docs/errors/E1416.md +27 -6
  161. package/docs/errors/E1417.md +11 -3
  162. package/docs/errors/E1418.md +12 -3
  163. package/docs/errors/E1419.md +13 -5
  164. package/docs/errors/E1420.md +11 -3
  165. package/docs/errors/E1421.md +11 -3
  166. package/docs/errors/E1422.md +12 -3
  167. package/docs/errors/E1423.md +12 -3
  168. package/docs/errors/E1424.md +24 -5
  169. package/docs/errors/E1425.md +11 -3
  170. package/docs/errors/E1426.md +11 -3
  171. package/docs/errors/E1430.md +11 -3
  172. package/docs/errors/E1431.md +11 -3
  173. package/docs/errors/E1432.md +11 -3
  174. package/docs/errors/E1433.md +11 -3
  175. package/docs/errors/E1434.md +15 -6
  176. package/docs/errors/E1435.md +11 -3
  177. package/docs/errors/E1436.md +11 -3
  178. package/docs/errors/E1437.md +14 -6
  179. package/docs/errors/E1501.md +41 -6
  180. package/docs/errors/E1502.md +13 -3
  181. package/docs/errors/E1503.md +11 -3
  182. package/docs/errors/E1504.md +11 -3
  183. package/docs/errors/E1505.md +23 -5
  184. package/docs/errors/E1506.md +11 -3
  185. package/docs/errors/index.md +52 -29
  186. package/docs/getting-started/cdn.md +15 -9
  187. package/docs/getting-started/first-scene.md +20 -12
  188. package/docs/getting-started/hosting.md +111 -63
  189. package/docs/getting-started/install.md +39 -24
  190. package/docs/getting-started/network-use.md +31 -21
  191. package/docs/getting-started/project-structure.md +20 -8
  192. package/docs/getting-started/third-party-notices.md +6 -10
  193. package/docs/guides/accessibility.md +4 -4
  194. package/docs/guides/add-ons.md +83 -13
  195. package/docs/guides/agents.md +2 -6
  196. package/docs/guides/assets-pipeline.md +248 -72
  197. package/docs/guides/audio.md +17 -15
  198. package/docs/guides/baked-light-data.md +44 -23
  199. package/docs/guides/car-paint.md +37 -31
  200. package/docs/guides/content-pages.md +53 -29
  201. package/docs/guides/custom-passes.md +59 -17
  202. package/docs/guides/custom-shaders.md +54 -37
  203. package/docs/guides/debugging.md +31 -41
  204. package/docs/guides/deploying.md +6 -27
  205. package/docs/guides/deterministic-simulation.md +23 -16
  206. package/docs/guides/first-use-shaders.md +83 -45
  207. package/docs/guides/lens-kit.md +29 -26
  208. package/docs/guides/loading-screens.md +70 -30
  209. package/docs/guides/multiple-views.md +22 -11
  210. package/docs/guides/performance.md +188 -37
  211. package/docs/guides/phones.md +71 -19
  212. package/docs/guides/physics.md +6 -10
  213. package/docs/guides/screens.md +41 -29
  214. package/docs/guides/start-time.md +120 -85
  215. package/docs/guides/testing.md +137 -98
  216. package/docs/guides/ui-overlays.md +17 -12
  217. package/docs/guides/video-textures.md +14 -13
  218. package/docs/images/api/animation/character.webp +0 -0
  219. package/docs/images/api/animation/look-at-ring.webp +0 -0
  220. package/docs/images/api/animation/morph-tulips.webp +0 -0
  221. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  222. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  223. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  224. package/docs/images/api/debug/debug-shapes.webp +0 -0
  225. package/docs/images/api/debug/levels-view.webp +0 -0
  226. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  227. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  228. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  229. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  230. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  231. package/docs/images/api/geometry/generators.webp +0 -0
  232. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  233. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  234. package/docs/images/api/grass/grass-grove.webp +0 -0
  235. package/docs/images/api/grass/grass-presets.webp +0 -0
  236. package/docs/images/api/grass/grass-shadow.webp +0 -0
  237. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  238. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  239. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  240. package/docs/images/api/lights/spot-cookies.webp +0 -0
  241. package/docs/images/api/lines/lines-lit.webp +0 -0
  242. package/docs/images/api/lines/lines-widths.webp +0 -0
  243. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  244. package/docs/images/api/materials/decals.webp +0 -0
  245. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  246. package/docs/images/api/materials/relief.webp +0 -0
  247. package/docs/images/api/materials/shader-inputs.webp +0 -0
  248. package/docs/images/api/materials/standard-grid.webp +0 -0
  249. package/docs/images/api/materials/subsurface.webp +0 -0
  250. package/docs/images/api/materials/translucency.webp +0 -0
  251. package/docs/images/api/objects/objects-turntable.webp +0 -0
  252. package/docs/images/api/particles/campfire.webp +0 -0
  253. package/docs/images/api/points/galaxy.webp +0 -0
  254. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  255. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  256. package/docs/images/api/render/reflection-mirror.webp +0 -0
  257. package/docs/images/api/render/security-camera.webp +0 -0
  258. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  259. package/docs/images/api/sound/sound-demo.webp +0 -0
  260. package/docs/images/api/splats/splats-demo.webp +0 -0
  261. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  262. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  263. package/docs/images/api/textures/canvas-screen.webp +0 -0
  264. package/docs/images/api/textures/mipmaps.webp +0 -0
  265. package/docs/images/api/vertex-draws/rain.webp +0 -0
  266. package/docs/images/api/water/ocean.webp +0 -0
  267. package/docs/images/api/water/water-demo.webp +0 -0
  268. package/docs/images/api/water/water-rain.webp +0 -0
  269. package/docs/images/api/water/waterfall.webp +0 -0
  270. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  271. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  272. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  273. package/docs/images/concepts/instances/instances.webp +0 -0
  274. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  275. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  276. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  277. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  278. package/docs/images/concepts/lighting/environment.webp +0 -0
  279. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  280. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  281. package/docs/images/concepts/lod/forest.webp +0 -0
  282. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  283. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  284. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  285. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  286. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  287. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  288. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  289. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  290. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  291. package/docs/images/cookbook/index/picking.webp +0 -0
  292. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  293. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  294. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  295. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  296. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  297. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  298. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  299. package/docs/images/index/showcase-island.webp +0 -0
  300. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  301. package/docs/images/shaders/builtins/builtins.webp +0 -0
  302. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  303. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  304. package/docs/images/shots.json +2231 -0
  305. package/docs/index.md +14 -23
  306. package/docs/moves.json +1 -0
  307. package/docs/nav.json +300 -0
  308. package/docs/pages.md +230 -212
  309. package/docs/porting/react-three-fiber.md +2 -6
  310. package/docs/porting/threejs-loop-and-threads.md +1 -5
  311. package/docs/porting/threejs-mapping.md +1248 -234
  312. package/docs/porting/threejs-materials.md +10 -5
  313. package/docs/porting/threejs-overview.md +26 -6
  314. package/docs/porting/threejs-postprocessing.md +2 -6
  315. package/docs/porting/threejs-shaders.md +16 -14
  316. package/docs/porting/threejs-unsupported.md +6 -6
  317. package/docs/porting/verification.md +0 -4
  318. package/docs/shaders/builtins.md +15 -4
  319. package/docs/shaders/library.md +9 -6
  320. package/docs/shaders/surface-functions.md +51 -16
  321. package/docs/shaders/wgsl-rules.md +12 -5
  322. package/lib/debug/debug.d.ts +2 -2
  323. package/lib/debug/draw.d.ts +2 -2
  324. package/lib/debug/draw.js +8 -4
  325. package/lib/debug/overlay-look.d.ts +6 -0
  326. package/lib/debug/overlay-look.js +29 -7
  327. package/lib/debug/overlay.js +15 -11
  328. package/lib/debug/stats-options.d.ts +13 -0
  329. package/lib/debug/stats-panel.d.ts +21 -6
  330. package/lib/debug/stats-panel.js +80 -13
  331. package/lib/errors/codes.d.ts +17 -3
  332. package/lib/errors/codes.js +111 -105
  333. package/lib/errors/fixes.js +18 -18
  334. package/lib/gpu/variants.d.ts +8 -2
  335. package/lib/gpu/variants.js +39 -7
  336. package/lib/gpu/webgl2/programs.js +1 -1
  337. package/lib/gpu/webgpu/pipelines.js +13 -13
  338. package/lib/index.d.ts +1 -1
  339. package/lib/page/capabilities.d.ts +1 -1
  340. package/lib/page/engine.d.ts +14 -5
  341. package/lib/page/engine.js +18 -2
  342. package/lib/page/label-loop.js +9 -4
  343. package/lib/page/stats-switch.js +2 -0
  344. package/lib/page/switches.d.ts +6 -4
  345. package/lib/page/switches.js +20 -4
  346. package/lib/scene/baked-light.d.ts +2 -2
  347. package/lib/scene/fake-call-values.js +2 -2
  348. package/lib/scene/frame-cameras.d.ts +16 -4
  349. package/lib/scene/frame-cameras.js +28 -10
  350. package/lib/scene/gltf.d.ts +1 -1
  351. package/lib/scene/level-rule.d.ts +6 -5
  352. package/lib/scene/level-rule.js +2 -2
  353. package/lib/scene/particles.d.ts +7 -3
  354. package/lib/scene/particles.js +3 -1
  355. package/lib/scene/post.d.ts +3 -2
  356. package/lib/scene/resources.d.ts +15 -9
  357. package/lib/scene/scene.d.ts +18 -2
  358. package/lib/scene/scene.js +47 -5
  359. package/lib/scene/time-of-day.d.ts +10 -5
  360. package/lib/scene/time-of-day.js +11 -7
  361. package/lib/shader-artifact.json +1 -1
  362. package/lib/shared/labels.d.ts +5 -2
  363. package/lib/shared/labels.js +5 -2
  364. package/lib/shared/permutation-words.d.ts +2 -0
  365. package/lib/shared/permutation-words.js +8 -0
  366. package/lib/shared/recording.d.ts +13 -5
  367. package/lib/shared/recording.js +31 -10
  368. package/lib/shared/sketch-data.d.ts +9 -0
  369. package/lib/shared/sketch-data.js +57 -0
  370. package/lib/shared/version.d.ts +1 -1
  371. package/lib/shared/version.js +1 -1
  372. package/lib/sketch/define-sketch.d.ts +16 -7
  373. package/lib/sketch/define-sketch.js +2 -1
  374. package/lib/sketch/runner.d.ts +4 -0
  375. package/lib/sketch/runner.js +5 -0
  376. package/lib/sketch/ui.js +4 -2
  377. package/lib/stats.d.ts +1 -0
  378. package/lib/workers/protocol.d.ts +10 -0
  379. package/lib/workers/render-worker.js +4 -1
  380. package/lib/workers/sketch-worker.js +4 -1
  381. package/package.json +1 -1
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  id: concepts/quality-presets
3
3
  title: "Quality presets, dynamic resolution and frame budgets"
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "Low to Ultra; pixel-ratio caps; the preset check; switching presets; the frame-budget governor; quality events for sketch code."
7
5
  ---
8
6
 
9
7
  # Quality presets, dynamic resolution and frame budgets
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. The engine chooses a preset and checks it in the first frames of play, or before play when the page asks. It applies the preset's pixel ratio cap, render scale range, shadow, texture and anti-aliasing settings, depth prepass, occlusion culling and memory maximum. During play, the frame-budget governor moves a sketch's budgets and the render scale in turn, a budget's step first, then the live shadow settings. A sketch can switch presets with `quality.setPreset`. The presets do not cap the count of point and spot lights. The camera lists up to 1,024 of them on every preset, and up to 128 in each cluster.
9
+ > The engine chooses a preset and checks it in the first frames of play, or before play when the page asks. It applies the preset's pixel ratio cap, render scale range, shadow, texture and anti-aliasing settings, depth prepass, occlusion culling and memory maximum. During play, the frame-budget governor moves a sketch's budgets and the render scale in turn, a budget's step first, then the live shadow settings.
10
+ >
11
+ > A sketch can switch presets with `quality.setPreset`.
12
12
 
13
13
  ```mermaid
14
14
  flowchart TD
@@ -60,7 +60,14 @@ The [starting preset of each device](quality-preset-tables.md#starting-preset-of
60
60
 
61
61
  Only Chromium browsers report the device's memory, and they report at most 8 GB. So memory can lower a preset, but it never raises one. The engine picks Ultra only when a page asks for it.
62
62
 
63
- A tablet slows down as it heats up, and then Medium and High can take longer than a frame. In the S4 benchmark, an 11-inch iPad Pro held 60 frames per second at Medium while cool. After a few minutes it ran at about 45, with the governor at its lowest render scale and every shadow step taken. A cool tablet passes the preset check at Medium, so the engine still starts tablets there. At Low, the same iPad held 60 frames per second in 298 of 299 seconds after 5 minutes of warm-up. Medium and High trade frame rate for sharper shadows and edges. When a steady rate matters more, name Low: `createEngine({ canvas, sketch, preset: 'low' })`.
63
+ A tablet slows down as it heats up, so Medium and High can fall below 60 frames per second after a few minutes. A cool tablet passes the preset check at Medium, so the engine still starts tablets there. Medium and High trade frame rate for sharper shadows and edges. When a steady rate matters more, name Low: `createEngine({ canvas, sketch, preset: 'low' })`.
64
+
65
+ <details>
66
+ <summary>Technical details: an iPad Pro as it heats up</summary>
67
+
68
+ In the S4 benchmark, an 11-inch iPad Pro held 60 frames per second at Medium while cool. The benchmark is [a town of 5,000 still objects and 200 moving vehicles with a shadow-casting sun](../guides/performance.md#phones-and-tablets). After a few minutes it ran at about 45, with the governor at its lowest render scale and every shadow step taken. At Low, the same iPad held 60 frames per second in 298 of 299 seconds after 5 minutes of warm-up.
69
+
70
+ </details>
64
71
 
65
72
  The GPU path then caps the preset, because WebGL2 and WebGPU's compatibility mode lack features that the heavier presets use. For example, compatibility mode cannot draw multisampled float targets.
66
73
 
@@ -82,7 +89,9 @@ A phone closes a tab that uses too much memory, and the page gets no event for i
82
89
  - After one crashed start, the engine starts one preset lower than it would.
83
90
  - After two in a row, it starts at Low, in the [lowest quality tier](#the-lowest-quality-tier). If the start that crashed drew with WebGPU, it draws with WebGL2, unless the page names a GPU path.
84
91
 
85
- This also applies to a preset that the page names, so a device that crashed at the player's choice can start again. The `?preset=` switch fixes the preset and starts outside the tier, as it ignores the crashes. The page can read the count in `engine.mode.crashedStarts` and tell the player. When the browser refuses the storage, as in a sandboxed frame, each start counts as a normal one. Hold mode and the `?preset=` switch leave the note alone. The note belongs to one sketch module and one origin.
92
+ This also applies to a preset that the page names, so a device that crashed at the player's choice can start again. A crashed start still lowers a named preset by one, and two in a row still start it at Low. The `?preset=` switch skips the preset check and the lowest-tier entry, not the crash lowering. The page can read the count in `engine.mode.crashedStarts` and tell the player.
93
+
94
+ When the browser refuses the storage, as in a sandboxed frame, each start counts as a normal one. Hold mode ([Testing your sketch](../guides/testing.md#hold-mode)) and the `?preset=` switch leave the note alone. The note belongs to one sketch module and one origin.
86
95
 
87
96
  ## The preset check
88
97
 
@@ -91,7 +100,9 @@ Device hints only suggest a preset. A laptop with a weak GPU and a desktop with
91
100
  1. The sketch's setup runs at the chosen preset and builds its scene. `createEngine` resolves.
92
101
  2. The engine draws the first frame, with every pipeline built, and play starts: the sketch's `onUpdate`, its input and its animations run as usual.
93
102
  3. The engine waits until the GPU has finished the first frame and draws at play's rate, for up to 4 seconds. Then, for a moment, it measures two rates: the frames that it presented, and the frames that the GPU finished. It reads the lower one, so frames that wait in a queue on the GPU cannot pass for a healthy rate.
94
- 4. When that rate misses the target, the engine lowers the preset by one, waits for the new preset's first frame, and measures again. It stops at a preset that holds the target, or at Low. A rate under a quarter of the target is far below it: the engine then lowers the preset straight to Low, and measures Low. The sketch's `quality.onChange` handlers hear of each lighter preset in the next frame. A setting that the sketch changed with `quality.set` keeps its value on the lighter preset. The lighter preset also gives the anti-aliasing mode, which the device moves its canvas to before it draws that preset's first frame. Every other setting that a device fixes at start keeps the value it started with.
103
+ 4. When that rate misses the target, the engine lowers the preset by one, waits for the new preset's first frame, and measures again. It stops at a preset that holds the target, or at Low. A rate under a quarter of the target is far below it: the engine then lowers the preset straight to Low, and measures Low.
104
+
105
+ The sketch's `quality.onChange` handlers hear of each lighter preset in the next frame. A setting that the sketch changed with `quality.set` keeps its value on the lighter preset. The lighter preset also gives the anti-aliasing mode, which the device moves its canvas to before it draws that preset's first frame. Every other setting that a device fixes at start keeps the value it started with.
95
106
  5. The check ends, and `engine.presetChecked` resolves. The [frame-budget governor](#the-frame-budget-governor) waits until then, so the check measures each preset at the full render scale.
96
107
 
97
108
  The viewer sees the scene from its first frame, so a lighter preset applies in front of the viewer. A sketch that asks for a preset itself with `quality.setPreset` while the check runs ends the check. The sketch's choice then stands, and `engine.mode.presetCheck` stays null.
@@ -119,13 +130,20 @@ const engine = await createEngine({ canvas, sketch, targetFps: 'display' });
119
130
 
120
131
  A whole number, such as `targetFps: 90`, caps the target at that rate. The target never goes above the display's rate. A higher target costs quality: the check picks a lighter preset where the GPU cannot hold it, and the governor lowers the render scale sooner. The `?target-fps=display` or `?target-fps=90` switch sets the target from the page's address, and wins over the option. Until the engine has measured the display's rate, the target is 60, or the option's rate when that is lower. The [stats overlay](../api/debug.md#stats-overlay-and-frame-figures) shows the display's rate beside the target.
121
132
 
122
- The preset check starts its target at the display's rate that the engine measured before the check's first frame. It never lowers its target during the check. A GPU that falls behind slows the frame callbacks, so the rate measured under the check's own load can read as a slower display. On a Galaxy Tab A9 Plus with a 90 Hz display, that rate read 30 to 45 while Skyway drew.
133
+ The preset check starts its target at the display's rate that the engine measured before the check's first frame. It never lowers its target during the check. A GPU that falls behind slows the frame callbacks, so the rate measured under the check's own load can read as a slower display. On a Galaxy Tab A9 Plus with a 90 Hz display, that rate read 30 to 45 while the Skyway showcase demo drew.
123
134
 
124
- The engine checks only a preset that it chose itself, when a lighter preset exists. A preset that the page names, the `?preset=` switch, and hold mode skip the check. So does Low, as on phones. The check takes at least three quarters of a second for each preset that it measures. That was about 0.8 seconds on a MacBook Pro, and about 1 second on an 11-inch iPad Pro. During play, neither `createEngine` nor the first frame waits for it. Before play, `createEngine` waits for it, so keep the loading screen until `createEngine` has resolved and `engine.firstFrame` has too.
135
+ The engine checks only a preset that it chose itself, when a lighter preset exists. A preset that the page names, the `?preset=` switch, and hold mode skip the check. So does Low, as on phones. The check takes at least three quarters of a second for each preset that it measures. During play, neither `createEngine` nor the first frame waits for it. Before play, `createEngine` waits for it, so keep the loading screen until `createEngine` has resolved and `engine.firstFrame` has too.
125
136
 
126
137
  ### Repeat visits
127
138
 
128
- The engine stores the check's result in the page's `localStorage`, one for each sketch module. A later start of the sketch in the same browser on the same device takes that result and skips the check. [Caches between visits](../getting-started/hosting.md#caches-between-visits) shows the other caches that a repeat visit uses. Its setup already runs at the preset that the check chose, so it plays at that preset from its first frame, and `engine.presetChecked` resolves with `createEngine`. On an 11-inch iPad Pro, the check took about a second for each preset that it measured. With the check before play, the benchmark scenes and demos there showed their first frame after 1 to 2.4 seconds on a first visit. A repeat visit took 0.25 to 0.52 seconds.
139
+ The engine stores the check's result in the page's `localStorage`, one for each sketch module. A later start of the sketch in the same browser on the same device takes that result and skips the check. [Caches between visits](../getting-started/hosting.md#caches-between-visits) shows the other caches that a repeat visit uses. Its setup already runs at the preset that the check chose, so it plays at that preset from its first frame, and `engine.presetChecked` resolves with `createEngine`.
140
+
141
+ <details>
142
+ <summary>Technical details: first and repeat visit times</summary>
143
+
144
+ On an 11-inch iPad Pro, the check took about a second for each preset that it measured. With the check before play, the benchmark scenes and demos there showed their first frame after 1 to 2.4 seconds on a first visit. A repeat visit took 0.25 to 0.52 seconds. The check took about 0.8 seconds on a MacBook Pro.
145
+
146
+ </details>
129
147
 
130
148
  A stored result applies only while the start matches the one that the check measured:
131
149
 
@@ -164,8 +182,16 @@ Each value is a starting point, which measurements on phones, tablets and deskto
164
182
 
165
183
  The [settings of each preset](quality-preset-tables.md#settings-of-each-preset) give each setting that the engine applies, with its value on each preset and when it changes.
166
184
 
185
+ The engine makes its memory while it tests the GPU paths. So the memory maximum follows the starting preset and the crashed starts, and the GPU path does not cap it. The `memory` option of `createEngine` replaces it: [Page API](../api/engine.md#memory).
186
+
187
+ The presets do not cap the count of point and spot lights. The camera lists up to 1,024 of them on every preset, and up to 128 in each cluster.
188
+
189
+ ### Pixel ratio cap
190
+
167
191
  The pixel ratio cap is the cheapest large saving on phones. The GPU fills each device pixel, and a screen's device pixels grow with the square of its ratio. So a ratio of 3 fills 2.25 times the pixels of a ratio of 2. The `maxPixelRatio` option of `createEngine` replaces the preset's cap, and `quality.set({ maxPixelRatio })` changes it during play.
168
192
 
193
+ ### Shadow memory
194
+
169
195
  The shadow settings set the GPU memory that shadows take. The shadow map stores 2 bytes per texel. The atlas stores 4: the tiles of spot and point lights, and the sun's hero tile. The table gives the memory with every tile in use.
170
196
 
171
197
  | Preset | Shadow map | Shadow atlas | Both | Atlas with a hero |
@@ -175,13 +201,19 @@ The shadow settings set the GPU memory that shadows take. The shadow map stores
175
201
  | High | 24 MiB | 64 MiB | 88 MiB | 272 MiB |
176
202
  | Ultra | 128 MiB | 96 MiB | 224 MiB | 1,536 MiB, refused |
177
203
 
178
- The shadow map takes its memory once the directional light casts shadows. The atlas takes its own once a spot or point light casts. While the sun names a [hero shadow](shadows.md#a-hero-shadow), the atlas has one more layer. Every layer then takes the size of the preset's `heroTileSize`: 1,024 texels on Low, 2,048 on Medium and High, and 4,096 on Ultra. An atlas above 1 GiB fails with [E1501](../errors/E1501.md). So on Ultra, a hero leaves room for 15 light tiles at most. [Shadows](shadows.md#what-shadows-cost) gives the cost of each.
204
+ The shadow map takes its memory once the directional light casts shadows. The atlas takes its own once a spot or point light casts. While the sun names a [hero shadow](shadows.md#a-hero-shadow), the atlas has one more layer.
205
+
206
+ Every layer then takes the size of the preset's `heroTileSize`: 1,024 texels on Low, 2,048 on Medium and High, and 4,096 on Ultra. An atlas above 1 GiB fails with [E1501](../errors/E1501.md). So on Ultra, a hero leaves room for 15 light tiles at most. [Shadows](shadows.md#what-shadows-cost) gives the cost of each.
207
+
208
+ ### Texture filtering and uploads
179
209
 
180
210
  The anisotropic filtering cap limits the `anisotropy` option of every texture, so surfaces seen at a slant cost fewer texture reads on the lighter presets. The upload budget limits the texel bytes that one frame sends to the GPU, so loading many textures does not make one frame slow. A larger texture goes up over several frames. `quality.set({ maxAnisotropy, uploadBytesPerFrame })` changes either during play.
181
211
 
182
212
  ### Texture memory
183
213
 
184
- The texture memory budget caps the GPU memory of the scene's textures. A phone or a tablet closes a tab that uses too much memory, with no warning, so the budget keeps textures well below that point. Each preset's budget stays under half the lowest point that the engine's tab memory test measured on the devices that the preset serves. Phones and tablets take at most 1,008 MiB on any preset: half the 2,016 MiB at which an iPad Pro's tab closed. The page's `textureMemoryMiB` option replaces the preset's budget and the cap, and `quality.set({ textureMemoryMiB })` changes it during play.
214
+ The texture memory budget caps the GPU memory of the scene's textures. A phone or a tablet closes a tab that uses too much memory, with no warning, so the budget keeps textures well below that point. Each preset's budget stays under half the lowest point that the engine's tab memory test measured on the devices that the preset serves.
215
+
216
+ Phones and tablets take at most 1,008 MiB on any preset: half the 2,016 MiB at which an iPad Pro's tab closed. The page's `textureMemoryMiB` option replaces the preset's budget and the cap, and `quality.set({ textureMemoryMiB })` changes it during play.
185
217
 
186
218
  ```mermaid
187
219
  flowchart LR
@@ -201,27 +233,55 @@ A texture loses at most 3 levels, so a texture of 1024 x 1024 texels keeps at le
201
233
 
202
234
  When room returns, 5% under the budget, the engine loads the dropped levels again from the texture's file. The browser's cache usually holds the file. The texture draws with the levels it has until the new ones are on the GPU. The band of 5% on either side keeps the engine from dropping and loading the same levels in turn. The sketch reads the memory and the dropped levels in `quality.textureMemory`: [Quality API](../api/quality.md#texture-memory).
203
235
 
204
- Low smooths edges with FXAA, and the other presets with MSAA. MSAA draws 4 samples per pixel, which costs a phone's GPU memory and bandwidth. FXAA draws one sample and smooths edges in the final pass, at a small cost in sharpness. The `antialias` option of `createEngine` replaces the preset's mode. The mode then stays fixed while the engine runs, because the scene's targets and pipelines depend on it. The start-up preset check is the one case that moves it: a preset that the check lowers draws with the lower preset's own mode, and the engine moves the canvas to that lighter mode before the scene plays. A sketch's own `quality.setPreset` keeps the mode that the engine started with. [GPU tiers and backends](backends.md#color-and-anti-aliasing-on-each-tier) compares the modes.
236
+ ### Anti-aliasing
205
237
 
206
- The engine makes its memory while it tests the GPU paths. So the memory maximum follows the starting preset and the crashed starts, and the GPU path does not cap it. The `memory` option of `createEngine` replaces it: [Page API](../api/engine.md#memory).
238
+ Low smooths edges with FXAA, and the other presets with MSAA. MSAA draws 4 samples per pixel, which costs a phone's GPU memory and bandwidth. FXAA draws one sample and smooths edges in the final pass, at a small cost in sharpness.
239
+
240
+ The `antialias` option of `createEngine` replaces the preset's mode. The mode stays fixed while the engine runs, because the scene's targets and pipelines depend on it. Two cases move it. When the start-up preset check lowers the preset, the engine draws with the lower preset's mode. In compatibility mode with MSAA, the first effect that needs HDR color moves the engine to FXAA ([The post-processing chain](post-processing.md#effects-on-devices-without-hdr-color)).
241
+
242
+ A sketch's own preset change never moves it. [GPU tiers and backends](backends.md#color-and-anti-aliasing-on-each-tier) compares the modes.
207
243
 
208
244
  ### Moment transparency
209
245
 
210
- The `momentTransparency` option of `createEngine`, or the `?moments=on` or `?moments=off` switch, blends the camera's blended surfaces in the moment transparency layer, which needs no sort. [Moment transparency](../api/materials.md#moment-transparency) describes the layer and the materials that it draws. Every preset leaves it off, because it draws those surfaces twice, and the setting stays fixed while the engine runs.
246
+ The `momentTransparency` option of `createEngine`, or the `?moments=on` or `?moments=off` switch, blends the camera's blended surfaces in the moment transparency layer, which needs no sort. [Moment transparency](../api/materials.md#moment-transparency) describes the layer and the materials that it draws. Every preset leaves it off, because it draws those surfaces twice, and the setting stays fixed while the engine runs. The [Island showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island) starts the engine with the layer on.
247
+
248
+ The layer costs memory and GPU time. On the Island showcase at High at 1920 x 1080, GPU textures grew by 40 MiB on WebGPU and by 52 MiB on WebGL2. In the [S1 benchmark](../guides/performance.md) at High, on a MacBook Pro in Chrome, it added about 0.6 ms of GPU time a frame on WebGPU. On WebGL2 it added about 1.1 ms. It adds almost no processor time. A desktop GPU's fill rate is not a phone's, so measure on the phone.
249
+
250
+ <details>
251
+ <summary>Technical details: the moment layer's memory</summary>
252
+
253
+ The layer's moment store and color sum take 8 bytes per pixel each at the render size. Its surfaces write both, which is 16 bytes per pixel a frame, or 33 MB at 1920 x 1080.
211
254
 
212
- The layer's moment store and color sum take 8 bytes per pixel each at the render size, and its surfaces write both: 16 bytes per pixel a frame, which is 33 MB at 1920 x 1080. The composite reads both and writes the scene color, and SMAA 1x's two 8-bit steps take 8 bytes per pixel more. Its resolve step writes a copy of the scene color, at 4 or 8 bytes per pixel by the scene color's format. A multisampled scene also needs a copy of one depth sample, at 4 bytes per pixel. So the targets that the layer adds come to 32 to 36 bytes per pixel before the render graph shares any with another pass. The 33 MB counts the writes alone, and the memory is larger: on the Island showcase at High at 1920 x 1080, the stats overlay's `GPU textures` rose by 40 MiB on WebGPU with direct draws and by 52 MiB on WebGL2. The weighted blending writes 10 bytes per pixel into its two sums. SMAA smooths the layer's edges under the share that its moments cover, and the opaque geometry keeps MSAA's samples.
255
+ The composite reads both and writes the scene color, and SMAA 1x's two 8-bit steps take 8 bytes per pixel more. Its resolve step writes a copy of the scene color, at 4 or 8 bytes per pixel by the scene color's format. A multisampled scene also needs a copy of one depth sample, at 4 bytes per pixel. So the targets that the layer adds come to 32 to 36 bytes per pixel before the render graph shares any with another pass.
213
256
 
214
- In the S1 benchmark with its smoke switch, at High on this computer's GPU in Chrome 156, the layer added about 0.05 ms of processor time and 0.58 ms of GPU time a frame on WebGPU, about sixteen per cent of that scene's GPU frame, and about 1.12 ms on WebGL2, about twenty per cent. A phone's figure is owed, and a desktop GPU's fill rate is not a phone's.
257
+ The 33 MB counts the writes alone, and the memory is larger. The weighted blending writes 10 bytes per pixel into its two sums. SMAA smooths the layer's edges under the share that its moments cover, and the opaque geometry keeps MSAA's samples.
258
+
259
+ </details>
215
260
 
216
261
  ### The depth prepass
217
262
 
218
- With the depth prepass, the engine first draws the depth of the opaque objects, with no color. The opaque pass then shades each pixel once, for its nearest surface. Without the prepass, a pixel can be shaded for several surfaces before the nearest one covers them. The prepass costs a second pass over the objects' vertices. So it saves GPU time where objects hide many others and their shading costs much, such as in a lit street of buildings. It costs time where a scene has many vertices and little overdraw.
263
+ With the depth prepass, the engine first draws the depth of the opaque objects, with no color. The opaque pass then shades each pixel once, for its nearest surface. Without the prepass, a pixel can be shaded for several surfaces before the nearest one covers them.
264
+
265
+ The prepass costs a second pass over the objects' vertices. So it saves GPU time where objects hide many others and their shading costs much, such as in a lit street of buildings. It costs time where a scene has many vertices and little overdraw.
266
+
267
+ Some objects stay out of the prepass and shade as they would without it. These are blended objects, line batches, and objects whose material has an alpha cutoff or skips depth writes or the depth test.
268
+
269
+ On WebGL2, every preset turns the prepass on, except on the [lowest quality tier](#the-lowest-quality-tier). On WebGPU and in its compatibility mode, every preset leaves it off. The preset table shows this default. Ambient occlusion, [contact shadows](shadows.md#contact-shadows), screen-space bounce light and screen-space reflections read the prepass's depth. So they draw the prepass while they run, whatever the preset or the option says. Bounce light runs on High and Ultra on WebGPU outside compatibility mode, so those presets draw the prepass there.
270
+
271
+ Each opaque object then has a depth pipeline beside its own, which the first frame and a warm-up build too. The `depthPrepass` option of `createEngine` replaces the preset's choice. Compare the scene's GPU time with `?prepass=on` and `?prepass=off`, and `quality.set({ depthPrepass })` changes it during play.
272
+
273
+ WebGL2 draws the prepass because of Apple GPUs. On them, a depth prepass restores early rejection of hidden pixels in WebGL2, so each pixel is shaded about once. In the S4 benchmark on an iPad, WebGL2 went from 38 to 60 frames per second on Low. On Medium it went from 17 to 37 frames per second. The images stay the same.
219
274
 
220
- Some objects stay out of the prepass and shade as they would without it. These are blended objects, line batches, and objects whose material has an alpha cutoff or skips depth writes or the depth test. On WebGL2, every preset turns the prepass on. On WebGPU and in its compatibility mode, every preset leaves it off. Ambient occlusion, the directional light's [contact shadows](shadows.md#contact-shadows), screen-space bounce light and screen-space reflections turn it on while they draw. They read the prepass's depth ([post-processing](post-processing.md#ambient-occlusion)). So High and Ultra draw it on WebGPU outside compatibility mode, where the bounce light runs. The [lowest quality tier](#the-lowest-quality-tier) turns it off on WebGL2. Each opaque object then has a depth pipeline beside its own, which the first frame and a warm-up build too. The `depthPrepass` option of `createEngine` replaces the preset's choice. Compare the scene's GPU time with `?prepass=on` and `?prepass=off`. `quality.set({ depthPrepass })` changes it during play.
275
+ On Android phones that ran S4, WebGL2 kept its frame rate with the prepass, and its CPU time did not change. On WebGPU the GPU removes hidden surfaces itself, so the prepass only adds work. On the same iPad it added about 4 ms per frame to S4 on Medium.
221
276
 
222
- WebGL2 draws the prepass because of Apple GPUs. On them, a depth prepass restores early rejection of hidden pixels in WebGL2, so each pixel is shaded about once. In the S4 benchmark on an iPad, WebGL2 went from 38 to 60 frames per second on Low. On Medium it went from 17 to 37 frames per second. The images stay the same. On Android phones that ran S4, WebGL2 kept its frame rate with the prepass, and its CPU time did not change. On WebGPU the GPU removes hidden surfaces itself, so the prepass only adds work. On the same iPad it added about 4 ms per frame to S4 on Medium.
277
+ Both GPU paths draw the prepass, and it gives the same image as a frame without it. The opaque pass shades a pixel only where its depth equals the prepass's depth exactly.
223
278
 
224
- Both GPU paths draw the prepass, and it gives the same image as a frame without it. The opaque pass shades a pixel only where its depth equals the prepass's depth exactly. So both passes must compute each vertex's depth to the last bit. On WebGPU, the prepass uses a shader that computes positions only. Custom materials and sprites place their vertices in their own way, so there they draw with their own vertex shader. On WebGL2, every object draws with the vertex shader of its own material. A fragment shader that writes nothing completes each such program. On WebGL2, two separate shader programs can compute slightly different depths for one triangle, and a surface would then vanish from the frame.
279
+ <details>
280
+ <summary>Technical details: why both passes compute the same depth</summary>
281
+
282
+ So both passes must compute each vertex's depth to the last bit. On WebGPU, the prepass uses a shader that computes positions only. Custom materials and sprites place their vertices in their own way, so there they draw with their own vertex shader. On WebGL2, every object draws with the vertex shader of its own material. A fragment shader that writes nothing completes each such program. On WebGL2, two separate shader programs can compute slightly different depths for one triangle, and a surface would then vanish from the frame.
283
+
284
+ </details>
225
285
 
226
286
  One case differs: two opaque surfaces at exactly the same depth. Without the prepass, the surface drawn first shows. With it, both pass the test for equal depth, so the surface drawn last shows. The engine chooses its own draw order, so an exact tie has no defined winner. The winner may also differ between GPU paths, as WebGL2 draws the prepass by default and WebGPU does not. Give overlapping surfaces, such as decals and ground markings, a depth bias, or move one a little, so one is nearer.
227
287
 
@@ -234,7 +294,9 @@ const plain = await createEngine({ canvas, sketch, depthPrepass: false });
234
294
 
235
295
  ### GPU occlusion culling
236
296
 
237
- With GPU occlusion culling, each camera skips the opaque objects that others hide. It draws the depth of the large opaque objects that showed in its last frame, and builds a depth pyramid from it. Then it draws only the objects that show. [Culling](culling.md#gpu-occlusion-culling-on-webgpu) describes the two phases. High and Ultra turn it on for desktops. Phones and tablets keep it off on every preset. A check during play turns its passes off while they hide too little or make the GPU's frame longer, so a scene where they do not pay loses almost nothing.
297
+ With GPU occlusion culling, each camera skips the opaque objects that others hide. It draws the depth of the large opaque objects that showed in its last frame, and builds a depth pyramid from it. Then it draws only the objects that show. [Culling](culling.md#gpu-occlusion-culling-on-webgpu) describes the two phases.
298
+
299
+ High and Ultra turn it on for desktops. Phones and tablets keep it off on every preset. A check during play turns its passes off while they hide too little or make the GPU's frame longer, so a scene where they do not pay loses almost nothing.
238
300
 
239
301
  The `gpuOcclusion` option of `createEngine` replaces the preset's choice, and `?occlusion=on` or `?occlusion=off` wins over the option, to compare the scene's GPU time. It is fixed while the engine runs. It runs only on WebGPU, so `quality.settings.gpuOcclusion` is false on WebGL2. It runs beside the depth prepass, which ambient occlusion and screen-space bounce light turn on.
240
302
 
@@ -254,15 +316,26 @@ The engine can draw the scene at a render scale below the canvas's size. Its fin
254
316
  During play, the engine moves the scale between the `minRenderScale` and `maxRenderScale` settings:
255
317
 
256
318
  - It watches how often frames reach the screen and how often the GPU finishes one. It also watches how long the GPU takes to finish each frame.
257
- - A second of frames is over budget when its frame rate, on average, is under 95% of the target rate. At a target of 60, that is under 57 frames per second. The engine's benchmark reports count such a second as a miss too. Each quarter of the second must also run at least 2% slower than the target, so one short stall amid full-rate frames does not count. A second is over budget too when the GPU finishes each frame two frames late or later.
258
- - The target is the [target frame rate](#the-target-frame-rate): the display's refresh rate, at most 60 frames per second unless the page asks for more. The `?fps=` switch caps it at the rate that it holds. Safari calls a drawing worker from a timer, which slows when the GPU falls behind. There the engine takes the display's rate from the page's frame callbacks.
259
- - The governor's target starts at the display's rate that the engine measured when the sketch's setup returned. A GPU that falls behind slows the frame callbacks, which then read as a slower display. So the target falls to a slower rate only while the GPU finishes each frame within the target's own frame time. Then the display or the browser slowed the frames, as a display that saves power does.
260
- - After a second over budget, the scale drops by 0.05. The engine then waits a second, so it judges frames at the new scale.
261
- - After 5 seconds at the target rate on average, with the GPU done with each frame within about one frame, the scale rises by 0.05. The average covers the whole 5 seconds. In Safari, some frames wait an extra callback even at the full rate.
262
- - Frames at 57 to 59 frames per second hold the target but have no time to spare, so the scale stays where it is.
263
- - A rise is on trial for 30 seconds. If the scale drops back within that time, the next rise to that scale waits twice as long, up to 80 seconds. Each scale keeps its own wait, so a rise to a scale that has not failed still comes after 5 seconds. A phone that heats up can hold a higher scale for a few seconds and then fall behind. So the scale settles below the point where frames fall behind.
319
+ - A second of frames is over budget when its frame rate, on average, is under 95% of the target rate. At a target of 60, that is under 57 frames per second. After a second over budget, the scale drops by 0.05. The engine then waits a second, so it judges frames at the new scale.
320
+ - After 5 seconds at the target rate on average, with the GPU done with each frame within about one frame, the scale rises by 0.05. The average covers the whole 5 seconds.
321
+ - The target is the [target frame rate](#the-target-frame-rate): the display's refresh rate, at most 60 frames per second unless the page asks for more. The `?fps=` switch caps it at the rate that it holds.
264
322
  - It takes no step in the first 2 seconds of play, or while textures wait to upload. It starts to judge the frames again after a pause.
265
323
 
324
+ <details>
325
+ <summary>Technical details: how the controller judges frames and trials a rise</summary>
326
+
327
+ The engine's benchmark reports count such a second as a miss too. Each quarter of the second must also run at least 2% slower than the target, so one short stall amid full-rate frames does not count. A second is over budget too when the GPU finishes each frame two frames late or later.
328
+
329
+ Safari calls a drawing worker from a timer, which slows when the GPU falls behind. There the engine takes the display's rate from the page's frame callbacks. In Safari, some frames wait an extra callback even at the full rate.
330
+
331
+ The governor's target starts at the display's rate that the engine measured when the sketch's setup returned. A GPU that falls behind slows the frame callbacks, which then read as a slower display. So the target falls to a slower rate only while the GPU finishes each frame within the target's own frame time. Then the display or the browser slowed the frames, as a display that saves power does.
332
+
333
+ Frames at 57 to 59 frames per second hold the target but have no time to spare, so the scale stays where it is.
334
+
335
+ A rise is on trial for 30 seconds. If the scale drops back within that time, the next rise to that scale waits twice as long, up to 80 seconds. Each scale keeps its own wait, so a rise to a scale that has not failed still comes after 5 seconds. A phone that heats up can hold a higher scale for a few seconds and then fall behind. So the scale settles below the point where frames fall behind.
336
+
337
+ </details>
338
+
266
339
  The scene's render targets keep the canvas's size at every scale, and the scene draws into their top-left corner. So a new scale makes no GPU object and allocates no memory. `engine.measure()` counts the GPU objects that the engine made, in `gpuObjects`.
267
340
 
268
341
  A sketch reads the scale in `quality.renderScale`, and changes the range with `quality.set`:
@@ -284,16 +357,22 @@ export default defineSketch(({ quality, page }) => {
284
357
  });
285
358
  ```
286
359
 
287
- A `minRenderScale` of 1 keeps the whole canvas. Hold mode draws at `maxRenderScale`, so tests draw the same image on every run. Some GPU paths draw the scene's color in 8 bits: WebGPU's compatibility mode, and WebGL2 devices that cannot draw multisampled float targets. There, with MSAA, a lowest scale below 1 adds the final pass, which copies the image to the canvas. At a lowest scale of 1, the scene's render pass writes straight to the canvas. Below a scale of 1, the final pass runs in two steps: the first draws at the render size and smooths edges with FXAA, which the pass at the whole canvas's scale always did, and the second scales the image up to the canvas with GSR 1, an edge-aware upscaler. [The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale) describes both steps, and the two costs that a lowest scale of 1 avoids. A sketch that sets `post.set({ sharpen })` draws those two steps at every scale. Its image then sharpens at the whole canvas's scale too, and it pays the same two costs.
360
+ A `minRenderScale` of 1 keeps the whole canvas. Hold mode draws at `maxRenderScale`, so tests draw the same image on every run. Below a scale of 1, the final pass runs in two steps. [The post-processing chain](post-processing.md#below-the-whole-canvass-render-scale) gives both steps, the effect of `sharpen` and the two costs that a lowest scale of 1 avoids.
361
+
362
+ <details>
363
+ <summary>Technical details: the 8-bit GPU paths</summary>
364
+
365
+ Some GPU paths draw the scene's color in 8 bits: WebGPU's compatibility mode, and WebGL2 devices that cannot draw multisampled float targets. There, with MSAA, a lowest scale below 1 adds the final pass, which copies the image to the canvas. At a lowest scale of 1, the scene's render pass writes straight to the canvas.
366
+
367
+ </details>
288
368
 
289
369
  ## The frame-budget governor
290
370
 
291
371
  ```mermaid
292
372
  flowchart LR
293
- over["1 s over budget"] --> scale["1. Sketch budgets: 0.25 lower, and<br/>render scale: 0.05 lower, in turn,<br/>down to minRenderScale"]
294
- scale -- "still over budget" --> detail["2. Levels of detail:<br/>twice the threshold, twice at most"]
295
- detail -- "still over budget" --> far["3. Far shadow cascades:<br/>half as often, down to every 8th frame"]
296
- far -- "still over budget" --> filter["4. Shadow filter: 3 x 3 texels"]
373
+ over["1 s over budget"] --> budgets["Sketch budgets: 0.25 lower, and<br/>render scale: 0.05 lower, in turn,<br/>down to minRenderScale"]
374
+ budgets -- "still over budget" --> detail["Detail, shadow and effect steps,<br/>in the order below"]
375
+ detail -- "still over budget" --> effects["Then bloom, ambient occlusion,<br/>reflections, contact shadows,<br/>far animation and fog, one step each"]
297
376
  room["5 s with time to spare"] --> back["One step back up,<br/>in the reverse order"]
298
377
  ```
299
378
 
@@ -310,7 +389,9 @@ Dynamic resolution is the first part of the frame-budget governor. A sketch can
310
389
  9. Far characters update their poses half as often, up to every 4th frame. Each step doubles the interval, so the step happens only while the `farAnimationInterval` setting is below 4. A sketch reads `quality.governor.farAnimationInterval` to give it to its far characters ([Animation](../api/animation.md#crowds)).
311
390
  10. The volumetric fog draws half the slices of its grid, into the same textures, so its rays turn a little coarser along the view and no texture is made. This step happens only while the volumetric fog draws.
312
391
 
313
- Each step follows the rules of dynamic resolution. Frames must stay over budget for a second before a step down, and keep time to spare for 5 seconds before a step up. A wait follows each step, and no step happens early in play, after a pause, or during uploads. The governor raises the settings in the reverse order, so the render scale comes back last. It takes shadow steps only where a directional light casts shadows. A lower render scale picks coarser levels of detail too, as the render height counts in each level's error in pixels. It never changes the preset, nor a setting that is fixed while the preset runs, such as the shadow map's size.
392
+ Each step follows the rules of dynamic resolution. Frames must stay over budget for a second before a step down, and keep time to spare for 5 seconds before a step up. A wait follows each step, and no step happens early in play, after a pause, or during uploads.
393
+
394
+ The governor raises the settings in the reverse order, so the render scale comes back last. It takes shadow steps only where a directional light casts shadows. A lower render scale picks coarser levels of detail too, as the render height counts in each level's error in pixels. It never changes the preset, nor a setting that is fixed while the preset runs, such as the shadow map's size.
314
395
 
315
396
  Phones slow down as they heat up, often after a few minutes of play. The governor responds as it does to any slow frames: after a second over budget, it lowers the next setting. The target is the [target frame rate](#the-target-frame-rate): by default the display's refresh rate, at most 60 frames per second. When the browser lowers the rate of its frames to save battery, the rate that the engine measures falls. The target falls with it, as long as the GPU keeps up with the frames.
316
397
 
@@ -318,19 +399,21 @@ Phones slow down as they heat up, often after a few minutes of play. The governo
318
399
 
319
400
  ### The lowest quality tier
320
401
 
321
- Some devices reach the lowest render scale and still miss the target. Below the four presets sits a lowest tier for them. The governor enters it when the render scale has held at its floor through the sustained window, and the judged frames still miss. Its cuts are a third-size render scale floor, no sun shadows, no bloom, and reflection passes at a quarter of the render size. On WebGL2 it also turns the depth prepass off.
402
+ Some devices reach the lowest render scale and still miss the target. Below the four presets sits a lowest tier for them. The governor enters it when the render scale has held at its floor for 5 seconds and frames still miss the target. Its cuts are a render scale floor of one third of the canvas's width and height, no sun shadows, and no bloom. Reflection passes draw at a quarter of the render size. On WebGL2 it also turns the depth prepass off.
322
403
 
323
404
  The tier changes live settings that a sketch can read. These are `minRenderScale`, `castShadows`, `bloom` and `reflectionScale`, and `depthPrepass` where the GPU path draws it. The four presets keep their values, so no other look changes. `quality.governor.lowest` reports whether the tier applies. A `minRenderScale` that the sketch sets itself wins over the tier's floor and cap. The scale stays at or above it in the tier and after it, and the tier keeps its other cuts.
324
405
 
325
- The entry goes on trial as a step down does. Frames that come clearly slower after it take the tier back, and close it for a wait that doubles with each failed entry. The governor leaves the tier when the frames keep room through the window that raises a step. It then waits that same window before the tier can enter again, so a device cannot flap.
406
+ The entry goes on trial as a step down does. Frames that come clearly slower after it take the tier back, and close it for a wait that doubles with each failed entry. The governor leaves the tier when the frames keep time to spare for as long as a step up waits. That is 5 seconds at first, and longer after failed step ups. It then waits 5 seconds before the tier can enter again, so a device cannot flap.
326
407
 
327
- `?tier=lowest` starts a page in the tier, for tests, devices and a known weak class. The governor stays the default path to the tier.
408
+ `?tier=lowest` starts a page in the tier, for tests, devices and a known weak class. A page that starts in the tier also caps the render scale at one third, so it draws at that scale from the first frame. The governor stays the default path to the tier.
328
409
 
329
- A sketch whose own thread limits its frames keeps the tier out. Its smaller render cannot make the sketch work cheaper, so the picture only loses detail. `defineSketch(setup, { lowestTier: false })` sets that.
410
+ A sketch whose own thread limits its frames keeps the tier out. Its smaller render cannot make the sketch work cheaper, so the picture only loses detail. `defineSketch(setup, { lowestTier: false })` sets that. The [Island showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island) opts out this way.
330
411
 
331
412
  ### Settings of an add-on's feature
332
413
 
333
- An add-on's feature declares its own settings in the same form as the engine's table: a value on each preset, an optional WebGL2 column, and the values it takes. The feature's budget joins the sketch's budgets. A step of the budgets' scale then lowers the feature's share of full quality with the sketch's own systems. A setting that names a `governor` follows that share: a count shrinks with it, and an interval doubles with each step. The stats overlay shows the feature's values and its budget beside the engine's figures. [Add-on feature descriptions](../api/features.md#preset-settings-and-the-frame-budget-governor) shows how a feature declares them.
414
+ An add-on's feature declares its own settings in the same form as the engine's table: a value on each preset, an optional WebGL2 column, and the values it takes. The feature's budget joins the sketch's budgets. A step of the budgets' scale then lowers the feature's share of full quality with the sketch's own systems.
415
+
416
+ A setting that names a `governor` follows that share: a count shrinks with it, and an interval doubles with each step. The stats overlay shows the feature's values and its budget beside the engine's figures. [Add-on feature descriptions](../api/features.md#preset-settings-and-the-frame-budget-governor) shows how a feature declares them.
334
417
 
335
418
  ## Related pages
336
419
 
@@ -1,18 +1,14 @@
1
1
  ---
2
2
  id: concepts/render-graph
3
3
  title: The render graph
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "Declared reads and writes; automatic order; transient memory; validation errors; the text dump."
7
5
  ---
8
6
 
9
7
  # The render graph
10
8
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
-
13
9
  ```mermaid
14
10
  flowchart LR
15
- objects[("objects")] --> culling["Culling<br/>GPU-driven path only"] --> visible[("visible instances")]
11
+ objects[("objects")] --> culling["Culling<br/>on WebGPU, except on direct draws"] --> visible[("visible instances")]
16
12
  visible --> opaque
17
13
  visible -.-> prepass
18
14
  subgraph scene["One render pass"]
@@ -34,7 +30,9 @@ null3D draws each frame as a series of passes. A pass is one job for the GPU, su
34
30
 
35
31
  The engine declares its own passes. A sketch adds scene passes of its own with `render.addPass`, and `render.dumpGraph()` prints the graph ([Render graph API](../api/render.md)).
36
32
 
37
- In the diagram, boxes are passes and cylinders are data. An arrow into a pass shows what it reads, and an arrow out of a pass shows what it writes. The opaque and transparent passes share one render pass on the GPU. The scene color reaches the canvas through the final pass on devices that draw HDR color. So it does in the FXAA and no anti-aliasing modes. On the other devices with MSAA, the resolve pass takes its place, along the dotted arrows. It shares the opaque and transparent passes' render pass.
33
+ In the diagram, boxes are passes and cylinders are data. An arrow into a pass shows what it reads, and an arrow out of a pass shows what it writes.
34
+
35
+ The opaque and transparent passes share one render pass on the GPU. The final pass takes the scene color to the canvas. On the 8-bit path with MSAA, the resolve pass can take its place, along the dotted arrows. It shares the opaque and transparent passes' render pass. The last paragraph of this section says when.
38
36
 
39
37
  ## The engine's passes
40
38
 
@@ -42,7 +40,7 @@ In the diagram, boxes are passes and cylinders are data. An arrow into a pass sh
42
40
  | --- | --- | --- | --- |
43
41
  | Light clustering | Compute, on WebGPU only | The point and spot lights of the camera's view and of each scene pass that sees one, and the depth range that the light depth pass measured | The list of lights of each cluster of each view, and the fitted slice bounds in its header |
44
42
  | Light depth | Compute, on WebGPU only, while the camera sees a local light | The camera view's scene depth | The nearest and farthest depth that the next frame's light clustering fits its slices to |
45
- | Culling | Compute, one pass per view (the camera's, and each shadow cascade's and tile's), on WebGPU only | The world matrix and bounds of every object and instance | The view's visible instances and draw counts |
43
+ | Culling | Compute, one pass per view (the camera's, and each shadow cascade's and tile's), on WebGPU unless the device draws directly | The world matrix and bounds of every object and instance | The view's visible instances and draw counts |
46
44
  | Skinning | Compute, on WebGPU only, while the scene has meshes that the vertex shaders do not skin, such as morphed meshes | The meshes' vertices, joints and morph weights | A buffer of skinned vertices, which the shadow and scene passes draw |
47
45
  | Shadow | Scene, one pass per shadow cascade and per tile of the shadow atlas, in the frames in which it draws | The visible casters of its view | Its layer of the shadow map or of the shadow atlas |
48
46
  | Depth prepass | Scene, one pass per view, with the `depthPrepass` setting | The view's visible instances | The scene depth |
@@ -63,7 +61,7 @@ In the diagram, boxes are passes and cylinders are data. An arrow into a pass sh
63
61
  | A sketch's full-screen pass | Fullscreen, one per `render.addPass({ kind: 'fullscreen' })` | Its input image, the scene depth if its WGSL reads it, and the textures of other passes that it reads | Its texture, which the graph keeps between frames |
64
62
  | A sketch's compute pass | Compute, one per `render.addPass({ kind: 'compute' })` | The textures of other passes that it reads | Its texture, a storage texture that the pass writes and that the graph keeps between frames |
65
63
  | Resolve | Resolve, on the 8-bit path with MSAA, while the render scale cannot drop below 1 and no effect needs the final pass | The scene color | The canvas |
66
- | Final pass | Fullscreen, on the HDR path, with FXAA or no anti-aliasing, while the render scale can drop below 1, and while an effect needs it | The scene color | The canvas |
64
+ | Final pass | Fullscreen. Runs when any of these holds: the scene draws HDR color; the anti-aliasing is FXAA or none; the render scale can drop below 1; an effect needs it | The scene color | The canvas |
67
65
 
68
66
  The table lists the core passes. Each effect adds passes of its own while it is on. These are ambient occlusion, screen-space reflections, the bounce light, decals and the transparency layers. So are subsurface scattering, volumetric fog, custom effects, depth of field, bloom, automatic exposure, outlines and the still accumulation. The pick pass runs when a page asks what is under a pixel. [The post-processing chain](post-processing.md) describes most of them, and `render.dumpGraph()` lists every pass of a frame.
69
67
 
@@ -71,26 +69,44 @@ On WebGL2 the job workers cull the objects and list the lights of each cluster b
71
69
 
72
70
  With the depth prepass on, each view draws the depth of its opaque objects first, in the render pass that then shades them. The opaque pass then shades only the nearest surface at each pixel. [Quality presets](quality-presets.md#the-depth-prepass) says when the prepass saves time.
73
71
 
74
- With GPU occlusion culling on, each camera view's culling pass keeps the large objects that showed in its last frame. The occluders' pass draws their depth into a target of its own, and the depth pyramid pass reads it. The late culling pass tests every object in view against the pyramid, and writes the visible instances again. The occluders' pass must read them before that write. The graph runs a pass that reads a resource "so far" after the writers declared before it, and before the writers declared after it. The depth prepass, where it runs, and the opaque pass then draw what the late culling pass kept. [Culling](culling.md#gpu-occlusion-culling-on-webgpu) describes the method.
72
+ With GPU occlusion culling on, each camera view's culling pass keeps the large objects that showed in its last frame. The occluders' pass draws their depth into a target of its own, and the depth pyramid pass reads it. The late culling pass tests every object in view against the pyramid, and writes the visible instances again. The occluders' pass must read them before that write. The depth prepass, where it runs, and the opaque pass then draw what the late culling pass kept. [Culling](culling.md#gpu-occlusion-culling-on-webgpu) describes the method.
73
+
74
+ ## Views and a sketch's passes
75
+
76
+ A view is the scene seen from one camera, culled on its own. On WebGPU each view has a culling pass, and on WebGL2 the job workers list the visible objects of each view. A start-up measurement can pick direct draws on an Apple GPU in Safari, or in any browser on iPhone and iPad ([Culling](culling.md#how-each-path-culls)). There the job workers list them on WebGPU too.
77
+
78
+ The camera's view draws the scene color and depth, and the scene color reaches the canvas. Each scene pass that a sketch adds has a view of its own, which draws into its texture. The camera's passes read the texture of every scene pass that a material shows, so those passes run first.
79
+
80
+ A view that a sketch adds with `scene.createView` draws after the camera's passes. It draws into a rectangle of the camera's scene color through the viewport and the scissor. It has a depth target of its own, so its image covers the camera's there.
81
+
82
+ WebGPU draws an image's top row first, and materials sample the bottom row at v = 0. So on WebGPU a copy pass turns each pass's image over into its texture. WebGL2 draws the rows in that order already. A reflection view on the HDR WebGPU path is the exception. It draws into its target directly, and `reflection_uv` turns the rows of the lookups that read it.
83
+
84
+ A full-screen pass that a sketch adds is a view without a camera. It draws one triangle over its texture, and its shader writes the rows bottom first on both paths, so it needs no copy.
85
+
86
+ A pass that reads only other passes' textures runs before the passes that read its own. A pass that reads the scene color, the outline mask or the scene depth runs after the camera's passes. So the camera's passes do not read its texture in the same frame: a material that shows it shows the frame before. A custom effect that reads it runs after it.
87
+
88
+ A compute pass that a sketch adds is a view without a camera too. Its shader writes its texture as a storage texture. A material, an effect or another pass samples that texture in the same frame, because the graph orders the pass before them. A custom material's vertex offset that reads it also draws it in the material's shadow, motion and pick passes. So the graph orders the pass before those too.
75
89
 
76
- A view is the scene seen from one camera, culled on its own. On WebGPU each view has a culling pass, and on WebGL2 the job workers list the visible objects of each view. On a device that draws directly, the job workers list them on WebGPU too. The camera's view draws the scene color and depth, and the scene color reaches the canvas. Each scene pass that a sketch adds has a view of its own, which draws into its texture. The camera's passes read the texture of every scene pass that a material shows, so those passes run first. A view that a sketch adds with `scene.createView` draws after the camera's passes. It draws into a rectangle of the camera's scene color through the viewport and the scissor, with a depth target of its own, so its image covers the camera's there. WebGPU draws an image's top row first, and materials sample the bottom row at v = 0. So on WebGPU a copy pass turns each pass's image over into its texture. WebGL2 draws the rows in that order already. A reflection view on the HDR WebGPU path is the exception: it draws into its target directly, and `reflection_uv` turns the rows of the lookups that read it.
90
+ ## The final pass and the resolve pass
77
91
 
78
- A full-screen pass that a sketch adds is a view without a camera. It draws one triangle over its texture, and its shader writes the rows bottom first on both paths, so it needs no copy. A pass that reads only other passes' textures runs before the passes that read its own. A pass that reads the scene color, the outline mask or the scene depth runs after the camera's passes, so the camera's passes do not read its texture in the same frame: a material that shows it shows the frame before. A custom effect that reads it runs after it. A compute pass that a sketch adds is a view without a camera too. Its shader writes its texture as a storage texture. A material, an effect or another pass samples that texture in the same frame, because the graph orders the pass before them. A custom material's vertex offset that reads it also draws it in the material's shadow, motion and pick passes, so the graph orders the pass before those too.
92
+ Where the scene draws HDR color, the final pass reads it and draws the canvas. It applies the exposure and the tone mapping, and encodes the color for the display. In the FXAA anti-aliasing mode it also smooths the edges.
79
93
 
80
- Where the scene draws HDR color, the final pass reads it and draws the canvas. It applies the exposure and the tone mapping, and encodes the color for the display. In the FXAA anti-aliasing mode it also smooths the edges. Some devices cannot draw float targets in the anti-aliasing mode. There the scene shaders tone map their own output into an 8-bit target. With MSAA the resolve pass then runs instead of the final pass, while no effect needs the final pass ([Color management](color-management.md#the-8-bit-path) lists them). It draws nothing: the scene's render pass resolves its multisampled color straight into the canvas. The frame then needs no extra pass, copy or texture. With FXAA or none, the final pass reads the 8-bit target and keeps its colors. [Color management](color-management.md) covers both paths.
94
+ Some devices cannot draw float targets in the anti-aliasing mode. There the scene shaders tone map their own output into an 8-bit target. With MSAA the resolve pass then runs instead of the final pass, while no effect needs the final pass ([Color management](color-management.md#the-8-bit-path) lists them). It draws nothing: the scene's render pass resolves its multisampled color straight into the canvas. The frame then needs no extra pass, copy or texture.
95
+
96
+ With FXAA or none, the final pass reads the 8-bit target and keeps its colors. [Color management](color-management.md) covers both paths.
81
97
 
82
98
  ## Scene inputs
83
99
 
84
100
  A custom material or an add-on feature can read scene resources that the frame makes before it draws:
85
101
 
86
- | Input | What it holds | Made where |
87
- | --- | --- | --- |
88
- | `'sceneColor'` | The scene's color before the tone curve | The camera's opaque and transparent passes |
89
- | `'sceneDepth'` | The scene's depth | The camera's opaque pass |
90
- | `'normals'` | The surface normals | No pass makes them |
91
- | `'motionVectors'` | How far each pixel's surface moved since the last frame | The motion pass, while the motion debug view shows it |
102
+ | Input | What it holds | Made where | Who can read it |
103
+ | --- | --- | --- | --- |
104
+ | `'sceneColor'` | The scene's color before the tone curve | The camera's opaque and transparent passes | Full-screen effects |
105
+ | `'sceneDepth'` | The scene's depth | The camera's opaque pass | Full-screen effects and custom materials |
106
+ | `'normals'` | The surface normals | No pass makes them | No reader |
107
+ | `'motionVectors'` | How far each pixel's surface moved since the last frame | The motion pass, while the motion debug view shows it | Only the motion debug view |
92
108
 
93
- A feature declares the inputs in its `reads` ([Add-on feature descriptions](../api/features.md#scene-resources)). The render graph then runs it after the passes that write them. A full-screen effect reads only `'sceneColor'` and `'sceneDepth'`, and a custom material reads only `'sceneDepth'`. No pass makes `'normals'`, and the adapters refuse `'motionVectors'`. A custom material declares `sceneInputs: ['sceneDepth']` and reads the depth with `sceneDepth` or `sceneDistance` ([Materials](../api/materials.md#the-scene-behind-a-surface)).
109
+ A feature declares the inputs in its `reads` ([Add-on feature descriptions](../api/features.md#scene-resources)). The render graph then runs it after the passes that write them. No pass makes `'normals'`, so a feature that reads them gets a neutral value. No custom material, full-screen effect or add-on pass gets the motion vectors bound. A custom material declares `sceneInputs: ['sceneDepth']` and reads the depth with `sceneDepth` or `sceneDistance` ([Materials](../api/materials.md#the-scene-behind-a-surface)).
94
110
 
95
111
  A blended material that reads the depth binds a copy of it, one texel for each pixel. The frame makes the copy after the opaque pass and before the transparent pass, so the material never samples the depth target that its own pass writes. While the copy does not exist, a draw binds one texel at the far plane and reads 0:
96
112
 
@@ -101,7 +117,7 @@ The frame makes the copy while a material that reads it draws, or while a partic
101
117
 
102
118
  ## Motion vectors
103
119
 
104
- Motion vectors record how far each pixel's surface moved on the screen since the last frame. Temporal anti-aliasing, motion blur and reflections that reuse the last frame need them. Today the motion debug view, `debug.view('motion')`, reads them.
120
+ Motion vectors record how far each pixel's surface moved on the screen since the last frame. Effects such as temporal anti-aliasing and motion blur use them, but null3D ships neither. The motion debug view, `debug.view('motion')`, reads them.
105
121
 
106
122
  The motion pass runs after the transparent pass. It draws only the opaque objects that moved into a target of two 16-bit floats per pixel, with the scene's depth as its depth test:
107
123
 
@@ -133,13 +149,31 @@ Two rules decide the order:
133
149
  1. Passes that write one target run in the order they were declared. The first one that draws into it in a frame clears it, and each later one draws over what the earlier ones left.
134
150
  2. A pass that reads a target or a buffer runs after every pass that writes it, so it sees what they wrote.
135
151
 
152
+ The exception is the occluders' pass. It reads the visible instances before late culling writes them again. So a pass that reads a resource "so far" runs after the writers declared before it, and before the writers declared after it.
153
+
136
154
  Where the rules leave a choice, the graph first runs a pass that can join the open render or compute pass. Next it runs a compute pass: compute passes never share a render pass, so running them early keeps later render passes whole. After that it takes the first pass in the order of declaration.
137
155
 
138
156
  For example, the resolve pass reads the scene color, so it runs after the opaque pass that draws it. The order holds even when the resolve pass is declared first. On WebGPU the opaque pass reads the visible instances, so the culling pass runs before it.
139
157
 
158
+ A sketch's scene pass follows the same rule. The graph runs it before the camera's passes, because a material reads its texture:
159
+
160
+ ```ts
161
+ // A scene pass draws the security camera's view into a texture, and the monitor shows it.
162
+ const size = [512, 288] as const;
163
+ const feed = render.addPass({ kind: 'scene', camera: security, writes: 'security', size });
164
+ const shown = { feed: textures.fromPass(feed) };
165
+ const screen = materials.shader({ wgsl: monitor, roughness: 0.15, textures: shown });
166
+ ```
167
+
168
+ [The security camera demo](https://github.com/null3d-engine/null3d/tree/main/examples/security-camera) shows the whole sketch.
169
+
140
170
  ## Targets and memory
141
171
 
142
- A target is a texture that passes draw into. A temporary target lives for one frame, and the pass that creates it sets its size. That size is the render size, half or a quarter of it, the canvas size, or a fixed size in pixels. The render size is the canvas size at the render scale, which [dynamic resolution](quality-presets.md#dynamic-resolution) moves. The engine makes each target of a relative size at the canvas's size, and passes draw into its top-left corner at a lower scale. So a new scale needs no new texture. The kept targets of [custom passes](../api/render.md) with a `scale`, reflections included, are the exception: each texture takes the render size's share, and a new scale makes it again, so materials read it whole. A kept target holds its contents from one frame to the next, in a texture of its own. The engine's scene color and depth are temporary targets.
172
+ A target is a texture that passes draw into. A temporary target lives for one frame, and the pass that creates it sets its size. That size is the render size, half or a quarter of it, the canvas size, or a fixed size in pixels. The render size is the canvas size at the render scale, which [dynamic resolution](quality-presets.md#dynamic-resolution) moves.
173
+
174
+ The engine makes each target of a relative size at the canvas's size, and passes draw into its top-left corner at a lower scale. So a new scale needs no new texture. The engine's scene color and depth are temporary targets.
175
+
176
+ A kept target holds its contents from one frame to the next, in a texture of its own. The kept targets of [custom passes](../api/render.md) with a `scale`, reflections included, are the exception: each texture takes the render size's share, and a new scale makes it again, so materials read it whole.
143
177
 
144
178
  Temporary targets share memory when their lifetimes do not overlap. Such targets must also need the same format, size, sample count and usage. For example, a blur can pass an image through three half-size targets in a row. The first one is done before the third one starts, so the two share one texture. The blur then needs two half-size textures instead of three.
145
179
 
@@ -220,3 +254,4 @@ digraph "render graph" {
220
254
  - [Shadows](shadows.md): the shadow cascades.
221
255
  - [Render graph API](../api/render.md): adding passes and printing the graph.
222
256
  - [The security camera demo](https://github.com/null3d-engine/null3d/tree/main/examples/security-camera): a scene pass that draws a second camera's view for a monitor.
257
+ - [Multiple views](https://github.com/null3d-engine/null3d/tree/main/examples/multiple-views): one scene drawn from two cameras in the same frame, split across the canvas or in an inset.
@@ -1,14 +1,12 @@
1
1
  ---
2
2
  id: concepts/render-layers
3
3
  title: Render layers
4
- status: experimental
5
- since: "0.1"
6
4
  summary: "32-bit layer masks that choose which cameras draw which objects and instance batches."
7
5
  ---
8
6
 
9
7
  # Render layers
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. Raycasts, overlap queries and declared render passes take layer masks too. See [Raycasting and spatial queries](../api/raycast.md) and [Custom passes and render targets](../guides/custom-passes.md).
9
+ > Raycasts, overlap queries and declared render passes take layer masks too. See [Raycasting and spatial queries](../api/raycast.md) and [Custom passes and render targets](../guides/custom-passes.md).
12
10
 
13
11
  ```mermaid
14
12
  flowchart LR
@@ -23,6 +21,10 @@ A layer mask is a 32-bit number. Bit n puts an object on layer n, so the mask `1
23
21
 
24
22
  New objects, batches and cameras are on layer 0 alone, with the mask 1. Every camera draws every object until you change a mask.
25
23
 
24
+ ![Brick cottages drawn without their roof layer, so the rooms inside show, with a red map pin above each house.](../images/concepts/render-layers/layers-cottages.webp)
25
+
26
+ The camera's mask leaves out the roof layer and draws the pin layer.
27
+
26
28
  ## Setting layers
27
29
 
28
30
  ```ts
@@ -63,7 +65,9 @@ export default defineSketch(({ scene, geometry, materials, input }) => {
63
65
  - `obj.setLayers(mask)` changes an object's layers, and `batch.setLayers(mask)` changes the layers of every row of a batch.
64
66
  - `camera.setLayers(mask)` changes the layers that the camera draws.
65
67
  - A mask of 0 puts an object on no layer, so no camera draws it. A mask of `0xffffffff` puts it on all 32 layers.
66
- - In development builds, a mask that is not a whole number of 32 bits throws E1207. Negative numbers down to `-(2 ** 31)` work too, so `1 << 31`, which JavaScript makes negative, is layer 31.
68
+ - In development builds, a mask must be a whole number from `-(2 ** 31)` to `0xffffffff`, or the call throws [E1207](../errors/E1207.md). Negative masks are allowed so that `1 << 31`, which JavaScript makes negative, names layer 31.
69
+
70
+ [Camera layer masks](https://github.com/null3d-engine/null3d/tree/main/examples/layers) shows a camera that changes its layers every 2 seconds, to show or hide roofs and map pins.
67
71
 
68
72
  ## Layers and visibility
69
73
 
@@ -108,4 +112,4 @@ A new mask rebuilds none of the engine's tables of what it draws. On WebGPU it r
108
112
  - [Cameras](../api/cameras.md): the camera's layers.
109
113
  - [Scene](../api/scene.md): the `layers` option, and when changes take effect.
110
114
  - [Culling](culling.md): the test that masks join.
111
- - [The render layers demo](https://github.com/null3d-engine/null3d/tree/main/examples/layers): a camera that changes its layers every 2 seconds, to show or hide roofs and map pins.
115
+ - [Camera layer masks](https://github.com/null3d-engine/null3d/tree/main/examples/layers): a camera that changes its layers every 2 seconds, to show or hide roofs and map pins.