@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
@@ -8,7 +8,7 @@ summary: "standard, unlit, shader, shadowCatcher; every option."
8
8
 
9
9
  # Materials
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds typed uniforms, custom material textures, `destroy`, the specular and index of refraction values, transmission, light through thin surfaces and under the surface, decals, the weighted blending, the clear coat and sheen layers, the shadow catcher, bump maps, displacement maps, parallax and wireframes. The API is experimental, so it can still change between versions. `materials.shader` takes no standard texture maps. Coding agents must not use the parts that are not built.
11
+ > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. `materials.shader` takes no standard texture maps. It takes up to 6 textures of its own.
12
12
 
13
13
  A material sets how the surfaces of the objects that use it look. `materials.standard` makes a lit material, and `materials.unlit` makes one that ignores lights. Create materials in the setup, and share each one between the objects that look alike.
14
14
 
@@ -35,17 +35,17 @@ export default defineSketch(({ scene, geometry, materials, page }) => {
35
35
 
36
36
  | Factory | How it looks |
37
37
  | --- | --- |
38
- | `materials.standard(options)` | Lit by the scene's lights with glTF's metallic-roughness model and the formulas of three.js's `MeshStandardMaterial` |
39
- | `materials.unlit(options)` | Its color as it is, whatever the lights, like three.js's `MeshBasicMaterial`. The exposure and the tone mapping still apply to it. |
38
+ | `materials.standard(options)` | Lit by the scene's lights, with glTF's metallic-roughness model |
39
+ | `materials.unlit(options)` | Its color as it is, whatever the lights. The exposure and the tone mapping still apply to it. |
40
40
  | `materials.shader(options)` | A standard material whose WGSL changes its look before the engine lights it, or moves its vertices |
41
- | `materials.shadowCatcher(options)` | Only the shadows that fall on it, as three.js's `ShadowMaterial` |
42
- | `materials.decal(options)` | A standard material that a box projects onto the surfaces inside it, like three.js's `DecalGeometry` ([Decals](#decals)) |
41
+ | `materials.shadowCatcher(options)` | Only the shadows that fall on it |
42
+ | `materials.decal(options)` | A standard material that a box projects onto the surfaces inside it ([Decals](#decals)) |
43
43
 
44
44
  Without lights, a standard material draws black, apart from its emissive color. [Lights](lights.md) explains how light colors and intensities shade it.
45
45
 
46
46
  ## Shadow catchers
47
47
 
48
- `materials.shadowCatcher({ color, opacity })` draws a surface that shows only the shadows that fall on it, as three.js's `ShadowMaterial`. It shows its `color` where the main directional light's shadow falls, and nothing at all where the light reaches it. The shadows of point and spot lights do not show on it. The mesh must receive shadows with `setReceiveShadows(true)`, as three.js's `receiveShadow` must be set.
48
+ `materials.shadowCatcher({ color, opacity })` draws a surface that shows only the shadows that fall on it. It shows its `color` where the main directional light's shadow falls, and nothing at all where the light reaches it. The shadows of point and spot lights do not show on it. The mesh must receive shadows with `setReceiveShadows(true)`.
49
49
 
50
50
  The default color is black and the default opacity is 1. The material blends, so it draws in the transparent pass after the opaque objects, and the scene's fog leaves it alone. It takes no texture maps. Its shadows are the main directional light's, so a scene needs a directional light that casts shadows.
51
51
 
@@ -85,7 +85,7 @@ Put the catcher a little above the surface it lies on, so its shadows show over
85
85
  | `ior` | 1 or more | 1.5 | The index of refraction of the non-metallic part. It sets how much light the surface reflects head on |
86
86
  | `specularIntensity` | 0 to 1 | 1 | The strength of the non-metallic part's specular reflection, at every angle |
87
87
  | `specularColor` | A [color](#color), or linear components of 0 or more | White | Tints the non-metallic part's specular reflection head on |
88
- | `envIntensity` | 0 or more | 1 | The factor of the scene environment's light on the surface, as three.js's `envMapIntensity` |
88
+ | `envIntensity` | 0 or more | 1 | The factor of the scene environment's light on the surface. It multiplies the intensity that `scene.setEnvironment` gives |
89
89
  | `transmission` | 0 to 1 | 0 | How much of the light behind the surface passes through it, for glass and clear water. See "Transmission" |
90
90
  | `thickness` | 0 or more | 0 | The thickness of the volume under a surface that lets light through, in the mesh's own units |
91
91
  | `attenuationColor` | A [color](#color) | White | The color that white light takes inside the volume over `attenuationDistance` |
@@ -107,11 +107,11 @@ Put the catcher a little above the surface it lies on, so its shadows show over
107
107
  | `uvTransform` | An offset, a repeat and a rotation | None | Where every map sits on the texture coordinates |
108
108
  | `mapUvTransforms` | A transform for a map, by the map's option name | None | Where one map sits, where it differs from the others |
109
109
 
110
- The values have the meaning and the defaults of three.js's `MeshStandardMaterial`. `ior`, `specularIntensity`, `specularColor`, the four transmission values and the ten layer values have those of three.js's `MeshPhysicalMaterial`, as the next sections explain. three.js has no diffuse transmission, so its two values take the names and defaults of glTF's `KHR_materials_diffuse_transmission`. A metal takes its color from what it reflects. Without an environment, a smooth metal shows little more than its highlights, so give the scene one with [`scene.setEnvironment`](scene.md#the-environment). three.js uses `scene.environmentIntensity` in place of `envMapIntensity` under a scene environment. The engine multiplies the two.
110
+ The next sections explain the specular, transmission, diffuse transmission and layer values. The two diffuse transmission values follow glTF's `KHR_materials_diffuse_transmission`. A metal takes its color from what it reflects. Without an environment, a smooth metal shows little more than its highlights, so give the scene one with [`scene.setEnvironment`](scene.md#the-environment).
111
111
 
112
112
  ## Specular reflection and index of refraction
113
113
 
114
- A surface reflects some light like a mirror, blurred by its roughness. This is its specular reflection. A metal's reflection takes its base color. A non-metal's reflection is white, and weak when you look at the surface head on: 4% of the light with the defaults. It grows to all the light at grazing angles. Three values change the non-metallic part, as glTF's `KHR_materials_ior` and `KHR_materials_specular` extensions do. The engine draws them with the formulas of three.js's `MeshPhysicalMaterial`, in the standard material's own lighting and shaders.
114
+ A surface reflects some light like a mirror, blurred by its roughness. This is its specular reflection. A metal's reflection takes its base color. A non-metal's reflection is white, and weak when you look at the surface head on: 4% of the light with the defaults. It grows to all the light at grazing angles. Three values change the non-metallic part, as glTF's `KHR_materials_ior` and `KHR_materials_specular` extensions do. The standard material's own lighting and shaders draw them, with the formulas in this table.
115
115
 
116
116
  | Value | Head on | At grazing angles |
117
117
  | --- | --- | --- |
@@ -130,7 +130,7 @@ const cloth = materials.standard({ color: '#4a5a70', roughness: 0.8, specularInt
130
130
 
131
131
  ## Transmission
132
132
 
133
- A surface with `transmission` lets the light behind it through, as three.js's `MeshPhysicalMaterial` does. Use it for glass, ice, gems and clear water. The `blend` alpha mode only mixes the surface's color over what lies behind it. Light that passes through a surface bends, blurs and takes the color of the volume under it:
133
+ A surface with `transmission` lets the light behind it through. Use it for glass, ice, gems and clear water. The `blend` alpha mode only mixes the surface's color over what lies behind it. Light that passes through a surface bends, blurs and takes the color of the volume under it:
134
134
 
135
135
  | Value | What it does |
136
136
  | --- | --- |
@@ -157,12 +157,12 @@ Give `transmission` when you create the material, even as 0, to change it later
157
157
 
158
158
  ### How it draws
159
159
 
160
- After the camera's view draws its opaque objects, the engine copies their colors into a texture with a chain of smaller, blurred copies. Surfaces that let light through then draw with the blended objects, farthest first. Each one samples the copy where its bent light ray leaves the volume, at a blur that its roughness picks. three.js draws its transmission the same way.
160
+ After the camera's view draws its opaque objects, the engine copies their colors into a texture with a chain of smaller, blurred copies. Surfaces that let light through then draw with the blended objects, farthest first. Each one samples the copy where its bent light ray leaves the volume, at a blur that its roughness picks.
161
161
 
162
162
  - Only opaque objects show through. Another surface that lets light through, or a blended one, does not show through glass in front of it.
163
- - The copy keeps the opaque objects' depth too. A bent ray can land on an opaque object in front of the surface, such as a flower on the bank of a stream. The surface then shows what lies straight behind it instead. three.js shows the flower's color in the water there.
164
- - The volume is a model, not a ray through the real shape. A ball with `thickness` set to its diameter looks right through its middle. three.js uses the same model.
165
- - With `dispersion`, light follows three rays, one per color, each bent by a slightly different index of refraction. Red takes the lowest index, as three.js draws it. Each color keeps the light that its own ray reaches, so a gem's edges separate white light into colors.
163
+ - The copy keeps the opaque objects' depth too. A bent ray can land on an opaque object in front of the surface, such as a flower on the bank of a stream. The surface then shows what lies straight behind it instead.
164
+ - The volume is a model, not a ray through the real shape. A ball with `thickness` set to its diameter looks right through its middle.
165
+ - With `dispersion`, light follows three rays, one per color, each bent by a slightly different index of refraction. Red takes the lowest index. Each color keeps the light that its own ray reaches, so a gem's edges separate white light into colors.
166
166
  - `thickness` is in the mesh's own units, and the object's scale multiplies it.
167
167
  - Such a surface takes the `opaque`, `mask` or `blend` alpha mode. A mask decides which pixels draw, and the light from behind fills the pixels that remain. `hash` throws E1217.
168
168
  - Views other than the camera's, such as [scene passes](render.md#scene-passes) and [reflection passes](render.md#reflection-passes), have no copy. There the surface shows the environment's light along the bent ray.
@@ -251,7 +251,7 @@ Nothing of it runs, and none of its shaders download, while no material has `sub
251
251
 
252
252
  ## Clear coat and sheen
253
253
 
254
- Two layers can lie over the standard material's surface, as three.js's `MeshPhysicalMaterial` and glTF's `KHR_materials_clearcoat` and `KHR_materials_sheen` extensions draw them:
254
+ Two layers can lie over the standard material's surface, as glTF's `KHR_materials_clearcoat` and `KHR_materials_sheen` extensions describe them:
255
255
 
256
256
  - A **clear coat** is a thin, clear, shiny film, such as the lacquer of car paint, varnish on wood, or water on a stone. It has highlights and a reflection of its own, at its own roughness. Where it reflects light, it dims what lies under it. So a rough red paint under a smooth coat shows a sharp reflection over a soft color.
257
257
  - A **sheen** is the soft glow that cloth, velvet and fuzz take at grazing angles, where the light catches the tips of their fibers. Its color tints the glow. Light that the sheen reflects does not reach the surface under it.
@@ -297,10 +297,8 @@ A material with `transmission` keeps its `transmissionMap` and `thicknessMap` be
297
297
 
298
298
  ### How the layers draw
299
299
 
300
- The engine uses the formulas of three.js's `MeshPhysicalMaterial`:
301
-
302
300
  - The coat is a second GGX highlight, which reflects 4% of the light head on and all of it at grazing angles. It reflects the scene's environment at its own roughness, and the occlusion map and ambient occlusion darken that reflection.
303
- - The sheen is the Charlie highlight of cloth (Estevez and Kulla), lit by each light, and by the ambient light and the environment. How much light the sheen keeps from the surface under it comes from three.js's curve fit of the sheen's reflectance, which needs no lookup table. At grazing angles the fit gives a little less than the exact value, so the surface under a strong sheen shows slightly brighter there than the extension's reference. three.js draws the same.
301
+ - The sheen is the Charlie highlight of cloth (Estevez and Kulla), lit by each light, and by the ambient light and the environment. A curve fit of the sheen's reflectance, which needs no lookup table, gives how much light the sheen keeps from the surface under it. At grazing angles the fit gives a little less than the exact value. So the surface under a strong sheen shows slightly brighter there than the extension's reference.
304
302
  - Emitted light lies under the coat too, so a coat dims a glowing surface where it reflects.
305
303
 
306
304
  ### Cost of the layers
@@ -311,8 +309,8 @@ The layers' shaders load the first time you create a material with layers. To lo
311
309
 
312
310
  Two more effects sit in the same shaders as the clear coat and the sheen, and a material takes them with the same options:
313
311
 
314
- - **Iridescence** is the color that a thin film adds to a reflection, as on a soap bubble, an oil slick, a beetle's shell or a pearl. The film reflects each wavelength by its own phase, so the color depends on the film's thickness and on the angle you see it from. The engine uses the formulas of three.js's `MeshPhysicalMaterial`, after Belcour and Barla.
315
- - **Anisotropy** stretches the surface's highlight along one direction, as the grain of brushed metal spreads it across the grooves instead of around them. The engine uses the anisotropic GGX lobe of three.js's `MeshPhysicalMaterial`, after Filament.
312
+ - **Iridescence** is the color that a thin film adds to a reflection, as on a soap bubble, an oil slick, a beetle's shell or a pearl. The film reflects each wavelength by its own phase, so the color depends on the film's thickness and on the angle you see it from. The engine uses Belcour and Barla's thin-film formulas.
313
+ - **Anisotropy** stretches the surface's highlight along one direction, as the grain of brushed metal spreads it across the grooves instead of around them. The engine uses an anisotropic GGX lobe, after Filament.
316
314
 
317
315
  | Value | What it does |
318
316
  | --- | --- |
@@ -347,14 +345,15 @@ Give any of these values, or a map, when you create the material, to change the
347
345
 
348
346
  A material with these maps takes no `lightMap` and no specular maps, since the maps take their places. A material takes the maps of a clear coat and a sheen, or the maps of iridescence and the anisotropy: the coat's and the sheen's maps fill every place. Development builds throw E1217 for a material that asks for both families. Production builds keep the coat's and the sheen's maps and draw the others' values alone. The glTF loader keeps the coat's and the sheen's maps and notes the others. A material with `transmission` keeps its `transmissionMap` and `thicknessMap` beside these maps where the array of one stays free: `iridescenceThicknessMap` fills the array that the transmission map samples and `anisotropyMap` the one that the thickness map samples, so a material takes one of each pair.
349
347
 
350
- A material with `anisotropy` draws with or without a map. The direction that it stretches along comes from the surface's tangent frame. The frame is the mesh's tangents where it has them, else the texture coordinates, else the normal map's coordinates where the material also has a normal map. A material without a map and with no texture coordinates takes any frame square to the surface. Three.js builds the frame the same way from the tangents or the coordinates.
348
+ A material with `anisotropy` draws with or without a map. The direction that it stretches along comes from the surface's tangent frame. The frame is the mesh's tangents where it has them, else the texture coordinates, else the normal map's coordinates where the material also has a normal map. A material without a map and with no texture coordinates takes any frame square to the surface.
351
349
 
352
350
  ### How the film and the stretch draw
353
351
 
354
352
  - The film's Fresnel term takes the place of the surface's own where `iridescence` applies. So the highlight and the reflection both take the film's colors, and a metal shows them over its base color.
355
353
  - The film does not change the shape of the highlight, the diffuse light or the light that passes through the surface.
356
- - The stretched lobe changes how each light's highlight spreads. The reflection of the environment about the surface bends away from the normal across the stretched direction, as three.js bends it, so brushed metal shows a long reflection rather than a dot.
357
- - Rectangles and tubes of light shade the surface without the stretch, as three.js's rectangle lights do.
354
+ - The stretched lobe changes how each light's highlight spreads.
355
+ - The reflection of the environment bends away from the normal across the stretched direction. So brushed metal shows a long reflection rather than a dot.
356
+ - Rectangles and tubes of light shade the surface without the stretch.
358
357
 
359
358
  ### Cost of iridescence and anisotropy
360
359
 
@@ -362,7 +361,7 @@ These effects add nothing to a material without them. They run in the shaders of
362
361
 
363
362
  ## Decals
364
363
 
365
- A decal material projects a standard material onto every opaque surface inside a box, as three.js's `DecalGeometry` places a decal. Use decals for scorch marks, mud, puddles, road paint, moss, cracks and posters. Give the material to a mesh of `geometry.box()`: the object's position, rotation and scale place the box.
364
+ A decal material projects a standard material onto every opaque surface inside a box. Use decals for scorch marks, mud, puddles, road paint, moss, cracks and posters. Give the material to a mesh of `geometry.box()`: the object's position, rotation and scale place the box.
366
365
 
367
366
  ```ts
368
367
  // sketch.ts: a scorch mark on the ground, and cracks on a wall. The maps come from textures.
@@ -376,7 +375,7 @@ const cracks = materials.decal({ map: crackColors, normalMap: crackBumps });
376
375
  scene.createMesh({ mesh: box, material: cracks, position: [0, 1.5, -2], scale: [2, 2, 0.5] });
377
376
  ```
378
377
 
379
- The box's z axis is the decal's direction: it points out of the surfaces that the decal marks. The maps lie across the box's x and y sides, with u along x and v along y, as `DecalGeometry` lays them. The box's z size sets how far into and out of a surface the decal reaches, so a deep box marks a bumpy or curved surface all over.
378
+ The box's z axis is the decal's direction: it points out of the surfaces that the decal marks. The maps lie across the box's x and y sides, with u along x and v along y. The box's z size sets how far into and out of a surface the decal reaches, so a deep box marks a bumpy or curved surface all over.
380
379
 
381
380
  A decal takes the standard material's values and maps. They light it as they light any surface, at the place where the decal lies:
382
381
 
@@ -466,7 +465,7 @@ The maps of a material are fixed when you create it. A mesh needs texture coordi
466
465
 
467
466
  A light map adds baked light to the ambient light. A bake often places its light map on each mesh with its own scale and offset, which `lightMapOffset` and `lightMapRepeat` give; the other maps keep their coordinates. A directional light map also stores the light's direction at each texel: give its `lightMapDirection` and the material's normal map bends the baked light, so relief faces the light of the bake and turns away from it. `assets.loadLightMap` reads a directional map from a [baked light file](../guides/baked-light-data.md). A material made from a model for Needle's viewer takes that model's light maps with their RGBM decode.
468
467
 
469
- A normal map takes its frame from the mesh's tangents when the mesh has them, as `geometry.fromArrays` with `computeTangents` makes them. Otherwise the shader finds the frame from how the positions and the coordinates change between pixels, as three.js does.
468
+ A normal map takes its frame from the mesh's tangents when the mesh has them, as `geometry.fromArrays` with `computeTangents` makes them. Otherwise the shader finds the frame from how the positions and the coordinates change between pixels.
470
469
 
471
470
  Until a map's image reaches the GPU, the material draws as without that map.
472
471
 
@@ -474,7 +473,7 @@ On WebGL2, the maps of one material share at most six textures on the GPU. Maps
474
473
 
475
474
  ## Relief
476
475
 
477
- Three maps give a surface relief. Each reads heights from its red channel, in the `linear` color space. They follow three.js's options of the same names.
476
+ Three maps give a surface relief. Each reads heights from its red channel, in the `linear` color space.
478
477
 
479
478
  ```ts
480
479
  // sketch.ts
@@ -495,18 +494,18 @@ scene.createMesh({ mesh: geometry.sphere({ radius: 1, widthSegments: 128, height
495
494
 
496
495
  | Option | What it does | Cost |
497
496
  | --- | --- | --- |
498
- | `bumpMap` | Bends the normals by the change of its heights from one pixel to the next, times `bumpScale`, as three.js's bump map does. The shape stays flat | Three texture reads per pixel |
497
+ | `bumpMap` | Bends the normals by the change of its heights from one pixel to the next, times `bumpScale`. The shape stays flat | Three texture reads per pixel |
499
498
  | `displacementMap` | Moves each vertex along its normal by its height times `displacementScale`, plus `displacementBias`, in the mesh's units. The shape changes | One texture read per vertex in each pass that draws it, and three per pixel where it bends the normals |
500
499
  | `parallax: true` | With a displacement map, shifts where each pixel reads the maps, so relief finer than the vertices hides and shows the surface behind it as the view turns | 8 to 32 texture reads per pixel, more at grazing views |
501
500
 
502
- A bump map gives fine relief to a flat surface, such as the grain of stone. Its bend depends on the surface's size on the screen, as in three.js. A normal map wins over a bump map, so a material draws one or the other.
501
+ A bump map gives fine relief to a flat surface, such as the grain of stone. Its bend depends on the surface's size on the screen. A normal map wins over a bump map, so a material draws one or the other.
503
502
 
504
- A displacement map changes the shape itself, so its silhouette and its shadows move too. The vertex shader reads the map at its full size, so the mesh needs about as many vertices as the detail it should show. `geometry.plane` and `geometry.sphere` take segment counts for this. The map moves vertices after skinning and morph targets, as in three.js.
503
+ A displacement map changes the shape itself, so its silhouette and its shadows move too. The vertex shader reads the map at its full size. So the mesh needs about as many vertices as the detail it should show. `geometry.plane` and `geometry.sphere` take segment counts for this. The map moves vertices after skinning and morph targets.
505
504
 
506
- - Without a normal map or a bump map, the displacement map's slope also bends the normals, so the light follows the moved surface. three.js keeps the mesh's normals there, so a port of such a material looks less flat in null3D.
507
- - With a normal map, the normal map bends the normals, as in three.js. A normal map made from the same heights already holds their slope.
505
+ - Without a normal map or a bump map, the displacement map's slope also bends the normals, so the light follows the moved surface.
506
+ - With a normal map, the normal map bends the normals. A normal map made from the same heights already holds their slope.
508
507
  - Shadows and the depth prepass follow the moved vertices. Culling grows each object's bounds by the farthest that the material has moved a vertex, so no `setBounds` call is needed.
509
- - Raycasts, outlines and debug views see the mesh before it moves, as three.js's raycasts do.
508
+ - Raycasts, outlines and debug views see the mesh before it moves.
510
509
 
511
510
  `parallax` adds the detail that the vertices cannot hold, such as the joints between bricks or cobbles. Silhouettes and shadows keep the vertices' shape. It takes only opaque and masked surfaces: the `blend` alpha mode and `transmission` with `parallax` throw E1217. The quality preset's `parallax` setting turns it off on Low, where such materials draw with their displacement alone.
512
511
 
@@ -514,11 +513,11 @@ A page without relief pays nothing for it. The first material with a bump map lo
514
513
 
515
514
  ## Texture coordinate transform
516
515
 
517
- `uvTransform` places every map of a material on the texture coordinates: `offset`, `repeat` and `rotation` in radians. They act as three.js's texture `offset`, `repeat` and `rotation` with the default `center`. A transform that leaves a value out takes its default. `set` changes the transform at any time. `mapUvTransforms` places one map by its option name, such as `emissiveMap`, where it differs from the others. A map without one keeps the transform that `uvTransform` gives it. Two maps that share a slot, as a sheen map and an anisotropy map do, share one transform too. A glTF file keeps a transform for each of its textures, so the loader places each map with its own.
516
+ `uvTransform` places every map of a material on the texture coordinates: `offset`, `repeat` and `rotation` in radians. The engine turns the coordinates by `rotation` about their origin, scales them by `repeat`, and then adds `offset`: u' = repeat.u × (u cos r + v sin r) + offset.u, and v' = repeat.v × (v cos r − u sin r) + offset.v. A transform that leaves a value out takes its default. `set` changes the transform at any time. `mapUvTransforms` places one map by its option name, such as `emissiveMap`, where it differs from the others. A map without one keeps the transform that `uvTransform` gives it. Two maps that share a slot, as a sheen map and an anisotropy map do, share one transform too. A glTF file keeps a transform for each of its textures, so the loader places each map with its own.
518
517
 
519
518
  ## Color
520
519
 
521
- `color`, `emissive` and `specularColor` take an sRGB color, as three.js does. That is a hex string such as `'#4a8cff'` or `'#48f'`, a number such as `0x4a8cff`, or three linear components from 0 to 1. The engine converts the color to linear once, when the call receives it. Any other value, such as the name `'red'`, throws E1204. The linear components of `specularColor` may also exceed 1, as glTF allows.
520
+ `color`, `emissive` and `specularColor` take an sRGB color. That is a hex string such as `'#4a8cff'` or `'#48f'`, a number such as `0x4a8cff`, or three linear components from 0 to 1. The engine converts the color to linear once, when the call receives it. Any other value, such as the name `'red'`, throws E1204. The linear components of `specularColor` may also exceed 1, as glTF allows.
522
521
 
523
522
  ## Changing a material
524
523
 
@@ -530,7 +529,7 @@ A page without relief pays nothing for it. The first material with a bump map lo
530
529
 
531
530
  ## Destroying a material
532
531
 
533
- `material.destroy()` frees a material that the sketch no longer needs, as three.js's `material.dispose()` does. From the next frame, objects and instance batches that still use it draw nothing, until `setMaterial` gives them another material. Once no object or batch uses it, its place in the engine's table of materials goes to the next material that you create. When the last material of a custom material's WGSL goes, the engine also frees that WGSL's pipelines.
532
+ `material.destroy()` frees a material that the sketch no longer needs. From the next frame, objects and instance batches that still use it draw nothing, until `setMaterial` gives them another material. Once no object or batch uses it, its place in the engine's table of materials goes to the next material that you create. When the last material of a custom material's WGSL goes, the engine also frees that WGSL's pipelines.
534
533
 
535
534
  `destroy` leaves the material's textures, which other materials may share. Destroy them apart with `texture.destroy()`. Calls on a destroyed material, and calls that pass it, such as `createMesh`, throw [E1101](../errors/E1101.md). Destroying a material changes which objects draw, so the next frame rebuilds the engine's draw tables, as creating one does.
536
535
 
@@ -540,25 +539,25 @@ These options are fixed when you create the material. Most of them choose the ma
540
539
 
541
540
  | Option | Materials | Default | What it does |
542
541
  | --- | --- | --- | --- |
543
- | `doubleSided` | Both | false | Draws both faces of each triangle. A back face lights as if it faced the camera, as with three.js's `side: DoubleSide` |
542
+ | `doubleSided` | Both | false | Draws both faces of each triangle. A back face lights as if it faced the camera |
544
543
  | `vertexColors` | Both | false | Multiplies the base color by the mesh's vertex colors, on meshes that have them. [Geometry](geometry.md) makes meshes with colors |
545
544
  | `flatShading` | Standard | false | Lights each triangle with the normal of its face, so the mesh looks faceted |
546
545
  | `alphaMode` | Both | `'opaque'` | How the material uses its alpha: `'opaque'`, `'mask'`, `'hash'` or `'blend'`. See "Alpha modes" |
547
- | `alphaToCoverage` | Both | true | With the `mask` alpha mode, smooths the cut edges with MSAA, as three.js's `alphaToCoverage` does. `false` gives the hard cut edges of three.js's `alphaTest`. See "Alpha to coverage" |
546
+ | `alphaToCoverage` | Both | true | With the `mask` alpha mode, smooths the cut edges with MSAA. `false` gives hard cut edges. See "Alpha to coverage" |
548
547
  | `blending` | Both | `'normal'` | With the `blend` alpha mode, how the surface meets what lies behind it: `'normal'`, `'additive'`, `'multiply'` or `'weighted'`. See "Blending" |
549
548
  | `depthWrite` | Both | true | False writes no depth, so the surface hides nothing that draws after it |
550
- | `depthTest` | Both | true | False draws the surface whatever lies in front of it. It then writes no depth either, as in three.js's WebGL renderer |
551
- | `colorWrite` | Both | true | False writes no color, so the surface shows nothing itself and hides what lies behind it, as three.js's `colorWrite: false` does. See "Invisible surfaces that hide" |
552
- | `depthBias` | Both | No bias | Moves the surface's depth, as three.js's polygon offset does. See "Depth bias" |
553
- | `forceSinglePass` | Both | false | With the `blend` alpha mode and `doubleSided`, draws both faces in one draw, as three.js's `forceSinglePass` does. See "Double-sided blended surfaces" |
549
+ | `depthTest` | Both | true | False draws the surface whatever lies in front of it. It then writes no depth either |
550
+ | `colorWrite` | Both | true | False writes no color, so the surface shows nothing itself and hides what lies behind it. See "Invisible surfaces that hide" |
551
+ | `depthBias` | Both | No bias | Moves the surface's depth before the depth test. See "Depth bias" |
552
+ | `forceSinglePass` | Both | false | With the `blend` alpha mode and `doubleSided`, draws both faces in one draw. See "Double-sided blended surfaces" |
554
553
  | `transmission` | Standard | None | Given at all, even as 0, lets light through the surface, and `set` can then change its value. See "Transmission" |
555
554
  | `diffuseTransmission` | Standard | None | Given at all, even as 0, lets light through to the surface's other side, and `set` can then change its value. See "Light through thin surfaces" |
556
555
  | `subsurfaceRadius` | Standard | None | Given at all, even as 0, spreads the surface's light under it, and `set` can then change its value. See "Light under the surface" |
557
556
  | The layer values and maps | Standard | None | Any of them gives the material its layers above the surface, even a coat of 0, and `set` can then change their values. See "Clear coat and sheen" and "Iridescence and anisotropy" |
558
- | `fog` | Both | true | Takes the scene's fog. With `false`, the material keeps its color at every distance, as with three.js's `fog: false`. [Scene](scene.md#fog) sets the fog |
559
- | `toneMapped` | Both | true | With `false`, keeps the color as the display shows it, as with three.js's `toneMapped: false`: the tone curve leaves it alone. The 8-bit path decides that in the material's own shader. The HDR path reads a mask of these surfaces in its final pass and skips the curve where one draws. The vignette and the sRGB encoding still apply, and the exposure scales the material's colors, so the color shows brighter than the same color tone mapped. A blended surface keeps the curve on the HDR path, since a blended pixel mixes two surfaces. [Color management](../concepts/color-management.md) explains the two paths |
557
+ | `fog` | Both | true | Takes the scene's fog. With `false`, the material keeps its color at every distance. [Scene](scene.md#fog) sets the fog |
558
+ | `toneMapped` | Both | true | With `false`, keeps the color as the display shows it: the tone curve leaves it alone. The 8-bit path decides that in the material's own shader. The HDR path reads a mask of these surfaces in its final pass and skips the curve where one draws. The vignette and the sRGB encoding still apply, and the exposure scales the material's colors, so the color shows brighter than the same color tone mapped. A blended surface keeps the curve on the HDR path, since a blended pixel mixes two surfaces. [Color management](../concepts/color-management.md) explains the two paths |
560
559
  | `contactShadows` | Standard | true | Takes the main directional light's contact shadows. With `false`, the surface takes none and keeps the shadow map's shadows. Use it on grass, leaf cards and other thin surfaces that crowd together or sway, where contact shadows make them dark and grainy and flicker as they move. [Shadows](../concepts/shadows.md#grass-and-other-thin-surfaces) explains why |
561
- | `wireframe` | Both | false | Draws the edges of each triangle as lines one pixel wide, with the material's own shading, as three.js's `wireframe` does. See "Wireframe" |
560
+ | `wireframe` | Both | false | Draws the edges of each triangle as lines one pixel wide, with the material's own shading. See "Wireframe" |
562
561
  | `parallax` | Standard | false | With a `displacementMap`, adds parallax occlusion mapping. See "Relief" |
563
562
  | `sceneInputs` | Custom | None | The scene inputs that the material's WGSL reads, which fix its shader. `['sceneDepth']` binds the copy of the opaque scene's depth. See "The scene behind a surface" |
564
563
 
@@ -566,26 +565,26 @@ A material with `vertexColors` draws a mesh without colors in its base color alo
566
565
 
567
566
  ### Wireframe
568
567
 
569
- A material with `wireframe: true` draws each triangle's three edges as lines, as three.js does. An edge that two triangles share draws twice. The engine keeps an edge list for each mesh from the first wireframe on, which takes twice the GPU memory of the mesh's triangle indices. Its shadows draw lines too. Flat shading and bump maps have no effect, as in three.js, because lines have no faces. Lines are one pixel wide on every GPU path. For wide lines, or for a mesh's outline edges alone, use [Lines](lines.md).
568
+ A material with `wireframe: true` draws each triangle's three edges as lines. An edge that two triangles share draws twice. The engine keeps an edge list for each mesh from the first wireframe on, which takes twice the GPU memory of the mesh's triangle indices. Its shadows draw lines too. Flat shading and bump maps have no effect, because lines have no faces. Lines are one pixel wide on every GPU path. For wide lines, or for a mesh's outline edges alone, use [Lines](lines.md).
570
569
 
571
570
  ## Alpha modes
572
571
 
573
572
  A surface's alpha is its `opacity`, times the alpha of its base color map. With `vertexColors`, the alpha of the mesh's vertex colors multiplies it too. `alphaMode` says how the material uses the alpha:
574
573
 
575
- | Mode | What it draws | three.js |
576
- | --- | --- | --- |
577
- | `'opaque'` | The whole surface, opaque. The alpha has no effect | The default material |
578
- | `'mask'` | Nothing where the alpha is below `alphaCutoff`, and the rest opaque | `alphaTest: alphaCutoff` |
579
- | `'hash'` | Each point of the surface opaque or not at all, so the alpha sets how much of the surface draws | `alphaHash: true` |
580
- | `'blend'` | The surface blended over what lies behind it, as far as the alpha says | `transparent: true` |
574
+ | Mode | What it draws |
575
+ | --- | --- |
576
+ | `'opaque'` | The whole surface, opaque. The alpha has no effect |
577
+ | `'mask'` | Nothing where the alpha is below `alphaCutoff`, and the rest opaque |
578
+ | `'hash'` | Each point of the surface opaque or not at all, so the alpha sets how much of the surface draws |
579
+ | `'blend'` | The surface blended over what lies behind it, as far as the alpha says |
581
580
 
582
581
  A masked surface has hard edges, and it hides what lies behind it as an opaque one does, so its objects draw in any order. Use it for leaves, fences and cut-out shapes. Only masked and hashed materials draw with the shader that drops fragments, so opaque ones keep the GPU's early depth test.
583
582
 
584
- A hashed surface draws a share of its points that its alpha sets: half of them at an alpha of 0.5. A hash of each point's place on the mesh picks the points, as three.js's `alphaHash` picks them. So the pattern moves with the object and does not crawl as the camera moves. The hash uses integer math, so every GPU draws the same pattern. three.js's pattern differs from GPU to GPU, so the two engines' patterns differ, but each draws the same share of the surface. Hashed objects draw in any order, as masked ones do. They suit fades and see-through surfaces that cross each other, where blending would need a sort. The pattern is noisy up close. `alphaCutoff` has no effect in this mode.
583
+ A hashed surface draws a share of its points that its alpha sets: half of them at an alpha of 0.5. A hash of each point's place on the mesh picks the points. So the pattern moves with the object and does not crawl as the camera moves. The hash uses integer math, so every GPU draws the same pattern. Hashed objects draw in any order, as masked ones do. They suit fades and see-through surfaces that cross each other, where blending would need a sort. The pattern is noisy up close. `alphaCutoff` has no effect in this mode.
585
584
 
586
585
  A blended surface lets what lies behind it show through. Blended objects draw after the opaque ones, farthest first, so each one blends over the objects behind it. A call to `mesh.setRenderOrder(order)` draws an object before or after the others, whatever its depth. The rows of an instance batch sort one by one. The page [Materials and pipelines](../concepts/materials.md#the-transparent-pass) explains the sort. It also says where the sort cannot help.
587
586
 
588
- A blended material writes depth, as three.js's transparent materials do. Give particles, glows and other surfaces that cross `depthWrite: false`, so they never hide each other.
587
+ A blended material writes depth by default. Give particles, glows and other surfaces that cross `depthWrite: false`, so they never hide each other.
589
588
 
590
589
  ```ts
591
590
  // sketch.ts: leaves whose vertex alpha cuts their shape.
@@ -596,9 +595,9 @@ leaves.set({ alphaCutoff: 0.2 });
596
595
 
597
596
  ### Alpha to coverage
598
597
 
599
- A masked surface's cut edges are as smooth as its outer edges, as `alphaToCoverage` is on by default. The alpha fades from nothing at `alphaCutoff` to full over about one pixel, as three.js's `alphaToCoverage` makes it fade. MSAA then draws the surface on that share of each edge pixel's samples. Foliage and fences lose their stair steps, and their objects still draw in any order.
598
+ A masked surface's cut edges are as smooth as its outer edges, as `alphaToCoverage` is on by default. The alpha fades from nothing at `alphaCutoff` to full over about one pixel. MSAA then draws the surface on that share of each edge pixel's samples. Foliage and fences lose their stair steps, and their objects still draw in any order.
600
599
 
601
- This is the best technique for cut-out shapes, so it is the default, as in Filament. three.js's `alphaTest` alone cuts hard edges: give `alphaToCoverage: false` for that look. The option needs MSAA, the default anti-aliasing. With FXAA or no anti-aliasing, as on the Low preset, the mask cuts as without it. On WebGPU, where the scene's colors have no alpha channel, the shader sets the covered samples itself, with the same look. The first such material loads the shader builds of alpha to coverage, and the first hashed material those of the hash. To load them before the first frame instead, list `'coverage'` and `'hash'` in `createEngine`'s `preload` option.
600
+ This is the best technique for cut-out shapes, so it is the default, as in Filament. For hard cut edges, give `alphaToCoverage: false`. The option needs MSAA, the default anti-aliasing. With FXAA or no anti-aliasing, as on the Low preset, the mask cuts as without it. On WebGPU, where the scene's colors have no alpha channel, the shader sets the covered samples itself, with the same look. The first such material loads the shader builds of alpha to coverage, and the first hashed material those of the hash. To load them before the first frame instead, list `'coverage'` and `'hash'` in `createEngine`'s `preload` option.
602
601
 
603
602
  A [custom material](materials.md#custom-materials) takes both, but only where its WGSL sets or reads the surface's `alpha`. Such a material's shadow caster and motion build run that alpha too, so its shadow and its motion keep the mask's holes. WGSL that never names the alpha throws E1217 for `alphaToCoverage` and for the `hash` mode, and it casts its mesh's whole shape, as it did before.
604
603
 
@@ -610,7 +609,7 @@ const fence = materials.standard({ map: fenceTexture, alphaMode: 'mask', alphaTo
610
609
 
611
610
  ## Invisible surfaces that hide
612
611
 
613
- `colorWrite: false` draws a surface that shows nothing itself. It still writes depth, so it hides what lies behind it. Its objects draw before the opaque objects that write color, so the depth it writes holds back their color. Use it for a plane that hides the scene behind a page, as three.js's `colorWrite: false` does.
612
+ `colorWrite: false` draws a surface that shows nothing itself. It still writes depth, so it hides what lies behind it. Its objects draw before the opaque objects that write color, so the depth it writes holds back their color. Use it for a plane that hides the scene behind a page.
614
613
 
615
614
  With the `mask` or `hash` alpha mode, the parts that the alpha drops write no depth either. The surface then cuts a shape out of the space it holds.
616
615
 
@@ -624,9 +623,9 @@ scene.createMesh({ mesh: geometry.plane({ width: 8, height: 6 }), material: hold
624
623
 
625
624
  ## Double-sided blended surfaces
626
625
 
627
- A blended surface with `doubleSided: true` draws in two draws, as three.js draws it. Its back faces draw first, then its front faces. So the near side of a glass box or a sphere always covers its far side, whatever the order of the mesh's triangles. Neighbors that share the mesh and the material draw together: all their back faces, then all their front faces.
626
+ A blended surface with `doubleSided: true` draws in two draws. Its back faces draw first, then its front faces. So the near side of a glass box or a sphere always covers its far side, whatever the order of the mesh's triangles. Neighbors that share the mesh and the material draw together: all their back faces, then all their front faces.
628
627
 
629
- `forceSinglePass: true` draws both faces in one draw, as three.js's `forceSinglePass` does. The triangles then cover each other in the mesh's order. Use it for flat surfaces, such as leaves and planes of glass, whose two faces never overlap on screen: it saves one draw per object. The second draw costs about as much as the first, so it is the speed setting for scenes with many double-sided blended objects. Solid double-sided materials always draw once.
628
+ `forceSinglePass: true` draws both faces in one draw. The triangles then cover each other in the mesh's order. Use it for flat surfaces, such as leaves and planes of glass, whose two faces never overlap on screen: it saves one draw per object. The second draw costs about as much as the first, so it is the speed setting for scenes with many double-sided blended objects. Solid double-sided materials always draw once.
630
629
 
631
630
  ```ts
632
631
  // sketch.ts: a glass globe that shows its far side, and a flat pane that needs one draw.
@@ -645,9 +644,9 @@ const pane = materials.standard({ color: '#a8d8ff', opacity: 0.3, alphaMode: 'bl
645
644
  | `'multiply'` | Tints what lies behind by the surface's color, as far as the alpha says | Stains, shadows painted on, tinted film |
646
645
  | `'weighted'` | Covers what lies behind as `'normal'` does, but blends with the other weighted surfaces in any order | Smoke, dust, clouds of particles, many panes of glass that cross |
647
646
 
648
- The engine blends colors multiplied by their alpha, as three.js does with `premultipliedAlpha: true`. Textures loaded with `premultipliedAlpha: true` blend correctly too.
647
+ The engine blends colors multiplied by their alpha (premultiplied alpha). Textures loaded with `premultipliedAlpha: true` blend correctly too.
649
648
 
650
- The engine blends in linear color, before the tone mapping, as three.js's `WebGPURenderer` does. three.js's `WebGLRenderer` tone maps each surface and encodes it as sRGB first, and then blends it on the canvas. So a see-through surface over a different color looks a little lighter in null3D than in a `WebGLRenderer` port, and an additive glow a little weaker. The [8-bit path](../concepts/color-management.md#the-8-bit-path) of some devices tone maps and encodes each surface first too, so there the engine blends as `WebGLRenderer` does.
649
+ The engine blends in linear color, before the tone mapping. The [8-bit path](../concepts/color-management.md#the-8-bit-path) of some devices is the exception: it tone maps each surface and encodes it as sRGB first, and then blends it. On the HDR path, a see-through surface over a different color therefore looks a little lighter than on the 8-bit path, and an additive glow a little weaker.
651
650
 
652
651
  ```ts
653
652
  // sketch.ts: a pane of glass and a glow that never hides what it crosses.
@@ -659,7 +658,7 @@ const glow = materials.unlit({ color: '#ffb040', alphaMode: 'blend', blending: '
659
658
 
660
659
  Blended objects draw farthest first, and the sort orders whole objects, or the rows of a batch. Surfaces that cross, a large surface around a small one, and puffs of smoke inside each other have no right order. The sort then puts some of them in the wrong order, and they pop as the camera moves. Additive and multiply blending give the same result in any order, so only normal blending needs the sort.
661
660
 
662
- `blending: 'weighted'` blends such surfaces without a sort. The engine uses weighted blended order-independent transparency (McGuire and Bavoil, 2013), as three.js's `OITPassNode` does. Each weighted surface adds its color and its coverage into two targets, in any order, and near surfaces weigh more than far ones. A full-screen step then blends the average color over the scene, as far as the surfaces cover it.
661
+ `blending: 'weighted'` blends such surfaces without a sort. The engine uses weighted blended order-independent transparency (McGuire and Bavoil, 2013). Each weighted surface adds its color and its coverage into two targets, in any order, and near surfaces weigh more than far ones. A full-screen step then blends the average color over the scene, as far as the surfaces cover it.
663
662
 
664
663
  ```ts
665
664
  // sketch.ts: smoke puffs that cross each other, and panes of glass that cross, without popping.
@@ -697,15 +696,15 @@ const engine = await createEngine({ canvas, sketch, momentTransparency: true });
697
696
 
698
697
  `depthBias: { constant, slopeScale }` moves a surface's depth before the depth test. A decal that lies on a wall has the wall's depth, so without a bias the two fight pixel by pixel. Where the depths are exactly equal, no surface is defined to win, and the winner may differ between GPU paths ([The depth prepass](../concepts/quality-presets.md#the-depth-prepass)). A bias toward the camera makes the decal win.
699
698
 
700
- | Field | three.js | What it does |
701
- | --- | --- | --- |
702
- | `constant` | `polygonOffsetUnits` | Steps of the depth buffer's smallest difference. A fraction rounds to the nearest whole number |
703
- | `slopeScale` | `polygonOffsetFactor` | A factor of how steeply the surface's depth changes across the screen. It moves surfaces seen at a grazing angle further |
699
+ | Field | What it does |
700
+ | --- | --- |
701
+ | `constant` | Steps of the depth buffer's smallest difference. A fraction rounds to the nearest whole number |
702
+ | `slopeScale` | A factor of how steeply the surface's depth changes across the screen. It moves surfaces seen at a grazing angle further |
704
703
 
705
- Negative values pull the surface toward the camera, and positive values push it away, as in three.js. The engine draws with reversed depth, and it turns the signs for you. Both fields default to 0.
704
+ Negative values pull the surface toward the camera, and positive values push it away. The engine draws with reversed depth, and it turns the signs for you. Both fields default to 0.
706
705
 
707
706
  ```ts
708
- // sketch.ts: a poster on a wall, as three.js's polygonOffsetFactor: -4, polygonOffsetUnits: -4.
707
+ // sketch.ts: a poster on a wall, pulled toward the camera so that it wins the depth test.
709
708
  const poster = materials.standard({ color: '#e8554e', depthBias: { constant: -4, slopeScale: -4 } });
710
709
  ```
711
710
 
@@ -813,8 +812,8 @@ const sheet = materials.shader({
813
812
  - A surface in the opaque pass reads 0, the far plane, because the copy comes later. A surface in a scene pass or a reflection pass reads 0 too, because its view makes no copy.
814
813
  - The copy is made while a material that declares the input draws, whatever the quality preset says. It costs one full-screen pass and one texture of four bytes for each pixel.
815
814
  - On WebGL2 the copy holds the depth that the device stores. Where the device draws `reversed-gl` depth, `sceneDistance` is less precise. The engine draws `reversed` depth where the browser has `EXT_clip_control`.
816
- - A material that reads the scene's depth takes up to seven textures of its own: its maps' group gives up one slot, so that the copy of the depth fits the fragment stage beside the maps under WebGPU's limit of 16 sampled textures. A material that declares eight textures beside the depth is refused, and development builds throw E1217 and name how many to drop.
817
- - The declaration and the WGSL must agree. Development builds throw E1217 for a declaration that the WGSL never uses, and for WGSL that reads the depth without the declaration. They throw it for a scene input that custom materials do not read yet too.
815
+ - A material that reads the scene's depth samples up to 6 textures of its own, as every custom material does. The copy of the depth takes a slot of its maps' group that those textures leave free. So the fragment stage stays under WebGPU's limit of 16 sampled textures.
816
+ - The declaration and the WGSL must agree. Development builds throw E1217 for a declaration that the WGSL never uses, and for WGSL that reads the depth without the declaration. They throw it too for a scene input that custom materials do not read.
818
817
 
819
818
  [Surface functions](../shaders/surface-functions.md#the-scenes-depth) shows the helpers among the WGSL.
820
819
 
package/docs/api/math.md CHANGED
@@ -69,16 +69,15 @@ The [vector and quaternion math demo](https://github.com/null3d-engine/null3d/tr
69
69
  ## Conventions
70
70
 
71
71
  - Units are meters and radians. Convert degrees with `math.degToRad`.
72
- - Coordinates are right-handed, with +Y up, as in three.js and glTF.
72
+ - Coordinates are right-handed, with +Y up, as in glTF.
73
73
  - A quaternion is (x, y, z, w), in the order that `setRotation` and instance batches use.
74
- - A matrix stores its 16 numbers column by column, as three.js and WebGPU do. Elements 12, 13 and 14 hold the translation.
74
+ - A matrix stores its 16 numbers column by column, as WebGPU does. Elements 12, 13 and 14 hold the translation.
75
75
  - `quat.lookAt` turns an object's +Z axis toward a point, as a mesh's `lookAt` does. Cameras and lights look down their -Z axis, so swap the eye and the target for them.
76
- - `quat.fromEuler` takes radians and three.js's axis orders, such as `'XYZ'`. gl-matrix's `fromEuler` takes degrees.
77
- - Where three.js has the same operation, a helper does three.js's arithmetic, so the results match three.js. The reference below names the matching three.js call, where there is one.
76
+ - `quat.fromEuler` takes radians and an axis order: `'XYZ'`, `'YXZ'`, `'ZXY'`, `'ZYX'`, `'YZX'` or `'XZY'`. The default, `'XYZ'`, turns about the object's own X axis, then its Y axis, then its Z axis. gl-matrix's `fromEuler` takes degrees.
78
77
 
79
78
  ## Colors
80
79
 
81
- The color helpers give linear RGB, the color space that the engine lights in. The color options of materials, lights and the background take hex colors, which are sRGB, and convert them for you, as three.js does. They take three linear components as they are, so the helpers' results go straight into them. The colors of an instance batch are linear too, so convert sRGB colors with the helpers first:
80
+ The color helpers give linear RGB, the color space that the engine lights in. The color options of materials, lights and the background take hex colors, which are sRGB, and convert them for you. They take three linear components as they are, so the helpers' results go straight into them. The colors of an instance batch are linear too, so convert sRGB colors with the helpers first:
82
81
 
83
82
  ```ts
84
83
  // In the setup: a color for each box.
@@ -89,7 +88,7 @@ const boxes = scene.createInstances(geometry.box(), 100, {
89
88
  const rgb = vec3.create();
90
89
  const colors = boxes.colors as Float32Array;
91
90
  for (let i = 0; i < boxes.count; i++) {
92
- color.fromHsl(rgb, i / boxes.count, 0.7, 0.5); // the color three.js's setHSL gives
91
+ color.fromHsl(rgb, i / boxes.count, 0.7, 0.5); // a new hue for each box
93
92
  colors.set(rgb, i * 4);
94
93
  }
95
94
  boxes.markDirty();
@@ -103,7 +102,7 @@ Each row's color multiplies its material's base color and opacity, as [Instances
103
102
  `math.random()` gives a number from 0 up to but not including 1, as `Math.random` does. Each thread has one generator:
104
103
 
105
104
  - It starts from an unpredictable seed, so a live sketch draws new numbers on every run.
106
- - `math.seed(n)` starts it again from the seed `n`, and the same numbers follow on every run. `math.seed(n)` followed by `math.random()` gives what three.js's `MathUtils.seededRandom(n)` gives.
105
+ - `math.seed(n)` starts it again from the seed `n`, and the same numbers follow on every run.
107
106
  - Hold mode seeds it before the sketch loads, and makes `Math.random` draw from it too. A held frame is then the same on every run. See [Testing your sketch](../guides/testing.md).
108
107
  - `math.randFloat`, `math.randInt` and `math.randFloatSpread` draw their numbers from it.
109
108
 
@@ -8,7 +8,7 @@ summary: "Setters and getters; parents; flags; destroy; pointer events."
8
8
 
9
9
  # Objects and transforms
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds pointer events. 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
  Groups, meshes, cameras and lights are objects: nodes in the scene with a position, a rotation, a scale and a parent. Each class extends `Object3D`, so the calls in the first sections of this page work on all of them. Meshes have more calls, which [Mesh calls](#mesh-calls) lists, and [Lights](lights.md) gives the calls of each kind of light.
14
14
 
@@ -44,10 +44,10 @@ export default defineSketch(({ scene, geometry, materials }) => {
44
44
  Each object has a position, a rotation and a scale, all relative to its parent. Positions are in meters and angles in radians.
45
45
 
46
46
  - `setPosition(x, y, z)` and `setScale(x, y, z)` set the position and the scale.
47
- - `setRotation(x, y, z, w)` sets the rotation as a quaternion. `setRotationEuler(x, y, z, order)` sets it from Euler angles, with three.js's axis orders. The default order is `'XYZ'`.
47
+ - `setRotation(x, y, z, w)` sets the rotation as a quaternion. `setRotationEuler(x, y, z, order)` sets it from Euler angles. The order names the axes in turn: the default, `'XYZ'`, turns the object about its own X axis, then its Y axis, then its Z axis. The other orders are `'YXZ'`, `'ZXY'`, `'ZYX'`, `'YZX'` and `'XZY'`.
48
48
  - `setPose(position, rotation)` sets the position and, when you give it, the rotation, from two arrays that hold them: `[x, y, z]` and the quaternion `[x, y, z, w]`. Give it the arrays that a pose lives in, and no number crosses the call. The calls above pass each number on its own. A number passed to a call that the browser does not inline becomes an object of its own. The controls write a camera's pose this way in every frame.
49
- - `rotateX(angle)`, `rotateY(angle)` and `rotateZ(angle)` turn the object about its own axes, as three.js's calls of the same names do.
50
- - `translate(x, y, z)` moves the object along its own axes, as three.js's `translateX`, `translateY` and `translateZ` do together. The object's rotation turns the vector, but its scale does not stretch it. So `camera.translate(0, 0, -1)` moves a camera 1 m forward.
49
+ - `rotateX(angle)`, `rotateY(angle)` and `rotateZ(angle)` turn the object by an angle about its own X, Y or Z axis.
50
+ - `translate(x, y, z)` moves the object along its own axes. The object's rotation turns the vector, but its scale does not stretch it. So `camera.translate(0, 0, -1)` moves a camera 1 m forward.
51
51
  - `lookAt(x, y, z)` turns a mesh or a group so that its +Z axis points at a point. A camera or a light turns its -Z axis there instead. The call assumes that the object's parents are not rotated.
52
52
 
53
53
  Setters write straight into the engine's memory and mark the object as changed. They send no message and allocate nothing, so `onUpdate` can call them for many objects in every frame. In development builds, a setter that gets `NaN` or an infinite number throws E1203.
@@ -60,7 +60,7 @@ Getters copy into an array you pass, so they allocate nothing. Make the array on
60
60
 
61
61
  - `getPosition(out)` copies the position that you set, relative to the parent. In large-world mode it keeps its full precision, so pass a plain array or a `Float64Array`. `getRotation(out)` copies the rotation, as a quaternion (x, y, z, w).
62
62
  - `getWorldPosition(out)` copies the position in the world, and `getWorldQuaternion(out)` the rotation in the world.
63
- - `getWorldMatrix(out)` copies the world matrix: 16 numbers, column by column, as the [math helpers](math.md) and three.js's `matrixWorld` hold them.
63
+ - `getWorldMatrix(out)` copies the world matrix: 16 numbers, column by column, as the [math helpers](math.md) hold them.
64
64
 
65
65
  The world getters read the engine's last transform update. A change that you make in `onUpdate` shows in them in the same frame's `onLateUpdate`, and from the next `onUpdate` call on. Their positions are 64-bit numbers, which keep their precision far from the origin. Pass a plain array or a `Float64Array`, because a `Float32Array` rounds them to 32 bits.
66
66
 
@@ -68,7 +68,7 @@ The world getters read the engine's last transform update. A change that you mak
68
68
 
69
69
  An object gets a parent from the `parent` option, or later from `setParent(parent)`. `setParent(null)` makes it a root object. `getParent()` returns the parent, or null for a root object.
70
70
 
71
- By default the object keeps its position, rotation and scale relative to the parent, as three.js's `add` does. Its place in the world then changes with the new parent. `setParent(parent, { keepWorld: true })` keeps its place, rotation and size in the world instead, as three.js's `attach` does. The engine gives the object the position, rotation and scale that do that under the new parent.
71
+ By default the object keeps its position, rotation and scale relative to the parent. Its place in the world then changes with the new parent. `setParent(parent, { keepWorld: true })` keeps its place, rotation and size in the world instead. The engine gives the object the position, rotation and scale that do that under the new parent.
72
72
 
73
73
  ```ts
74
74
  // Pick up a crate: it stays where it is, then moves with the hand.
@@ -81,7 +81,7 @@ The engine works out those values when it applies the change, after `onUpdate` r
81
81
 
82
82
  Two kinds of parent change the result:
83
83
 
84
- - A parent that is turned and scaled by different amounts on its axes shears its children. No position, rotation and scale can express a shear. The object keeps its place, but its rotation and scale come out close to the old ones. three.js has the same limit.
84
+ - A parent that is turned and scaled by different amounts on its axes shears its children. No position, rotation and scale can express a shear. The object keeps its place, but its rotation and scale come out close to the old ones.
85
85
  - A parent scaled to 0 on an axis flattens its children, and no transform can undo that. The object then keeps its values relative to the parent.
86
86
 
87
87
  Children move with their parent. A static child of a dynamic parent follows it too, because the engine recomputes the child whenever the parent moves.
@@ -96,7 +96,7 @@ A parent loop puts an object under itself, or under an object below it, so it ca
96
96
 
97
97
  These calls change the structure of the scene, so they take effect when the engine processes the frame, after `onUpdate` returns. [Scene](scene.md#when-changes-take-effect) gives the details.
98
98
 
99
- In development builds, every call on an object apart from `describe` throws E1101 once you destroy the object. So does a call that gets a destroyed object, such as `setParent`. Once the frame has removed the object, the world getters throw E1101 in every build. In a release build, the other calls on a destroyed object change nothing, and never reach the object that takes its slot ([Handles](../concepts/handles.md#stale-handles)).
99
+ In development builds, every call on an object apart from `describe` and `off` throws E1101 once you destroy the object. A model's copy also keeps `find` and `setOutlined`, which skip its destroyed parts. So does a call that gets a destroyed object, such as `setParent`. Once the frame has removed the object, the world getters throw E1101 in every build. In a release build, the other calls on a destroyed object change nothing, and never reach the object that takes its slot ([Handles](../concepts/handles.md#stale-handles)).
100
100
 
101
101
  ## Layers
102
102
 
@@ -109,13 +109,13 @@ The mask belongs to the object alone, so its children keep their own. Like `setV
109
109
  A mesh has these calls besides the ones above. Like the structural calls, they take effect in the next frame.
110
110
 
111
111
  - `setMaterial(material)` changes the material, and `setMesh(mesh)` changes the shape. The new mesh's bounding sphere replaces any bounds that `setBounds` gave.
112
- - `setCastShadows(true)` and `setReceiveShadows(true)` make the mesh cast and receive the directional light's shadows, as three.js's `castShadow` and `receiveShadow` do. The `castShadows` and `receiveShadows` options of `createMesh` set them at the start. Both are false by default. Unlit materials show no shadows. [Shadows](../concepts/shadows.md) explains them.
112
+ - `setCastShadows(true)` and `setReceiveShadows(true)` make the mesh cast and receive the shadows of every light that casts them. The `castShadows` and `receiveShadows` options of `createMesh` set them at the start. Both are false by default. Unlit materials show no shadows. [Shadows](../concepts/shadows.md) explains them.
113
113
  - `shaderId` is the number that a custom material reads as `object.id` for the mesh. Pass it to a uniform to pick out the mesh in a shader, as [Built-in shader inputs](../shaders/builtins.md#object) shows.
114
- - `setOutlined(true)` draws an outline around the mesh while `post.set({ outline })` turns outlines on, as adding it to three.js's `OutlinePass.selectedObjects` does. It is false by default. A model's copy from `scene.instantiate` has `setOutlined` too, which outlines each of its meshes. [Outlines](post.md#outlines) gives the outline's settings.
115
- - `setRenderOrder(order)` sets the order in which blended objects draw, lower first, as three.js's `renderOrder` does. Objects of one order draw farthest first. The engine orders opaque and masked objects itself, for speed, as the depth test decides what shows. The order costs nothing: the engine sorts blended objects in every frame anyway. [Materials and pipelines](../concepts/materials.md#the-transparent-pass) explains the sort.
114
+ - `setOutlined(true)` draws an outline around the mesh while `post.set({ outline })` turns outlines on. It is false by default. A model's copy from `scene.instantiate` has `setOutlined` too, which outlines each of its meshes. [Outlines](post.md#outlines) gives the outline's settings.
115
+ - `setRenderOrder(order)` sets the order in which blended objects draw, lower first. Objects of one order draw farthest first. The engine orders opaque and masked objects itself, for speed, as the depth test decides what shows. The order costs nothing: the engine sorts blended objects in every frame anyway. [Materials and pipelines](../concepts/materials.md#the-transparent-pass) explains the sort.
116
116
  - `setMorphWeight(nameOrIndex, weight)` and `getMorphWeight(nameOrIndex)` set and read a morph target's weight: [Morph targets](animation.md#morph-targets).
117
- - `setFrustumCulled(false)` makes the engine draw the mesh even when its bounds are out of view, as three.js's `frustumCulled = false` does.
118
- - `setBounds(center, radius)` gives the object a bounding sphere of its own, which culling tests instead of the mesh's sphere. The center is relative to the object's origin, and both values are before the object's scale. Use it when a shader moves vertices outside the mesh's sphere: bounds that cover the moved vertices keep culling at work, where `setFrustumCulled(false)` turns it off. A group has no sphere of its own, so it needs one wherever a sphere is read, as a directional light's [hero shadow](../concepts/shadows.md#a-hero-shadow) reads it. A negative radius throws E1108 in development builds.
117
+ - `setFrustumCulled(false)` makes the engine draw the mesh even when its bounds are out of view.
118
+ - `setBounds(center, radius)`, which every object has, gives the object a bounding sphere of its own, which culling tests instead of the mesh's sphere. The center is relative to the object's origin, and both values are before the object's scale. Use it when a shader moves vertices outside the mesh's sphere: bounds that cover the moved vertices keep culling at work, where `setFrustumCulled(false)` turns it off. A group has no sphere of its own, so it needs one wherever a sphere is read, as a directional light's [hero shadow](../concepts/shadows.md#a-hero-shadow) reads it. A negative radius throws E1108 in development builds.
119
119
  - `setLevelBias(bias)` raises or lowers the threshold that picks this object's levels of detail, as Godot's `lod_bias` does. A bias above 1 draws coarser levels, and one below 1 keeps the object's detail. The same factor moves the distance at which the object hides. The bias is 1 by default, and does nothing without a mesh that has levels. [Levels of detail](../concepts/lod.md#the-bias-of-one-object) shows it.
120
120
  - `setDrawRange(start, end)` draws the mesh only between those distances from the camera to its nearest point, fading at each edge. [Distance bands](../concepts/lod.md#distance-bands) shows it.
121
121
  - `setOccluder(true)` makes the mesh block the view on WebGL2: the objects wholly behind it skip the GPU while software occlusion culling runs, which every preset leaves off. The `occluder` option of `createMesh` and `instantiate` sets it at the start, and it needs no rebuild. A model that `assets optimize` gave blockers starts with its meshes that have one blocking. On WebGL2, each such mesh draws its blocker in place of its mesh. Mark large, solid meshes of up to 4,096 triangles, such as buildings. Meshes that blend, use an alpha mask or a custom material, or are skinned never block on WebGL2. On WebGPU, GPU occlusion culling needs no mark: every opaque mesh may hide what lies behind it, and `setOccluder(false)` keeps one out. [Culling](../concepts/culling.md#gpu-occlusion-culling-on-webgpu) explains both methods.
@@ -8,7 +8,7 @@ summary: "createParticles: emitters, bursts and sub-emitters; closed-form GPU mo
8
8
 
9
9
  # Particles (@null3d/particles)
10
10
 
11
- > Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Particles do not cast shadows, lights do not light them, and a system does not sort its own particles back to front. Coding agents must not use these parts.
11
+ > Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Particles do not cast shadows, and lights do not light them. A system does not sort its own particles back to front.
12
12
 
13
13
  ```mermaid
14
14
  flowchart LR
@@ -178,7 +178,7 @@ A particle that crosses the ground or a wall shows a hard line where it cuts int
178
178
 
179
179
  ## Drawing
180
180
 
181
- A system is one scene object, with one draw of all its particles. It sorts among the other blended objects by its bounds. Its own particles draw in the order they were born, so `additive` blending, which needs no order, suits most effects. With `normal` blending, keep particles soft and faint, as smoke is.
181
+ A system is one scene object, with one draw of all its particles. The particles blend and write no depth. The system sorts among the other blended objects by its bounds. Its own particles draw in the order they were born, so `additive` blending, which needs no order, suits most effects. With `normal` blending, keep particles soft and faint, as smoke is.
182
182
 
183
183
  The system keeps its object's culling sphere around its live particles, from where they were born and how far they can move. Particles do not cast shadows, and lights do not light them. Fog fades them as it fades other surfaces. Additive particles fade out in fog, and others take on its color.
184
184
 
@@ -192,18 +192,6 @@ Each live particle costs the GPU one quad, whose vertex shader works out its sta
192
192
 
193
193
  The GPU keeps birth times as 32-bit floats. So every 1,024 seconds, a system moves the time that its birth times count from. It rewrites the records' birth times 16,384 at a time, one share per frame, so even a system of a million particles adds no long frame. A system with sub-emitters keeps a table of the events to come, 80 bytes per event. It starts small and doubles while the system warms up, up to one event per sub-emitter for each particle.
194
194
 
195
- ## Compared with three.js
196
-
197
- three.js has no particle system of its own. Projects build one from `THREE.Points` or `InstancedMesh` with a custom shader, and move the particles on the CPU each frame. Others use a library such as three.quarks or three-nebula.
198
-
199
- | three.js | null3D |
200
- | --- | --- |
201
- | `THREE.Points` with a `PointsMaterial`, moved on the CPU | `createParticles`, moved on the GPU |
202
- | A sprite atlas in `PointsMaterial.map` | `map` with `flipbook` |
203
- | `blending: THREE.AdditiveBlending`, `depthWrite: false` | `blending: 'additive'`; particles never write depth |
204
- | Velocity and gravity updated in the loop | `speed`, `gravity`, `drag`, `wind` and `turbulence` |
205
- | three.quarks's `ParticleSystem` and `BatchedRenderer` | `createParticles`, with `system.update()` in `onLateUpdate` |
206
-
207
195
  ## Related pages
208
196
 
209
197
  - [The particle buffer](../concepts/particle-buffer.md): the engine table that holds a system's particles, for emitters that you write yourself.