@null3d/engine 0.1.0 → 0.1.2

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 (388) 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 +40 -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 +68 -24
  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/E1308.md +31 -0
  146. package/docs/errors/E1401.md +11 -3
  147. package/docs/errors/E1402.md +13 -5
  148. package/docs/errors/E1403.md +11 -3
  149. package/docs/errors/E1404.md +13 -3
  150. package/docs/errors/E1405.md +15 -4
  151. package/docs/errors/E1406.md +31 -5
  152. package/docs/errors/E1407.md +11 -3
  153. package/docs/errors/E1408.md +11 -3
  154. package/docs/errors/E1409.md +11 -3
  155. package/docs/errors/E1410.md +13 -5
  156. package/docs/errors/E1411.md +11 -3
  157. package/docs/errors/E1412.md +29 -6
  158. package/docs/errors/E1413.md +11 -3
  159. package/docs/errors/E1414.md +11 -3
  160. package/docs/errors/E1415.md +11 -3
  161. package/docs/errors/E1416.md +27 -6
  162. package/docs/errors/E1417.md +11 -3
  163. package/docs/errors/E1418.md +12 -3
  164. package/docs/errors/E1419.md +13 -5
  165. package/docs/errors/E1420.md +11 -3
  166. package/docs/errors/E1421.md +11 -3
  167. package/docs/errors/E1422.md +12 -3
  168. package/docs/errors/E1423.md +12 -3
  169. package/docs/errors/E1424.md +24 -5
  170. package/docs/errors/E1425.md +11 -3
  171. package/docs/errors/E1426.md +11 -3
  172. package/docs/errors/E1430.md +11 -3
  173. package/docs/errors/E1431.md +11 -3
  174. package/docs/errors/E1432.md +11 -3
  175. package/docs/errors/E1433.md +11 -3
  176. package/docs/errors/E1434.md +15 -6
  177. package/docs/errors/E1435.md +11 -3
  178. package/docs/errors/E1436.md +11 -3
  179. package/docs/errors/E1437.md +14 -6
  180. package/docs/errors/E1501.md +41 -6
  181. package/docs/errors/E1502.md +13 -3
  182. package/docs/errors/E1503.md +11 -3
  183. package/docs/errors/E1504.md +11 -3
  184. package/docs/errors/E1505.md +23 -5
  185. package/docs/errors/E1506.md +11 -3
  186. package/docs/errors/index.md +53 -29
  187. package/docs/getting-started/cdn.md +15 -9
  188. package/docs/getting-started/first-scene.md +20 -12
  189. package/docs/getting-started/hosting.md +113 -63
  190. package/docs/getting-started/install.md +39 -24
  191. package/docs/getting-started/network-use.md +31 -21
  192. package/docs/getting-started/project-structure.md +20 -8
  193. package/docs/getting-started/third-party-notices.md +6 -10
  194. package/docs/guides/accessibility.md +4 -4
  195. package/docs/guides/add-ons.md +83 -13
  196. package/docs/guides/agents.md +13 -14
  197. package/docs/guides/assets-pipeline.md +294 -72
  198. package/docs/guides/audio.md +17 -15
  199. package/docs/guides/baked-light-data.md +44 -23
  200. package/docs/guides/car-paint.md +37 -31
  201. package/docs/guides/content-pages.md +86 -29
  202. package/docs/guides/custom-passes.md +59 -17
  203. package/docs/guides/custom-shaders.md +54 -37
  204. package/docs/guides/debugging.md +31 -41
  205. package/docs/guides/deploying.md +10 -27
  206. package/docs/guides/deterministic-simulation.md +23 -16
  207. package/docs/guides/first-use-shaders.md +83 -45
  208. package/docs/guides/lens-kit.md +29 -26
  209. package/docs/guides/loading-screens.md +74 -30
  210. package/docs/guides/multiple-views.md +22 -11
  211. package/docs/guides/performance.md +188 -37
  212. package/docs/guides/phones.md +71 -19
  213. package/docs/guides/physics.md +6 -10
  214. package/docs/guides/screens.md +41 -29
  215. package/docs/guides/start-time.md +126 -85
  216. package/docs/guides/testing.md +137 -98
  217. package/docs/guides/ui-overlays.md +17 -12
  218. package/docs/guides/video-textures.md +14 -13
  219. package/docs/images/api/animation/character.webp +0 -0
  220. package/docs/images/api/animation/look-at-ring.webp +0 -0
  221. package/docs/images/api/animation/morph-tulips.webp +0 -0
  222. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  223. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  224. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  225. package/docs/images/api/debug/debug-shapes.webp +0 -0
  226. package/docs/images/api/debug/levels-view.webp +0 -0
  227. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  228. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  229. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  230. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  231. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  232. package/docs/images/api/geometry/generators.webp +0 -0
  233. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  234. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  235. package/docs/images/api/grass/grass-grove.webp +0 -0
  236. package/docs/images/api/grass/grass-presets.webp +0 -0
  237. package/docs/images/api/grass/grass-shadow.webp +0 -0
  238. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  239. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  240. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  241. package/docs/images/api/lights/spot-cookies.webp +0 -0
  242. package/docs/images/api/lines/lines-lit.webp +0 -0
  243. package/docs/images/api/lines/lines-widths.webp +0 -0
  244. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  245. package/docs/images/api/materials/decals.webp +0 -0
  246. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  247. package/docs/images/api/materials/relief.webp +0 -0
  248. package/docs/images/api/materials/shader-inputs.webp +0 -0
  249. package/docs/images/api/materials/standard-grid.webp +0 -0
  250. package/docs/images/api/materials/subsurface.webp +0 -0
  251. package/docs/images/api/materials/translucency.webp +0 -0
  252. package/docs/images/api/objects/objects-turntable.webp +0 -0
  253. package/docs/images/api/particles/campfire.webp +0 -0
  254. package/docs/images/api/points/galaxy.webp +0 -0
  255. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  256. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  257. package/docs/images/api/render/reflection-mirror.webp +0 -0
  258. package/docs/images/api/render/security-camera.webp +0 -0
  259. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  260. package/docs/images/api/sound/sound-demo.webp +0 -0
  261. package/docs/images/api/splats/splats-demo.webp +0 -0
  262. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  263. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  264. package/docs/images/api/textures/canvas-screen.webp +0 -0
  265. package/docs/images/api/textures/mipmaps.webp +0 -0
  266. package/docs/images/api/vertex-draws/rain.webp +0 -0
  267. package/docs/images/api/water/ocean.webp +0 -0
  268. package/docs/images/api/water/water-demo.webp +0 -0
  269. package/docs/images/api/water/water-rain.webp +0 -0
  270. package/docs/images/api/water/waterfall.webp +0 -0
  271. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  272. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  273. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  274. package/docs/images/concepts/instances/instances.webp +0 -0
  275. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  276. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  277. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  278. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  279. package/docs/images/concepts/lighting/environment.webp +0 -0
  280. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  281. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  282. package/docs/images/concepts/lod/forest.webp +0 -0
  283. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  284. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  285. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  286. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  287. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  288. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  289. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  290. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  291. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  292. package/docs/images/cookbook/index/picking.webp +0 -0
  293. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  294. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  295. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  296. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  297. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  298. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  299. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  300. package/docs/images/index/showcase-island.webp +0 -0
  301. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  302. package/docs/images/shaders/builtins/builtins.webp +0 -0
  303. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  304. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  305. package/docs/images/shots.json +2231 -0
  306. package/docs/index.md +14 -23
  307. package/docs/moves.json +1 -0
  308. package/docs/nav.json +300 -0
  309. package/docs/pages.md +230 -212
  310. package/docs/porting/react-three-fiber.md +2 -6
  311. package/docs/porting/threejs-loop-and-threads.md +1 -5
  312. package/docs/porting/threejs-mapping.md +1248 -234
  313. package/docs/porting/threejs-materials.md +10 -5
  314. package/docs/porting/threejs-overview.md +26 -6
  315. package/docs/porting/threejs-postprocessing.md +2 -6
  316. package/docs/porting/threejs-shaders.md +16 -14
  317. package/docs/porting/threejs-unsupported.md +6 -6
  318. package/docs/porting/verification.md +0 -4
  319. package/docs/shaders/builtins.md +15 -4
  320. package/docs/shaders/library.md +9 -6
  321. package/docs/shaders/surface-functions.md +51 -16
  322. package/docs/shaders/wgsl-rules.md +12 -5
  323. package/lib/debug/debug.d.ts +2 -2
  324. package/lib/debug/draw.d.ts +2 -2
  325. package/lib/debug/draw.js +8 -4
  326. package/lib/debug/overlay-look.d.ts +6 -0
  327. package/lib/debug/overlay-look.js +29 -7
  328. package/lib/debug/overlay.js +15 -11
  329. package/lib/debug/stats-options.d.ts +13 -0
  330. package/lib/debug/stats-panel.d.ts +21 -6
  331. package/lib/debug/stats-panel.js +80 -13
  332. package/lib/errors/codes.d.ts +17 -3
  333. package/lib/errors/codes.js +116 -105
  334. package/lib/errors/engine-error.js +1 -1
  335. package/lib/errors/fixes.d.ts +1 -0
  336. package/lib/errors/fixes.js +19 -18
  337. package/lib/generated/shader-permutations.d.ts +6 -0
  338. package/lib/generated/shader-permutations.js +6 -0
  339. package/lib/gpu/variants.d.ts +8 -2
  340. package/lib/gpu/variants.js +39 -7
  341. package/lib/gpu/webgl2/programs.js +1 -1
  342. package/lib/gpu/webgpu/pipelines.js +13 -13
  343. package/lib/index.d.ts +1 -1
  344. package/lib/page/capabilities.d.ts +1 -1
  345. package/lib/page/engine.d.ts +29 -7
  346. package/lib/page/engine.js +79 -7
  347. package/lib/page/label-loop.js +9 -4
  348. package/lib/page/stats-switch.js +2 -0
  349. package/lib/page/switches.d.ts +6 -4
  350. package/lib/page/switches.js +20 -4
  351. package/lib/scene/baked-light.d.ts +2 -2
  352. package/lib/scene/fake-call-values.js +2 -2
  353. package/lib/scene/frame-cameras.d.ts +16 -4
  354. package/lib/scene/frame-cameras.js +28 -10
  355. package/lib/scene/gltf.d.ts +1 -1
  356. package/lib/scene/level-rule.d.ts +6 -5
  357. package/lib/scene/level-rule.js +2 -2
  358. package/lib/scene/particles.d.ts +7 -3
  359. package/lib/scene/particles.js +3 -1
  360. package/lib/scene/post.d.ts +3 -2
  361. package/lib/scene/resources.d.ts +15 -9
  362. package/lib/scene/scene.d.ts +18 -2
  363. package/lib/scene/scene.js +47 -5
  364. package/lib/scene/time-of-day.d.ts +10 -5
  365. package/lib/scene/time-of-day.js +11 -7
  366. package/lib/shader-artifact.json +1 -1
  367. package/lib/shared/labels.d.ts +5 -2
  368. package/lib/shared/labels.js +5 -2
  369. package/lib/shared/permutation-words.d.ts +8 -0
  370. package/lib/shared/permutation-words.js +14 -0
  371. package/lib/shared/recording.d.ts +13 -5
  372. package/lib/shared/recording.js +31 -10
  373. package/lib/shared/sketch-data.d.ts +9 -0
  374. package/lib/shared/sketch-data.js +57 -0
  375. package/lib/shared/tier.d.ts +9 -0
  376. package/lib/shared/tier.js +4 -1
  377. package/lib/shared/version.d.ts +1 -1
  378. package/lib/shared/version.js +1 -1
  379. package/lib/sketch/define-sketch.d.ts +16 -7
  380. package/lib/sketch/define-sketch.js +2 -1
  381. package/lib/sketch/runner.d.ts +4 -0
  382. package/lib/sketch/runner.js +5 -0
  383. package/lib/sketch/ui.js +4 -2
  384. package/lib/stats.d.ts +1 -0
  385. package/lib/workers/protocol.d.ts +10 -0
  386. package/lib/workers/render-worker.js +4 -1
  387. package/lib/workers/sketch-worker.js +4 -1
  388. package/package.json +1 -1
@@ -1,15 +1,11 @@
1
1
  ---
2
2
  id: guides/assets-pipeline
3
3
  title: "The asset pipeline (the `assets` command)"
4
- status: experimental
5
- since: "0.2"
6
4
  summary: "optimize, convert, pack-orm, normal-from-bump, env; LODs; texture compression; blockers and stored trees; budget reports."
7
5
  ---
8
6
 
9
7
  # The asset pipeline (the `assets` command)
10
8
 
11
- > Roadmap step 0.2, first released in null3D 0.1.0. The command is experimental, so it can still change between versions.
12
-
13
9
  ```mermaid
14
10
  flowchart LR
15
11
  source["Your glTF models:<br/>.glb or .gltf files,<br/>PNG and JPEG textures"] --> optimize["bunx @null3d/cli<br/>assets optimize"]
@@ -20,7 +16,17 @@ flowchart LR
20
16
  ktx2 --> load
21
17
  ```
22
18
 
23
- The `assets optimize` command makes glTF models smaller and faster to load and draw. It stores each mesh's vertices as small integers, in the order that the GPU reads them fastest. It stores each animation clip in the form the engine keeps in memory. It encodes each texture as a KTX2 file, which the GPU keeps compressed. Your files download less, take less GPU memory and upload in fewer frames. The command runs on your computer before you publish, from npm, with nothing else to install. The same files give the same output bytes on every computer.
19
+ The `assets optimize` command makes glTF models smaller and faster to load and draw. It stores each mesh's vertices as small integers, in the order that the GPU reads them fastest. It stores each animation clip in the form the engine keeps in memory. It encodes each texture as a KTX2 file, which the GPU keeps compressed. Your files download less, take less GPU memory and upload in fewer frames.
20
+
21
+ The command runs on your computer before you publish, from npm, with nothing else to install. The same files give the same output bytes on every computer.
22
+
23
+ The command's sub-commands:
24
+
25
+ - [`optimize`](#optimize-a-model): quantizes a model and encodes its textures.
26
+ - [`convert`](#convert-other-formats): turns another format into glTF.
27
+ - [`pack-orm`](#pack-occlusion-roughness-and-metalness): packs occlusion, roughness and metalness into one texture.
28
+ - [`normal-from-bump`](#normal-maps-from-bump-maps): makes a normal map from a bump map.
29
+ - [`env`](#environment-maps): filters an HDR image into an environment map.
24
30
 
25
31
  ## Optimize a model
26
32
 
@@ -41,7 +47,7 @@ BoomBox.glb: 10.1 MB to 2.2 MB (the model 107.0 KB), in 9.6 s
41
47
  standard_maps uv0+tangent VERTEX_TANGENT: 1 object
42
48
  ```
43
49
 
44
- That is Khronos's BoomBox sample model, whose four PNG textures of 2048 x 2048 made most of its 10.1 MB.
50
+ That is Khronos's BoomBox sample model, whose four PNG textures of 2048 x 2048 made most of its 10.1 MB. The [glTF model demo](https://github.com/null3d-engine/null3d/tree/main/examples/gltf-model) loads the same BoomBox from a file.
45
51
 
46
52
  Each `.glb` and `.gltf` file in the input folder and its subfolders becomes one `.glb` file in the output folder, at the same place. The textures of every model go into one `textures` folder in the output folder. Each texture file takes its name from its contents. So models that share a texture share its file, and a host can let browsers keep the files for good. Then load a model as any other:
47
53
 
@@ -62,11 +68,44 @@ scene.instantiate(ship);
62
68
  | `--texture-quality <size\|high>` | `high` encodes color and data maps in UASTC, several times larger than ETC1S, with less loss | `size` |
63
69
  | `--no-roughness-bake` | Leaves the roughness levels of metal-rough maps as plain averages, with no detail from the normal maps | [The roughness bake](#the-roughness-bake) |
64
70
  | `--compression <none\|meshopt>` | `none` leaves the file's buffers uncompressed | `meshopt` |
65
- | `--no-blockers` | Gives no mesh a blocker for software occlusion culling | Blockers for meshes that enclose space |
66
- | `--bvh <triangles>` | Stores the tree that raycasts walk for each mesh part of at least this many triangles, or for none with 0 | 20000 |
71
+ | `--no-blockers` | Gives no mesh a blocker for software occlusion culling ([Blockers](#blockers)) | Blockers for meshes that enclose space |
72
+ | `--bvh <triangles>` | Stores the tree that raycasts walk for each mesh part of at least this many triangles, or for none with 0 ([Stored raycast trees](#stored-raycast-trees)) | 20000 |
67
73
  | `--jobs <count>` | The worker threads that encode textures | One per CPU core |
68
74
  | `--report <file.json>` | Also writes the budget report as a JSON file | No file |
69
75
 
76
+ The command writes no model that the engine would refuse to load. One array may hold at most 256 MiB, and one file may decode to at most 1 GiB ([Limits on each file](../concepts/assets.md#limits-on-each-file)). A model that passes a limit fails with an error that names it. Split such a scene into several files, each with a part of its meshes, and load each one with `assets.loadGltf()`.
77
+
78
+ ## In a Vite project
79
+
80
+ A Vite project with the null3D plugin can encode a model as a module imports it, with no command of its own. The null3D Vite plugin runs the same steps on a model that a module imports with `?optimized`. The import gives the address of the optimized model:
81
+
82
+ ```ts
83
+ // sketch.ts
84
+ import shipUrl from './models/ship.glb?optimized';
85
+
86
+ const ship = await assets.loadGltf(shipUrl);
87
+ ```
88
+
89
+ The plugin uses the tool of `@null3d/cli`, so add the command-line tool to your project first. With Bun, use Bun 1.4.3 or newer ([Install null3D](../getting-started/install.md) says why):
90
+
91
+ ```sh
92
+ bun add -d @null3d/cli
93
+ ```
94
+
95
+ The first import of a model encodes it. The plugin keeps the result in `node_modules/.cache/null3d-assets`, keyed by the model's files, the tool's version and the options. Later starts and builds take it from there, until one of those changes. A production build writes the files into its assets folder. The plugin's `assets` option takes the command's options: `lod`, `clusters`, `stages` (the levels and bands as separate downloads, with `lod` or `clusters`), `simplify`, `simplifyError`, `maxTextureSize`, `textureQuality`, `roughnessBake` (false for `--no-roughness-bake`), `meshopt` (false for `--compression none`), `blockers` (false for `--no-blockers`) and `bvh`:
96
+
97
+ ```ts
98
+ // vite.config.ts
99
+ import null3d from '@null3d/vite-plugin';
100
+ import { defineConfig } from 'vite';
101
+
102
+ export default defineConfig({
103
+ plugins: [null3d({ assets: { lod: true, maxTextureSize: 1024, bvh: 5000 } })],
104
+ });
105
+ ```
106
+
107
+ For TypeScript, add `@null3d/vite-plugin/client` to the `types` of your `tsconfig.json`, so `?optimized` imports have the type `string`.
108
+
70
109
  ## What it does to meshes
71
110
 
72
111
  | Data | In the output | Why |
@@ -102,10 +141,14 @@ The engine keeps each animation clip at one fixed rate of keys, so it never sear
102
141
 
103
142
  The command drops no key and no track. A clip blends only where it has tracks, so a dropped track would change how the clip blends. Poses stay as accurate as the source file's: the KayKit Knight's skinning matrices from either file differ from three.js's by at most 7e-5.
104
143
 
105
- For the Knight and its 76 clips, the file's binary part falls from 838 KB to 405 KB after Brotli. On the engine's test page, its clips were ready in 8 ms on two job workers, against 16.5 ms for the source file.
144
+ For the Knight and its 76 clips, the file's binary part falls from 838 KB to 405 KB after Brotli. On the engine's test page, its clips were ready in 8 ms on two job workers, against 16.5 ms for the source file. The [character demo](https://github.com/null3d-engine/null3d/tree/main/examples/character) loads the KayKit Knight and its clips.
106
145
 
107
146
  ## Blockers and stored trees
108
147
 
148
+ The file keeps both in extensions of the engine's own, which other loaders ignore: `NULL3D_occluder` and `NULL3D_mesh_bvh`. A file optimized again gets new ones.
149
+
150
+ ### Blockers
151
+
109
152
  On WebGL2, objects that block the view hide the objects behind them from the GPU, as [Culling](../concepts/culling.md#software-occlusion-culling-on-webgl2) explains. The command gives each mesh that encloses space a blocker: one or two boxes that fill its inside, joined into one closed surface. The engine draws the blocker in place of the mesh, for the cost of a few dozen triangles. A copy of the model blocks with those meshes from the start.
110
153
 
111
154
  A blocker that bulged out of its mesh would hide objects that show. So the command checks each blocker against the mesh's triangles, and drops one that fails:
@@ -125,9 +168,11 @@ The command takes the ground into account. The ground hides a model that stands
125
168
 
126
169
  A mesh's glTF extras can override the choice. The extras `"occluder": false` give the mesh no blocker. The extras `"occluder": true` make a mesh without a blocker block with its own triangles, up to 4,096 of them. That suits a mesh that is solid but too thin for a box. In the scene, `scene.instantiate(model, { occluder: false })` keeps a copy's meshes from blocking. Later, `setOccluder` changes an object.
127
170
 
128
- Raycasts walk a tree over each mesh's triangles. The engine builds a mesh's tree on the job workers on the first query, in about 0.2 to 0.3 µs per triangle. The `--bvh` option stores the trees in the file instead, for each mesh part of at least that many triangles. A stored tree takes about 20 bytes per triangle, as much as the mesh's positions and indices together. meshopt compresses it to about 12. So a stored tree pays only for large meshes, whose build would hold up the first raycast. The engine checks each stored tree against the mesh in about a tenth of the time of a build. It builds its own tree where a stored one does not fit.
171
+ ### Stored raycast trees
129
172
 
130
- The file keeps both in extensions of the engine's own, which other loaders ignore: `NULL3D_occluder` and `NULL3D_mesh_bvh`. A file optimized again gets new ones.
173
+ Raycasts walk a tree over each mesh's triangles. The engine builds a mesh's tree on the job workers on the first query, in about 0.2 to 0.3 µs per triangle. The `--bvh` option stores the trees in the file instead, for each mesh part of at least that many triangles. A stored tree takes about 20 bytes per triangle, as much as the mesh's positions and indices together. meshopt compresses it to about 12.
174
+
175
+ So a stored tree pays only for large meshes, whose build would hold up the first raycast. The engine checks each stored tree against the mesh in about a tenth of the time of a build. It builds its own tree where a stored one does not fit.
131
176
 
132
177
  ## Textures
133
178
 
@@ -140,7 +185,9 @@ The command encodes each PNG and JPEG texture of a model as a KTX2 file of Basis
140
185
  | Metal-rough maps of materials with normal maps | UASTC, with [the roughness bake](#the-roughness-bake) | Linear |
141
186
  | Other metal-rough, occlusion and other maps | ETC1S, or UASTC with `--texture-quality high` | Linear |
142
187
 
143
- Each side of a texture becomes its nearest power of two, and then both halve together until the longer side fits `--max-texture-size`. A 1000 x 600 image becomes 1024 x 512. Every level of a mip chain then halves exactly. A side is never less than 4 texels, so each texture is whole blocks of 4 x 4 texels. A texture in part blocks would load uncompressed, at 4 to 8 times the GPU memory. The command cannot resize a KTX2 image that the model already had. When such an image is not whole blocks, the report names it and counts it as uncompressed. Give the command its PNG or JPEG source instead.
188
+ Each side of a texture becomes its nearest power of two, and then both halve together until the longer side fits `--max-texture-size`. A 1000 x 600 image becomes 1024 x 512. Every level of a mip chain then halves exactly. A side is never less than 4 texels, so each texture is whole blocks of 4 x 4 texels. A texture in part blocks would load uncompressed, at 4 to 8 times the GPU memory.
189
+
190
+ The command cannot resize a KTX2 image that the model already had. When such an image is not whole blocks, the report names it and counts it as uncompressed. Give the command its PNG or JPEG source instead.
144
191
 
145
192
  Textures are at most 2048 x 2048. The encoder is a 32-bit WebAssembly build, which refuses 4096 x 4096 images.
146
193
 
@@ -150,7 +197,9 @@ In 40 sets of photographed materials at 1024 x 1024, each ETC1S color map took a
150
197
 
151
198
  A normal map adds small bumps to a surface. Far away, many bumps fall in one pixel. The GPU then reads a lower mip level of the normal map, which averages the bumps into one flat normal. The surface looks smooth and sharp, and its highlights flicker as the camera moves. A real surface of tiny bumps looks rougher from far away.
152
199
 
153
- So when a material has both a normal map and a metal-rough map, the command makes the metal-rough map's mip levels itself. In each level below the full size, it measures how far the normal map's normals under each texel spread. It adds that spread to the texel's roughness, the green channel. A smooth texel becomes at most 0.4 rough, and a rough texel gains less. Occlusion and metalness keep their plain averages. The full size stays as you made it, because up close the GPU reads the normal map's own bumps.
200
+ So when a material has both a normal map and a metal-rough map, the command makes the metal-rough map's mip levels itself. In each level below the full size, it measures how far the normal map's normals under each texel spread. It adds that spread to the texel's roughness, the green channel.
201
+
202
+ A smooth texel becomes at most 0.4 rough, and a rough texel gains less. Occlusion and metalness keep their plain averages. The full size stays as you made it, because up close the GPU reads the normal map's own bumps.
154
203
 
155
204
  ```mermaid
156
205
  flowchart LR
@@ -172,6 +221,10 @@ The bake skips a material, and the report says why, when:
172
221
 
173
222
  `--no-roughness-bake` turns the bake off.
174
223
 
224
+ ### Encode time
225
+
226
+ Each texture encodes on its own worker thread, so a set of textures uses every CPU core. The same 40 sets, 144 textures in all, took 18 to 26 seconds on a MacBook Pro with 18 cores. A texture of 2048 x 2048 takes several seconds on its core. The command prints each model's time.
227
+
175
228
  ## Levels of detail
176
229
 
177
230
  `--lod` adds levels of detail to each mesh of 64 triangles or more. Each level has about half the triangles of the level above, down to about 32 triangles, in up to 15 levels. So a far copy that covers a few pixels draws a few dozen triangles. The levels stop early when a level would keep more than three quarters of the level above. They also stop when a level's error reaches the mesh's size.
@@ -186,25 +239,47 @@ The command plans the levels as follows:
186
239
 
187
240
  A simplified level shares the mesh's vertices, so only its indices add to the file. The engine loads such a level over the base mesh's own vertices too. The level then costs the GPU its indices alone. A card level stores its own positions, because its kept cards grew. Its position stream adds to the file, and the engine keeps a copy of it.
188
241
 
189
- The levels go into the file with `MSFT_lod`. Each node with levels stores the errors in its extras, as `NULL3D_lod_error`. A level is good enough where its error covers less than one pixel. The engine can then pick the level from the real screen height and the render scale. The loader switches these measured levels at once while the threshold stays small, because their switch does not show; the governor can raise the threshold past about one and a half pixels, where the level fades. The extras also hold `MSFT_screencoverage` for other readers of `MSFT_lod`, made for a screen 1080 pixels high. The loader reads that coverage as the mark of a measured error. A model whose file already has levels keeps them, with or without `--lod`. Their meshes take the steps of their base mesh, so they line up when drawn in its place. Their errors in `NULL3D_lod_error` change to those steps. A file that gives errors alone, without the coverage, holds levels whose author set the switches by hand. The loader fades those levels.
242
+ Each node with levels stores the errors in its extras, as `NULL3D_lod_error`. A level is good enough where its error covers less than one pixel. The engine can then pick the level from the real screen height and the render scale. A file whose levels the command wrote keeps them, with or without `--lod`.
243
+
244
+ <details>
245
+ <summary>Technical details: how the file stores levels</summary>
246
+
247
+ The levels go into the file with `MSFT_lod`. The extras also hold `MSFT_screencoverage` for other readers of `MSFT_lod`, made for a screen 1080 pixels high. The loader reads that coverage as the mark of a measured error. The loader switches these measured levels at once while the threshold stays small, because their switch does not show; the governor can raise the threshold past about one and a half pixels, where the level fades.
248
+
249
+ A model whose file already has levels keeps them. Their meshes take the steps of their base mesh, so they line up when drawn in its place. Their errors in `NULL3D_lod_error` change to those steps. A file that gives errors alone, without the coverage, holds levels whose author set the switches by hand. The loader fades those levels.
250
+
251
+ </details>
252
+
253
+ [Fading between levels](../concepts/lod.md#fading-between-levels) explains the switch.
190
254
 
191
255
  A large mesh also gets pieces: `--lod` sorts each of its levels of 32,768 triangles or more into 8 to 16 runs that each face about one way, and stores each run's bounds in `NULL3D_pieces`. Each copy then skips the pieces of its level that lie outside the view or face away from the camera, as [Levels of detail](../concepts/lod.md#pieces-of-a-large-level) explains. Only the order of the triangles changes, so other viewers draw the same mesh.
192
256
 
193
257
  Over the 213 models of four Kenney city kits, `--lod` gives levels to 162. The 45 models of under 64 triangles get none, and so do six flat road pieces that cannot lose a quarter of their triangles.
194
258
 
195
- `assets.loadGltf` gives each mesh its levels. So every copy of the model and every instance batch of it picks its level in each frame, as [Levels of detail](../concepts/lod.md) explains. A skinned mesh draws its levels too, because the tool's levels name the mesh's own vertices and the skin moves them. A glTF reader that ignores `MSFT_lod` draws the full mesh.
259
+ `assets.loadGltf` gives each mesh its levels. So every copy of the model and every instance batch of it picks its level in each frame, as [Levels of detail](../concepts/lod.md) explains. A skinned mesh draws its levels too, because the tool's levels name the mesh's own vertices and the skin moves them. A glTF reader that ignores `MSFT_lod` draws the full mesh. The [forest demo](https://github.com/null3d-engine/null3d/tree/main/examples/forest) draws 56,000 trees whose levels the engine picks in every frame. The [Island showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island) loads models with levels and far cards.
196
260
 
197
261
  ### Levels as separate downloads
198
262
 
199
263
  `--stages` writes the levels as separate files, so a model shows its coarse shape at once and gets finer while the page draws it. The command keeps the full vertex stream and the coarsest level in the model file, and writes each finer level to a file beside it, named after the model. Each node that draws the mesh names its stages in its extras, with the error of each level, as `NULL3D_stages`.
200
264
 
201
- The engine downloads the stages in order, from the next coarsest down to the finest, and draws each as it arrives. A copy that a page already made refines in place, with no new object and no flicker. A stage holds indices alone, because every level names the mesh's own vertices. The tool orders each mesh's vertices coarsest level first, so a level's triangles name a stretch at the start of the vertex buffer. A staged download can send that stretch first, then the finer levels' parts. A mesh whose levels hold positions of their own, such as a level of cards, keeps its levels in the file, as `MSFT_lod` gives them. So does a mesh with one level.
265
+ The engine downloads the stages in order, from the next coarsest down to the finest, and draws each as it arrives. A copy that a page already made refines in place, with no new object and no flicker. A stage holds indices alone, because every level names the mesh's own vertices. The tool orders each mesh's vertices coarsest level first, so a level's triangles name a stretch at the start of the vertex buffer. A staged download can send that stretch first, then the finer levels' parts.
266
+
267
+ A mesh whose levels hold positions of their own, such as a level of cards, keeps its levels in the file, as `MSFT_lod` gives them. So does a mesh with one level.
268
+
269
+ The loader sets aside a stage that the camera never shows. The stage after the file's own level always arrives. Each later stage waits until a view has drawn the level that the mesh has now, during a warm-up of about two seconds. A level that never draws cannot lead to a finer one.
202
270
 
203
- The loader sets aside a stage that the camera never shows. The stage after the file's own level always arrives. Each later stage waits until a view has drawn the level that the mesh has now, during a warm-up of about two seconds. A level that never draws cannot lead to a finer one. So the loader sets that stage and the finer ones aside, and asks for none of their files. It looks again about every second and a half, so a camera that comes close later brings those stages back.
271
+ So the loader sets that stage and the finer ones aside, and asks for none of their files. It looks again about every second and a half, so a camera that comes close later brings those stages back.
204
272
 
205
273
  The loader's `maxLevels` option stops the downloads after that many levels, the file's own counted first. A page whose camera never comes close enough to show the finest level sets it to 1, or to the number of levels that show. Other glTF readers draw the coarsest level, since the finer ones are not in the file.
206
274
 
207
- The same stage file layout carries a cluster tree's bands. A kind 1 stage holds one band. Its header comes first, then the patch count, each patch's sphere, run, parent and error, and last the band's indices. The model file holds the tree's first band, and that band draws the first picture. Each later band appends its patches below the patches that arrived before it. Parents come before children across the file and its bands. So 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. The first picture still covers the whole surface. `maxLevels` counts a band as it counts a level. The loader holds a band until a view draws a patch of the band above it.
275
+ The same stage file layout carries a cluster tree's bands. The model file holds the tree's first band, and that band draws the first picture. Each later band appends its patches below the patches that arrived before it, so the patches that a page holds always form a whole tree from the root. `maxLevels` counts a band as it counts a level. The loader holds a band until a view draws a patch of the band above it.
276
+
277
+ <details>
278
+ <summary>Technical details: the stage file layout</summary>
279
+
280
+ A kind 1 stage holds one band. Its header comes first, then the patch count, each patch's sphere, run, parent and error, and last the band's indices. Parents come before children across the file and its bands. A patch whose children have not arrived draws where the camera is close, so the first picture is coarse. The first picture still covers the whole surface.
281
+
282
+ </details>
208
283
 
209
284
  ### Cluster levels
210
285
 
@@ -216,7 +291,11 @@ The command splits each mesh part into patches and builds the tree above them wi
216
291
  2. A patch above a group simplifies its children's triangles to about half of them. The vertices that the group shares with other groups stay in place, so two patches of different detail still meet. The mesh's own open edge simplifies too, but its corners stay.
217
292
  3. Each patch stores its error and a sphere. The error is the patch's measured distance from the full mesh below it, and never less than a child's error. The sphere holds the spheres of the patch's children, and a leaf's sphere holds its triangles. So a patch never passes the view's threshold where one of its children fails, and the patches that draw cover the mesh once.
218
293
 
219
- The tree holds about twice the mesh's triangles. Every patch's indices name the mesh's own vertices, so the tree adds no vertex. On WebGL2, a mesh of more than 65,535 vertices draws its tree from a copy of its vertices, as [cluster levels](../concepts/lod.md#cluster-levels) describes. The tree goes into the file with `NULL3D_clusters`. Other glTF loaders ignore it and draw the whole mesh. The build also gives the mesh the whole levels that `--lod` makes, even without `--lod`. Each level has about half the triangles of the level above, and the levels share the mesh's vertices. A viewer that draws no patches draws these levels. The engine draws the patches on both GPU paths when one copy of the mesh draws: WebGPU picks them in a compute pass, and WebGL2 with `WEBGL_multi_draw` picks them on the job workers. Each shadow map picks its own patches too, in its own texels. The WebGPU path that draws objects directly and WebGL2 without `WEBGL_multi_draw`, such as Firefox, draw the whole levels.
294
+ The tree holds about twice the mesh's triangles. Every patch's indices name the mesh's own vertices, so the tree adds no vertex. On WebGL2, a mesh of more than 65,535 vertices draws its tree from a copy of its vertices, as [cluster levels](../concepts/lod.md#cluster-levels) describes. The tree goes into the file with `NULL3D_clusters`. Other glTF loaders ignore it and draw the whole mesh.
295
+
296
+ The build also gives the mesh the whole levels that `--lod` makes, even without `--lod`. Each level has about half the triangles of the level above, and the levels share the mesh's vertices. A viewer that draws no patches draws these levels.
297
+
298
+ The engine draws the patches on both GPU paths when one copy of the mesh draws: WebGPU picks them in a compute pass, and WebGL2 with `WEBGL_multi_draw` picks them on the job workers. Each shadow map picks its own patches too, in its own texels. The WebGPU path that draws objects directly and WebGL2 without `WEBGL_multi_draw`, such as Firefox, draw the whole levels.
220
299
 
221
300
  A mesh gets no tree in four cases. It has fewer than 20,000 triangles, or a skin or a morph target bends it. It also gets none when its material blends or masks, or more than four copies draw it. Those meshes keep whole levels.
222
301
 
@@ -254,14 +333,14 @@ The default limit, a hundredth of each mesh's size, changes little that a viewer
254
333
  | `shader permutations` | The permutation bits that the model's materials and meshes turn on |
255
334
  | `shader files that load on first use` | The shader files that the engine downloads when it loads the model, one per feature it uses |
256
335
  | `draw buckets` | Each pipeline key that the model's draws need, with the objects that draw with it. Every object of one key shares one pipeline |
257
- | `warning` | Each quality preset whose texture memory budget the model's textures pass, with the memory that passes it |
336
+ | `warning` | Each quality preset whose texture memory budget the model's textures pass, with the memory that passes it. Low and Medium count the ETC2 and ASTC bytes, as phones and tablets run them. High and Ultra count the BC7 bytes, as computers run them |
258
337
  | `blockers` | The meshes that got blockers, and their triangles |
259
338
  | `no blocker` | Each mesh that could block but got no blocker, with the reason |
260
339
  | `stored trees` | The mesh parts whose trees the file stores, and their bytes before compression |
261
340
 
262
341
  `--report` writes the same figures as JSON, with each texture's source size, output size and encode time.
263
342
 
264
- The command writes no model that the engine would refuse to load. One array may hold at most 256 MiB, and one file may decode to at most 1 GiB ([Limits on each file](../concepts/assets.md#limits-on-each-file)). A model that passes a limit fails with an error that names it. Split such a scene into several files, each with a part of its meshes, and load each one with `assets.loadGltf()`.
343
+ The warning is a guide: a scene that loads several models adds their texture memory together.
265
344
 
266
345
  ## The shader list
267
346
 
@@ -273,40 +352,21 @@ The command knows which features and bits each model needs, because it has just
273
352
  "NULL3D_shaders": { "permutations": ["VERTEX_COLOR", "ALPHA_MASK"], "features": ["cutout", "coverage"] }
274
353
  ```
275
354
 
276
- The engine reads the list as it loads the file and downloads those shader files beside the textures. It holds back a file that the page's settings cannot use. Alpha to coverage (`coverage`) needs MSAA, and a distance band's fading edges (`lod_fade`) need the `lodFade` setting, which Low turns off. A hand-set level's own fade needs the same shader file, whatever the setting, because its switch would pop without it. The list names `lod_fade` only for levels that fade: a level with a measured error, which comes with its screen coverage, switches at once while the threshold stays small, so a model whose levels the command cut names no fade file. A pipeline that needs a held feature still loads its file on first use, so the fade file downloads once the governor raises the threshold past the point where a measured switch shows. When the settings change to use one, its file downloads then. So `scene.warmUp()` builds only the pipelines that the model's objects need, and nothing new downloads while the game plays at a preset's own threshold. The list names only what the model itself decides. Bits that a device fixes, such as half precision, and bits that the scene decides, such as receiving shadows, are not part of it.
355
+ The engine reads the list as it loads the file and downloads those shader files beside the textures. It holds back a file that the page's settings cannot use, and downloads it later if the settings change to use it. So `scene.warmUp()` builds the pipelines that the model's objects need, and nothing new downloads while the game plays at a preset's own threshold.
277
356
 
278
- The report ends with the list and the pipeline keys it gives. It warns for each quality preset whose texture memory budget the model's textures pass. Phones and tablets run the Low and Medium presets, where the textures take their ETC2 or ASTC bytes. Computers run High and Ultra, where they take their BC7 bytes. The warning is a guide: a scene that loads several models adds their texture memory together.
357
+ <details>
358
+ <summary>Technical details: which listed files the engine holds back</summary>
279
359
 
280
- ## In a Vite project
360
+ - Alpha to coverage (`coverage`) needs MSAA.
361
+ - A distance band's fading edges (`lod_fade`) need the `lodFade` setting, which Low turns off.
362
+ - A hand-set level's own fade always needs the `lod_fade` file, whatever the setting, because its switch would pop without it.
363
+ - The list names `lod_fade` only for levels that fade. A level with a measured error switches at once while the threshold stays small, so a model whose levels the command cut names no fade file.
364
+ - A pipeline that needs a held feature still loads its file on first use. So the fade file downloads once the governor raises the threshold past the point where a measured switch shows.
365
+ - The list names only what the model itself decides. Bits that a device fixes, such as half precision, and bits that the scene decides, such as receiving shadows, are not part of it.
281
366
 
282
- The null3D Vite plugin runs the same steps on a model that a module imports with `?optimized`. The import gives the address of the optimized model:
367
+ </details>
283
368
 
284
- ```ts
285
- // sketch.ts
286
- import shipUrl from './models/ship.glb?optimized';
287
-
288
- const ship = await assets.loadGltf(shipUrl);
289
- ```
290
-
291
- The plugin uses the tool of `@null3d/cli`, so add the command-line tool to your project first. With Bun, use Bun 1.4.3 or newer ([Install null3D](../getting-started/install.md) says why):
292
-
293
- ```sh
294
- bun add -d @null3d/cli
295
- ```
296
-
297
- The first import of a model encodes it. The plugin keeps the result in `node_modules/.cache/null3d-assets`, keyed by the model's files, the tool's version and the options. Later starts and builds take it from there, until one of those changes. A production build writes the files into its assets folder. The plugin's `assets` option takes the command's options: `lod`, `clusters`, `stages` (the levels and bands as separate downloads, with `lod` or `clusters`), `simplify`, `simplifyError`, `maxTextureSize`, `textureQuality`, `roughnessBake` (false for `--no-roughness-bake`), `meshopt` (false for `--compression none`), `blockers` (false for `--no-blockers`) and `bvh`:
298
-
299
- ```ts
300
- // vite.config.ts
301
- import null3d from '@null3d/vite-plugin';
302
- import { defineConfig } from 'vite';
303
-
304
- export default defineConfig({
305
- plugins: [null3d({ assets: { lod: true, maxTextureSize: 1024, bvh: 5000 } })],
306
- });
307
- ```
308
-
309
- For TypeScript, add `@null3d/vite-plugin/client` to the `types` of your `tsconfig.json`, so `?optimized` imports have the type `string`.
369
+ The report ends with the list and the pipeline keys it gives.
310
370
 
311
371
  ## Convert other formats
312
372
 
@@ -425,6 +485,8 @@ The output is one KTX2 file:
425
485
  - A cube map. Level 0 holds the image. Each smaller level holds the light that a rougher surface reflects, filtered with the GGX distribution of the engine's materials. The smallest level has faces of 8 x 8 texels. More levels go to low roughness, where reflections change fastest.
426
486
  - Nine spherical harmonics coefficients of the light, for diffuse surfaces, in the file's key-value data.
427
487
 
488
+ The [environment light demo](https://github.com/null3d-engine/null3d/tree/main/examples/environment) shows the light of an HDR file, an EXR file and the built-in room.
489
+
428
490
  | Option | Effect | Without it |
429
491
  | --- | --- | --- |
430
492
  | `--size <texels>` | The width of the largest faces: a power of 2 from 32 to 2048 | 256 |
@@ -458,48 +520,208 @@ export default defineSketch(async ({ scene, assets }) => {
458
520
 
459
521
  [Lighting and environment](../concepts/lighting.md#environment-maps) says how the environment lights each surface.
460
522
 
461
- ## Encode time
523
+ ## Build only the shader permutations you draw with
462
524
 
463
- Each texture encodes on its own worker thread, so a set of textures uses every CPU core. On a MacBook Pro with 18 cores, those 40 sets, 144 textures in all, took 18 to 26 seconds. A texture of 2048 x 2048 takes several seconds on its core. The command prints each model's time.
525
+ The engine's shader set holds every build of every permutation word, which is thousands of files and gigabytes. A page downloads only the few files that its device needs. A production build still copies every file into its output, and the host stores them all. A list of the words that your pages draw with makes the build copy only the builds of those words.
464
526
 
465
- ## Build only the shader permutations you draw with
527
+ The list is a text file with one hexadecimal word on each line. A word leaves out the bits that a device fixes when it starts: the draw index, tone mapping in the shader and half precision. So one list serves every device. The build keeps each listed word's builds for every value of those bits.
528
+
529
+ The list belongs to one set of pages. A project that adds a scene records again, because the build compiles only what the list holds. `bun run build` without a list is a full build.
530
+
531
+ ### When to ship the full set
532
+
533
+ A list holds only the words that a recording saw. An app whose content arrives while it runs cannot record its words, because nobody knows that content at build time. Examples are models that users upload, a catalogue from a CMS, and glTF files from another server. A new model can need a word that no recording saw, and the page that draws it then stops.
466
534
 
467
- A production build can compile only the shader permutations that your scenes draw with, instead of every combination of every bit. That shortens the build and shrinks the set it writes. The build reads one file that lists the permutations as hexadecimal words, one on each line.
535
+ Build such an app without a list. The build copies the whole set, and each page still downloads only the files that its device needs.
468
536
 
469
- The list belongs to one set of pages. A project that adds a scene records again, because the build compiles only what the list holds. A build without the list stays a full build, as before.
537
+ An app whose content is all in the build can ship a list. Keep the list complete:
470
538
 
471
- A word leaves out the bits that a device fixes when it starts: the draw index, tone mapping in the shader and half precision. One list then serves every device module. A build compiles each word's builds for every value of those bits. Record both GPU paths, because a path's variants list a few bits of their own. WebGL2 has the morph targets, and WebGPU has the instance index.
539
+ - Run your browser tests against the production build with the list. A page that asks for a word that the list lacks stops with an error that names the word, so the suite fails. [Record from your browser tests](#record-from-your-browser-tests) shows how the same tests can write the list.
540
+ - Record again after you add a feature, a material or a level. The dev server also warns about a word that the list lacks, as [When the list lacks a word](#when-the-list-lacks-a-word) says.
472
541
 
473
- Record the list from a run of your pages. The recorder loads each page in hold mode at the low and high presets, because the words a preset turns on differ, and it loads each page live too. A live page advances the scene, and a showcase scene offers its controls: the recorder presses every button of its controls HUD, so the words that those states ask for reach the list.
542
+ ### Record the list
543
+
544
+ `shaders record` loads your pages in a headless browser and writes the words that their pipelines ask for. Run it in the project's folder. It starts the project's own Vite dev server:
474
545
 
475
546
  ```sh
476
- NULL3D_SHADER_PERMUTATIONS= bun run examples:build
477
- bun run examples:preview
478
- bun tools/shader-permutations.ts --base https://localhost:5173 --pages demos
547
+ bunx @null3d/cli shaders record --page / --live /
479
548
  ```
480
549
 
481
- The preview serves HTTPS by default. A secure origin is what makes WebGPU, and so the High and Ultra presets, available. `NULL3D_HTTPS=0` opts out to plain HTTP on the loopback. The recorder accepts the local certificate.
550
+ A held page (`--page`) loads in hold mode at the low and high quality presets, on WebGPU and on WebGL2. A preset turns on a few bits, and each GPU path lists bits of its own. WebGL2 has the morph targets, and WebGPU has the instance index.
482
551
 
483
- The empty variable makes a full set, because the recording reads every word that the pages ask for. Without it, the build narrows to the list that a recorded run wrote.
552
+ A live page (`--live`) loads on both GPU paths and draws for five seconds. The recorder presses every button of the page's controls HUD, when it has one, so the words of those states reach the list. Without either option, the command records `/` both ways. It writes `shader-permutations.txt`, or the file that `--out` names. [The `null3d` command](../cli/null3d.md#shaders-record) lists every option.
484
553
 
485
- The recorder writes `examples/shader-permutations.txt`, and `bun run examples:build` reads it. Its `--page-root` names the address that the pages sit under. Use `/` for a preview of the built site, or `/examples/` for this repository's own dev server. A demo that draws more in a state its controls cannot reach enters that state through the recorder's own query. The island's pages record with its highest walker count. The recorder runs from a checkout of this repository, because it drives a browser through the repository's own page list and browser launcher. A project outside the repository runs it from such a checkout and names its pages with one `--page <path>` for each, instead of `--pages demos`.
554
+ A page that builds more of its scene as the visitor scrolls needs `--scroll`. The recorder then scrolls each live page down to its end, one window's height at a time. After each step, it waits until the page has asked for nothing for half a second. So each stage that a scroll reveals has loaded its shaders, and its pipelines have asked for their words.
486
555
 
487
- A game page that starts its engine on a click needs `--live` pages and `--click <selector>`, such as `--click "#play"`. A production build of the engine folder ignores the URL switches. Record against a development build of that folder (`vite build --mode development`). The [deterministic simulation guide](deterministic-simulation.md#a-production-build-of-a-games-engine-files) gives the full sequence.
556
+ A game page that starts its engine on a click needs `--live` pages and `--click <selector>`, such as `--click "#play"`. Pages that another server serves take `--base <url>`. That server must serve a development build, because a production build ignores the recording switch. The [deterministic simulation guide](deterministic-simulation.md#a-production-build-of-a-games-engine-files) gives the full sequence for a game.
488
557
 
489
- Build with the list:
558
+ A state that no page reaches during the recording goes into the list by hand. An example is a feature that a visitor turns on later. Add its word with `--extra`, or add a line to the file:
490
559
 
491
560
  ```sh
492
- NULL3D_SHADER_PERMUTATIONS=examples/shader-permutations.txt bun run build
561
+ bunx @null3d/cli shaders record --page / --extra 0x00000010
493
562
  ```
494
563
 
495
- Without the variable, the build compiles every permutation, as before. With it, the build's cache keys and its input hash include the list, so a changed list builds again.
564
+ `0x00000010` is the alpha mask bit, for a masked material that a visitor's action shows. A word that you add by hand leaves out the device bits, as the recorded words do.
565
+
566
+ Each run adds its words to the list that `--out` names, once each, in order. So each level or mode of a game can be recorded in a run of its own into one list. The `--replace` option writes the run's words alone, for a list that starts afresh.
496
567
 
497
- Record again after a scene gains a feature that turns on a new permutation bit. The build then lacks that word. The engine fails with an error that names the word the first time a pipeline needs it, instead of drawing nothing. A path that a recording cannot reach, such as a feature that a visitor turns on later, goes into the list by hand:
568
+ ### Record at setup
569
+
570
+ A game that creates every material and object variant at setup, hidden, records nearly every word in one load. Its setup creates the objects that later states show, hides them, and awaits `scene.warmUp()`, as [Loading screens](loading-screens.md#a-later-loading-stage) advises. The engine builds the pipelines of hidden objects too, and each build reaches the recording. A hidden object with a clear coat added its 16 words to a scene's list, held and live, with or without the warm-up.
571
+
572
+ A game that loads its levels on demand can add a switch of its own that loads every level at setup, such as `?all-levels`. Record with that switch, such as `--page '/?all-levels'`. Ship the game without it.
573
+
574
+ ### Record by hand
575
+
576
+ `--manual` opens one page in a browser window on your own screen, with the recording switch. Play through every menu, setting, level and mode that the page offers. Then press Enter in the terminal, and the command adds the words to the list. Ctrl-C asks whether to discard them.
498
577
 
499
578
  ```sh
500
- bun tools/shader-permutations.ts --base https://localhost:5173 --pages demos --extra 0x00000010
579
+ bunx @null3d/cli shaders record --manual --gpu webgpu --preset low
580
+ bunx @null3d/cli shaders record --manual --gpu webgpu --preset high
581
+ bunx @null3d/cli shaders record --manual --gpu webgl2 --preset low
582
+ bunx @null3d/cli shaders record --manual --gpu webgl2 --preset high
583
+ ```
584
+
585
+ Run it on both GPU paths at the low and high presets, as the automatic run records them. A path and a preset each turn on words of their own. The `--live <path>` option names another page than `/`. A recording covers one load of the page. A reload or a link to another page starts a new recording, and the command says so. Record each page in a run of its own: each run adds to the list.
586
+
587
+ ### Record from your browser tests
588
+
589
+ A project's own browser tests already drive its states. `@null3d/cli/shaders` adds the words that a test reached to the list. Open the page with the recording switch, drive it, then save:
590
+
591
+ ```ts
592
+ // tests/record-shaders.spec.ts, a Playwright test
593
+ import { saveRecordedWords, withRecordingSwitch } from '@null3d/cli/shaders';
594
+ import { test } from '@playwright/test';
595
+
596
+ test('plays the first level', async ({ page }) => {
597
+ await page.goto(withRecordingSwitch('/?gpu=webgl2&preset=low'));
598
+ // ... the steps that play the level ...
599
+ await saveRecordedWords(page, 'shader-permutations.txt');
600
+ });
601
+ ```
602
+
603
+ The `saveRecordedWords` call ends the page's recording, waits until the engine publishes its words, and adds them to the list. With `{ replace: true }` it writes them alone. The page must run a development build, such as the dev server. A production build ignores the recording switch, unless the plugin's `urlSwitches` option is on. Run the tests on both GPU paths at the low and high presets, as the switches in the address above do for one of them.
604
+
605
+ ### Build with the list
606
+
607
+ Name the list in the plugin's options. The path is relative to Vite's root:
608
+
609
+ ```ts
610
+ // vite.config.ts
611
+ import null3d from '@null3d/vite-plugin';
612
+ import { defineConfig } from 'vite';
613
+
614
+ export default defineConfig({
615
+ plugins: [null3d({ shaders: { list: 'shader-permutations.txt' } })],
616
+ });
617
+ ```
618
+
619
+ A production build then copies only the builds of the listed words. A shader file whose builds the list leaves out gives way to one small module that holds no build. A table of shared paragraphs keeps only the paragraphs that the kept builds read. The build compiles no shader. It takes the engine's set from the same place as before: the release asset, or the folder that `NULL3D_ENGINE_SHADERS` names.
620
+
621
+ The dev server serves the whole set, so a recording sees every word. It compares each word that a page draws with against the list, as [When the list lacks a word](#when-the-list-lacks-a-word) says.
622
+
623
+ The build prints what it copied, such as:
624
+
625
+ ```text
626
+ null3D: copied 218 shader files, 17 MB: the builds of the 6 permutation words of shader-permutations.txt.
627
+ ```
628
+
629
+ A build without a list warns with the size of the whole set, which it copies.
630
+
631
+ A list names words alone. A listed word keeps its builds in every shader that has one, in the files of features that your pages never use too. The word without any bit set keeps the most, because the engine's own passes and the passes of many features draw with it. Every page draws with it, so a list without `0x00000000` stops the build.
632
+
633
+ With null3D 0.1.0's shader set, the builds copied these shader files:
634
+
635
+ | List | Shader files | Size |
636
+ | --- | --- | --- |
637
+ | None, so the whole set | 7,597 | 4,115 MB |
638
+ | The 270 words of null3D's examples | 795 | 257 MB |
639
+ | The 6 words of a small scene | 218 | 17 MB |
640
+
641
+ ### When the list lacks a word
642
+
643
+ A listed word that no shader build of the project holds stops the build, and the message names the word. The builds are those of the engine's set and of the project's own shaders, such as its custom materials and its add-ons' shaders. Such a word comes from a typing mistake, or from a list that another version of the engine recorded. Record the list again.
644
+
645
+ A page that asks for a word that the list lacks fails the pipeline that needs it. The message names the word, as the list writes it:
646
+
647
+ ```text
648
+ the shader set holds only the permutation words of the project's shader list, and this pipeline asks for 0x00000010, which the list lacks. Record the pages again with bunx @null3d/cli shaders record so that the word reaches the list, or add 0x00000010 to the list by hand, and build again.
501
649
  ```
502
650
 
503
- A word that the recording cannot reach is written without the device bits, as the recorded words are. `0x00000010` is the alpha mask bit, for a masked material that a visitor's action shows.
651
+ The dev server names such a word before a build ships the page. It still draws with the whole set. When a page first draws with a word that the list lacks, the terminal and the browser's console show a warning:
652
+
653
+ ```text
654
+ null3D: /level.html draws with the permutation word 0x00000010, which the shader list shader-permutations.txt lacks. The dev server draws it, but a production build with this list stops the page with an error that names the word. Record the page again with bunx @null3d/cli shaders record, or add the word by hand with bunx @null3d/cli shaders record --extra 0x00000010.
655
+ ```
656
+
657
+ The terminal shows each word once, until the list changes. The dev server reads the list again after each change, so a word that a new recording adds stops the warning at once. A recording run shows no warning, because it adds its words to the list.
658
+
659
+ Record again after a scene gains a feature that turns on a new permutation bit.
660
+
661
+ ### In a checkout of null3D
662
+
663
+ This repository records the list of its examples with its own script, which runs the same recorder over every demo:
664
+
665
+ ```sh
666
+ NULL3D_SHADER_PERMUTATIONS= bun run examples:build
667
+ bun run examples:preview
668
+ bun tools/shader-permutations.ts --base https://localhost:5173 --pages demos
669
+ ```
670
+
671
+ The empty variable builds the full set, so the recording sees every word. The preview serves HTTPS by default, because a secure origin makes WebGPU, and so the High and Ultra presets, available. The script writes `examples/shader-permutations.txt`. Its `--page-root` names the address that the pages sit under: `/` for a preview of the built site, or `/examples/` for the repository's own dev server. The island's pages record with its highest walker count, a state that its controls cannot reach.
672
+
673
+ The shader build of a checkout takes a list too, and then compiles only those words:
674
+
675
+ ```sh
676
+ NULL3D_SHADER_PERMUTATIONS=examples/shader-permutations.txt bun run build
677
+ ```
678
+
679
+ Without the variable, or with it empty, `bun run build` compiles every permutation. `bun run examples:build` reads the examples' list this way. With it, the build's cache keys and its input hash include the list, so a changed list builds again.
680
+
681
+ The file that the asset command writes into a model, `asset.extras.NULL3D_shaders`, names the bits that the model turns on. The list here is different: it holds the whole words that your scenes draw with. [Loading screens](loading-screens.md#loading-everything-up-front) describes the model's list.
682
+
683
+ ## Ship a subset of the GPU paths
684
+
685
+ The engine draws with WebGPU where the browser offers it, and with WebGL2 everywhere else ([GPU tiers and backends](../concepts/backends.md)). A production build copies the shaders of both paths, so a host or a desktop app stores both. Most of that is the WebGL2 half: GLSL text is about nine tenths of the shader set's bytes.
686
+
687
+ A deployment that knows which paths its devices offer can ship a subset of them. An Electron app ships Chromium, and Chromium draws with WebGPU where the device lets it. A kiosk, a game inside a WebView, and a game that requires Chrome all know the same. Such a build drops the other path's shader files, and its app package holds no WebGL2 shader files.
688
+
689
+ The build, the app package and the installer get smaller. The download shrinks too, wherever a visitor downloads the whole app. That covers an Electron installer, an archive of the site, and the files that a service worker caches for offline play. A page's own start download does not change, because a page already downloads one path's files.
690
+
691
+ Ship a subset only when every device that runs the app offers the paths it keeps. A page on a device without WebGPU stops with [E1308](../errors/E1308.md), and the engine cannot fall back. Check the devices and the operating systems that the app ships on, with a run of `navigator.gpu` or `engine.capabilities.tier` on each.
692
+
693
+ ```ts
694
+ // vite.config.ts
695
+ import null3d from '@null3d/vite-plugin';
696
+ import { defineConfig } from 'vite';
697
+
698
+ export default defineConfig({
699
+ plugins: [null3d({ shaders: { gpuPaths: ['webgpu'] } })],
700
+ });
701
+ ```
702
+
703
+ The option takes `'webgpu'` and `'webgl2'`, and it must include `'webgpu'`. The shader compiler builds every shader for WebGPU, so a project's own shaders and its add-ons' shaders have no other form. That leaves `['webgpu']` as the one path a build can ship, and leaving the option out ships both.
704
+
705
+ A build with the option does these things:
706
+
707
+ - It copies only the WebGPU files of the engine's shader set. The set keeps its module of loader tables, which name the WebGL2 files, so those tables resolve to one empty module instead.
708
+ - It compiles your own custom shaders and their materials for WebGPU alone, and drops the WebGL2 sets of a custom material, effect or sky layer.
709
+ - It drops the WebGL2 builds of an add-on package's compiled shaders.
710
+ - It writes the shipped paths into the engine's marker module, which is how the engine knows its build's choice.
711
+
712
+ The examples' production build, with the whole set and no list, shows the difference:
713
+
714
+ | GPU paths that the build ships | Shader files | Size |
715
+ | --- | --- | --- |
716
+ | Both, the default | 8,689 | 4,118 MB |
717
+ | WebGPU alone | 1,967 | 330 MB |
718
+
719
+ The files that remain of the dropped path are eight stub modules of about 60 bytes. Each stands in for a module that a page would load by name, and a page never reads one on the WebGPU path.
720
+
721
+ The option combines with `shaders.list`: a build with both copies only the listed words' builds of the shipped path.
722
+
723
+ The dev server keeps both paths, so you can test the other one with `?gpu=webgl2`. When a page draws with a path that a production build does not ship, the dev server warns. It warns in its terminal and in the browser's console, once for each page.
724
+
725
+ Test the production build on the shipped path before you ship it. Run your browser tests against it, and check that each page draws. A test that forces the other path with `?gpu=webgl2` fails with E1308, which is the message that a device without WebGPU shows.
504
726
 
505
- The file that the asset command writes into a model, `asset.extras.NULL3D_shaders`, names the bits that the model turns on. The list here is different: it holds the whole words that your scenes draw with. A narrowed build compiles those words. [Loading screens](loading-screens.md#loading-everything-up-front) describes the model's list.
727
+ The build still holds the JavaScript of both GPU paths, which is a small part of the engine's code. It also holds the engine's own passes' GLSL text, which is in the shared shader module. An add-on that a page loads from a CDN at run time keeps both paths, because the plugin narrows only what the build bundles.