@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,12 @@
1
1
  ---
2
2
  id: concepts/lod
3
3
  title: Levels of detail
4
- status: experimental
5
- since: "0.2"
6
4
  summary: "LOD groups; levels that meshes made in code plan on the job workers; generated LODs; cluster patches; staged downloads; per-instance selection; small-object hiding."
7
5
  ---
8
6
 
9
7
  # Levels of detail
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. Morphed objects, and materials that blend or let light through, draw their base mesh at every distance. A skinned object draws a level while the level names the base mesh's own vertices, as the asset tool's levels do. Masks with the `'hash'` alpha mode switch levels at once, with no fading band. A distance band cuts at once for them too.
9
+ > Morphed objects, and materials that blend or let light through, draw their base mesh at every distance. A skinned object draws a level while the level names the base mesh's own vertices, as the asset tool's levels do. Masks with the `'hash'` alpha mode switch levels at once, with no fading band. A distance band cuts at once for them too.
12
10
 
13
11
  ```mermaid
14
12
  flowchart LR
@@ -24,9 +22,15 @@ An object far from the camera covers few pixels. Its full mesh then costs vertex
24
22
 
25
23
  A mesh with levels draws one of them per frame in every object and every instance row that uses it. The engine picks the level on the GPU on WebGPU, and on its job workers on WebGL2. Both use the same rule, so a level switches in at the same distance on every GPU path.
26
24
 
25
+ ![A dense mixed forest at golden hour, under a cloudy sky.](../images/concepts/lod/forest.webp)
26
+
27
+ What you see. The levels view beside it shows what the engine picks.
28
+
27
29
  ## Levels of meshes made in code
28
30
 
29
- A mesh made in code plans its levels the first time the scene draws it, when it holds 4,096 triangles or more, or when it holds at least 256 triangles and its copies hold 65,536 triangles together, whether `geometry.fromArrays` or a generator made it. A page's meshes and an add-on's plan alike. A mesh that no object draws plans nothing, and the plan sees the material that draws the mesh first. The plan runs on the job workers, never in a frame, and the mesh draws its full shape until the levels arrive. It runs the planner that the asset tool's `--lod` runs, with the same build of meshoptimizer's simplifier, so the same mesh gets the same levels in code as in a file. The copies that already draw the mesh then pick their levels, as the streamed levels of a file refine in place.
31
+ A mesh made in code plans its levels the first time the scene draws it. It plans when it holds 4,096 triangles or more, or when it holds at least 256 triangles and its copies hold 65,536 triangles together. This holds whether `geometry.fromArrays` or a generator made it. A page's meshes and an add-on's plan alike. A mesh that no object draws plans nothing, and the plan sees the material that draws the mesh first.
32
+
33
+ The plan runs on the job workers, never in a frame, and the mesh draws its full shape until the levels arrive. It runs the same planner as the asset tool's `--lod`, with the same build of meshoptimizer's simplifier. So the same mesh gets the same levels in code as in a file. The copies that already draw the mesh then pick their levels, as the streamed levels of a file refine in place.
30
34
 
31
35
  ```ts
32
36
  const rock = geometry.fromArrays(rockArrays(20_000));
@@ -34,7 +38,9 @@ scene.createInstances(rock, 5_000, { material: stone }); // the first draw plans
34
38
  await rock.buildLevels(); // resolves with the levels once they are in
35
39
  ```
36
40
 
37
- Each level about halves the triangles of the level above, down to a few dozen, and keeps its measured error, so it switches in at once where the error covers less than the `lodThreshold` setting's pixels. The threshold is live, and the governor can raise it to 4 or 8 pixels, where such a switch shows; a measured level then fades, as [Fading between levels](#fading-between-levels) describes. The levels name the mesh's own vertices, so they cost indices alone, and the mesh keeps its vertex and triangle order: raycasts and `updateVertices` see the mesh as it was made. The [geometry page](../api/geometry.md#levels-of-detail) gives the `levels` option, which turns the plan off or on, and the meshes that plan none: meshes that pose or move, meshes that a shader shapes, meshes whose vertices change, and meshes whose levels you set by hand.
41
+ Each level about halves the triangles of the level above, down to a few dozen. It keeps its measured error, so it switches in at once where the error covers less than the `lodThreshold` setting's pixels. The threshold is live. The [frame-budget governor](quality-presets.md#the-frame-budget-governor), which lowers quality when frames run late, can raise it to 4 or 8 pixels, where such a switch shows. A measured level then fades, as [Fading between levels](#fading-between-levels) describes.
42
+
43
+ The levels name the mesh's own vertices, so they cost indices alone. The mesh keeps its vertex and triangle order, so raycasts and `updateVertices` see the mesh as it was made. The [geometry page](../api/geometry.md#levels-of-detail) gives the `levels` option, which turns the plan off or on. It also names the meshes that plan none. These are meshes that pose or move, meshes that a shader shapes, meshes whose vertices change, and meshes whose levels you set by hand.
38
44
 
39
45
  A mesh of separate quads plans as any other mesh unless it asks for cards with `levels: { cards: true }`. The walls of a building kit are separate quads too, and thinning them as cards would cut holes in them. Without cards, a level drops only whole small pieces, such as a shutter's slats, where they cover under a pixel.
40
46
 
@@ -46,6 +52,8 @@ A mesh of separate quads plans as any other mesh unless it asks for cards with `
46
52
  - `distance`: a distance in meters for an object of scale 1. It holds on every screen height and at every render scale.
47
53
  - `coverage`: the share of the render's height that the object's bounds cover, from 0 to 1. It holds on every screen height too.
48
54
 
55
+ The levels of detail demo gives four kinds of tree made in code four levels each, with their errors, over 56,000 trees (8,000 on phones). Press B to turn the hero fir's bias on and off, and L to turn levels off.
56
+
49
57
  ```ts
50
58
  const tree = geometry.fromArrays(treeArrays(64));
51
59
  tree.setLevels([
@@ -90,13 +98,23 @@ bunx @null3d/cli assets optimize models/ public/models/ --lod --stages
90
98
 
91
99
  The model file then holds the full vertices and the coarsest level, and each finer level downloads from a file of its own. The engine draws each level as it arrives, and the copies that already draw the model refine in place.
92
100
 
93
- The loader also holds back a level that the camera never shows. It fetches the stage after the file's own level at once. Then it keeps each finer stage until a view has drawn the level that the mesh has now. It waits about two seconds of drawn frames for that pick. A level that never draws cannot lead to a finer one. So the loader sets that stage and the finer ones aside, and their files do not download. The engine decides from the levels that it picked, never from the device's name. The switch follows the camera, the render scale and the `lodThreshold` setting. What the loader set aside is not lost. It looks again about every second and a half. A camera that comes close enough to draw that level then brings the stage and the finer ones. So a level that the camera never draws costs no download, and a level that the camera starts to draw arrives.
101
+ The loader also holds back a level that the camera never shows. It fetches the stage after the file's own level at once. Then it keeps each finer stage until a view has drawn the level that the mesh has now. It waits about two seconds of drawn frames for that pick. A level that never draws cannot lead to a finer one. So the loader sets that stage and the finer ones aside, and their files do not download.
102
+
103
+ The engine decides from the levels that it picked, never from the device's name. The switch follows the camera, the render scale and the `lodThreshold` setting. What the loader set aside is not lost.
104
+
105
+ It looks again about every second and a half. A camera that comes close enough to draw that level then brings the stage and the finer ones. So a level that the camera never draws costs no download, and a level that the camera starts to draw arrives.
94
106
 
95
107
  `assets.loadGltf` takes `maxLevels` to stop after that many levels, counting the file's own: a page whose objects never come close enough to show the finest level sets 1, and downloads less. [The asset pipeline](../guides/assets-pipeline.md#levels-as-separate-downloads) has the detail.
96
108
 
97
- Each level has about half the triangles of the level above, down to a few dozen triangles. A mesh of a million triangles takes 15 levels to get there. Each level shares the mesh's vertices. The loader stores each level over the base mesh's own vertices, so the level costs the GPU its indices alone. The tool orders the vertices coarsest level first, so a coarse level reads a stretch at the start of the vertex buffer. Some levels keep a copy of their vertices instead. A level of cards brings positions of its own, and a level whose base mesh the engine had to split into parts cannot share them. Each level stores its error in the units of the mesh's own positions. The tool stores the levels with the `MSFT_lod` glTF extension. Each node with levels keeps its errors in its extras, as `NULL3D_lod_error`. It also writes the screen coverage that each error implies, in `MSFT_screencoverage`, for a screen 1,080 pixels high. The loader reads the coverage that comes beside an error to tell a measured error from a hand-set one, and reads the coverage alone as the measure for a file that holds no errors. `assets.loadGltf` gives each mesh its levels. So a model's copies and its instance batches pick their levels with no code. Other glTF loaders draw the full mesh.
109
+ Each level has about half the triangles of the level above, down to a few dozen triangles. A mesh of a million triangles takes 15 levels to get there. Each level shares the mesh's vertices. The loader stores each level over the base mesh's own vertices, so the level costs the GPU its indices alone. The tool orders the vertices coarsest level first, so a coarse level reads a stretch at the start of the vertex buffer.
110
+
111
+ Some levels keep a copy of their vertices instead. A level of cards brings positions of its own, and a level whose base mesh the engine had to split into parts cannot share them. Each level stores its error in the units of the mesh's own positions. The tool stores the levels with the `MSFT_lod` glTF extension. Each node with levels keeps its errors in its extras, as `NULL3D_lod_error`. It also writes the screen coverage that each error implies, in `MSFT_screencoverage`, for a screen 1,080 pixels high.
112
+
113
+ The loader reads the coverage that comes beside an error to tell a measured error from a hand-set one. It reads the coverage alone as the measure for a file that holds no errors. `assets.loadGltf` gives each mesh its levels. So a model's copies and its instance batches pick their levels with no code. Other glTF loaders draw the full mesh.
98
114
 
99
- A measured error changes the picture by less than a pixel at a small threshold, so such a level switches at once there. The loader reads an error as measured only where the file also gives the coverage that the tool writes beside it. A file that gives errors alone holds switch distances that its author set by hand. Those levels fade, as levels given by a distance or a coverage do. A file may bring its own levels, such as levels made in Blender, with errors in the units of the mesh's positions. `assets optimize` keeps them. It stores each level's positions in its base mesh's integer steps, and converts their errors to those steps.
115
+ A measured error changes the picture by less than a pixel at a small threshold, so such a level switches at once there. The loader reads an error as measured only where the file also gives the coverage that the tool writes beside it. A file that gives errors alone holds switch distances that its author set by hand. Those levels fade, as levels given by a distance or a coverage do.
116
+
117
+ A file may bring its own levels, such as levels made in Blender, with errors in the units of the mesh's positions. `assets optimize` keeps them. It stores each level's positions in its base mesh's integer steps, and converts their errors to those steps.
100
118
 
101
119
  ## Cluster levels
102
120
 
@@ -104,29 +122,63 @@ A level covers the whole mesh at one detail. A mesh that is close at one end and
104
122
 
105
123
  The asset tool builds the tree with `--clusters`, as [the asset pipeline](../guides/assets-pipeline.md#cluster-levels) explains. It splits a large static mesh into patches, then simplifies groups of patches into the patches above them. Every patch's indices name the mesh's own vertices, so the tree adds no vertex. It costs about twice the mesh's indices.
106
124
 
107
- A view draws a patch while the patch's own error passes its threshold and the error of the patch above it does not. Each error is tested at the distance to its own patch's bounds. A patch that fails the threshold is too coarse for that distance, so the walk descends into its children. The chosen patches are the frontier of that one rule. A patch's bounds hold its children's bounds, and its error is at least theirs. So a patch never passes where one of its children fails, and the patches cover the mesh once. Neighbours of different detail meet at their edges with no gap. The engine draws a tree from an older asset tool as whole levels, and in development it asks you to optimize the file again.
125
+ A view draws a patch while the patch's own error passes its threshold and the error of the patch above it does not.
126
+
127
+ Each error is tested at the distance to its own patch's bounds. A patch that fails the threshold is too coarse for that distance, so the walk descends into its children. The chosen patches are the frontier of that one rule.
108
128
 
109
- The engine draws a tree's patches on both GPU paths, in the camera's view and in each shadow map. On WebGPU, a compute pass picks the patches that a view draws, copies their indices into a list of the view's own, and the view draws them in one draw. A view that sees none of a mesh's patches draws none of it. The pass runs three dispatches: one to test each patch, one to add the counts up, and one to copy the indices that draw. The list takes four bytes an index. The engine counts the indices that each view picks in each frame, and sizes the view's list to them with room to spare.
129
+ A patch's bounds hold its children's bounds, and its error is at least theirs. So a patch never passes where one of its children fails, and the patches cover the mesh once. Neighbors of different detail meet at their edges with no gap. The engine draws a tree from an older asset tool as whole levels, and in development it asks you to optimize the file again.
110
130
 
111
- On WebGL2, the job workers walk the tree for each view with the same rule, where the device has `WEBGL_multi_draw` (Chrome and Safari). Each chosen patch is a range of the mesh's tree in one multi-draw call, so a frame uploads ranges and no triangles. Ranges that are neighbours in the tree's index list merge, so a frame makes fewer calls. A WebGL2 browser without `WEBGL_multi_draw`, such as Firefox, draws the mesh's whole levels instead. The tool writes them beside the tree. They are the levels that `--lod` makes, and other glTF viewers draw them too.
131
+ The engine draws a tree's patches on both GPU paths, in the camera's view and in each shadow map. On WebGPU, a compute pass picks the patches that a view draws, copies their indices into a list of the view's own, and the view draws them in one draw. A view that sees none of a mesh's patches draws none of it.
112
132
 
113
- The engine splits a mesh of more than 65,535 vertices into parts, because a draw's 16-bit indices reach no further. On WebGPU such a mesh still draws its patches. The engine puts all of its parts in one vertex buffer, one after another. The tree's 32-bit indices reach every vertex there. That buffer holds at most 128 MiB, the default size of a storage binding: about 4 million vertices of 32 bytes. A larger mesh draws whole levels instead. The trees that a scene draws also share 128 MiB of indices, about 33 million. They share at most 65,535 patches too, which a mesh of about 4 million triangles fills. A tree that does not fit draws whole levels.
133
+ The pass runs three dispatches: one to test each patch, one to add the counts up, and one to copy the indices that draw. The list takes four bytes an index. The engine counts the indices that each view picks in each frame, and sizes the view's list to them with room to spare.
114
134
 
115
- On WebGL2, a vertex buffer holds at most 65,535 vertices, so a mesh of more vertices lies in several buffers. Its tree then draws from a copy of the mesh's vertices that the tree keeps for itself, with 32-bit indices. The copy costs the mesh's vertex bytes a second time: 12 MB for a ground of a million vertices of 12 bytes. This needs the `WEBGL_provoking_vertex` extension, which Chrome offers, and WebKit, Safari's engine. Without the extension's first-vertex rule, Chrome on the Mac would copy the tree's whole index list before each range it draws. So a browser without the extension draws such a mesh's whole levels instead. A tree of a mesh in one buffer draws its patches either way.
135
+ On WebGL2, the job workers walk the tree for each view with the same rule, where the device has `WEBGL_multi_draw` (Chrome and Safari). Each chosen patch is a range of the mesh's tree in one multi-draw call, so a frame uploads ranges and no triangles. Ranges that are neighbors in the tree's index list merge, so a frame makes fewer calls.
116
136
 
117
- A tree can stream as a model loads, with `--clusters --stages`. The model file then holds the tree's first band, and that band draws the first picture. Each later band downloads from a file of its own. A band appends its patches below the patches that already arrived, so the tree refines as the bands come and no new object appears. The patches that a page holds always form a whole tree from the root. A patch whose children have not arrived draws where the camera is close, so the first picture is coarse and still covers the whole surface. The loader holds a band until a view draws a patch of the band above it. `maxLevels` counts a band as it counts a level. [The asset pipeline](../guides/assets-pipeline.md#levels-as-separate-downloads) has the detail.
137
+ A WebGL2 browser without `WEBGL_multi_draw`, such as Firefox, draws the mesh's whole levels instead. The tool writes them beside the tree. They are the levels that `--lod` makes, and other glTF viewers draw them too.
118
138
 
119
- The patch path draws a mesh that one copy draws, and the file may still hold a tree for a mesh with more copies. A mesh that draws several copies at once draws its whole levels, because the walk picks the patches of one copy. An instance batch draws whole levels too, even with one row. The tool counts only the copies that the file places. A mesh that page code draws in an instance batch therefore still gets a tree, and its copies draw the whole levels. The levels go down to a few dozen triangles, so far copies stay cheap. The WebGPU path that draws objects directly also draws the whole levels, because it has no cluster pass. Meshes that a skin or a morph target bends, and meshes whose material blends or masks, keep whole levels too. A shadow map draws a caster's patches where the camera's view draws the same object's tree, and the caster's whole levels elsewhere.
139
+ The engine splits a mesh of more than 65,535 vertices into parts, because a draw's 16-bit indices reach no further. On WebGPU such a mesh still draws its patches. The engine puts all of its parts in one vertex buffer, one after another. The tree's 32-bit indices reach every vertex there. That buffer holds at most 128 MiB, the default size of a storage binding: about 4 million vertices of 32 bytes. A larger mesh draws whole levels instead.
140
+
141
+ The trees that a scene draws also share 128 MiB of indices, about 33 million. They share at most 65,535 patches too, which a mesh of about 4 million triangles fills. A tree that does not fit draws whole levels.
142
+
143
+ On WebGL2, a vertex buffer holds at most 65,535 vertices, so a mesh of more vertices lies in several buffers. Its tree then draws from a copy of the mesh's vertices that the tree keeps for itself, with 32-bit indices. The copy costs the mesh's vertex bytes a second time: 12 MB for a ground of a million vertices of 12 bytes.
144
+
145
+ This needs the `WEBGL_provoking_vertex` extension, which Chrome offers, and WebKit, Safari's engine. Without the extension's first-vertex rule, Chrome on the Mac would copy the tree's whole index list before each range it draws. So a browser without the extension draws such a mesh's whole levels instead. A tree of a mesh in one buffer draws its patches either way.
146
+
147
+ A tree can stream as a model loads, with `--clusters --stages`. The model file then holds the tree's first band, and that band draws the first picture. Each later band downloads from a file of its own. A band appends its patches below the patches that already arrived, so the tree refines as the bands come and no new object appears. The patches that a page holds always form a whole tree from the root.
148
+
149
+ A patch whose children have not arrived draws where the camera is close, so the first picture is coarse and still covers the whole surface. The loader holds a band until a view draws a patch of the band above it. `maxLevels` counts a band as it counts a level. [The asset pipeline](../guides/assets-pipeline.md#levels-as-separate-downloads) has the detail.
150
+
151
+ The patch path draws a mesh that one copy draws, and the file may still hold a tree for a mesh with more copies. A mesh that draws several copies at once draws its whole levels, because the walk picks the patches of one copy. An instance batch draws whole levels too, even with one row.
152
+
153
+ The tool counts only the copies that the file places. A mesh that page code draws in an instance batch therefore still gets a tree, and its copies draw the whole levels. The levels go down to a few dozen triangles, so far copies stay cheap.
154
+
155
+ The WebGPU path that draws objects directly also draws the whole levels, because it has no cluster pass. Meshes that a skin or a morph target bends, and meshes whose material blends or masks, keep whole levels too. A shadow map draws a caster's patches where the camera's view draws the same object's tree, and the caster's whole levels elsewhere.
120
156
 
121
157
  ## Pieces of a large level
122
158
 
123
159
  A copy that the view cuts through, or that turns half its surface away from the camera, still draws every triangle of its level. So `--lod` also sorts each level of 32,768 triangles or more into 8 to 16 pieces. Each piece faces about one way and has its own bounds. The file stores them in `NULL3D_pieces`, and other viewers draw the same triangles in the new order.
124
160
 
125
- Each copy picks its level as before. It then skips each piece of that level that lies outside the view. In the camera's own view it also skips each piece whose triangles all face away from the camera. With GPU occlusion culling on, it skips each piece that the occluders hide as well. The picture is the same as without pieces. A material that draws both faces keeps every piece that faces away, and so does a copy that is mirrored or stretched. Each piece adds a draw to its level, so a smaller level keeps whole unless many copies draw it.
161
+ Each copy picks its level as before. It then skips each piece of that level that lies outside the view. In the camera's own view it also skips each piece whose triangles all face away from the camera. With GPU occlusion culling on, it skips each piece that the occluders hide as well.
162
+
163
+ The picture is the same as without pieces. A material that draws both faces keeps every piece that faces away, and so does a copy that is mirrored or stretched. Each piece adds a draw to its level, so a smaller level keeps whole unless many copies draw it.
164
+
165
+ A smaller list gets pieces only where the way it faces makes them pay, since the view seldom cuts a small copy. Many copies must draw it: a list of 1,024 to 32,767 triangles whose copies hold 65,536 triangles or more together. Its triangles must also fall into a few tight facing groups, as a building's sides, tops and undersides do.
166
+
167
+ Such a list gets one piece for each of up to six ways that it faces. One more piece holds the triangles that face between them, such as a pot's or a sloped cap's. Each copy then skips the sides that face away from the camera. The group must let each copy skip a quarter of the list's triangles or more, over views from all around.
126
168
 
127
- A smaller list gets pieces only where the way it faces makes them pay, since the view seldom cuts a small copy. Many copies must draw it: a list of 1,024 to 32,767 triangles whose copies hold 65,536 triangles or more together. Its triangles must also fall into a few tight facing groups, as a building's sides, tops and undersides do. Such a list gets one piece for each of up to six ways that it faces. One more piece holds the triangles that face between them, such as a pot's or a sloped cap's. Each copy then skips the sides that face away from the camera. The group must let each copy skip a quarter of the list's triangles or more, over views from all around. A list that faces every way, such as a rough rock, gets no facing pieces, and neither does one whose material blends. The engine plans none for a material that draws both faces either, since the cone test would drop none of them. A file's stored pieces still cull by the view. A list that faces mostly one way, such as a ground, stays whole too, since a view sees its front. The asset tool stores such pieces whatever copies the file places, since a page may copy a file's mesh many times. The engine counts the copies that the scene draws of each mesh. Until they pay, the list draws whole, with no draw more. A file's mesh whose smaller list holds no pieces, as from an older file, plans them on the job workers once its copies pay.
169
+ A list that faces every way, such as a rough rock, gets no facing pieces, and neither does one whose material blends. The engine plans none for a material that draws both faces either, since the cone test would drop none of them. A file's stored pieces still cull by the view. A list that faces mostly one way, such as a ground, stays whole too, since a view sees its front.
128
170
 
129
- A mesh made in code gets pieces with its planned levels. The plan on the job workers sorts the mesh and each of its levels of 32,768 triangles or more into pieces, as `--lod` does. The mesh keeps its own triangles in their order, so raycasts and `updateVertices` see it as it was made. A mesh that one object draws, such as a ground around the camera, gets pieces of its own too. They draw a sorted copy of its indices, which shares its vertices. Copies of a large mesh draw their full mesh only near the camera, so they keep the pieces of their levels and spare that copy. The copy of a smaller list's indices costs little, so a smaller mesh that many copies draw gets pieces of its own as well. A list whose triangles mostly face one way, such as a ground, a road or a wall, splits by space alone, so the view cuts the pieces that it leaves out. A mesh of more than 65,535 vertices, which the engine splits into parts, sorts each part's triangles into pieces of their own, and a mesh of more than 32 parts gets none. A mesh with `levels: false` gets no pieces. A mesh whose levels are set by hand plans no levels. It still plans facing pieces of its own list at its first draw when it holds under 32,768 triangles and many copies draw it. A town's house walls are such meshes. `levels: 'pieces'` asks for pieces alone: a mesh of 32,768 triangles or more sorts into pieces by space at its first draw, as the impostors' merged far cells do. A surface that blends or lets light through, such as water, draws whole in the transparent pass, so it takes no pieces.
171
+ The asset tool stores such pieces whatever copies the file places, since a page may copy a file's mesh many times. The engine counts the copies that the scene draws of each mesh. Until they pay, the list draws whole, with no draw more. A file's mesh whose smaller list holds no pieces, as from an older file, plans them on the job workers once its copies pay.
172
+
173
+ A mesh made in code gets pieces with its planned levels. The plan on the job workers sorts the mesh and each of its levels of 32,768 triangles or more into pieces, as `--lod` does. The mesh keeps its own triangles in their order, so raycasts and `updateVertices` see it as it was made.
174
+
175
+ A mesh that one object draws, such as a ground around the camera, gets pieces of its own too. They draw a sorted copy of its indices, which shares its vertices. Copies of a large mesh draw their full mesh only near the camera, so they keep the pieces of their levels and spare that copy. The copy of a smaller list's indices costs little, so a smaller mesh that many copies draw gets pieces of its own as well.
176
+
177
+ A list whose triangles mostly face one way, such as a ground, a road or a wall, splits by space alone, so the view cuts the pieces that it leaves out. A mesh of more than 65,535 vertices, which the engine splits into parts, sorts each part's triangles into pieces of their own, and a mesh of more than 32 parts gets none. A mesh with `levels: false` gets no pieces.
178
+
179
+ A mesh whose levels are set by hand plans no levels. It still plans facing pieces of its own list at its first draw when it holds under 32,768 triangles and many copies draw it. A town's house walls are such meshes.
180
+
181
+ `levels: 'pieces'` asks for pieces alone: a mesh of 32,768 triangles or more sorts into pieces by space at its first draw, as the impostors' merged far cells do. A surface that blends or lets light through, such as water, draws whole in the transparent pass, so it takes no pieces.
130
182
 
131
183
  ## How the engine picks a level
132
184
 
@@ -136,13 +188,26 @@ A level given by its error switches in where that error covers fewer pixels than
136
188
  pixels = error × scale × render height / (2 × distance × tan(field of view / 2))
137
189
  ```
138
190
 
139
- The factor is the render height in pixels times the projection's `P[1][1]`, over twice the threshold in pixels. The setting is 1 pixel from Medium up, and 2 on Low. The render height includes the render scale. So on a taller screen, or at a higher render scale, such a level switches in farther away. When the frame-budget governor lowers the render scale, coarser levels draw. When frames still take too long, the governor doubles this threshold and the shadow maps' threshold together, twice at most.
191
+ The engine folds the render height, the field of view and the threshold into one number per view, the factor. A level switches in where error × scale × factor / distance falls under 1. The threshold is 1 pixel from Medium up, and 2 on Low. The render height includes the render scale. So on a taller screen, or at a higher render scale, such a level switches in farther away.
192
+
193
+ When the frame-budget governor lowers the render scale, coarser levels draw. When frames still take too long, the governor doubles this threshold and the shadow maps' threshold together, twice at most.
194
+
195
+ <details>
196
+ <summary>Technical details: the factor and the distance</summary>
197
+
198
+ The factor is the render height in pixels times the projection's `P[1][1]`, over twice the threshold in pixels. `P[1][1]` is 1 / tan(field of view / 2), so this form equals the formula above.
199
+
200
+ For a level given by its error, the distance runs from the camera to the center of the object's bounding sphere, less half the sphere's radius. It is capped at twice the distance to the sphere's nearest point. A level's error is its largest anywhere on the mesh. A large object therefore switches at a point between its near side and its middle. It does not turn coarse too early, and its far side does not keep detail that only its near side shows.
201
+
202
+ The cap keeps a camera standing on a large mesh measuring the surface below it. Half the radius of a ground two kilometers across would be hundreds of meters. The near side then shows an error of up to two pixels rather than one.
203
+
204
+ </details>
140
205
 
141
206
  A level given by its distance switches where the camera is that far from the object's nearest point. The camera's field of view, the screen height and the render scale do not move it. A level given by its coverage switches where the object's bounds cover that share of the render's height. A taller screen does not move that switch either.
142
207
 
143
208
  An orthographic camera's pixels do not shrink with distance. So its levels given by an error follow the object's scale and the camera's zoom alone. A level given by a distance, and a distance band, measure the camera's distance to the object's nearest point in every view, so an orthographic camera still switches and hides them by that distance.
144
209
 
145
- For a level given by its error, the distance runs from the camera to the center of the object's bounding sphere, less half the sphere's radius, and is capped at twice the distance to the sphere's nearest point. A level's error is its largest anywhere on the mesh. A large object therefore switches at a point between its near side and its middle: it does not turn coarse too early, and its far side does not keep detail that only its near side shows. The cap keeps a camera standing on a large mesh measuring the surface below it. Half the radius of a ground two kilometers across would be hundreds of meters. The near side then shows an error of up to two pixels rather than one. A level given by its distance or its coverage measures to the nearest point of the bounding sphere, as its author set it. Turning the camera never changes a level. A camera inside the bounds, or near its middle, measures almost no distance, so the object keeps its full detail. A view with a camera of its own, such as a render pass, picks with that camera. Mirrors and the outline effect pick as the main camera does.
210
+ A level given by its distance or its coverage measures to the nearest point of the bounding sphere, as its author set it. Turning the camera never changes a level. A camera inside the bounds, or near its middle, measures almost no distance, so the object keeps its full detail. A view with a camera of its own, such as a render pass, picks with that camera. Mirrors and the outline effect pick as the main camera does.
146
211
 
147
212
  The same threshold hides an object of a mesh with levels that has nothing left to show. A bound that covers fewer pixels than the threshold draws nothing, and the mesh's last level holds no geometry. [Small objects](#small-objects) gives the distance and the fade.
148
213
 
@@ -150,7 +215,7 @@ Levels add no second copy of each object's data. Each view keeps about the room
150
215
 
151
216
  ## The bias of one object
152
217
 
153
- `setLevelBias` raises or lowers the threshold for one object, as Godot's `lod_bias` does. The bias divides the factor that picks the levels. A bias above 1 draws each switch at a nearer distance, and a bias below 1 keeps the object's detail:
218
+ `setLevelBias` raises or lowers the threshold for one object, as the inverse of Godot's `lod_bias`: a Godot bias of 2 is about a null3D bias of 0.5. The bias divides the factor that picks the levels. A bias above 1 draws each switch at a nearer distance, and a bias below 1 keeps the object's detail:
154
219
 
155
220
  ```ts
156
221
  hero.setLevelBias(0.5); // the hero keeps its detail twice as far out
@@ -163,10 +228,14 @@ The same factor moves the distance at which the object hides. A detailed hero ob
163
228
 
164
229
  A level that switches in at once can pop. The engine fades only where a switch would show:
165
230
 
166
- - A level with a measured error, which the asset tool writes and a mesh made in code plans, changes the picture by under a pixel at a small threshold. It switches at once there, so it pays for no second draw. When the governor raises the threshold above about one and a half pixels, the switch shows, and the level fades then. A preset's own threshold, Low's two pixels among them, never makes it fade. A file's error counts as measured only where the file also gives the coverage that the tool writes beside it.
231
+ - A level with a measured error, which the asset tool writes and a mesh made in code plans, changes the picture by under a pixel at a small threshold. It switches at once there, so it pays for no second draw.
232
+
233
+ When the governor raises the threshold above about one and a half pixels, the switch shows, and the level fades then. A preset's own threshold, Low's two pixels among them, never makes it fade. A file's error counts as measured only where the file also gives the coverage that the tool writes beside it.
167
234
  - A level given by a distance, by a coverage or by a hand-set error changes the picture more. It fades at every threshold.
168
235
 
169
- A fading level hands over in a short band past its switch distance. The band is 8% of the distance long, and the old level and the new one both draw in it. A 4 × 4 dither pattern gives each pixel to one of them, and the share of the new level grows across the band. Each copy shifts the pattern by a phase from a hash of the copy, so neighboring copies do not line up into one grid. The two levels of a band take the same phase, so no pixel draws twice. Nothing sorts.
236
+ A fading level hands over in a short band past its switch distance. The band is 8% of the distance long, and the old level and the new one both draw in it. A 4 × 4 dither pattern gives each pixel to one of them, and the share of the new level grows across the band.
237
+
238
+ Each copy shifts the pattern by a phase from a hash of the copy, so neighboring copies do not line up into one grid. The two levels of a band take the same phase, so no pixel draws twice. Nothing sorts.
170
239
 
171
240
  ```ts
172
241
  // A hand-set error fades by default. This one switches at once while the threshold stays small.
@@ -181,7 +250,9 @@ The fragments that the dither drops cost a tile GPU, such as a phone's or an App
181
250
 
182
251
  [Custom materials](../shaders/surface-functions.md) fade too, through their own builds, which download with the material's first use. Three kinds switch at once: a material that tests its mask by the [alpha hash](../api/materials.md#alpha-modes), a skinned material, and a material whose displacement moves its vertices.
183
252
 
184
- One add-on morphs a level instead of fading it. The terrain add-on moves each block's vertices toward its parent block's surface over the last part of the approach. The block then matches its parent when the selection hands over. It writes the target in the mesh's four-number vertex record, which its own custom material's `vertexOffset` reads. The morph adds no draw and writes no vertex in a frame. The impostors add-on's hand-over from meshes to cards fades with the dither instead. The cards stand at full coverage before the meshes thin out, so no pixel drops out of both. File meshes keep the dither too: the asset tool's simplifier records no mapping between one level's vertices and the next.
253
+ One add-on morphs a level instead of fading it. The terrain add-on moves each block's vertices toward its parent block's surface over the last part of the approach. The block then matches its parent when the selection hands over. It writes the target in the mesh's four-number vertex record, which its own custom material's `vertexOffset` reads. The morph adds no draw and writes no vertex in a frame.
254
+
255
+ The impostors add-on's hand-over from meshes to cards fades with the dither instead. The cards stand at full coverage before the meshes thin out, so no pixel drops out of both. File meshes keep the dither too: the asset tool's simplifier records no mapping between one level's vertices and the next.
185
256
 
186
257
  ## Small objects
187
258
 
@@ -190,10 +261,10 @@ An object far away can cover less than a pixel. Its levels then save vertex work
190
261
  The rule reads the object's bounding sphere, at the distance that a level given by its error measures. The number of pixels that its world diameter covers follows from the same factor as every level's switch distance:
191
262
 
192
263
  ```text
193
- pixels = diameter × factor × threshold / distance
264
+ pixels = diameter × factor / distance
194
265
  ```
195
266
 
196
- The object hides where that diameter covers fewer pixels than the `lodThreshold` setting. The render height, the render scale and the governor's doubled threshold all feed the factor, so they move the hide distance too. An orthographic camera hides an object by its diameter and the camera's zoom alone.
267
+ The object hides where its diameter gives fewer pixels than the `lodThreshold` setting, that is past the distance diameter × factor. The render height, the render scale and the governor's doubled threshold all feed the factor, so they move the hide distance too. An orthographic camera hides an object by its diameter and the camera's zoom alone.
197
268
 
198
269
  The object draws nothing past the band that follows the hide distance. That band, 8% of the hide distance long, thins the coarsest level out with the same dither. A shrinking object then fades away instead of popping. The band needs a fading build, which a level that fades has. A mesh whose levels all switch at once, which a small threshold keeps, disappears at the hide distance.
199
270
 
@@ -208,11 +279,15 @@ stone.setDrawRange(8, 120); // nothing nearer than 8 m, nothing past 120 m
208
279
  grass.setDrawRange(0, 60); // a far edge only
209
280
  ```
210
281
 
211
- The mesh draws only while the camera's distance to its nearest point lies inside the band. Each edge fades inside the range over an 8% band, through the same dither. A stone then fades in as it comes near and out as it passes. A mesh that lies outside its band costs no draw on either GPU path. The `lodFade` quality setting turns these edges off on Low, where the dither costs tile GPUs their hidden-surface removal. A row's own range, in the array that `ranges: true` makes for a batch, overrides the batch's.
282
+ The mesh draws only while the camera's distance to its nearest point lies inside the band. Each edge fades inside the range over an 8% band, through the same dither. A stone then fades in as it comes near and out as it passes.
283
+
284
+ A mesh that lies outside its band costs no draw on either GPU path. The `lodFade` quality setting turns these edges off on Low, where the dither costs tile GPUs their hidden-surface removal. A row's own range, in the array that `ranges: true` makes for a batch, overrides the batch's.
212
285
 
213
286
  ## See the levels
214
287
 
215
- The development build draws a levels view: `debug.view('levels')` from the sketch, or `?view=levels` in a page's address. Each draw takes a color for its level, from blue for the base mesh to cyan for the sixth lower level. Every level past it draws gray. Where two levels hand over in a fading band, the view dithers the two colors, so the band shows. A source that the size rule or a draw range hid draws at its base level in a checked magenta marker, at the place it would have drawn. The view then shows what the culling dropped, rather than a hole.
288
+ The development build draws a levels view: `debug.view('levels')` from the sketch, or `?view=levels` in a page's address. Each draw takes a color for its level, from blue for the base mesh to cyan for the sixth lower level. Every level past it draws gray.
289
+
290
+ Where two levels hand over in a fading band, the view dithers the two colors, so the band shows. A source that the size rule or a draw range hid draws at its base level in a checked magenta marker, at the place it would have drawn. The view then shows what the culling dropped, rather than a hole.
216
291
 
217
292
  The view reads the level that the culling picks, so it needs no shader for each material. `debug.cullingSpheres(true)` draws the bounding sphere that culling tests for each object whose mesh has levels, up to the first 128 objects, so a sphere that hid by its size shows where it lies. It draws in a development build only. An add-on registers a view of its own through the `debugViews` field of its [feature description](../api/features.md#the-fields).
218
293
 
@@ -230,12 +305,32 @@ Distance bands, and levels given by a distance or by screen coverage, keep the c
230
305
 
231
306
  ## Cards beyond the levels
232
307
 
233
- A level of detail keeps one draw and one mesh per object. Far past the last level, an object can draw as a card instead: a quad that stands upright, turns to the eye, and shows a picture of the object. The picture should come from a bake of several views with the engine's baker, so the card holds the object from every side; a hand-painted side view belongs only on a card that never covers more than a few pixels. The `@null3d/impostors` add-on draws those cards, and a distance band on the meshes hands the object over to them. [Impostors](../api/impostors.md#bake-several-views-not-one-side) shows the bake.
308
+ A level of detail keeps one draw and one mesh per object. Far past the last level, an object can draw as a card instead: a quad that stands upright, turns to the eye, and shows a picture of the object.
309
+
310
+ The picture should come from a bake of several views with the engine's baker, so the card holds the object from every side. A hand-painted side view belongs only on a card that never covers more than a few pixels. The `@null3d/impostors` add-on draws those cards, and a distance band on the meshes hands the object over to them. [Impostors](../api/impostors.md#bake-several-views-not-one-side) shows the bake.
311
+
312
+ The card's light comes from the scene, through the stored normal, so a sun that moves relights the cards exactly as it relights the meshes. A copy's turn about the world's up turns its views and its light too, so a turned tree hands over to a card whose crown matches it.
313
+
314
+ A camera that moves around the tree does not turn its light. The card turns to the eye, and the stored normal turns only with the tree. A card casts the crown's shape, and takes the shadows that fall on the surface it shows, when the sketch asks for it.
315
+
316
+ <details>
317
+ <summary>Technical details: how a card stores the object</summary>
318
+
319
+ The bake folds the views onto an octahedral grid, in a color atlas and a surface atlas of normals and depths. Each card blends the three stored views nearest the direction from the card toward the eye, so the picture changes smoothly as the camera moves rather than jumping between views.
320
+
321
+ </details>
234
322
 
235
- A bake stores the object from many directions, folded onto an octahedral grid, in a color atlas and a surface atlas of normals and depths. Each card blends the three stored views nearest the direction from the card toward the eye, so the picture changes smoothly as the camera moves rather than jumping between views. The card's light comes from the scene, through the stored normal, so a sun that moves relights the cards exactly as it relights the meshes. A copy's turn about the world's up turns its views and its light too, so a turned tree hands over to a card whose crown matches it. A camera that moves around the tree does not turn its light: the card turns to the eye, and the stored normal turns only with the tree. A card casts the crown's shape, and takes the shadows that fall on the surface it shows, when the sketch asks for it.
323
+ `setDrawRange` fades a band's edges with the dither, so the hand-over from a mesh to its cards need not pop. The impostors add-on's `handOverToCards` sets the two bands for a batch of meshes and its cards. It starts the cards early enough that their own dithered edge finishes first.
236
324
 
237
- `setDrawRange` fades a band's edges with the dither, so the hand-over from a mesh to its cards need not pop. The impostors add-on's `handOverToCards` sets the two bands for a batch of meshes and its cards. It starts the cards early enough that their own dithered edge finishes first. The mesh and the card are different sources, so their dither phases differ. The card must already cover every pixel that the mesh will drop. [Impostors](../api/impostors.md#hand-the-near-meshes-over-to-the-cards) gives the calls, and the demo `examples/impostors` draws a forest three ways by distance.
325
+ The mesh and the card are different sources, so their dither phases differ. The card must already cover every pixel that the mesh will drop. [Impostors](../api/impostors.md#hand-the-near-meshes-over-to-the-cards) gives the calls. The impostors demo draws a forest three ways by distance.
238
326
 
239
- ## API reference
327
+ ## Related pages
240
328
 
241
- `mesh.setLevels`, `mesh.buildLevels` and the options they take are on the [geometry page's reference](../api/reference/geometry.md). The quality settings are on [the quality page](../api/quality.md).
329
+ - [The geometry reference](../api/reference/geometry.md): `setLevels`, `buildLevels` and their options.
330
+ - [Quality and the governor](../api/quality.md): the `lodThreshold` and related settings.
331
+ - [The asset pipeline](../guides/assets-pipeline.md#levels-of-detail): the levels that `assets optimize` writes.
332
+ - [Impostors](../api/impostors.md): cards beyond the last level.
333
+ - [Shadows](shadows.md): the shadow threshold that follows the level threshold.
334
+ - [The forest demo](https://github.com/null3d-engine/null3d/tree/main/examples/forest): trees made in code with levels given by hand.
335
+ - [The impostors demo](https://github.com/null3d-engine/null3d/tree/main/examples/impostors): a forest drawn three ways by distance.
336
+ - [The terrain demo](https://github.com/null3d-engine/null3d/tree/main/examples/terrain): a 1.2 km valley whose far hills draw as coarser blocks.
@@ -1,14 +1,12 @@
1
1
  ---
2
2
  id: concepts/materials
3
3
  title: Materials and pipelines
4
- status: experimental
5
- since: "0.1"
6
- summary: "Built-in materials; permutations; pipeline warm-up; why changing shader features can stall a frame."
4
+ summary: "Built-in materials; shader variants; pipeline warm-up; why a new combination of shader features costs a build."
7
5
  ---
8
6
 
9
7
  # Materials and pipelines
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. Custom materials take a surface function, a vertex offset, their uniforms and up to 6 textures of their own, or a full shader. They take none of the standard texture maps.
9
+ > Custom materials take a surface function, a vertex offset, their uniforms and up to 6 textures of their own, or a full shader. They take none of the standard texture maps.
12
10
 
13
11
  ```mermaid
14
12
  flowchart LR
@@ -20,7 +18,9 @@ flowchart LR
20
18
  pipeline --> draw
21
19
  ```
22
20
 
23
- A material has two parts. Its values, such as its color and roughness, sit in one row of a table that every shader reads. Its kind and its fixed options choose the render pipeline that draws it. The GPU compiles a pipeline once for each combination of its shader variant, its state and the mesh's vertex format. A new combination therefore costs a compile, while a new value costs almost nothing.
21
+ A material has two parts. Its values, such as its color and roughness, sit in one row of a table that every shader reads. Its kind and its fixed options choose the render pipeline that draws it.
22
+
23
+ The GPU compiles a pipeline once for each combination of its shader variant, its state and the mesh's vertex format. A new combination therefore costs a compile, while a new value costs almost nothing.
24
24
 
25
25
  ## The built-in materials
26
26
 
@@ -36,7 +36,7 @@ The standard material lights a surface with Lambert diffuse light and a GGX high
36
36
 
37
37
  ## Values cost almost nothing
38
38
 
39
- `set()` writes a material's values into its row, and the next frame uploads the rows that changed. No pipeline changes, so no shader compiles, and every object that uses the material changes with it.
39
+ `set()` writes a material's values into its row, and the next frame uploads the rows that changed. No pipeline changes, so no shader compiles, and every object that uses the material changes with it. The [animated values demo](https://github.com/null3d-engine/null3d/tree/main/examples/property-animation) changes a lamp, a material and a camera every frame at no cost.
40
40
 
41
41
  ```ts
42
42
  // sketch.ts
@@ -82,18 +82,31 @@ The `hash` mode draws each point opaque or not at all. A hash of the point's pla
82
82
 
83
83
  The shader that drops fragments costs more than one that never does: a GPU cannot always test depth before it runs such a shader. Tile GPUs, as in phones and Apple's chips, also lose part of their hidden-surface removal. So only masked and hashed materials draw with that variant. The cutoff is a value, and `set({ alphaCutoff })` changes it at no cost.
84
84
 
85
- `alphaToCoverage`, on by default, smooths a mask's cut edges with MSAA. The masked alpha fades over about one pixel above the cutoff, and MSAA covers that share of each edge pixel's samples. Where the target's format has an alpha channel, the GPU turns the alpha into coverage. WebGPU's HDR scene color has none, so there the shader writes the covered samples itself. Those shader builds load the first time a material needs them. Without MSAA, alpha to coverage is a plain mask.
85
+ `alphaToCoverage`, on by default, smooths a mask's cut edges with MSAA. The masked alpha fades over about one pixel above the cutoff, and MSAA covers that share of each edge pixel's samples. The first such material loads extra shader builds; list `'coverage'` in `createEngine`'s `preload` option to load them before play ([Alpha to coverage](../api/materials.md#alpha-to-coverage)). Without MSAA, alpha to coverage is a plain mask.
86
+
87
+ <details>
88
+ <summary>Technical details: alpha to coverage on each path</summary>
89
+
90
+ Where the target's format has an alpha channel, the GPU turns the alpha into coverage. WebGPU's HDR scene color has none, so there the shader writes the covered samples itself.
91
+
92
+ </details>
86
93
 
87
94
  The `blend` mode blends the surface over what lies behind it. Its `blending` chooses how: `normal`, `additive`, `multiply` or `weighted` ([Weighted blending](../api/materials.md#weighted-blending)). [Materials](../api/materials.md#alpha-modes) shows each mode.
88
95
 
89
96
  ## The transparent pass
90
97
 
98
+ ![Crossing panes of stained glass and smoke in a pavilion, blended in any order.](../images/concepts/materials/weighted-transparency.webp)
99
+
100
+ Weighted blending needs no sort.
101
+
91
102
  ```mermaid
92
103
  flowchart LR
93
104
  opaque["Opaque pass:<br/>any order, depth decides"] --> sort["Job workers: cull the blended<br/>objects and sort them far to near"]
94
105
  sort --> transparent["Transparent pass:<br/>each blends over the ones before"]
95
106
  ```
96
107
 
108
+ ### Sorting the blended objects
109
+
97
110
  The result of blending depends on the order in which surfaces draw. A surface must blend over everything behind it. So the engine draws blended objects in a pass of their own, after the opaque ones, farthest first. In each frame, for each view, the job workers cull the blended objects and sort them. An object's depth is the depth of its bounding sphere's center. `mesh.setRenderOrder(order)` comes first: a lower order draws first, at any depth.
98
111
 
99
112
  The rows of an instance batch sort one by one, so a batch of blended particles draws in the right order. Neighbors in the sorted order that share a mesh and a material draw together. A batch that no other blended object crosses therefore draws in few draw calls.
@@ -104,21 +117,31 @@ Sorting by object has these limits:
104
117
  - A large object, such as a long glass wall, has one center. A small object can have a center that is farther away than the wall's while it stands in front of the wall. Split large blended meshes, or set their order with `setRenderOrder`.
105
118
  - The triangles of one mesh draw in the mesh's own order. A closed blended mesh, such as a sphere, draws only its front faces unless it is double-sided. A double-sided one draws its back faces first, then its front faces. So its near side covers its far side. Each run of neighbors that share its mesh and material takes a second draw. On flat surfaces, whose faces never overlap, `forceSinglePass: true` saves it.
106
119
 
107
- Surfaces of the `weighted` blending need no sort. In the camera's view they leave the transparent pass and draw after it, in any order, into two targets of their own. A last step blends their weighted average over the scene, as far as they cover it together ([Weighted blending](../api/materials.md#weighted-blending)). Use it where the limits above make smoke, particles or crossing panes pop.
120
+ ### Blending without a sort
121
+
122
+ Surfaces of the `weighted` blending need no sort. In the camera's view they leave the transparent pass and draw after it, in any order, into two targets of their own. A last step blends their weighted average over the scene, as far as they cover it together ([Weighted blending](../api/materials.md#weighted-blending)). Use it where the limits above make smoke, particles or crossing panes pop. The demo of [weighted blending](https://github.com/null3d-engine/null3d/tree/main/examples/weighted-transparency) blends eight crossing glass panes and 600 smoke puffs in any order.
123
+
124
+ ### Moment transparency
108
125
 
109
- The quality setting `momentTransparency` blends the same surfaces in a layer of its own, and it is nearer an exact back-to-front blend than the weighted average is. It draws each surface twice and keeps a store of four depth moments, so a page pays more for it ([Moment transparency](../api/materials.md#moment-transparency)).
126
+ The quality setting `momentTransparency` blends the same surfaces in a layer of its own. It is nearer an exact back-to-front blend than the weighted average is. The page turns it on with the `createEngine` option of the same name, and it stays fixed while the engine runs. It draws each surface twice and keeps a store of four depth moments, so a page pays more for it ([Moment transparency](../api/materials.md#moment-transparency)).
127
+
128
+ ### Transmission
110
129
 
111
130
  Surfaces that let light through, which `transmission` makes, draw in the transparent pass too, sorted with the blended ones. Before the camera's transparent pass, the engine copies its opaque objects' colors into a texture with blurred levels, which those surfaces sample behind them ([Transmission](../api/materials.md#transmission)).
112
131
 
132
+ ### What blending costs
133
+
113
134
  Blended objects cost more than opaque ones. The job workers cull and sort them in every frame, and on WebGPU the engine also writes each visible one's data for the GPU. Neighbors that differ in mesh or material need draw calls of their own. The GPU shades every blended layer of a pixel, so large overlapping surfaces cost GPU time. Keep blended objects to what needs them, and use the `mask` mode for cut-out shapes.
114
135
 
115
136
  ## Custom materials share shaders
116
137
 
117
- A custom material's WGSL becomes a shader of its own: the standard material's shader with the surface function in it. Every material made from the same WGSL shares that shader, and its pipelines, whatever its values. Its uniforms are values too: they sit beside the material's row, so `set()` changes them without a compile. The fixed options above choose its variants and states, as they do for a standard material. Each new WGSL therefore costs its own pipeline compiles, so reuse one WGSL for materials that differ only in their values.
138
+ Reuse one WGSL for materials that differ only in their values. A custom material's WGSL becomes a shader of its own: the standard material's shader with the surface function in it. Every material made from the same WGSL shares that shader, and its pipelines, whatever its values. Its uniforms are values too: they sit beside the material's row, so `set()` changes them without a compile. The fixed options above choose its variants and states, as they do for a standard material. Each new WGSL therefore costs its own pipeline compiles.
139
+
140
+ ## Why a new combination can appear late
118
141
 
119
- ## Why a new combination can make a frame late
142
+ A pipeline builds the first time the scene needs a combination of shader variant, state and vertex format that it did not need before. The GPU driver can take many milliseconds for that, on a phone above all. The first frame waits until all of its pipelines are built. After that, the engine does not wait: an object whose pipeline is still building draws nothing until the build ends. On WebGL2 without parallel shader compiles, as in Firefox, the first draw waits for its compile, so that frame is late.
120
143
 
121
- A pipeline compiles the first time a frame draws a combination of shader variant, state and vertex format that no earlier frame drew. The GPU driver can take many milliseconds for that, on a phone above all. So an object that appears in play with a new combination can make that frame late. Create every material in the setup, and use its combinations in the first frames, so the compiles happen before play starts.
144
+ Create every material in the setup and `await scene.warmUp()` before play starts. For objects that appear later, create them hidden, await `scene.warmUp()`, then show them. Some material features, such as transmission and clear coat, download their shaders on first use. List them in `createEngine`'s `preload` option so nothing downloads during play. [Loading screens and warm-up](../guides/loading-screens.md#pipelines-and-warm-up) shows how.
122
145
 
123
146
  ## Related pages
124
147
 
@@ -126,3 +149,11 @@ A pipeline compiles the first time a frame draws a combination of shader variant
126
149
  - [Surface functions](../shaders/surface-functions.md): the WGSL of a custom material.
127
150
  - [Lights](../api/lights.md): what lights a standard material.
128
151
  - [Color management](color-management.md): how colors turn into linear values.
152
+ - [Loading screens and warm-up](../guides/loading-screens.md): build pipelines before play, and load feature shaders up front.
153
+ - [Clear coat and sheen variants](https://github.com/null3d-engine/null3d/tree/main/examples/coat-and-sheen): candy paint and carbon fiber under a clear coat, and velvet that glows at its edges.
154
+ - [Iridescence and anisotropy variants](https://github.com/null3d-engine/null3d/tree/main/examples/iridescence-and-anisotropy): a beetle's shell, soap bubbles and an oil slick.
155
+ - [Diffuse transmission](https://github.com/null3d-engine/null3d/tree/main/examples/translucency): broad leaves and coral petals let the low sun through.
156
+ - [Subsurface light and the skin pass](https://github.com/null3d-engine/null3d/tree/main/examples/subsurface): wax, jade and soap glow under the surface.
157
+ - [Custom material WGSL and uniforms](https://github.com/null3d-engine/null3d/tree/main/examples/shader-inputs): 900 crystals take their color and their wave from their row.
158
+ - [Decal material](https://github.com/null3d-engine/null3d/tree/main/examples/decals): road paint, puddles, cracks and posters project onto a street.
159
+ - [Invisible surfaces that hide](https://github.com/null3d-engine/null3d/tree/main/examples/depth-only): a plane with `colorWrite: false` holds back the hall behind it.