@null3d/engine 0.0.0 → 0.1.0

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 (311) hide show
  1. package/README.md +109 -0
  2. package/THIRD-PARTY-NOTICES.txt +0 -1
  3. package/dist/wasm/single/null3d.js +19 -6
  4. package/dist/wasm/single/null3d_bg.wasm +0 -0
  5. package/dist/wasm/threaded/null3d.js +19 -6
  6. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  7. package/docs/api/animation.md +23 -67
  8. package/docs/api/assets.md +42 -26
  9. package/docs/api/cameras.md +8 -6
  10. package/docs/api/controls.md +46 -44
  11. package/docs/api/debug.md +13 -8
  12. package/docs/api/engine.md +17 -11
  13. package/docs/api/feature-draws.md +3 -3
  14. package/docs/api/feature-effects.md +3 -3
  15. package/docs/api/feature-instances.md +2 -2
  16. package/docs/api/features.md +14 -15
  17. package/docs/api/geometry.md +56 -75
  18. package/docs/api/grass.md +1 -1
  19. package/docs/api/impostors.md +120 -9
  20. package/docs/api/input.md +4 -11
  21. package/docs/api/lights.md +14 -38
  22. package/docs/api/lines.md +8 -25
  23. package/docs/api/materials.md +69 -70
  24. package/docs/api/math.md +6 -7
  25. package/docs/api/objects.md +13 -13
  26. package/docs/api/particles.md +2 -14
  27. package/docs/api/points.md +3 -25
  28. package/docs/api/post.md +22 -23
  29. package/docs/api/quality.md +11 -6
  30. package/docs/api/raycast.md +13 -32
  31. package/docs/api/reference/animation.md +9 -9
  32. package/docs/api/reference/assets.md +18 -18
  33. package/docs/api/reference/cameras.md +5 -2
  34. package/docs/api/reference/controls.md +75 -23
  35. package/docs/api/reference/debug.md +23 -8
  36. package/docs/api/reference/engine.md +22 -10
  37. package/docs/api/reference/geometry.md +161 -82
  38. package/docs/api/reference/grass.md +1 -1
  39. package/docs/api/reference/impostors.md +92 -1
  40. package/docs/api/reference/input.md +3 -3
  41. package/docs/api/reference/lights.md +9 -9
  42. package/docs/api/reference/lines.md +7 -7
  43. package/docs/api/reference/materials.md +48 -48
  44. package/docs/api/reference/math.md +22 -22
  45. package/docs/api/reference/objects.md +9 -9
  46. package/docs/api/reference/points.md +4 -4
  47. package/docs/api/reference/post.md +18 -18
  48. package/docs/api/reference/quality.md +7 -3
  49. package/docs/api/reference/raycast.md +6 -6
  50. package/docs/api/reference/render.md +2 -2
  51. package/docs/api/reference/scene.md +29 -26
  52. package/docs/api/reference/sketch.md +4 -0
  53. package/docs/api/reference/sound.md +203 -0
  54. package/docs/api/reference/sprites.md +5 -5
  55. package/docs/api/reference/terrain.md +2 -1
  56. package/docs/api/reference/textures.md +4 -4
  57. package/docs/api/reference/ui.md +3 -3
  58. package/docs/api/reference/vertex-draws.md +3 -3
  59. package/docs/api/reference/water.md +77 -6
  60. package/docs/api/reference/wind.md +2 -2
  61. package/docs/api/render.md +12 -10
  62. package/docs/api/scene.md +40 -29
  63. package/docs/api/sketch.md +64 -3
  64. package/docs/api/sound.md +169 -0
  65. package/docs/api/splats.md +7 -0
  66. package/docs/api/sprites.md +4 -20
  67. package/docs/api/tasks.md +2 -2
  68. package/docs/api/terrain.md +2 -14
  69. package/docs/api/textures.md +9 -9
  70. package/docs/api/ui.md +3 -15
  71. package/docs/api/water.md +198 -15
  72. package/docs/api/wind.md +5 -5
  73. package/docs/cli/null3d.md +93 -18
  74. package/docs/concepts/architecture.md +10 -10
  75. package/docs/concepts/assets.md +2 -19
  76. package/docs/concepts/backends.md +7 -5
  77. package/docs/concepts/color-management.md +15 -26
  78. package/docs/concepts/culling.md +1 -1
  79. package/docs/concepts/instances.md +5 -5
  80. package/docs/concepts/large-worlds.md +1 -1
  81. package/docs/concepts/lighting.md +50 -55
  82. package/docs/concepts/lod.md +2 -15
  83. package/docs/concepts/materials.md +16 -16
  84. package/docs/concepts/post-processing.md +7 -29
  85. package/docs/concepts/quality-preset-tables.md +53 -50
  86. package/docs/concepts/quality-presets.md +56 -27
  87. package/docs/concepts/render-graph.md +19 -14
  88. package/docs/concepts/render-layers.md +3 -17
  89. package/docs/concepts/shadows.md +10 -28
  90. package/docs/concepts/static-dynamic.md +2 -2
  91. package/docs/cookbook/index.md +1 -1
  92. package/docs/data/threejs-mapping.json +136 -102
  93. package/docs/errors/E1214.md +3 -3
  94. package/docs/errors/E1307.md +23 -0
  95. package/docs/errors/E1420.md +3 -3
  96. package/docs/errors/index.md +3 -2
  97. package/docs/getting-started/cdn.md +17 -1
  98. package/docs/getting-started/first-scene.md +1 -1
  99. package/docs/getting-started/hosting.md +50 -9
  100. package/docs/getting-started/install.md +8 -7
  101. package/docs/getting-started/network-use.md +10 -2
  102. package/docs/getting-started/project-structure.md +15 -6
  103. package/docs/getting-started/third-party-notices.md +8 -6
  104. package/docs/guides/accessibility.md +1 -1
  105. package/docs/guides/add-ons.md +3 -2
  106. package/docs/guides/agents.md +16 -5
  107. package/docs/guides/assets-pipeline.md +13 -12
  108. package/docs/guides/audio.md +109 -124
  109. package/docs/guides/car-paint.md +1 -1
  110. package/docs/guides/content-pages.md +10 -6
  111. package/docs/guides/custom-passes.md +9 -8
  112. package/docs/guides/custom-shaders.md +6 -3
  113. package/docs/guides/debugging.md +78 -4
  114. package/docs/guides/deploying.md +105 -5
  115. package/docs/guides/deterministic-simulation.md +1 -1
  116. package/docs/guides/first-use-shaders.md +4 -4
  117. package/docs/guides/loading-screens.md +78 -33
  118. package/docs/guides/multiple-views.md +41 -2
  119. package/docs/guides/performance.md +6 -3
  120. package/docs/guides/phones.md +12 -1
  121. package/docs/guides/physics.md +1 -1
  122. package/docs/guides/screens.md +7 -5
  123. package/docs/guides/start-time.md +328 -0
  124. package/docs/guides/testing.md +23 -5
  125. package/docs/guides/ui-overlays.md +3 -3
  126. package/docs/index.md +12 -8
  127. package/docs/pages.md +26 -23
  128. package/docs/porting/react-three-fiber.md +228 -5
  129. package/docs/porting/threejs-loop-and-threads.md +220 -6
  130. package/docs/porting/threejs-mapping.md +86 -84
  131. package/docs/porting/threejs-materials.md +212 -5
  132. package/docs/porting/threejs-overview.md +218 -5
  133. package/docs/porting/threejs-postprocessing.md +2 -2
  134. package/docs/porting/threejs-shaders.md +298 -5
  135. package/docs/porting/threejs-unsupported.md +82 -6
  136. package/docs/porting/verification.md +181 -5
  137. package/docs/shaders/builtins.md +1 -1
  138. package/docs/shaders/library.md +63 -39
  139. package/docs/shaders/surface-functions.md +11 -10
  140. package/docs/shaders/wgsl-rules.md +1 -1
  141. package/lib/debug/channel.d.ts +103 -0
  142. package/lib/debug/channel.js +269 -0
  143. package/lib/debug/debug.d.ts +9 -7
  144. package/lib/debug/draw.d.ts +9 -0
  145. package/lib/debug/draw.js +49 -2
  146. package/lib/debug/inspector.d.ts +60 -0
  147. package/lib/debug/inspector.js +475 -0
  148. package/lib/debug/stats-panel.d.ts +1 -1
  149. package/lib/debug/stats.d.ts +2 -3
  150. package/lib/errors/codes.js +8 -2
  151. package/lib/errors/engine-error.js +25 -10
  152. package/lib/errors/fixes.d.ts +1 -0
  153. package/lib/errors/fixes.js +3 -2
  154. package/lib/generated/core.d.ts +1 -1
  155. package/lib/generated/core.js +1 -1
  156. package/lib/gpu/early-builds.d.ts +68 -0
  157. package/lib/gpu/early-builds.js +158 -0
  158. package/lib/gpu/pipeline-name.d.ts +6 -0
  159. package/lib/gpu/pipeline-name.js +23 -0
  160. package/lib/gpu/webgl2/backend.d.ts +63 -2
  161. package/lib/gpu/webgl2/backend.js +226 -8
  162. package/lib/gpu/webgl2/programs.d.ts +18 -0
  163. package/lib/gpu/webgl2/programs.js +4 -1
  164. package/lib/gpu/webgpu/backend.d.ts +89 -2
  165. package/lib/gpu/webgpu/backend.js +255 -8
  166. package/lib/gpu/webgpu/pipelines.d.ts +13 -0
  167. package/lib/gpu/webgpu/pipelines.js +15 -1
  168. package/lib/index.d.ts +6 -4
  169. package/lib/index.js +3 -2
  170. package/lib/math/color.d.ts +5 -5
  171. package/lib/math/color.js +5 -5
  172. package/lib/math/mat4.d.ts +6 -12
  173. package/lib/math/mat4.js +6 -12
  174. package/lib/math/namespaces/quat.d.ts +3 -3
  175. package/lib/math/namespaces/quat.js +3 -3
  176. package/lib/math/quat.d.ts +8 -12
  177. package/lib/math/quat.js +8 -12
  178. package/lib/math/random.d.ts +2 -3
  179. package/lib/math/random.js +2 -3
  180. package/lib/math/types.d.ts +4 -4
  181. package/lib/math/vec3.d.ts +3 -6
  182. package/lib/math/vec3.js +3 -6
  183. package/lib/page/capabilities.d.ts +7 -7
  184. package/lib/page/capabilities.js +39 -25
  185. package/lib/page/check-store.d.ts +14 -2
  186. package/lib/page/check-store.js +34 -11
  187. package/lib/page/engine.d.ts +103 -26
  188. package/lib/page/engine.js +420 -97
  189. package/lib/page/first-frame.d.ts +16 -0
  190. package/lib/page/first-frame.js +35 -0
  191. package/lib/page/frame-stats.d.ts +34 -1
  192. package/lib/page/frame-stats.js +15 -0
  193. package/lib/page/label-loop.d.ts +7 -3
  194. package/lib/page/label-loop.js +17 -10
  195. package/lib/page/labels.d.ts +3 -3
  196. package/lib/page/pipeline-store.d.ts +25 -0
  197. package/lib/page/pipeline-store.js +84 -0
  198. package/lib/page/start-marker.d.ts +4 -1
  199. package/lib/page/start-marker.js +5 -2
  200. package/lib/page/switches.d.ts +32 -2
  201. package/lib/page/switches.js +9 -1
  202. package/lib/quality/check.d.ts +24 -3
  203. package/lib/quality/check.js +21 -7
  204. package/lib/quality/chooser.d.ts +6 -0
  205. package/lib/quality/chooser.js +8 -0
  206. package/lib/quality/governor.d.ts +98 -6
  207. package/lib/quality/governor.js +250 -20
  208. package/lib/quality/preset-docs.d.ts +16 -1
  209. package/lib/quality/preset-docs.js +3 -0
  210. package/lib/quality/presets.d.ts +84 -7
  211. package/lib/quality/presets.js +94 -2
  212. package/lib/render/draw.d.ts +3 -2
  213. package/lib/render/draw.js +15 -5
  214. package/lib/render/load-draw.d.ts +7 -5
  215. package/lib/render/load-draw.js +7 -5
  216. package/lib/render/loss.d.ts +28 -10
  217. package/lib/render/loss.js +50 -22
  218. package/lib/render/recovery.d.ts +20 -0
  219. package/lib/render/recovery.js +44 -4
  220. package/lib/render/renderer.d.ts +85 -9
  221. package/lib/render/renderer.js +181 -42
  222. package/lib/render/scene-renderer.d.ts +19 -1
  223. package/lib/render/scene-renderer.js +25 -1
  224. package/lib/render/webgl2-renderers.js +8 -5
  225. package/lib/render/webgpu-renderers.js +5 -4
  226. package/lib/scene/animation.d.ts +28 -32
  227. package/lib/scene/animation.js +12 -15
  228. package/lib/scene/assets.d.ts +61 -86
  229. package/lib/scene/assets.js +103 -236
  230. package/lib/scene/background.d.ts +14 -18
  231. package/lib/scene/background.js +5 -2
  232. package/lib/scene/color.d.ts +3 -3
  233. package/lib/scene/downloads.d.ts +2 -0
  234. package/lib/scene/downloads.js +371 -0
  235. package/lib/scene/environment.d.ts +7 -7
  236. package/lib/scene/environment.js +1 -1
  237. package/lib/scene/fake-call-values.js +1 -1
  238. package/lib/scene/fog.d.ts +11 -4
  239. package/lib/scene/fog.js +8 -2
  240. package/lib/scene/frame-cameras.d.ts +19 -0
  241. package/lib/scene/frame-cameras.js +58 -0
  242. package/lib/scene/gltf.d.ts +32 -2
  243. package/lib/scene/gltf.js +78 -49
  244. package/lib/scene/grading.d.ts +2 -2
  245. package/lib/scene/grading.js +3 -3
  246. package/lib/scene/ktx2.d.ts +9 -1
  247. package/lib/scene/ktx2.js +3 -2
  248. package/lib/scene/level-rule.d.ts +120 -0
  249. package/lib/scene/level-rule.js +130 -0
  250. package/lib/scene/lines.d.ts +13 -17
  251. package/lib/scene/lines.js +3 -3
  252. package/lib/scene/lut.d.ts +1 -2
  253. package/lib/scene/lut.js +1 -2
  254. package/lib/scene/picks.d.ts +2 -2
  255. package/lib/scene/pointer-events.d.ts +4 -7
  256. package/lib/scene/post.d.ts +38 -43
  257. package/lib/scene/post.js +4 -1
  258. package/lib/scene/prefab.d.ts +7 -8
  259. package/lib/scene/prefab.js +7 -8
  260. package/lib/scene/property-animation.d.ts +1 -1
  261. package/lib/scene/property-animation.js +1 -1
  262. package/lib/scene/queries.d.ts +7 -13
  263. package/lib/scene/resources.d.ts +225 -254
  264. package/lib/scene/resources.js +179 -81
  265. package/lib/scene/scene.d.ts +149 -118
  266. package/lib/scene/scene.js +196 -98
  267. package/lib/scene/serial-loads.d.ts +29 -0
  268. package/lib/scene/serial-loads.js +68 -0
  269. package/lib/scene/shader-preloads.d.ts +34 -0
  270. package/lib/scene/shader-preloads.js +38 -0
  271. package/lib/scene/sprites.d.ts +14 -17
  272. package/lib/scene/sprites.js +5 -6
  273. package/lib/scene/textures.d.ts +11 -12
  274. package/lib/scene/textures.js +9 -10
  275. package/lib/scene/time-of-day.d.ts +3 -4
  276. package/lib/scene/time-of-day.js +2 -3
  277. package/lib/scene/vertex-draws.d.ts +5 -4
  278. package/lib/scene/vertex-draws.js +7 -5
  279. package/lib/shader-artifact.json +1 -0
  280. package/lib/shared/core.d.ts +5 -0
  281. package/lib/shared/core.js +1 -0
  282. package/lib/shared/import-once.d.ts +6 -0
  283. package/lib/shared/import-once.js +19 -0
  284. package/lib/shared/metrics.d.ts +38 -0
  285. package/lib/shared/metrics.js +62 -1
  286. package/lib/shared/run-task.js +7 -1
  287. package/lib/shared/task-pending.d.ts +12 -0
  288. package/lib/shared/task-pending.js +61 -1
  289. package/lib/shared/tasks.js +79 -32
  290. package/lib/shared/version.d.ts +17 -1
  291. package/lib/shared/version.js +19 -1
  292. package/lib/shared/wasm.d.ts +12 -4
  293. package/lib/shared/wasm.js +50 -27
  294. package/lib/shared/worker-start.d.ts +7 -0
  295. package/lib/shared/worker-start.js +27 -0
  296. package/lib/sketch/define-sketch.d.ts +35 -0
  297. package/lib/sketch/input.d.ts +2 -2
  298. package/lib/sketch/preset-check.d.ts +20 -6
  299. package/lib/sketch/preset-check.js +42 -17
  300. package/lib/sketch/quality.d.ts +69 -11
  301. package/lib/sketch/quality.js +54 -13
  302. package/lib/sketch/runner.d.ts +76 -9
  303. package/lib/sketch/runner.js +385 -52
  304. package/lib/sketch/ui.d.ts +5 -8
  305. package/lib/workers/probe-worker.d.ts +5 -0
  306. package/lib/workers/probe-worker.js +13 -4
  307. package/lib/workers/protocol.d.ts +61 -13
  308. package/lib/workers/protocol.js +4 -0
  309. package/lib/workers/render-worker.js +25 -4
  310. package/lib/workers/sketch-worker.js +104 -15
  311. package/package.json +2 -2
@@ -14,12 +14,12 @@ summary: "Every export of the Draws from a vertex count API, from the engine's d
14
14
 
15
15
  Class `VertexDraw`.
16
16
 
17
- A draw that has a material and a vertex count but no mesh data. Its shader makes every vertex of every copy from the indices, so the draw uploads nothing per frame. Change its counts, its sphere and its material's uniforms with the calls here, and free it with `destroy`.
17
+ A draw that has a material and a vertex count but no mesh data. Its shader makes every vertex of every copy from the indices, so the draw uploads nothing per frame. The engine writes no uniforms for its WGSL, so `frame.time` moves its shapes. Change its counts and its sphere with the calls here, and free it with `destroy`.
18
18
 
19
19
  | Member | Description |
20
20
  | --- | --- |
21
21
  | `readonly object: Mesh` | The scene object that gives the draw its place, its layers and its culling sphere. |
22
- | `readonly material: Material<ShaderValues<Wgsl>>` | The draw's custom material, whose uniforms the WGSL reads. |
22
+ | `readonly material: Material<ShaderValues<Wgsl>>` | The draw's custom material. |
23
23
  | `readonly vertices: number` | The vertices of one shape. |
24
24
  | `readonly instances: number` | The copies of the shape. |
25
25
  | `setCounts(vertices: number, instances: number): this` | Sets the vertices of one shape and the copies of the shape, from the next frame on. Each is a whole number from 1 to the most that the draw holds. |
@@ -41,7 +41,7 @@ The sphere that culls a draw. The engine draws the whole draw or none of it, so
41
41
 
42
42
  Interface `VertexDrawOptions`, which extends `Omit`.
43
43
 
44
- Options of `scene.createVertexDraw`: the shader, its two counts, its bounds, and every option of `materials.shader`, such as the uniforms, the blending and `doubleSided`. A draw blends, so its material draws in the transparent pass, where its sphere culls it and one shape covers the ones behind it.
44
+ Options of `scene.createVertexDraw`: the shader, its two counts, its bounds, and every option of `materials.shader`, such as the blending and `doubleSided`. A draw blends, so its material draws in the transparent pass, where its sphere culls it and one shape covers the ones behind it.
45
45
 
46
46
  | Member | Description |
47
47
  | --- | --- |
@@ -42,6 +42,14 @@ function createWater(ctx: SketchContext, options: WaterOptions): Water
42
42
 
43
43
  Makes the water that a scene draws, and the reflection pass that mirrors the scene in it. The bodies come from one description: a river that follows a line, or a lake that fills an outline. The surface reads the copy of the opaque scene's depth, or the bed that the shapes describe, so its shores fade against the bed, and the reflection redraws as often as the quality preset affords.
44
44
 
45
+ ## `createWaterfall`
46
+
47
+ ```ts
48
+ function createWaterfall(ctx: SketchContext, options: WaterfallOptions): Promise<Waterfall>
49
+ ```
50
+
51
+ Makes a waterfall that falls from a river's lip: a sheet of water that curves over the lip and drops almost straight, glassy at the lip and white lower down, with spray at the lip, a cloud of mist that it bursts into lower down and a plume of mist at its foot. Give it the lip, the way the water runs, the river's half width, its surface height and its current there, and the drop. End the river's own surface at the lip: the sheet starts a short way upstream, on the river's surface, and fades in over it.
52
+
45
53
  ## `FlowAt`
46
54
 
47
55
  ```ts
@@ -82,7 +90,7 @@ Options of `foamMap`.
82
90
  | `readonly size: readonly [x: number, z: number]` | The world area that the map covers, as [x, z] in meters. |
83
91
  | `readonly width?: number` | The map's texels along x. It is 1024 by default. |
84
92
  | `readonly height?: number` | The map's texels along z. It is 224 by default. |
85
- | `readonly reach?: number` | How far the foam reaches around an obstacle, in meters. It is 0.35 by default. |
93
+ | `readonly reach?: number` | How far the foam reaches around an obstacle, in meters. It is 0.35 by default, and every obstacle that gives no reach of its own takes it. |
86
94
  | `readonly trail?: number` | How far downstream, toward +x, the foam trails behind an obstacle, in meters. It is 1.6 by default, and 0 leaves a ring. |
87
95
 
88
96
  ## `FoamObstacle`
@@ -96,6 +104,7 @@ Something that breaks the water's surface: its middle and its radius at the surf
96
104
  | `readonly x: number` | The x of the obstacle's middle, in meters. |
97
105
  | `readonly z: number` | The z of the obstacle's middle, in meters. |
98
106
  | `readonly r: number` | The obstacle's radius at the water's surface, in meters. |
107
+ | `readonly reach?: number` | How far this obstacle's foam reaches from its edge, in meters, in place of the map's `reach`. It suits a scene whose parts of one water carry different foam, such as a creek whose arms break the surface by different amounts. |
99
108
 
100
109
  ## `LakeDepth`
101
110
 
@@ -144,7 +153,7 @@ The sea that `createOcean` made.
144
153
  | `readonly level: number` | The height of the sea's surface, in meters. |
145
154
  | `readonly bands: readonly OceanBand[]` | The bands of the sea, in the order that they sum. |
146
155
  | `readonly reflectionEvery: number` | The frames between two draws of the reflection now. |
147
- | `update(): void` | Moves the sea's mesh about the camera. The reflection pass carries its own cadence. Call once in each frame, after the camera moves and before the engine draws. |
156
+ | `update(): void` | Moves the sea's mesh about the camera, and draws the reflection in every frame while that camera moves or turns. Call once in each frame, after the camera moves and before the engine draws. |
148
157
  | `heightAt(x: number, z: number): number` | The height of the sea at a world place, in meters, as the bands sum at the sketch time. It runs the bands' transforms on this thread, and transforms again only when the sketch time moves, so several reads in a frame share one transform. |
149
158
  | `destroy(): void` | Removes the surface, the transform's passes, the reflection and the material. |
150
159
 
@@ -194,8 +203,9 @@ Options of `createOcean`.
194
203
  | `readonly foam?: number` | The height at which foam breaks on a crest, in meters. It is 1.1 by default. |
195
204
  | `readonly softness?: number` | The meters of the gap to the bed over which the water fades at a shore. It is 0.12 by default. |
196
205
  | `readonly reflectionEvery?: Partial<Record<QualityPreset, number>>` | The frames between two draws of the reflection at each preset, which replaces the add-on's own cadence for the presets that it names. |
206
+ | `readonly reflectionFollowsBudget?: boolean` | False keeps the frame-budget governor from raising the frames between two draws of the reflection. Between draws the sea shows the reflection of an older camera, so on a moving camera a raised count reads as a reflection that lags behind what it mirrors. The default, true, lets the governor trade that for time. |
197
207
  | `readonly layers?: number` | The layers that the reflection pass draws, as a 32-bit mask. It is the camera's by default. |
198
- | `readonly reflectionScale?: 1 \| 0.5 \| 0.25` | The reflection's size as a share of the render size each way: 1, 0.5 or 0.25. It is the render size by default. |
208
+ | `readonly reflectionScale?: 1 \| 0.5 \| 0.25` | The reflection's size as a share of the render size each way: 1, 0.5 or 0.25. By default it follows the quality preset's `reflectionScale`. |
199
209
  | `readonly material?: OceanMaterialOptions` | The standard material values, such as the water's tint and its thickness. |
200
210
 
201
211
  ## `RiverDepth`
@@ -263,6 +273,7 @@ Water that `createWater` made.
263
273
  | `surfaceHeight(x: number, z: number, t: number): number` | The height of the water's surface at a point and a sketch time, in meters, as its long waves move it. It uses the current of the body that the point lies over. Where two bodies meet, it follows the surface there, which lies flat and mixes the river's waves into the lake's. |
264
274
  | `currentAt(x: number, z: number, out: [x: number, z: number]): void` | The current of the body that a point lies over, as a velocity in meters a second, written into `out`. It is zero for still water and outside every body. Where a river runs into a lake, the lake owns the water inside its shore. |
265
275
  | `setCaustics(light: readonly [x: number, y: number, z: number]): void` | Sets the light that the ripples focus on the bed, as a linear color. |
276
+ | `setRain(amount: number): void` | Sets how hard rain falls on the surface, from 0 for none to 1 for a downpour. |
266
277
  | `destroy(): void` | Removes the surface, its reflection pass and its material. |
267
278
 
268
279
  ## `waterBody`
@@ -290,13 +301,70 @@ A water body that a shape resolved to: its bounds, the depth of its bed at a poi
290
301
  | `contains(x: number, z: number): boolean` | True when the point lies over the water, where its depth is above 0. |
291
302
  | `currentAt(x: number, z: number, out: [x: number, z: number]): void` | The current at a point, as a velocity in meters a second, written into `out`. It is zero for still water. A river carries its current along its middle line, or along the `current` function that it gives. |
292
303
 
304
+ ## `Waterfall`
305
+
306
+ Interface `Waterfall`.
307
+
308
+ A waterfall that `createWaterfall` made.
309
+
310
+ | Member | Description |
311
+ | --- | --- |
312
+ | `readonly fallTime: number` | The seconds that the water takes to fall from the lip to the foot. |
313
+ | `update(): void` | Steps the spray and the mist by the frame's time. Call it once in each frame, in `onLateUpdate`, after the wind's field steps, as a particle system's `update` is called. |
314
+ | `setLight(color: readonly [red: number, green: number, blue: number]): void` | Sets the air's light on the spray and the mist, as a linear color. Particles are not lit, so a scene gives them its light in each mood. The sheet takes the scene's own light, and its white water gives back a share of this one too, as the mist round it does. |
315
+ | `setSpray(amount: number): void` | Sets the spray and the mist, as a factor of the fall's own, from 0 to 3. A storm raises it. |
316
+ | `destroy(): void` | Removes the sheet, its material and its particles. |
317
+
318
+ ## `WaterfallMaterialOptions`
319
+
320
+ ```ts
321
+ type WaterfallMaterialOptions = { wireframe?: boolean | undefined; transmission?: number | undefined; castsStill?: boolean | undefined; swayDistance?: number | undefined; flatShading?: boolean | undefined; lightMapOffset?: readonly [number, number] | undefined; lightMapRepeat?: readonly [number, number] | undefined; lightMapDecode?: 'srgb' | 'rgbm' | undefined; lightMapDirection?: Texture | undefined; contactShadows?: boolean | undefined; metalness?: number | undefined; roughness?: number | undefined; emissive?: ColorInput | undefined; emissiveIntensity?: number | undefined; normalScale?: readonly [number, number] | undefined; bumpScale?: number | undefined; displacementScale?: number | undefined; displacementBias?: number | undefined; aoMapIntensity?: number | undefined; lightMapIntensity?: number | undefined; ior?: number | undefined; specularIntensity?: number | undefined; specularColor?: ColorInput | undefined; envIntensity?: number | undefined; uvTransform?: UvTransform | undefined; mapUvTransforms?: Partial<Record<'lightMap' | 'transmissionMap' | 'thicknessMap' | 'map' | 'metalnessRoughnessMap' | 'normalMap' | 'bumpMap' | 'displacementMap' | 'aoMap' | 'emissiveMap' | 'specularIntensityMap' | 'specularColorMap' | 'diffuseTransmissionMap' | 'diffuseTransmissionColorMap' | 'clearcoatMap' | 'clearcoatRoughnessMap' | 'clearcoatNormalMap' | 'sheenColorMap' | 'sheenRoughnessMap' | 'iridescenceMap' | 'iridescenceThicknessMap' | 'anisotropyMap', UvTransform>> | undefined; thickness?: number | undefined; attenuationColor?: ColorInput | undefined; attenuationDistance?: number | undefined; dispersion?: number | undefined; diffuseTransmission?: number | undefined; diffuseTransmissionColor?: ColorInput | undefined; subsurfaceRadius?: number | undefined; subsurfaceColor?: ColorInput | undefined; clearcoat?: number | undefined; clearcoatRoughness?: number | undefined; clearcoatNormalScale?: readonly [number, number] | undefined; sheenColor?: ColorInput | undefined; sheenRoughness?: number | undefined; iridescence?: number | undefined; iridescenceIor?: number | undefined; iridescenceThicknessRange?: readonly [number, number] | undefined; anisotropy?: number | undefined; anisotropyRotation?: number | undefined; color?: ColorInput | undefined; opacity?: number | undefined; alphaCutoff?: number | undefined; doubleSided?: boolean | undefined; vertexColors?: boolean | undefined; fog?: boolean | undefined; toneMapped?: boolean | undefined; alphaMode?: AlphaMode | undefined; alphaToCoverage?: boolean | undefined; forceSinglePass?: boolean | undefined; blending?: Blending | undefined; depthWrite?: boolean | undefined; depthTest?: boolean | undefined; colorWrite?: boolean | undefined; depthBias?: DepthBias | undefined; };
322
+ ```
323
+
324
+ The standard material values that a waterfall's sheet takes, such as the color of its white water.
325
+
326
+ ## `WaterfallMesh`
327
+
328
+ Interface `WaterfallMesh`.
329
+
330
+ How fine a waterfall's mesh is.
331
+
332
+ | Member | Description |
333
+ | --- | --- |
334
+ | `across?: number` | The sections round the column. It is 24 by default. |
335
+ | `down?: number` | The rows from the lip to the foot of the fall. It is 40 by default. |
336
+
337
+ ## `WaterfallOptions`
338
+
339
+ Interface `WaterfallOptions`.
340
+
341
+ Options of `createWaterfall`.
342
+
343
+ | Member | Description |
344
+ | --- | --- |
345
+ | `readonly lip: WaterPoint` | The middle of the lip, where the river's surface ends and the water falls, as [x, z] in meters. |
346
+ | `readonly direction: WaterPoint` | The way the water runs over the lip, as [x, z]. Its length does not matter. |
347
+ | `readonly halfWidth: number` | Half the river's width at the lip, in meters. |
348
+ | `readonly level?: number` | The height of the water's surface at the lip, in meters. It is 0 by default. |
349
+ | `readonly speed?: number` | The current's speed at the lip, in meters a second. It sets how far the water leaps out from the lip's line: at 1.2 m/s the back of the column is 0.6 m out 2 m down and 1.3 m out 13 m down. A wall below the lip that leans out further than that meets the water, and the column fades where it nears the rock. A river runs faster as it nears a brink, so give the speed at the lip itself. It is 1.2 by default. |
350
+ | `readonly drop: number` | How far the fall drops below the lip, in meters. The sheet thins into mist over the lower half of the drop, and never lands. |
351
+ | `readonly spread?: number` | How far each side of the sheet widens for each meter that the water falls, once it has fallen a few meters: it spreads little at first, and opens into a veil lower down. It is 0.3 by default. |
352
+ | `readonly apron?: number` | How far upstream of the lip the fall's water starts, lying on the river's surface, in meters. There it fades in at uneven distances and takes the place of the river's own surface, so the river's square end at the lip is covered and the water runs into the fall with no straight edge. Give the reach of the broken water before the brink. It is 1 by default. |
353
+ | `readonly fadeBelow?: number` | The world height of a cloud sea, a fog bank or a mist that the fall drops into, in meters. A cloud that draws before the fall does not hide it, so below this height the fall vanishes itself over `SINK_DEPTH`, 2.5 m, each clump at its own depth. The water then breaks up and bursts into mist over the part of the drop above the cloud. By default it never vanishes. |
354
+ | `readonly spray?: number` | The spray and the mist, as a factor of the fall's own, from 0 to 3. It is 1 by default. At 0 the fall makes no particles, neither the particles add-on nor the engine's particle code loads, and `setSpray` has nothing to raise. |
355
+ | `readonly mist?: number` | The mist round the fall's foot and the plume that rises from it, as a factor of the fall's own, from 0 to 3, which `spray` scales too. It is 1 by default. At 0 the fall makes neither, for a scene whose own cloud draws the mist at the fall's foot: puffs lit apart from that cloud would draw a gray patch over it. |
356
+ | `readonly layers?: number` | The layers that the sheet and its spray draw on, as a 32-bit mask. It is layer 0 by default. Leave out the layers that a water's reflection draws when the fall lies past the water's edge. |
357
+ | `readonly wind?: ParticleWindField` | A field of air that carries the mist, such as the wind add-on's field. |
358
+ | `readonly material?: WaterfallMaterialOptions` | The sheet's standard material values, such as the color of its white water. |
359
+ | `readonly mesh?: WaterfallMesh` | How fine the sheet's mesh is. |
360
+
293
361
  ## `WaterMaterialOptions`
294
362
 
295
363
  ```ts
296
364
  type WaterMaterialOptions = { wireframe?: boolean | undefined; transmission?: number | undefined; castsStill?: boolean | undefined; swayDistance?: number | undefined; flatShading?: boolean | undefined; lightMapOffset?: readonly [number, number] | undefined; lightMapRepeat?: readonly [number, number] | undefined; lightMapDecode?: 'srgb' | 'rgbm' | undefined; lightMapDirection?: Texture | undefined; contactShadows?: boolean | undefined; metalness?: number | undefined; roughness?: number | undefined; emissive?: ColorInput | undefined; emissiveIntensity?: number | undefined; normalScale?: readonly [number, number] | undefined; bumpScale?: number | undefined; displacementScale?: number | undefined; displacementBias?: number | undefined; aoMapIntensity?: number | undefined; lightMapIntensity?: number | undefined; ior?: number | undefined; specularIntensity?: number | undefined; specularColor?: ColorInput | undefined; envIntensity?: number | undefined; uvTransform?: UvTransform | undefined; mapUvTransforms?: Partial<Record<'lightMap' | 'transmissionMap' | 'thicknessMap' | 'map' | 'metalnessRoughnessMap' | 'normalMap' | 'bumpMap' | 'displacementMap' | 'aoMap' | 'emissiveMap' | 'specularIntensityMap' | 'specularColorMap' | 'diffuseTransmissionMap' | 'diffuseTransmissionColorMap' | 'clearcoatMap' | 'clearcoatRoughnessMap' | 'clearcoatNormalMap' | 'sheenColorMap' | 'sheenRoughnessMap' | 'iridescenceMap' | 'iridescenceThicknessMap' | 'anisotropyMap', UvTransform>> | undefined; thickness?: number | undefined; attenuationColor?: ColorInput | undefined; attenuationDistance?: number | undefined; dispersion?: number | undefined; diffuseTransmission?: number | undefined; diffuseTransmissionColor?: ColorInput | undefined; subsurfaceRadius?: number | undefined; subsurfaceColor?: ColorInput | undefined; clearcoat?: number | undefined; clearcoatRoughness?: number | undefined; clearcoatNormalScale?: readonly [number, number] | undefined; sheenColor?: ColorInput | undefined; sheenRoughness?: number | undefined; iridescence?: number | undefined; iridescenceIor?: number | undefined; iridescenceThicknessRange?: readonly [number, number] | undefined; anisotropy?: number | undefined; anisotropyRotation?: number | undefined; color?: ColorInput | undefined; opacity?: number | undefined; alphaCutoff?: number | undefined; doubleSided?: boolean | undefined; vertexColors?: boolean | undefined; fog?: boolean | undefined; toneMapped?: boolean | undefined; alphaMode?: AlphaMode | undefined; alphaToCoverage?: boolean | undefined; forceSinglePass?: boolean | undefined; blending?: Blending | undefined; depthWrite?: boolean | undefined; depthTest?: boolean | undefined; colorWrite?: boolean | undefined; depthBias?: DepthBias | undefined; };
297
365
  ```
298
366
 
299
- The standard material values that the water's surface takes.
367
+ The standard material values that the water's surface takes. The surface works two of them out for each pixel, so a value that a call gives for them does not apply: the volume's thickness, which is the depth of the bed under the surface there, and the transmission, which falls away where the foam covers the water. Give `attenuationColor` and `attenuationDistance` to tint the water: the bed's light keeps the share that the attenuation leaves over the bed's depth, so a shallow, clear creek needs a pale colour over a distance far above its own depth, and a short distance with a dark colour turns it into an opaque slab that hides the bed.
300
368
 
301
369
  ## `WaterOptions`
302
370
 
@@ -312,15 +380,18 @@ Options of `createWater`.
312
380
  | `readonly ripple?: number` | The water's ripples, as a factor of their base height, from 0. It is 1 by default. |
313
381
  | `readonly waveAmplitude?: number` | The height of the long waves and of the wind's lift, as a factor of their base height, from 0. It is 1 by default. The fine ripples keep the strength that `ripple` gives them, so a small value gives a nearly flat surface that still ripples. |
314
382
  | `readonly softness?: number` | The meters of the gap to the bed over which the water fades at a shore. It is 0.12 by default. |
383
+ | `readonly windRipple?: number` | The slope that the wind raises in short crests of its own, from 0, at a feature of a few tenths of a meter. It is 0 by default: the water's waves then run with their clocks alone. A surface that asks for it moves with the field's air as the scene's trees do, which suits a body small enough that a long swell would read as one flat tilt. |
315
384
  | `readonly colorAlongView?: number` | The share of the water's color at a low view, from 0 to 1, that reads the whole way the view runs through the water, as a wide sea's does: a low view then shows no sharp outline of the bed in the distance. A view from above keeps the depth. At 0, the default, it reads the depth at every view. |
316
385
  | `readonly reflectionEvery?: Partial<Record<QualityPreset, number>>` | The frames between two draws of the reflection at each preset, which replaces the add-on's own cadence for the presets that it names. The frame-budget governor may still double it while frames take too long. It is 2 on Low and Medium and 1 on High and Ultra. |
317
386
  | `readonly reflectionFollowsBudget?: boolean` | False keeps the frame-budget governor from raising the frames between two draws of the reflection. Between draws the water shows the reflection of an older camera, so on a moving camera a raised count reads as a reflection that lags behind what it mirrors. The default, true, lets the governor trade that for time. |
318
387
  | `readonly layers?: number` | The layers that the reflection pass draws, as a 32-bit mask. It is the camera's layers by default. Give the layer of the objects that the water mirrors to leave out the things that lie on or under its surface. |
319
- | `readonly reflectionScale?: 1 \| 0.5 \| 0.25` | The reflection's size as a share of the render size each way: 1, 0.5 or 0.25. It is the render size by default. A smaller share softens the reflection and costs less. |
388
+ | `readonly reflectionScale?: 1 \| 0.5 \| 0.25` | The reflection's size as a share of the render size each way: 1, 0.5 or 0.25. By default it follows the quality preset's `reflectionScale`. A smaller share softens the reflection and costs less. |
320
389
  | `readonly mesh?: MeshDetail` | How fine the surface's mesh is, for the bodies that give no detail of their own. |
321
390
  | `readonly bed?: 'scene' \| 'shape'` | Where the surface reads the depth of the bed: `'scene'`, the copy of the opaque scene's depth behind each pixel, or `'shape'`, the depth that each shape describes, carried in the mesh's vertex colors. It is `'scene'` by default. `'shape'` suits a bed that the scene states rather than draws, or one whose drawn shape differs from the depth that the water should read. |
322
391
  | `readonly material?: WaterMaterialOptions` | The standard material values, such as the volume's tint and its thickness. |
392
+ | `readonly camera?: Camera` | The camera that the reflection follows. While it moves or turns, the reflection draws in every frame, so a moving view never shows a mirror of an older one; a still camera keeps the cadence that the preset and the frame-budget governor give. Without one the reflection keeps that cadence whether the view moves or not. |
323
393
  | `readonly wind?: WaterWind` | The wind field that lifts the surface's short waves and carries their crests. A page gives the wind add-on's field here, and the surface reads it once for each vertex. |
394
+ | `readonly rain?: number` | How hard rain falls on the surface, from 0 for none to 1 for a downpour. Each drop rings the surface where it lands, and the rings drift with the current. It is 0 by default, and dry water pays nothing for the rings. |
324
395
 
325
396
  ## `WaterPoint`
326
397
 
@@ -356,4 +427,4 @@ The wind that a water surface reads: a plain field texture and its box, so that
356
427
  function waveHeight(x: number, z: number, t: number, level: number, current: readonly [x: number, z: number], ripple: number, waveAmplitude = 1): number
357
428
  ```
358
429
 
359
- The height of a water surface at a point and a sketch time, in meters, as its long waves move it. A `current` carries the whole set downstream, with each wave's direction turned into the current's frame; still water keeps the authored directions and each wave's own speed. `ripple` scales them, and `waveAmplitude` scales the surface's height above the level.
430
+ The height of a water surface at a point and a sketch time, in meters, as its long waves move it. A `current` carries the whole set downstream, with each wave's direction turned into the current's frame, in two copies that take turns as the surface's shader draws them; still water keeps the authored directions and each wave's own speed. `ripple` scales them, and `waveAmplitude` scales the surface's height above the level.
@@ -74,10 +74,10 @@ The field that a reader samples: a texture of the air, and the box it covers.
74
74
 
75
75
  | Member | Description |
76
76
  | --- | --- |
77
- | `readonly texture: Texture` | The texture. A reader declares it as `var wind: texture_2d<f32>;` and samples it through the sampling function, which gives the air back: the wind across the ground, the wind's rise, which is zero while the field is flat, and how fast the air moves. The grid keeps its state in the texture's own numbers, so a reader does not decode them itself. A preset change that changes the grid makes a new texture, so read this again after one. |
77
+ | `readonly texture: Texture` | The texture. A reader declares it as `var wind: texture_2d_array<f32>;` and samples it through the sampling function, which gives the air back: the wind across the ground, the wind's rise, which is zero while the field is flat, and how fast the air moves. The grid keeps its state in the texture's own numbers, so a reader does not decode them itself. A preset change that changes the grid makes a new texture, so read this again after one. |
78
78
  | `readonly origin: [number, number]` | The box's near corner across the ground, in meters: x and z. |
79
79
  | `readonly size: number` | The box's width across the ground, in meters, or zero on a device that keeps no grid. A reader that is given zero works out the air from `air` everywhere. That is the steady field which the grid's edge and the far field hold where a device keeps one. |
80
- | `readonly air: WindReading` | The steady settings that a reader works out beyond the box. Give them to a material with the sampling function's three vectors, and give them again when `setBase` or the air changes. |
80
+ | `readonly air: WindReading` | The steady settings that a reader works out beyond the box. Give them to a material in the first three of the sampling function's four vectors, and give them again when `setBase` or the air changes. The fourth holds the gust that the page sent last. |
81
81
 
82
82
  ## `WindOptions`
83
83
 
@@ -56,7 +56,7 @@ export default defineSketch(({ scene, materials, geometry, textures, render }) =
56
56
  - A pass runs only while something shows its texture: a texture from `textures.fromPass`, or another running pass that names it in `reads`. A pass that nothing shows costs nothing, not even its texture's memory.
57
57
  - The texture holds linear color, after the exposure and before the tone curve. On most devices it holds high dynamic range color. A material that shows it, such as an unlit material, gives the camera the same light that the pass saw. The final pass then maps it as it maps the rest of the scene.
58
58
  - Devices that draw 8-bit color tone map in each material's shader: compatibility mode with MSAA, and WebGL2 devices without float targets ([Color management](../concepts/color-management.md)). In compatibility mode the engine turns the pass's colors back to linear as it fills the texture. But they stay tone mapped, so the material that shows the texture applies the tone curve a second time. With the default curve the image then looks a little lighter in the middle tones. On WebGL2 devices without float targets the texture holds display color, so the image looks brighter and flatter.
59
- - The image stands upright on a plane, with v = 0 at its bottom row, as three.js's render targets do. A reflection pass's texture on the HDR WebGPU path is the exception: its rows start at the top, so read it with `reflection_uv`.
59
+ - The image stands upright on a plane, with v = 0 at its bottom row. A reflection pass's texture on the HDR WebGPU path is the exception: its rows start at the top, so read it with `reflection_uv`.
60
60
  - Each pass texture has the scene's anti-aliasing: with MSAA the pass draws with the same samples, then resolves.
61
61
  - A pass never draws an object whose material shows the texture of a pass that it does not read, or its own texture. So a mirror does not show itself, and a minimap's screen does not appear in the minimap. To show a mirror in a mirror, add a second pass for it.
62
62
  - A pass with a `scale` fills its whole texture at any render scale, so a material samples it from 0 to 1 across. Its texture follows the render size: when the engine lowers the render scale to keep up, the texture shrinks with it, and the pass costs less too.
@@ -64,9 +64,9 @@ export default defineSketch(({ scene, materials, geometry, textures, render }) =
64
64
 
65
65
  ### What a scene pass draws
66
66
 
67
- A scene pass draws the scene's objects with their materials, the sun and its shadows where the camera's shadow cascades reach. It draws the ambient and hemisphere lights, the environment's light and the fog. It also draws the point, spot and area lights that its camera sees. Such a light casts its shadow in the pass when the camera's view gives it one. A light that only the pass sees casts no shadow there. It draws the scene's background behind the objects, the sky included, as a three.js render target shows `scene.background`. With a `clearColor`, the texture clears to that color and shows no background, which suits a minimap. It culls each frame in one pass, without occlusion culling.
67
+ A scene pass draws the scene's objects with their materials, the sun and its shadows where the camera's shadow cascades reach. It draws the ambient and hemisphere lights, the environment's light and the fog. It also draws the point, spot and area lights that its camera sees. Such a light casts its shadow in the pass when the camera's view gives it one. A light that only the pass sees casts no shadow there. It draws the scene's background behind the objects, the sky included. With a `clearColor`, the texture clears to that color and shows no background, which suits a minimap. It culls each frame in one pass, without occlusion culling.
68
68
 
69
- A pass draws no ambient occlusion. three.js draws ambient occlusion as a post pass over the canvas, so its render targets have none either.
69
+ A pass draws no ambient occlusion.
70
70
 
71
71
  ## Reflection passes
72
72
 
@@ -395,12 +395,14 @@ A pass that does not run keeps the state that its last run wrote, as it keeps it
395
395
  A pass with history costs more than one state. On the WebGPU paths the target holds both states as
396
396
  `layers * 2` layers, and the pass keeps two state textures of `layers` layers each: four times the
397
397
  texels of one state. On WebGL2 the fragment form keeps both states in the target's layers and adds
398
- one scratch texture of one state: three times. At `rgba16float` that is 32 bytes for each texel of
399
- one state on the WebGPU paths and 24 on WebGL2; at `r32float`, 16 and 12. Size a history pass for
400
- its grid, not the canvas: 128 by 128 takes 512 KiB on the WebGPU paths and 384 KiB on WebGL2, and
401
- 256 by 256 takes 2 MiB and 1.5 MiB. The 8192 by 8192 side that the device allows would take 2 GiB
402
- on the WebGPU paths, which no page should choose by accident. `render.dumpGraph()` does not list the
403
- state textures, so budget them beside its figures.
398
+ one scratch texture of one layer. Before each layer's run, the engine copies the state that the run
399
+ reads into the scratch. That is `layers * 2 + 1` layers in all. For a pass of one layer, that is
400
+ three times the texels of one state. At `rgba16float` such a pass takes 32 bytes for each texel of
401
+ one state on the WebGPU paths and 24 on WebGL2. At `r32float` it takes 16 and 12. Size a history
402
+ pass for its grid, not the canvas. One layer of 128 by 128 takes 512 KiB on the WebGPU paths and 384
403
+ KiB on WebGL2. One layer of 256 by 256 takes 2 MiB and 1.5 MiB. The 8192 by 8192 side that the
404
+ device allows would take 2 GiB on the WebGPU paths, which no page should choose by accident.
405
+ `render.dumpGraph()` does not list the state textures, so budget them beside its figures.
404
406
 
405
407
  ### Reading a region back
406
408
 
@@ -444,7 +446,7 @@ A pass of several layers draws each layer in a pass of its own. `input.layer` gi
444
446
 
445
447
  ### Switching and removing passes
446
448
 
447
- - `render.setPassEnabled(pass, false)` stops a pass from the next frame on. Its texture keeps the last image that it drew. A pass that has never drawn is out of the plan while it is off, so switching it on compiles the render graph. Once a pass has drawn, its passes stay in the plan while it is off, so the switch compiles nothing. Switch a pass when a feature starts or stops, and pace it with `render.setPassEvery`.
449
+ - `render.setPassEnabled(pass, false)` stops a pass from the next frame on. Its texture keeps the last image that it drew. It keeps it through a change of quality preset too, while the texture's shape and size stay the same. When the change moves between HDR and 8-bit color, a stopped full-screen pass draws once into its new texture, with its values as they stand. A compute pass's stored state survives a change of the edge smoothing, such as from MSAA to FXAA. A pass that has never drawn is out of the plan while it is off, so switching it on compiles the render graph. Once a pass has drawn, its passes stay in the plan while it is off, so the switch compiles nothing. Switch a pass when a feature starts or stops, and pace it with `render.setPassEvery`.
448
450
  - `render.setPassEvery(pass, every)` makes a pass draw in one frame of every `every`, from the next frame on, and its texture keeps the last image that it drew in between. It compiles nothing, so a sketch may change the cadence whenever the quality preset or the frame budget moves, as often as once a frame. A cadence of 1 draws every frame. In [hold mode](../guides/testing.md#hold-mode) every pass draws in every frame, so a held frame never shows a pass's older picture. The call allocates nothing.
449
451
  - `render.removePass(pass)` removes a pass and destroys the textures that `textures.fromPass` made of it.
450
452
  - `pass.live` is false after `removePass`, and `pass.enabled` gives the switch.
package/docs/api/scene.md CHANGED
@@ -8,7 +8,7 @@ summary: "Creating objects; models and copies; find; multiple views of one scene
8
8
 
9
9
  # Scene
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds the environment, the sky and environment backgrounds, the sky's environment, the light probe grid, `timeOfDay` and volumetric fog. The API is experimental, so it can still change between versions.
11
+ > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
12
 
13
13
  The scene holds everything the engine draws: the objects, the camera that the canvas shows, the lights and the background. A sketch gets it as `scene` in its setup function, and creates everything through it.
14
14
 
@@ -50,15 +50,23 @@ export default defineSketch(({ scene, geometry, materials }) => {
50
50
  | `clone(object)` | A copy of an object and of every object below it |
51
51
  | `createPerspectiveCamera(options)` | A `PerspectiveCamera` that the scene can draw from |
52
52
  | `createOrthographicCamera(options)` | An `OrthographicCamera`, whose view is a box, that the scene can draw from |
53
+ | `createView({ camera, rect })` | A `SceneView` that draws the scene again from another camera, into a rectangle of the canvas: [Multiple views](#multiple-views) |
53
54
  | `createDirectionalLight(options)` | A `DirectionalLight`: light from one direction, like sunlight |
54
55
  | `createPointLight(options)` | A `PointLight`: light from a point in every direction, out to its range |
55
56
  | `createSpotLight(options)` | A `SpotLight`: light from a point in a cone, out to its range |
57
+ | `createRectAreaLight(options)` | A `RectAreaLight`: light from a glowing rectangle, out to its range: [Lights](lights.md) |
58
+ | `createTubeLight(options)` | A `TubeLight`: light from a glowing tube, out to its range: [Lights](lights.md) |
56
59
  | `createHemisphereLight(options)` | A `HemisphereLight`: light from the sky above and the ground below |
57
60
  | `createAmbientLight(options)` | An `AmbientLight`: the same light on every surface |
61
+ | `createReflectionProbe(options)` | A `ReflectionProbe` that lights the surfaces inside its box with the scene around a point: [Reflection probes](#reflection-probes) |
58
62
  | `createSprites(options)` | A batch of camera-facing quads, after an `await`: [Sprites](sprites.md) |
59
63
  | `createPoints(options)` | A batch of points, after an `await`: [Points](points.md) |
60
64
  | `createLines(options)` | A batch of wide lines, after an `await`: [Lines](lines.md) |
65
+ | `createParticleBuffer(options)` | A `ParticleBuffer`, a table of particles that the GPU moves, after an `await`. The [particles add-on](particles.md)'s emitters fill it: [The particle buffer](../concepts/particle-buffer.md) |
61
66
  | `addFeatureDraw(description, options)` | A draw that an add-on's feature description declares, after an `await`: [Add-on feature draws](feature-draws.md) |
67
+ | `addFeatureInstances(description, options)` | A draw of many copies of one shape that an add-on's feature description declares, after an `await`: [Add-on feature draws](feature-draws.md#many-copies-of-one-shape) |
68
+ | `addComputeInstances(description, options)` | A draw of instances from the add-on's own GPU buffer, after an `await`: [Add-on instance draws](feature-instances.md) |
69
+ | `createVertexDraw(options)` | A draw of a custom material over a vertex count, with no mesh data: [Draws from a vertex count](vertex-draws.md) |
62
70
 
63
71
  Groups, meshes, cameras and lights take the same object options: `name`, `position`, `rotation`, `scale`, `parent`, `dynamic` and `layers`. [Objects and transforms](objects.md) describes them. `createMesh` also takes `castShadows` and `receiveShadows`, which [Shadows](../concepts/shadows.md) explains. It takes `occluder` too, which [Culling](../concepts/culling.md) explains. `createInstances` takes `colors: true` and `values: true` for a color and four values per row: [Instances and batching](../concepts/instances.md). Meshes come from `geometry` and materials from `materials` in the sketch context. One mesh and one material can serve any number of objects.
64
72
 
@@ -75,7 +83,7 @@ turret?.rotateY(0.5);
75
83
 
76
84
  `instance.find(name)` gives the copy's object of a node, by the node's name in the file. `scene.find` searches every object. When several copies share a name, it gives the first copy's object.
77
85
 
78
- `scene.clone(object)` copies an object and every object below it, with their meshes, materials, lights, cameras and settings, as three.js's `clone` does. The copy goes under the same parent, so it starts in the same place. It uses the same path as `instantiate`: one call and one batch of changes for the whole tree. Instance batches are not objects, so `clone` leaves them out.
86
+ `scene.clone(object)` copies an object and every object below it, with their meshes, materials, lights, cameras and settings. The copy goes under the same parent, so it starts in the same place. It uses the same path as `instantiate`: one call and one batch of changes for the whole tree. Instance batches are not objects, so `clone` leaves them out.
79
87
 
80
88
  `scene.createInstances(prefab, count, options)` draws many copies of a model with instance batches, one for each mesh of the model. The batches share one set of rows, so each row places a whole copy. Write the returned batch's `positions`, `rotations` and `scales` as for a batch of one mesh. Each mesh keeps its place in the model. The model's lights are left out. A model with no meshes, or with instancing of its own, throws E1417. Give `createInstances` one of its meshes and a material instead, from `prefab.find(name)`.
81
89
 
@@ -100,11 +108,13 @@ door?.setVisible(false);
100
108
 
101
109
  `find` returns the general `Object3D` type. When you know which kind of object has the name, cast the result to its class, such as `Mesh`, to use its own calls. Look objects up at setup and keep them, rather than calling `find` in every frame.
102
110
 
111
+ `scene.listObjects()` returns every object of the scene that is not destroyed, in the order of their slots, as a new array. It walks the whole scene and allocates, so call it from tools and setup code, never in every frame.
112
+
103
113
  ## The camera and the background
104
114
 
105
115
  The canvas shows the scene from the active camera, which `setActiveCamera` picks. It can be either kind of camera, and [Cameras](cameras.md) covers both lenses. Until you pick a camera, the canvas shows only the background. `setBackground` takes a color. The default background is black, or the page behind a transparent canvas. Exposure and tone mapping change the background as they change the objects: [Color management](../concepts/color-management.md#the-background).
106
116
 
107
- `setBackground` also takes a [texture](textures.md). The texture fills the camera's view behind every object, as a texture in three.js's `scene.background` does. It stretches to the shape of the view. A texture that loads with the default `flipY` stands upright. The engine samples it with the texture's own filter and ignores its alpha. The texture draws behind every object, in the pixels that no object covers.
117
+ `setBackground` also takes a [texture](textures.md). The texture fills the camera's view behind every object. It stretches to the shape of the view. A texture that loads with the default `flipY` stands upright. The engine samples it with the texture's own filter and ignores its alpha. The texture draws behind every object, in the pixels that no object covers.
108
118
 
109
119
  ```ts
110
120
  import { defineSketch } from '@null3d/engine';
@@ -120,11 +130,11 @@ The color set before a texture shows until the texture's texels are on the GPU,
120
130
 
121
131
  ### Environments, cube maps and the sky
122
132
 
123
- `setBackground` also takes four backgrounds that surround the scene, as three.js's `scene.background` does with a cube texture and its `Sky` object:
133
+ `setBackground` also takes four backgrounds that surround the scene:
124
134
 
125
- - An environment from [`assets.loadEnvironment` or `assets.builtinEnvironment`](assets.md#environments). It can blur, as three.js's `backgroundBlurriness` blurs a PMREM texture.
135
+ - An environment from [`assets.loadEnvironment` or `assets.builtinEnvironment`](assets.md#environments). It can blur.
126
136
  - A cube map of six images from [`assets.loadCubemap`](assets.md#cube-maps), a sky box.
127
- - three.js's analytic sky: `{ sky: { sunPosition } }`, with the settings of three.js's `Sky` object.
137
+ - The analytic sky: `{ sky: { sunPosition } }`, the Preetham daylight model with a sun disc and drifting clouds.
128
138
  - The physical sky: `{ atmosphere: { sunPosition } }`, the earth's air lit by the sun and the moon. The same air hazes distant objects ([The physical sky](#the-physical-sky)).
129
139
 
130
140
  ```ts
@@ -141,17 +151,17 @@ export default defineSketch(async ({ scene, assets }) => {
141
151
 
142
152
  | Option | Takes | Default | What it sets |
143
153
  | --- | --- | --- | --- |
144
- | `intensity` | Every background but a color | 1 | The factor of the background's light, 0 or more, as three.js's `scene.backgroundIntensity` |
145
- | `blur` | Environments | 0 | How much the background blurs, from 0 (sharp) to 1, as `scene.backgroundBlurriness` |
146
- | `rotation` | Environments and cube maps | `[0, 0, 0]` | The background's turn, as Euler angles in radians in the order X, Y, Z, as `scene.backgroundRotation` |
154
+ | `intensity` | Every background but a color | 1 | The factor of the background's light, 0 or more |
155
+ | `blur` | Environments | 0 | How much the background blurs, from 0 (sharp) to 1 |
156
+ | `rotation` | Environments and cube maps | `[0, 0, 0]` | The background's turn, as Euler angles in radians in the order X, Y, Z |
147
157
 
148
- An environment's map holds its light blurred for each roughness. So the background reads the level of the blur's roughness, as three.js reads its PMREM texture. A blurred background costs no more than a sharp one. The background and `setEnvironment` are separate: a scene can show one environment and take its light from another. A cube map shows its six images as three.js's `CubeTextureLoader` shows them, and does not light the scene.
158
+ An environment's map holds its light blurred for each roughness. So the background reads the level of the blur's roughness. A blurred background costs no more than a sharp one. The background and `setEnvironment` are separate: a scene can show one environment and take its light from another. A cube map shows its six images without blur, and it does not light the scene.
149
159
 
150
- The sky takes the names and the defaults of three.js's `Sky` uniforms:
160
+ The analytic sky takes these settings:
151
161
 
152
162
  | Setting | Default | What it sets |
153
163
  | --- | --- | --- |
154
- | `sunPosition` | `[0, 0.0349, -0.9994]` | A point toward the sun, as `sunPosition`. The default puts the sun 2 degrees over the horizon, as three.js's sky example does |
164
+ | `sunPosition` | `[0, 0.0349, -0.9994]` | A point toward the sun. Its direction places the sun. The default puts the sun 2 degrees over the horizon, toward -Z |
155
165
  | `turbidity` | 2 | The haze in the air |
156
166
  | `rayleigh` | 1 | The scattering by the air's molecules, which makes the sky blue |
157
167
  | `mieCoefficient` | 0.005 | The scattering by haze |
@@ -166,7 +176,7 @@ The sky takes the names and the defaults of three.js's `Sky` uniforms:
166
176
 
167
177
  The quality preset's [`cloudSteps`](../concepts/quality-preset-tables.md#settings-of-each-preset) chooses which layer draws: Low and Medium draw the flat layer, and High and Ultra draw volumetric clouds, ray marched through a noise volume. Both read the same settings above, so a setting keeps its meaning when the preset changes. WebGL2 and compatibility mode stop at Medium, so a page there draws the tier with `quality.set({ cloudSteps })` or the `cloudSteps` option of `createEngine`. The tier's noise and shaders load at its first use, and a page on the flat presets downloads neither. The sky's environment map takes the clouds too, with two limits. A map marches at most 16 steps. It draws them only when the page starts with `cloudSteps` above 0, because the map picks the tier's shaders at the page's start.
168
178
 
169
- Two more settings are null3D's own. They add a second sky, which `timeOfDay` uses to fade the moon's sky in as night falls:
179
+ Two more settings add a second sky, which `timeOfDay` uses to fade the moon's sky in as night falls:
170
180
 
171
181
  | Setting | Default | What it sets |
172
182
  | --- | --- | --- |
@@ -229,7 +239,7 @@ export default defineSketch(async ({ scene, assets }) => {
229
239
  | `moonIntensity` | 0 | The moon's light above the air. It lights the air as the sun does, and the sky shows its disc, lit from the sun's side. 0 draws no moon |
230
240
  | `stars` | 0 | The stars' brightness. They show only where the sky is dark enough. 0 draws no stars |
231
241
 
232
- The sky's light is in the units of a directional light's intensity, so the exposure that suits the scene's lights suits the sky. It does not move a light: set the main light's direction and color with it, or take them from [`timeOfDay`](#time-of-day). The quality setting [`physicalSky`](../concepts/quality-presets.md) is off on Low. There three.js's analytic sky stands in, with the same sun, moon, air and clouds, matched to the physical sky's brightness, and the haze on objects stays. The first physical sky downloads its shaders, `'physical_sky'`, and the view shows the background color until its tables are drawn.
242
+ The sky's light is in the units of a directional light's intensity, so the exposure that suits the scene's lights suits the sky. It does not move a light: set the main light's direction and color with it, or take them from [`timeOfDay`](#time-of-day). The quality setting [`physicalSky`](../concepts/quality-presets.md) is off on Low. There the analytic sky stands in, with the same sun, moon, air and clouds, matched to the physical sky's brightness. The haze on objects stays. The first physical sky downloads its shaders, `'physical_sky'`, and the view shows the background color until its tables are drawn.
233
243
 
234
244
  The sky lights nothing by itself. [`assets.skyEnvironment()`](assets.md#environments) makes an environment of it, which follows the sky's settings as they change: [Lighting and environment](../concepts/lighting.md#sky-and-backgrounds) shows how.
235
245
 
@@ -245,7 +255,7 @@ Development builds throw E1203 for a number that is not finite, and E1108 for a
245
255
  import { defineFeature, defineSketch } from '@null3d/engine';
246
256
  import curtain from './curtain.wgsl';
247
257
 
248
- export default defineSketch(({ scene }) => {
258
+ export default defineSketch(({ scene, time }) => {
249
259
  scene.setBackground({ sky: { cloudCoverage: 0.1 } });
250
260
  const description = defineFeature({
251
261
  name: 'curtain',
@@ -256,7 +266,7 @@ export default defineSketch(({ scene }) => {
256
266
  });
257
267
  const layer = scene.setSkyLayer(description, { wgsl: curtain, sun: 0.2 });
258
268
  return {
259
- onUpdate(time) {
269
+ onUpdate() {
260
270
  layer.set({ opacity: 0.8 + 0.2 * Math.sin(time.now) });
261
271
  },
262
272
  };
@@ -285,7 +295,7 @@ A layer declares no uniforms, textures or bindings of its own: the engine binds
285
295
 
286
296
  The layer reaches the sky's environment map as well as the background, so every place that a sky is seen shows it: a lake or a window reflects the layer, and the diffuse light that the sky gives the scene carries its color, so it lights the ground under it. The engine builds the layer's WGSL a second time into the shader that fills the map's cube faces, and finds the map's light in the map itself: a small pass sums a level of the map onto the nine coefficients of its diffuse light, and the engine reads them back once for each fill, never in a frame and with nothing waiting: the read is asynchronous, and a fill that cannot start while another runs starts on a later frame. None of this is the add-on's work, and the light matches the reflections because it comes from them.
287
297
 
288
- A fill spreads over some twenty frames, one stage a frame, so a layer that its clock moves tells the map how often to capture it with `refresh`, in seconds. A shorter time follows a faster layer, at a rate of one fill each `refresh` seconds: at the default of a second that is 15 stage draws a second, and a page that asks for less waits for none of it. A layer of 0 stands still and costs one fill per change. Until the first capture of a new layer lands, the scene keeps the core sky's own light, and a frame or two passes before the map's light follows its texels. The aurora example add-on in `examples/addons/aurora/` draws one, over a frozen lake that reflects it.
298
+ A fill spreads over some twenty frames, one stage a frame, so a layer that its clock moves tells the map how often to capture it with `refresh`, in seconds. A shorter time follows a faster layer, at a rate of one fill each `refresh` seconds: at the default of a second that is 20 stage draws a second, and a page that asks for less waits for none of it. A layer of 0 stands still and costs one fill per change. Until the first capture of a new layer lands, the scene keeps the core sky's own light, and a frame or two passes before the map's light follows its texels. The aurora example add-on in `examples/addons/aurora/` draws one, over a frozen lake that reflects it.
289
299
 
290
300
  ## Multiple views
291
301
 
@@ -310,13 +320,13 @@ Each view culls the scene on its own, and draws it at its rectangle's pixels wit
310
320
 
311
321
  A view costs one more cull and one more scene draw. The camera's view still draws the whole canvas first, with the canvas's aspect ratio, so a split screen of two half-width views draws the scene three times: once across the canvas underneath and once for each half. A picture in picture draws it twice. The rectangle follows the render scale, as the camera's view does, so a lower scale lowers a view's cost too. A small rectangle costs little on a phone. Bloom's threshold and the tone curve see the whole image once.
312
322
 
313
- A view's objects take no ambient occlusion or screen-space reflections, which shade the camera's view. The camera's volumetric fog and outline are added to the whole image after the views draw, so they also reach a view's rectangle. An object whose material shows a render pass's texture does not draw in a view, as it does not draw in another pass. `screenToRay` and `worldToScreen` map the whole canvas, so they do not follow a view's rectangle. A scene and its passes share 32 views, the camera's included; `scene.createView` throws E1501 when none is free. Development builds throw E1213 for a camera or a rectangle that a view does not take, and E1203 for a number that is not finite.
323
+ A view's objects take no ambient occlusion or screen-space reflections, which shade the camera's view. The camera's volumetric fog and outline are added to the whole image after the views draw, so they also reach a view's rectangle. An object whose material shows a render pass's texture does not draw in a view, as it does not draw in another pass. `camera.screenToRay` and `camera.worldToScreen` map the whole canvas. `view.screenToRay` and `view.worldToScreen` map the view's image, and `scene.viewAt(x, y)` finds the view under a point ([Multiple views](../guides/multiple-views.md#picking-in-a-view)). A scene and its passes share 32 views, the camera's included; `scene.createView` throws E1501 when none is free. Development builds throw E1213 for a camera or a rectangle that a view does not take, and E1203 for a number that is not finite.
314
324
 
315
325
  [Multiple views](../guides/multiple-views.md) covers split screens, picture in picture and their cost.
316
326
 
317
327
  ## The environment
318
328
 
319
- `setEnvironment` lights the scene with an environment map from [`assets.loadEnvironment`, `assets.builtinEnvironment` or `assets.skyEnvironment`](assets.md#environments), as three.js's `scene.environment` does with a texture from `PMREMGenerator`. Standard materials reflect it, sharply when smooth and blurred when rough, and take its diffuse light. `setEnvironment(null)` removes it. The background stays as `setBackground` set it.
329
+ `setEnvironment` lights the scene with an environment map from [`assets.loadEnvironment`, `assets.builtinEnvironment` or `assets.skyEnvironment`](assets.md#environments). Standard materials reflect it, sharply when smooth and blurred when rough, and take its diffuse light. `setEnvironment(null)` removes it. The background stays as `setBackground` set it.
320
330
 
321
331
  ```ts
322
332
  const sunset = await assets.loadEnvironment('/env/sunset.ktx2');
@@ -325,8 +335,8 @@ scene.setEnvironment(sunset, { intensity: 0.8, rotation: [0, Math.PI / 2, 0] });
325
335
 
326
336
  | Option | Default | What it sets |
327
337
  | --- | --- | --- |
328
- | `intensity` | 1 | The factor of the environment's light, 0 or more, as three.js's `scene.environmentIntensity` |
329
- | `rotation` | `[0, 0, 0]` | The environment's turn, as Euler angles in radians in the order X, Y, Z, as `scene.environmentRotation` |
338
+ | `intensity` | 1 | The factor of the environment's light, 0 or more |
339
+ | `rotation` | `[0, 0, 0]` | The environment's turn, as Euler angles in radians in the order X, Y, Z |
330
340
 
331
341
  Each call sets both options, and an option left out takes its default. The call allocates nothing, so a sketch can turn the environment in every frame. `bun run bench:allocation --environment` checks it. A material's `envIntensity` scales the light on that material. The scene draws without a file's environment until its map is on the GPU. The built-in room's map and the sky's map are whole in the first frame that uses them. The sky's map follows the sky background: after a change that shows, the scene takes the new light up to 19 frames later, and a smaller change waits for its next step. The scene draws without the environment again after `environment.destroy()`. Development builds throw E1203 for a number that is not finite and E1108 for a negative intensity. They throw E1213 for a value that is not an environment. Every build throws E1101 for an environment that was destroyed. [Lighting and environment](../concepts/lighting.md#environment-maps) says how the environment lights a surface, and what it costs.
332
342
 
@@ -446,8 +456,8 @@ A scene has at most 16 probes, and their captures take 6 of the 32 views that th
446
456
  `setFog` covers every object in fog that thickens with its distance from the camera. The distance is the straight line from the camera to the point, so an object keeps its fog as the camera turns. A curve sets how the fog thickens:
447
457
 
448
458
  - `'exponential'`, the default: an even haze. An object at distance d takes the fog color by a factor of 1 - exp(-density × d).
449
- - `'exp2'`: thicker with the square of the distance, 1 - exp(-(density × d)²), as three.js's `FogExp2`.
450
- - `'linear'`: clear up to `near`, and hides objects from `far`, with a smooth change between them, as three.js's `Fog`.
459
+ - `'exp2'`: thicker with the square of the distance, 1 - exp(-(density × d)²).
460
+ - `'linear'`: clear up to `near`, and hides objects from `far`, with a smooth change between them.
451
461
 
452
462
  The fog can also thin with height, as mist lies in a valley, and glow toward the main directional light. `setFog(null)` removes the fog. The call allocates nothing, so a sketch can change the fog in every frame; `bun run bench:allocation --fog` checks it, the volumetric fog included.
453
463
 
@@ -471,10 +481,11 @@ scene.setFog({ color: '#b8c4d0', density: 0.04, sunGlow: 1.5 });
471
481
  | `heightFalloff` | All | 0 | How fast the fog thins with height, 0 or more. The fog's density falls to about a third every 1 / `heightFalloff` units up, and grows below `height`. 0 keeps the fog the same at every height |
472
482
  | `sunGlow` | All | 0 | How much of the main directional light the fog scatters toward the camera, 0 or more. Fog toward that light glows in its color |
473
483
  | `sunGlowExponent` | All | 8 | How tightly the glow gathers around the light's direction, above 0. Higher values make a smaller glow |
484
+ | `background` | All | 0 | How much of the fog the sky and the background take, from 0 to 1. At 1 they take the fog of a surface at the camera's far plane, so the haze over the land continues over the sky it meets; 0 leaves them unfogged |
474
485
 
475
486
  Height fog sums the fog along each line of sight. A view down into the mist then sees thick fog, and a view up sees clear air. The sun glow takes the color and the intensity of the scene's main directional light, so it follows the light as it moves. Shadows do not block the glow.
476
487
 
477
- The fog does not cover the background, so give the background the fog's color to fade far objects into it. Past the edge of an outdoor scene's land, the background shows with no fog at all. [Where the land ends](../concepts/lighting.md#where-the-land-ends) says how to hide that edge. A material created with `fog: false` keeps its color at every distance, as [Materials](materials.md#options-fixed-at-creation) says. The engine mixes the fog into each pixel as it shades the pixel, before the tone mapping, so fog adds almost no work. The fog applies from the next frame. Development builds throw E1108 for an unknown curve, a `far` that is not above `near`, a negative `density`, `heightFalloff` or `sunGlow`, and a `sunGlowExponent` that is not above 0. They throw E1203 for a value that is not a finite number. The `null3d::fog` module of the [shader library](../shaders/library.md#null3dfog) holds the same formulas for WGSL shaders.
488
+ `background` mixes the scene's fog into the sky and the background, as if they stood at the camera's far plane. The haze over the land then runs on over the sky it meets, so a scene needs no haze sheet. It runs from 0 to 1 and defaults to 0. At 0 the background takes no fog, and the background's color or the scene's own sheets must blend the edge; [Where the land ends](../concepts/lighting.md#where-the-land-ends) says how. A material created with `fog: false` keeps its color at every distance, as [Materials](materials.md#options-fixed-at-creation) says. The engine mixes the fog into each pixel as it shades the pixel, before the tone mapping, so fog adds almost no work. The fog applies from the next frame. Development builds throw E1108 for an unknown curve, a `far` that is not above `near`, a negative `density`, `heightFalloff` or `sunGlow`, and a `sunGlowExponent` that is not above 0. They throw E1203 for a value that is not a finite number, and E1108 for a `background` outside 0 to 1. The `null3d::fog` module of the [shader library](../shaders/library.md#null3dfog) holds the same formulas for WGSL shaders.
478
489
 
479
490
  ### Volumetric fog
480
491
 
@@ -541,7 +552,7 @@ A third argument is an object that the call fills, in place of making one: `time
541
552
 
542
553
  ## Lights
543
554
 
544
- Each light is an object, so a scene can hold many, and each call creates another. Without lights, standard materials draw black. [Lights](lights.md) covers each kind, and which of them light surfaces in this version.
555
+ Each light is an object, so a scene can hold many, and each call creates another. Without lights, standard materials draw black. [Lights](lights.md) covers each kind, and which of them light surfaces.
545
556
 
546
557
  ## Decals
547
558
 
@@ -549,15 +560,15 @@ A decal is a mesh of `geometry.box()` with a `materials.decal` material, which p
549
560
 
550
561
  ## Drawing every mesh with one material
551
562
 
552
- `scene.overrideMaterial = material` draws every mesh and instance batch of the main pass with that material, in place of each object's own. This matches three.js's `scene.overrideMaterial`. Each object keeps its mesh, its place and its instances. A batch draws all of its rows with the override. Set the property to `null` to draw each object with its own material again.
563
+ `scene.overrideMaterial = material` draws every mesh and instance batch of the main pass with that material, in place of each object's own. Each object keeps its mesh, its place and its instances. A batch draws all of its rows with the override. Set the property to `null` to draw each object with its own material again.
553
564
 
554
- Sprites, points, lines and particle systems keep their own materials. The shadow maps also keep each object's material, as three.js's shadow maps do, so a masked object still cuts its shadow. A sprite, point or line material throws E1224.
565
+ Sprites, points, lines and particle systems keep their own materials. The shadow maps also keep each object's material, so a masked object still cuts its shadow. A sprite, point or line material throws E1224.
555
566
 
556
567
  The change reaches the frame after the call, and that frame rebuilds the engine's draw tables. After that the override adds no draw call and no pipeline beyond the materials it replaces. For the built-in debug views, use `debug.view` instead.
557
568
 
558
569
  ## When changes take effect
559
570
 
560
- Creating an object, `destroy`, `setParent`, `setVisible`, `setLayers` and `setDynamic` change the structure of the scene, and so do the mesh calls: `setMaterial`, `setMesh`, `setCastShadows`, `setReceiveShadows`, `setRenderOrder`, `setFrustumCulled` and `setBounds`. The engine queues these changes and applies them after `onUpdate` returns, before it updates transforms and draws. The frame drawn after the call shows the change. Some of them make the engine rebuild its draw tables, as the [performance guide](../guides/performance.md#objects-during-play) lists.
571
+ Creating an object, `destroy`, `setParent`, `setVisible`, `setLayers` and `setDynamic` change the structure of the scene, and so do the mesh calls: `setMaterial`, `setMesh`, `setCastShadows`, `setReceiveShadows`, `setRenderOrder` and `setFrustumCulled`, and so does `setBounds`. The engine queues these changes and applies them after `onUpdate` returns, before it updates transforms and draws. The frame drawn after the call shows the change. Some of them make the engine rebuild its draw tables, as the [performance guide](../guides/performance.md#objects-during-play) lists.
561
572
 
562
573
  Values that the engine computes, such as the result of `getWorldPosition`, come from the engine's last transform update. In `onUpdate` they come from the previous frame. In `onLateUpdate` they already hold the frame's changes, because the engine updates transforms before it calls `onLateUpdate`. Setters that `onLateUpdate` calls show in the same frame, and structural changes that it makes wait for the next frame ([Sketch API](sketch.md#when-changes-show)).
563
574
 
@@ -576,7 +587,7 @@ An instance batch is one object that draws many copies of one mesh with one mate
576
587
  - A scene starts with room for 1,023 objects: groups, meshes, cameras and lights together. When it needs more, it grows on its own. It doubles its room at the start of a frame once it is three quarters full. A create call that finds it full doubles it at once. A destroyed object frees its place when the frame applies the change.
577
588
  - Each growth copies the scene's tables, about 267 bytes per object, in one short pause. A scene that knows its size can start with room for every object, with the `expectedObjects` option of [`createEngine`](engine.md#options), and never grows during play.
578
589
  - A scene holds up to 1,048,575 objects, the most that a handle can name. Past that, a create call throws E1102. A growth that the engine's memory cannot hold throws E1109. Each place counts toward the objects and instance rows that the GPU draws (`engine.capabilities.maxInstances`), and a growth past that limit throws E1501.
579
- - The rows of an instance batch take none of those places. One engine holds up to 256 batches, and `createInstances(prefab, ...)` takes one for each mesh of the model.
590
+ - The rows of an instance batch take none of those places. One engine holds up to 512 batches, and `createInstances(prefab, ...)` takes one for each mesh of the model.
580
591
  - The queue holds up to 65,536 changes between two frames. One more throws E1102.
581
592
  - Each copy of a model with clips or skins takes a place in the animation table, and its joints take places too. The table starts with room for 1,024 animated objects and 65,536 joints. When a copy does not fit, it doubles what it lacks, in one short pause that copies the table. It holds up to 1,048,576 joints in all. That is the most that the joint texture holds on every WebGL2 device: about 24,000 copies of a character of 43 joints. A copy past that throws E1102, and a growth that the engine's memory cannot hold throws E1109. Either way, `instantiate` or `clone` then creates no part of the copy.
582
593