@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
@@ -47,8 +47,8 @@ Imported names follow two rules:
47
47
  | --- | --- |
48
48
  | [`null3d::math`](#null3dmath) | Constants and small helpers that the other modules share: squares, ranges, a modulo that matches GLSL's `mod`, and rotations. |
49
49
  | [`null3d::noise`](#null3dnoise) | Hashes, random numbers and noise. |
50
- | [`null3d::color`](#null3dcolor) | Color in linear space: sRGB encoding and decoding, luminance, HSV, and the tone mapping curves that three.js offers. |
51
- | [`null3d::lighting`](#null3dlighting) | Lighting in linear color: the Lambert model, and the physically based model of glTF's metallic-roughness materials with the formulas of three.js's MeshStandardMaterial. |
50
+ | [`null3d::color`](#null3dcolor) | Color in linear space: sRGB encoding and decoding, luminance, HSV, and the tone mapping curves AgX, AgX punchy, Khronos PBR Neutral and ACES filmic. |
51
+ | [`null3d::lighting`](#null3dlighting) | Lighting in linear color: the Lambert model, and the physically based model of glTF's metallic-roughness materials, with Lambert diffuse light and a GGX highlight. |
52
52
  | [`null3d::fog`](#null3dfog) | The scene's fog. |
53
53
  | [`null3d::vertex`](#null3dvertex) | Helpers for vertex shaders: instance transforms, and positions relative to the camera. |
54
54
  | [`null3d::depth`](#null3ddepth) | Depth values and distances. |
@@ -97,7 +97,7 @@ One over pi.
97
97
  const EPSILON: f32 = 1e-6;
98
98
  ```
99
99
 
100
- A small positive number that keeps a divisor away from zero, the same as three.js's `EPSILON`.
100
+ A small positive number, one millionth, that keeps a divisor away from zero.
101
101
 
102
102
  ### `square`
103
103
 
@@ -369,7 +369,7 @@ Fractal noise in 2D from simplex noise, from about -1 to 1.
369
369
 
370
370
  ## `null3d::color`
371
371
 
372
- Color in linear space: sRGB encoding and decoding, luminance, HSV, and the tone mapping curves that three.js offers. Shaders light in linear color, and encode sRGB only at the output. The tone mapping curves take linear color that the exposure has already scaled, and return linear color from 0 to 1, ready for sRGB encoding.
372
+ Color in linear space: sRGB encoding and decoding, luminance, HSV, and the tone mapping curves AgX, AgX punchy, Khronos PBR Neutral and ACES filmic. Shaders light in linear color, and encode sRGB only at the output. The tone mapping curves take linear color that the exposure has already scaled, and return linear color from 0 to 1, ready for sRGB encoding.
373
373
 
374
374
  ### `linear_to_srgb`
375
375
 
@@ -409,7 +409,7 @@ A linear color with each channel no brighter than HDR_LIMIT, so that a 16-bit fl
409
409
  fn luminance(c: vec3f) -> f32
410
410
  ```
411
411
 
412
- The relative luminance of a linear color, with the Rec. 709 weights that three.js uses.
412
+ The relative luminance of a linear color, with the Rec. 709 weights 0.2126, 0.7152 and 0.0722.
413
413
 
414
414
  ### `rgb_to_hsv`
415
415
 
@@ -465,7 +465,7 @@ The curve fit of the ACES reference rendering transform and output device transf
465
465
  fn tone_map_aces(c: vec3f) -> vec3f
466
466
  ```
467
467
 
468
- ACES filmic tone mapping, as three.js's `ACESFilmicToneMapping`. Like three.js, it scales the color by 1 / 0.6 first, which suits a bright viewing place.
468
+ ACES filmic tone mapping, a fit of the ACES curve. It scales the color by 1 / 0.6 first, which suits a bright viewing place.
469
469
 
470
470
  ### `LINEAR_REC2020_TO_LINEAR_SRGB`
471
471
 
@@ -545,7 +545,7 @@ AgX's default contrast curve, as a polynomial fit.
545
545
  fn tone_map_agx(c: vec3f) -> vec3f
546
546
  ```
547
547
 
548
- AgX tone mapping, as three.js's `AgXToneMapping`, in Rec. 2020 primaries.
548
+ AgX tone mapping, the curve of Blender and Filament, in Rec. 2020 primaries.
549
549
 
550
550
  ### `AGX_PUNCHY_POWER`
551
551
 
@@ -577,11 +577,11 @@ AgX tone mapping with Filament's punchy look: more contrast and more color than
577
577
  fn tone_map_neutral(c: vec3f) -> vec3f
578
578
  ```
579
579
 
580
- Khronos PBR Neutral tone mapping, as three.js's `NeutralToneMapping`. It keeps base colors under about 0.8 as they are, apart from a small offset.
580
+ Khronos PBR Neutral tone mapping. It keeps base colors under about 0.8 as they are, apart from a small offset.
581
581
 
582
582
  ## `null3d::lighting`
583
583
 
584
- Lighting in linear color: the Lambert model, and the physically based model of glTF's metallic-roughness materials with the formulas of three.js's MeshStandardMaterial. Directions are unit vectors that point away from the surface: `to_light` toward the light and `to_view` toward the camera. Light colors include the intensity.
584
+ Lighting in linear color: the Lambert model, and the physically based model of glTF's metallic-roughness materials, with Lambert diffuse light and a GGX highlight. Directions are unit vectors that point away from the surface: `to_light` toward the light and `to_view` toward the camera. Light colors include the intensity.
585
585
 
586
586
  ### `ROUGHNESS_FLOOR`
587
587
 
@@ -589,7 +589,7 @@ Lighting in linear color: the Lambert model, and the physically based model of g
589
589
  const ROUGHNESS_FLOOR: f32 = 0.045;
590
590
  ```
591
591
 
592
- The lowest perceptual roughness of a surface, as Filament and three.js r187 have it: even a mirror shows a highlight of this width, and reads a prefiltered level of the environment.
592
+ The lowest perceptual roughness of a surface, as Filament has it. Even a mirror shows a highlight of this width, and reads a prefiltered level of the environment.
593
593
 
594
594
  ### `SPECULAR_AA_VARIANCE`
595
595
 
@@ -613,7 +613,7 @@ The most that the specular anti-aliasing kernel adds to the squared GGX alpha, s
613
613
  fn lambert(albedo: vec3f, normal: vec3f, to_light: vec3f, light: vec3f, ambient: vec3f) -> vec3f
614
614
  ```
615
615
 
616
- The light a Lambert surface reflects under one directional light and ambient light, as three.js's MeshLambertMaterial computes it. It is the albedo over pi times the irradiance. The direction `to_light` points from the surface toward the light. The colors `light` and `ambient` include their intensities.
616
+ The light a Lambert surface reflects under one directional light and ambient light. It is the albedo over pi times the irradiance. The direction `to_light` points from the surface toward the light. The colors `light` and `ambient` include their intensities.
617
617
 
618
618
  ### `brdf_lambert`
619
619
 
@@ -621,7 +621,7 @@ The light a Lambert surface reflects under one directional light and ambient lig
621
621
  fn brdf_lambert(diffuse: vec3f) -> vec3f
622
622
  ```
623
623
 
624
- The Lambert diffuse reflectance: the diffuse color over pi, as three.js's `BRDF_Lambert`.
624
+ The Lambert diffuse reflectance: the diffuse color over pi.
625
625
 
626
626
  ### `f_schlick`
627
627
 
@@ -629,7 +629,7 @@ The Lambert diffuse reflectance: the diffuse color over pi, as three.js's `BRDF_
629
629
  fn f_schlick(f0: vec3f, f90: f32, v_dot_h: f32) -> vec3f
630
630
  ```
631
631
 
632
- Schlick's Fresnel term, in the form with `exp2` that Epic gave and three.js's `F_Schlick` uses. It is the reflectance at a half vector whose cosine with the view is `v_dot_h`. It runs from `f0` at normal incidence to `f90` at grazing angles.
632
+ Schlick's Fresnel term, in the form with `exp2` that Epic gave. It is the reflectance at a half vector whose cosine with the view is `v_dot_h`. It runs from `f0` at normal incidence to `f90` at grazing angles.
633
633
 
634
634
  ### `d_ggx`
635
635
 
@@ -637,7 +637,7 @@ Schlick's Fresnel term, in the form with `exp2` that Epic gave and three.js's `F
637
637
  fn d_ggx(alpha: f32, n_dot_h: f32) -> f32
638
638
  ```
639
639
 
640
- The GGX normal distribution, as three.js's `D_GGX`. `alpha` is the square of the perceptual roughness.
640
+ The GGX normal distribution. `alpha` is the square of the perceptual roughness.
641
641
 
642
642
  ### `v_ggx_smith_correlated`
643
643
 
@@ -645,7 +645,7 @@ The GGX normal distribution, as three.js's `D_GGX`. `alpha` is the square of the
645
645
  fn v_ggx_smith_correlated(alpha: f32, n_dot_l: f32, n_dot_v: f32) -> f32
646
646
  ```
647
647
 
648
- The height-correlated Smith visibility term of GGX, as three.js's `V_GGX_SmithCorrelated`. It includes the 1 / (4 n.l n.v) of the microfacet model.
648
+ The height-correlated Smith visibility term of GGX. It includes the 1 / (4 n.l n.v) of the microfacet model.
649
649
 
650
650
  ### `brdf_ggx`
651
651
 
@@ -653,7 +653,7 @@ The height-correlated Smith visibility term of GGX, as three.js's `V_GGX_SmithCo
653
653
  fn brdf_ggx(to_light: vec3f, to_view: vec3f, normal: vec3f, f0: vec3f, f90: f32, roughness: f32) -> vec3f
654
654
  ```
655
655
 
656
- The GGX specular reflectance for one light, as three.js's `BRDF_GGX`: the GGX distribution, Schlick's Fresnel term and the correlated Smith visibility term. `roughness` is perceptual. Where the light and the view cancel there is no half vector, and the result is zero.
656
+ The GGX specular reflectance for one light: the GGX distribution, Schlick's Fresnel term and the correlated Smith visibility term. `roughness` is perceptual. Where the light and the view cancel there is no half vector, and the result is zero.
657
657
 
658
658
  ### `v_ggx_smith_correlated_anisotropic`
659
659
 
@@ -661,7 +661,7 @@ The GGX specular reflectance for one light, as three.js's `BRDF_GGX`: the GGX di
661
661
  fn v_ggx_smith_correlated_anisotropic(alpha_t: f32, alpha_b: f32, t_dot_v: f32, b_dot_v: f32, t_dot_l: f32, b_dot_l: f32, n_dot_v: f32, n_dot_l: f32) -> f32
662
662
  ```
663
663
 
664
- The height-correlated Smith visibility term of a lobe whose GGX alpha is `alpha_t` along the tangent and `alpha_b` along the bitangent, as three.js's `V_GGX_SmithCorrelated_Anisotropic`. The cosines `t_dot_v`, `b_dot_v`, `t_dot_l` and `b_dot_l` are of the view and the light with those two axes.
664
+ The height-correlated Smith visibility term of a lobe whose GGX alpha is `alpha_t` along the tangent and `alpha_b` along the bitangent. The cosines `t_dot_v`, `b_dot_v`, `t_dot_l` and `b_dot_l` are of the view and the light with those two axes.
665
665
 
666
666
  ### `d_ggx_anisotropic`
667
667
 
@@ -669,7 +669,7 @@ The height-correlated Smith visibility term of a lobe whose GGX alpha is `alpha_
669
669
  fn d_ggx_anisotropic(alpha_t: f32, alpha_b: f32, n_dot_h: f32, t_dot_h: f32, b_dot_h: f32) -> f32
670
670
  ```
671
671
 
672
- The GGX distribution of a lobe that stretches along the tangent, as three.js's `D_GGX_Anisotropic`, after Filament. The cosines `t_dot_h` and `b_dot_h` are of the half vector with the tangent and the bitangent.
672
+ The GGX distribution of a lobe that stretches along the tangent, after Filament. The cosines `t_dot_h` and `b_dot_h` are of the half vector with the tangent and the bitangent.
673
673
 
674
674
  ### `brdf_ggx_physical`
675
675
 
@@ -677,7 +677,7 @@ The GGX distribution of a lobe that stretches along the tangent, as three.js's `
677
677
  fn brdf_ggx_physical(m: PbrMaterial, normal: vec3f, to_view: vec3f, to_light: vec3f) -> vec3f
678
678
  ```
679
679
 
680
- The GGX specular reflectance for one direct light of a physical material, as three.js's `BRDF_GGX`: the distribution, the Fresnel term and the visibility term, with the thin film's Fresnel term where the material is iridescent, and stretched along the tangent where it is anisotropic. Where the light and the view cancel there is no half vector, and the result is zero.
680
+ The GGX specular reflectance for one direct light of a physical material: the distribution, the Fresnel term and the visibility term. The thin film's Fresnel term mixes in where the material is iridescent, and the lobe stretches along the tangent where it is anisotropic. Where the light and the view cancel there is no half vector, and the result is zero.
681
681
 
682
682
  ### `dfg_lut`
683
683
 
@@ -685,7 +685,7 @@ The GGX specular reflectance for one direct light of a physical material, as thr
685
685
  fn dfg_lut(n_dot_v: f32, roughness: f32) -> vec2f
686
686
  ```
687
687
 
688
- The scale and bias of the split-sum approximation of specular light from all directions, for a view at `n_dot_v` and a perceptual `roughness`. It reads three.js's table of these terms, as three.js does, filtered between the nearest four entries. The engine binds the table in group 0 at binding 3 of its mesh pipelines, and a shader that calls this function binds it there too. On WebGL2 the table sits in the material table's texture instead. The function reads the table with `textureLoad`, so the table needs no sampler and no filterable format.
688
+ The scale and bias of the split-sum approximation of specular light from all directions, for a view at `n_dot_v` and a perceptual `roughness`. It reads the engine's 16 x 16 table of these terms, with the roughness across and the cosine down, filtered between the nearest four entries. The table sits in the materials' custom values, group 0 at binding 2, and on WebGL2 in the material table's texture, group 0 at binding 1. A shader that calls this function binds the texture of its path there too. The function reads the table with `textureLoad`, so the table needs no sampler and no filterable format.
689
689
 
690
690
  ### `environment_brdf`
691
691
 
@@ -693,7 +693,7 @@ The scale and bias of the split-sum approximation of specular light from all dir
693
693
  fn environment_brdf(f0: vec3f, f90: f32, dfg: vec2f) -> vec3f
694
694
  ```
695
695
 
696
- The specular reflectance of light from the environment, from the split-sum terms `dfg`, as three.js's `EnvironmentBRDF`.
696
+ The specular reflectance of light from the environment, from the split-sum terms `dfg`: `f0` times the scale plus `f90` times the bias.
697
697
 
698
698
  ### `Scattering`
699
699
 
@@ -715,7 +715,7 @@ Light that a surface's microfacets reflect once, and light that they reflect mor
715
715
  fn multiscattering(f0: vec3f, f90: f32, dfg: vec2f) -> Scattering
716
716
  ```
717
717
 
718
- The single and multiple scattering of light from all directions, after Fdez-Agüera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting". It follows three.js's `computeMultiscattering`. `dfg` holds the split-sum terms.
718
+ The single and multiple scattering of light from all directions, after Fdez-Agüera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting". `dfg` holds the split-sum terms.
719
719
 
720
720
  ### `multiscatter_compensation`
721
721
 
@@ -723,7 +723,7 @@ The single and multiple scattering of light from all directions, after Fdez-Agü
723
723
  fn multiscatter_compensation(f0: vec3f, dfg: vec2f) -> vec3f
724
724
  ```
725
725
 
726
- The factor that gives direct specular light back the energy that single scattering loses on rough surfaces, after Turquin. It follows three.js's `multiScatteringCompensation`. `f0` is the reflectance at normal incidence, blended toward the base color by metalness.
726
+ The factor that gives direct specular light back the energy that single scattering loses on rough surfaces, after Turquin. Its input `f0` is the reflectance at normal incidence, blended toward the base color by metalness.
727
727
 
728
728
  ### `specular_occlusion`
729
729
 
@@ -731,7 +731,7 @@ The factor that gives direct specular light back the energy that single scatteri
731
731
  fn specular_occlusion(n_dot_v: f32, occlusion: f32, roughness: f32) -> f32
732
732
  ```
733
733
 
734
- How much of the environment's specular light ambient occlusion lets through, after Lagarde and de Rousiers. It follows three.js's `computeSpecularOcclusion`.
734
+ How much of the environment's specular light ambient occlusion lets through, after Lagarde and de Rousiers.
735
735
 
736
736
  ### `horizon_occlusion`
737
737
 
@@ -755,7 +755,7 @@ The amount that specular anti-aliasing adds to the squared GGX alpha: Filament's
755
755
  fn distance_attenuation(distance: f32, cutoff: f32, decay: f32) -> f32
756
756
  ```
757
757
 
758
- How a point or spot light fades with `distance`, as three.js's `getDistanceAttenuation`: one over the distance to the power `decay`. When `cutoff` is more than 0, the light also fades smoothly to nothing at that distance.
758
+ How a point or spot light fades with `distance`: one over the distance to the power `decay`, at most 100. When `cutoff` is more than 0, the light also fades smoothly to nothing at that distance, by the square of 1 less (distance / cutoff)^4.
759
759
 
760
760
  ### `spot_attenuation`
761
761
 
@@ -763,7 +763,7 @@ How a point or spot light fades with `distance`, as three.js's `getDistanceAtten
763
763
  fn spot_attenuation(cone_cos: f32, penumbra_cos: f32, angle_cos: f32) -> f32
764
764
  ```
765
765
 
766
- How a spot light fades toward the edge of its cone, as three.js's `getSpotAttenuation`. The arguments are cosines: of the cone's half angle, of the angle where the penumbra starts, and of the angle to the point.
766
+ How a spot light fades toward the edge of its cone: a smooth step from 0 at the edge to 1 where the penumbra starts. The arguments are cosines: of the cone's half angle, of the angle where the penumbra starts, and of the angle to the point.
767
767
 
768
768
  ### `hemisphere_irradiance`
769
769
 
@@ -771,7 +771,7 @@ How a spot light fades toward the edge of its cone, as three.js's `getSpotAttenu
771
771
  fn hemisphere_irradiance(normal: vec3f, up: vec3f, sky: vec3f, ground: vec3f) -> vec3f
772
772
  ```
773
773
 
774
- The irradiance of a hemisphere light, as three.js's `getHemisphereLightIrradiance`. It blends from the ground color to the sky color as the normal turns toward `up`.
774
+ The irradiance of a hemisphere light. It blends from the ground color to the sky color as the normal turns toward `up`. The sky color's weight is half of 1 plus the cosine between the normal and `up`.
775
775
 
776
776
  ### `ambient_irradiance`
777
777
 
@@ -787,7 +787,7 @@ The irradiance at a unit `normal` from ambient and hemisphere lights, summed as
787
787
  fn sh_irradiance(normal: vec3f, sh: array<vec3f, 9>) -> vec3f
788
788
  ```
789
789
 
790
- The irradiance at a unit `normal` from nine spherical harmonics coefficients in three.js's order, as three.js's `shGetIrradianceAt` computes it for light probes.
790
+ The irradiance at a unit `normal` from nine spherical harmonics coefficients, with Ramamoorthi and Hanrahan's constants. The coefficients are in band order: the constant term, then y, z and x, then xy, yz, 3z^2 - 1, xz and x^2 - y^2.
791
791
 
792
792
  ### `PbrMaterial`
793
793
 
@@ -813,7 +813,7 @@ struct PbrMaterial {
813
813
  }
814
814
  ```
815
815
 
816
- A surface of glTF's metallic-roughness model at one point, set up for lighting as three.js sets up MeshStandardMaterial.
816
+ A surface of glTF's metallic-roughness model at one point, set up for lighting.
817
817
 
818
818
  - `base_color`: The base color, which metals reflect.
819
819
  - `diffuse`: The color of diffuse light: the base color without its metallic part.
@@ -837,7 +837,7 @@ A surface of glTF's metallic-roughness model at one point, set up for lighting a
837
837
  fn pbr_material(base_color: vec3f, metalness: f32, roughness: f32, kernel: f32) -> PbrMaterial
838
838
  ```
839
839
 
840
- Sets up a PbrMaterial as three.js does, with Filament's specular anti-aliasing. It adds `kernel`, from `specular_aa_kernel`, to the squared GGX alpha of `roughness`, then keeps the result from ROUGHNESS_FLOOR to 1. Pass a kernel of 0 to leave the anti-aliasing out.
840
+ Sets up a PbrMaterial from glTF's base color, metalness and perceptual roughness, with Filament's specular anti-aliasing. It adds `kernel`, from `specular_aa_kernel`, to the squared GGX alpha of `roughness`, then keeps the result from ROUGHNESS_FLOOR to 1. Pass a kernel of 0 to leave the anti-aliasing out.
841
841
 
842
842
  ### `with_specular`
843
843
 
@@ -845,7 +845,7 @@ Sets up a PbrMaterial as three.js does, with Filament's specular anti-aliasing.
845
845
  fn with_specular(m: PbrMaterial, reflectance: f32, color: vec3f, intensity: f32) -> PbrMaterial
846
846
  ```
847
847
 
848
- A PbrMaterial with the dielectric specular values of glTF's KHR_materials_ior and KHR_materials_specular. It sets them as three.js's MeshPhysicalMaterial does. `reflectance` is `((ior - 1) / (ior + 1))^2`, which the color tints up to a reflectance of 1, and `intensity` scales. Metals keep their base color, and their grazing reflectance stays 1. A reflectance of 0.04 with a white color at full intensity gives `m` back unchanged.
848
+ A PbrMaterial with the dielectric specular values of glTF's KHR_materials_ior and KHR_materials_specular. `reflectance` is `((ior - 1) / (ior + 1))^2`, which the color tints up to a reflectance of 1, and `intensity` scales. Metals keep their base color, and their grazing reflectance stays 1. A reflectance of 0.04 with a white color at full intensity gives `m` back unchanged.
849
849
 
850
850
  ### `Reflected`
851
851
 
@@ -867,7 +867,7 @@ Light that a surface reflects toward the camera, in its diffuse and specular par
867
867
  fn direct_light(m: PbrMaterial, normal: vec3f, to_view: vec3f, to_light: vec3f, light: vec3f, compensation: vec3f) -> Reflected
868
868
  ```
869
869
 
870
- The light that a PBR surface reflects from one direct light, as three.js's `RE_Direct_Physical`. `light` is the light's color after attenuation and shadows. `compensation` comes from `multiscatter_compensation`. The diffuse part leaves out the light that the specular layer reflects.
870
+ The light that a PBR surface reflects from one direct light. `light` is the light's color after attenuation and shadows. `compensation` comes from `multiscatter_compensation`. The diffuse part leaves out the light that the specular layer reflects.
871
871
 
872
872
  ### `indirect_diffuse`
873
873
 
@@ -875,7 +875,7 @@ The light that a PBR surface reflects from one direct light, as three.js's `RE_D
875
875
  fn indirect_diffuse(m: PbrMaterial, irradiance: vec3f, dfg: vec2f) -> vec3f
876
876
  ```
877
877
 
878
- The diffuse light that a PBR surface reflects from ambient, hemisphere and probe light, as three.js's `RE_IndirectDiffuse_Physical`. It leaves out the light that the specular layer reflects. `dfg` holds the split-sum terms.
878
+ The diffuse light that a PBR surface reflects from ambient, hemisphere and probe light. It leaves out the light that the specular layer reflects. `dfg` holds the split-sum terms.
879
879
 
880
880
  ### `indirect_specular`
881
881
 
@@ -883,7 +883,7 @@ The diffuse light that a PBR surface reflects from ambient, hemisphere and probe
883
883
  fn indirect_specular(m: PbrMaterial, radiance: vec3f, irradiance: vec3f, dfg: vec2f) -> Reflected
884
884
  ```
885
885
 
886
- The light that a PBR surface reflects from an environment map, as three.js's `RE_IndirectSpecular_Physical`. The prefiltered reflection is `radiance`, and the environment's diffuse light is `irradiance`. The split-sum terms are in `dfg`.
886
+ The light that a PBR surface reflects from an environment map. The prefiltered reflection is `radiance`, and the environment's diffuse light is `irradiance`. The split-sum terms are in `dfg`.
887
887
 
888
888
  ## `null3d::fog`
889
889
 
@@ -929,7 +929,7 @@ struct Fog {
929
929
  shape: vec4f,
930
930
  sun_glow: f32,
931
931
  sun_exponent: f32,
932
- spare: f32,
932
+ background: f32,
933
933
  curve: u32,
934
934
  }
935
935
  ```
@@ -940,7 +940,7 @@ The scene's fog, as the engine writes it into each frame's values for the camera
940
940
  - `shape`: Where linear fog starts in `x`, and where it hides everything in `y`. How fast the fog thins with height in `z`: 0 for fog that is the same at every height. In `w`, the fog's density at the camera's height, as a share of its density at its base height.
941
941
  - `sun_glow`: How much of the sun's light the fog scatters toward the camera: 0 for no glow.
942
942
  - `sun_exponent`: The power of the glow's fall away from the sun: higher values make the glow smaller.
943
- - `spare`: Fills the block to a multiple of 16 bytes.
943
+ - `background`: How much of the fog the background takes, from 0 to 1: 1 gives the sky and a cube map the fog of a surface at the camera's far plane, 0 leaves them unfogged.
944
944
  - `curve`: The fog's curve: `OFF`, `LINEAR`, `EXP2` or `EXPONENTIAL`.
945
945
 
946
946
  ### `fog_linear`
@@ -949,7 +949,7 @@ The scene's fog, as the engine writes it into each frame's values for the camera
949
949
  fn fog_linear(distance: f32, near: f32, far: f32) -> f32
950
950
  ```
951
951
 
952
- The factor of linear fog, as three.js's `Fog`: 0 up to `near`, 1 from `far`, and a smooth step between them. `near` must be less than `far`.
952
+ The factor of linear fog: 0 up to `near`, 1 from `far`, and a smooth step between them. `near` must be less than `far`.
953
953
 
954
954
  ### `fog_exp2`
955
955
 
@@ -957,7 +957,7 @@ The factor of linear fog, as three.js's `Fog`: 0 up to `near`, 1 from `far`, and
957
957
  fn fog_exp2(distance: f32, density: f32) -> f32
958
958
  ```
959
959
 
960
- The factor of exponential squared fog, as three.js's `FogExp2`, for a `density` such as 0.02.
960
+ The factor of exponential squared fog, 1 - exp(-(density × distance)²), for a `density` such as 0.02.
961
961
 
962
962
  ### `fog_exponential`
963
963
 
@@ -999,6 +999,30 @@ fn apply_fog(c: vec3f, fog_color: vec3f, factor: f32) -> vec3f
999
999
 
1000
1000
  A color seen through fog: `c` blended toward `fog_color` by the fog factor.
1001
1001
 
1002
+ ### `background_share`
1003
+
1004
+ ```wgsl
1005
+ fn background_share(fog: Fog, direction: vec3f, far: f32) -> f32
1006
+ ```
1007
+
1008
+ The share of fog over the background along `direction`, `far` from the camera, from 0, no fog, to `fog.background`, the most that the background takes. It is the fog that a surface at that distance takes, so the far edge of the land and the sky behind it meet on one color. The direction's rise shortens the path through fog that thins with height, which leaves the sky overhead lighter than the haze at the horizon.
1009
+
1010
+ ### `fogged_background`
1011
+
1012
+ ```wgsl
1013
+ fn fogged_background(fog: Fog, color: vec3f, direction: vec3f, far: f32, light_direction: vec3f, light_color: vec3f) -> vec3f
1014
+ ```
1015
+
1016
+ A background's exposed linear color after the fog, mixed toward the fog's own as the mesh shaders mix theirs: the fog color plus the light that the fog scatters toward the camera.
1017
+
1018
+ ### `background_clear`
1019
+
1020
+ ```wgsl
1021
+ fn background_clear(fog: Fog, direction: vec3f, far: f32) -> f32
1022
+ ```
1023
+
1024
+ How much of a background's own light survives the fog along `direction`, `far` from the camera: 1 where the background takes no fog, and 0 where the fog hides everything. A light that a pass adds over the sky, such as a cloud's, dims by this, so it sits in the fog that the sky behind it takes instead of standing out of it.
1025
+
1002
1026
  ## `null3d::vertex`
1003
1027
 
1004
1028
  Helpers for vertex shaders: instance transforms, and positions relative to the camera. The engine stores each instance's world transform as three rows of a 3 x 4 affine matrix. It draws everything relative to the camera, so positions stay precise far from the origin. Each frame, it moves each transform by the offset from the camera to the transform's grid cell. The frame's view-projection matrix then puts the camera at the origin.
@@ -1109,7 +1133,7 @@ A position relative to the camera in clip space, through a view-projection matri
1109
1133
 
1110
1134
  ## `null3d::depth`
1111
1135
 
1112
- Depth values and distances. The engine draws with reversed depth on both GPU paths. Depth is 1 at the near plane and 0 at the far plane, which spreads a float's precision evenly over distance. Both paths store the same depth values, so these helpers work on each. View-space z is negative in front of the camera, as in three.js.
1136
+ Depth values and distances. The engine draws with reversed depth on both GPU paths. Depth is 1 at the near plane and 0 at the far plane, which spreads a float's precision evenly over distance. Both paths store the same depth values, so these helpers work on each. View-space z is negative in front of the camera.
1113
1137
 
1114
1138
  ### `perspective_depth_to_view_z`
1115
1139
 
@@ -8,7 +8,7 @@ summary: "The surface record; normals for the diffuse light and the sky's light;
8
8
 
9
9
  # Surface functions
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds typed uniforms, textures, values per row of a batch, the diffuse transmission fields, the clear coat and sheen fields, the second texture coordinates, the pixel's position and the instance's index. Step 0.3 adds a material's own specular lobe, the coverage that a shadow caster tests and the surface's shadow offset. It also adds the normals for the diffuse light and the sky's light, and the occlusion that counts once. 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
  A surface function changes how a material's surface looks, and keeps the engine's lighting. You write it in WGSL. For each pixel, the engine gives it a `SurfaceInput`, and it returns a `Surface`: the base color, roughness, metalness, normal and light of that point. The engine then lights the surface with the scene's lights and shadows, as it lights a standard material. The function works on every GPU path, because the null3D Vite plugin builds it into the standard material's shader for WebGPU and WebGL2.
14
14
 
@@ -59,11 +59,10 @@ The engine fills a `SurfaceInput` for each pixel. Positions and directions are i
59
59
  | `frontFacing` | `bool` | True on the front face of a triangle |
60
60
  | `fragCoord` | `vec3f` | The pixel's position: `x` and `y` in pixels from the top left corner of the target, at the pixel's center, and `z` its depth, 1 at the near plane and 0 at the far plane |
61
61
  | `instance` | `u32` | The instance's row in its batch, from 0. It is 0 for an object of the scene |
62
- | `vertexRecord` | `vec4f` | The mesh's four-number vertex record, for a generated shape: the position that the vertex takes at a coarser level of detail and that level's error, or whatever the shape writes |
63
62
 
64
63
  `fragCoord` counts from the top left on every GPU path, in the pixels of `frame.resolution`. GLSL's `gl_FragCoord` counts from the bottom left, so a port that reads `gl_FragCoord.y` reads `frame.resolution.y - input.fragCoord.y`.
65
64
 
66
- The plugin gives a material the inputs that cost something only where its WGSL reads them: `uv1`, `colors`, `instance`, and the object's matrices and id. [Built-in shader inputs](builtins.md#what-the-inputs-cost) lists their costs.
65
+ The plugin gives a material the inputs that cost something only where its WGSL reads them: `uv1`, `colors`, `instance`, `vertexRecord`, `tangent`, and the object's matrices and id. [Built-in shader inputs](builtins.md#what-the-inputs-cost) lists their costs.
67
66
 
68
67
  ## The surface
69
68
 
@@ -316,7 +315,7 @@ const wall = materials.shader({ wgsl: facade, textures: { facades } });
316
315
  - A texture that does not go straight to a texture function.
317
316
  - `textureNumLayers` of a texture that the WGSL declares as a 2D texture.
318
317
 
319
- Full shaders take no textures in this version.
318
+ Full shaders take no textures.
320
319
 
321
320
  ## Reflections
322
321
 
@@ -386,8 +385,8 @@ fn surface(input: SurfaceInput) -> Surface {
386
385
  - A surface that draws before the copy exists reads 0, the far plane. That is a surface in the opaque pass, and any surface in a scene pass or a reflection pass.
387
386
  - The engine makes the copy while a material that declares the input draws, whatever the quality preset says.
388
387
  - `sceneDistance` takes a perspective and an orthographic camera. On WebGL2, the values are the depth that the device stores, so a device that draws `reversed-gl` depth gives less precise distances.
389
- - A material that reads the scene's depth takes up to seven textures of its own. Its maps' group gives up one slot, which leaves the copy of the depth the fragment stage's last sampled texture.
390
- - Development builds throw E1217 when the declaration and the WGSL disagree, and for a material with both the depth and eight textures.
388
+ - A material that reads the scene's depth takes up to 6 textures of its own, as every custom material does. The copy of the depth binds in a group of its own, so it takes none of their slots.
389
+ - Development builds throw E1217 when the declaration and the WGSL disagree.
391
390
 
392
391
  [Custom materials](../api/materials.md#the-scene-behind-a-surface) gives the options and the cases where an input is absent.
393
392
 
@@ -487,7 +486,7 @@ const stone = materials.shader({ wgsl: wet, color: '#8d8a84', roughness: 0.85 })
487
486
  ```
488
487
 
489
488
  - Only WGSL that sets or reads one of the fields builds the shaders that light the layers. Such a material always has them, and its layer options give `defaultSurface` their values. A layer option on a material whose WGSL never names the fields throws E1217.
490
- - The three iridescence fields work as the coat's and the sheen's do. Anisotropy needs the standard material's tangent frame, which a surface function does not have, so a custom material cannot set it yet.
489
+ - The three iridescence fields work as the coat's and the sheen's do. Anisotropy needs the standard material's tangent frame, which a surface function does not have, so a custom material cannot set it.
491
490
  - Ripples on the water of a wet surface only need `clearcoatNormal`: the coat then shows them while the stone under it stays still.
492
491
 
493
492
  ## Vertex offsets
@@ -513,6 +512,8 @@ The engine calls the function once for each vertex, with a `VertexInput`:
513
512
  | `uv1` | `vec2f` | The vertex's second texture coordinates, or its first on a mesh with one set |
514
513
  | `colors` | `vec4f` | The mesh's vertex color, which a vertex offset reads as data, such as a branch index and a phase for wind. A material whose WGSL reads it draws only a mesh with vertex colors: a mesh without them draws nothing with it |
515
514
  | `instance` | `u32` | The instance's row in its batch, from 0. It is 0 for an object of the scene |
515
+ | `vertexRecord` | `vec4f` | The mesh's four-number vertex record, for a generated shape: the position that the vertex takes at a coarser level of detail and that level's error, or whatever the shape writes. The mesh carries it with `geometry.fromArrays({ targets })` |
516
+ | `tangent` | `vec4f` | The mesh's tangent attribute, as the mesh stores it, which a vertex offset can read as data |
516
517
 
517
518
  The row lets a vertex offset lay out a batch by itself, with no values from the sketch. This one lines up a batch's rows in a ring of 64, each lifted by a wave:
518
519
 
@@ -551,7 +552,7 @@ const card = materials.shader({
551
552
  - The caster reads the coverage in the light's view, so a card that turns toward the light cuts its shadow from the side that the light sees.
552
553
  - WGSL that declares a coverage function gets the caster builds, with a fragment stage on both GPU paths. A material that declares neither a vertex offset, a coverage function nor a surface alpha casts its whole shape through the engine's own depth template.
553
554
  - A caster of flat geometry draws both faces. The shadow pass culls the front faces of single-sided geometry, so a flat single-sided caster is culled whole and casts nothing; such a material sets `doubleSided: true`.
554
- - The caster tests the coverage under the material's `alphaCutoff`, so the material takes the `mask` alpha mode. A development build refuses a coverage function on a material that is not masked, because its caster would drop no texel and cast the whole shape.
555
+ - The caster tests the coverage under the material's `alphaCutoff`. So the material takes the `mask` alpha mode, or the `blend` mode with an `alphaCutoff`, which its caster tests. A development build refuses a coverage function on any other material, because its caster would drop no texel and cast the whole shape.
555
556
  - A surface function moves where the sun's shadow lookup reads by setting `s.shadowOffset`, in world space relative to the point. A stand-in card sets it to the surface that the stored depth shows, so the card takes the shadow that falls on the surface it shows rather than on its own plane, and its own cast does not darken it. `defaultSurface` leaves it zero.
556
557
  - A mesh's vertex record reaches the vertex offset as `input.vertexRecord` only where the WGSL reads it, and the mesh must then carry it, with `geometry.fromArrays({ targets })`. The record holds either the shape's four numbers or a morphed mesh's morph data, never both.
557
558
 
@@ -586,7 +587,7 @@ A custom material's levels of detail fade, and so do the edges of its distance b
586
587
 
587
588
  ## Built-in values
588
589
 
589
- Besides its inputs, a custom material reads the built-in values `frame`, `camera`, `object` and `material` anywhere in its WGSL. The sketch time, `frame.time`, animates a look. The origin of each object, `object.position`, gives each object its own look from one material. On the rows of a batch made with `values: true`, `object.values` holds the row's four numbers, such as a phase or a tint ([Instances and batching](../concepts/instances.md#per-row-values)). The camera's `view`, `projection`, `near` and `far`, and the object's `worldMatrix`, `normalMatrix` and `id`, give what three.js's `ShaderMaterial` gives its shaders. [Built-in shader inputs](builtins.md) lists every field.
590
+ Besides its inputs, a custom material reads the built-in values `frame`, `camera`, `object` and `material` anywhere in its WGSL. The sketch time, `frame.time`, animates a look. The origin of each object, `object.position`, gives each object its own look from one material. On the rows of a batch made with `values: true`, `object.values` holds the row's four numbers, such as a phase or a tint ([Instances and batching](../concepts/instances.md#per-row-values)). The material also reads the camera's `view`, `projection`, `near` and `far`, and the object's `worldMatrix`, `normalMatrix` and `id`. [Built-in shader inputs](builtins.md) lists every field.
590
591
 
591
592
  ## Library functions
592
593
 
@@ -607,7 +608,7 @@ fn surface(input: SurfaceInput) -> Surface {
607
608
 
608
609
  Your WGSL shares one file with the engine's standard material, so a few rules apply besides the [WGSL rules for portable shaders](wgsl-rules.md):
609
610
 
610
- - Do not declare a name that the engine declares. The build stops at your line when a name clashes. The engine's names are `SurfaceInput`, `Surface`, `VertexInput`, `surface_place`, `surface_input`, `LobeInput`, `defaultSurface`, `shade`, `light_surface`, `frame`, `camera`, `object`, `material`, `FrameValues`, `CameraValues`, `ObjectValues`, `fill_builtins`, `engine_frame`, `material_row`, `load_material_uniforms`, `custom_value`, `custom_texture_layers`, `load_custom_texture_layers`, `VertexIn`, `VertexOut`, `vs`, `fs`, `FLAT_SHADING`, `sceneDepth`, `sceneDistance`, `scene_depth_copy` and `scene_depth_texel`. They also include the library items that the standard material imports: `Material`, `InstanceIn`, `find_instance`, `clip_of`, `relative_position`, `world_normal`, `finish_exposed`, `fogged`, `fragment_color`, `material_of`, `PbrMaterial`, `pbr_material`, `with_specular`, `dfg_lut`, `direct_light`, `indirect_diffuse`, `multiscatter_compensation`, `clustered_light` and `sun_shadow`. WGSL that reads `instance` or `object.id` also meets `object_ids`, and WGSL that reads the object's matrices meets `affine_matrix` and `affine_normal_matrix`. A material that declares a lobe also meets `clustered_lobed_light`, `Reflected`, `half_vector`, `cluster_lights`, `cluster_sample`, `light_of`, `grid_word`, `KIND_RECT`, `area_light`, `AreaTerms` and `area_terms`, which its lobe's loop reads. The names `surface`, `vertexOffset` and `lobe` are yours to declare.
611
+ - Do not declare a name that the engine declares. The build stops at your line when a name clashes. The engine's names are `SurfaceInput`, `Surface`, `VertexInput`, `surface_place`, `surface_input`, `LobeInput`, `defaultSurface`, `shade`, `light_surface`, `frame`, `camera`, `object`, `material`, `FrameValues`, `CameraValues`, `ObjectValues`, `fill_builtins`, `engine_frame`, `material_row`, `load_material_uniforms`, `custom_value`, `custom_texture_layers`, `load_custom_texture_layers`, `VertexIn`, `VertexOut`, `vs`, `fs`, `FLAT_SHADING`, `sceneDepth`, `sceneDistance`, `scene_depth_copy` and `scene_depth_texel`. They also include the library items that the standard material imports, such as `Material`, `Instance`, `InstanceIn`, `find_instance`, `clip_of`, `relative_position`, `world_normal`, `finish_material`, `finish_exposed_material`, `fogged`, `fragment_color`, `material_of`, `PbrMaterial`, `pbr_material`, `with_specular`, `dfg_lut`, `direct_light`, `indirect_diffuse`, `multiscatter_compensation`, `clustered_light` and `sun_shadow`. WGSL that reads `instance` or `object.id` also meets `object_ids`, and WGSL that reads the object's matrices meets `affine_matrix` and `affine_normal_matrix`. A material that declares a lobe also meets `clustered_lobed_light`, `Reflected`, `half_vector`, `cluster_lights`, `cluster_sample`, `light_of`, `grid_word`, `KIND_RECT`, `area_light`, `AreaTerms` and `area_terms`, which its lobe's loop reads. The names `surface`, `vertexOffset`, `lobe`, `unlit` and `coverage` are yours to declare.
611
612
  - Import library items by name, as in `#import null3d::noise::{fbm3}`. An import of a whole module reserves the module's name. After `#import null3d::color`, no name in the file can be `color`.
612
613
  - The WGSL cannot hold directives such as `enable`.
613
614
  - Do not declare a name that ends in `Sampler` after a texture's name, such as `detailSampler` beside `detail`. The engine declares it.
@@ -8,7 +8,7 @@ summary: "The three shared language features; optional features; flat interpolat
8
8
 
9
9
  # WGSL rules for portable shaders
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. The engine draws custom materials with [surface functions](surface-functions.md) and [full shaders](../guides/custom-shaders.md#full-shaders). It draws no other shader of your own yet, so coding agents must not write one.
11
+ > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. The engine draws custom materials with [surface functions](surface-functions.md) and [full shaders](../guides/custom-shaders.md#full-shaders). It draws no other shader of your own.
12
12
 
13
13
  One WGSL shader runs on every null3D path: WebGPU, WebGPU's compatibility mode and WebGL2. For WebGL2, null3D's shader build translates it to GLSL ES 3.00. A shader can therefore use only what every path and every target browser supports.
14
14
 
@@ -0,0 +1,103 @@
1
+ import type { Render } from '../scene/render.js';
2
+ import type { MaterialOptions } from '../scene/resources.js';
3
+ import { type Scene } from '../scene/scene.js';
4
+ import type { SketchQuality } from '../sketch/quality.js';
5
+ import type { Debug } from './debug.js';
6
+ import type { DebugDraw } from './draw.js';
7
+ /** The calls that the inspection channel takes. */
8
+ export type InspectCall = 'objects' | 'object' | 'setObject' | 'setMaterial' | 'stats' | 'errors' | 'graph' | 'setQuality' | 'highlight' | 'info';
9
+ /** A request from the page or the inspector to the channel. */
10
+ export interface InspectRequest {
11
+ call: string;
12
+ args?: unknown;
13
+ }
14
+ /** The channel's answer: the value of the call, or why it failed. */
15
+ export type InspectReply = {
16
+ ok: true;
17
+ result: unknown;
18
+ } | {
19
+ ok: false;
20
+ error: string;
21
+ };
22
+ /** What a scene object looks like in a listing. */
23
+ export interface ObjectSummary {
24
+ /** The object's slot in the scene, or its handle with the generation bits. */
25
+ slot: number;
26
+ handle: number;
27
+ name: string;
28
+ kind: string;
29
+ dynamic: boolean;
30
+ visible: boolean;
31
+ layers: number;
32
+ /** The slot of the object's live parent, or null for a root. */
33
+ parent: number | null;
34
+ children: number;
35
+ /** The material's id for a mesh, or absent. */
36
+ material?: number;
37
+ }
38
+ /** A scene object with its transform and its material. */
39
+ export interface ObjectDetail extends ObjectSummary {
40
+ position: [number, number, number];
41
+ rotation: [number, number, number, number];
42
+ scale: [number, number, number];
43
+ worldPosition: [number, number, number];
44
+ materialValues?: Record<string, unknown>;
45
+ shading?: number;
46
+ }
47
+ /** What a call that changes a material takes. */
48
+ export interface SetMaterialArgs {
49
+ selector: number | string;
50
+ values: MaterialOptions & Record<string, unknown>;
51
+ }
52
+ /** What a call that changes an object takes. */
53
+ export interface SetObjectArgs {
54
+ selector: number | string;
55
+ position?: readonly number[];
56
+ rotation?: readonly number[];
57
+ /** Euler angles in radians, around X, then Y, then Z. */
58
+ rotationEuler?: readonly number[];
59
+ scale?: readonly number[];
60
+ visible?: boolean;
61
+ dynamic?: boolean;
62
+ layers?: number;
63
+ }
64
+ /** What the channel reads the scene and the engine from. */
65
+ export interface DebugChannelHost {
66
+ scene: Scene;
67
+ render: Render;
68
+ quality: SketchQuality;
69
+ debug: Debug;
70
+ /** The development build's debug drawing, which outlines the selected object. */
71
+ debugDraw?: DebugDraw;
72
+ /** The engine's tier, preset and thread mode, as the page reports them. */
73
+ info(): Record<string, unknown>;
74
+ }
75
+ /** The development build's inspection channel. */
76
+ export declare class DebugChannel {
77
+ private readonly host;
78
+ private readonly errors;
79
+ constructor(host: DebugChannelHost);
80
+ /** Records an error that the runner reported, for the `errors` call. */
81
+ recordError(message: string): void;
82
+ /** Runs one inspection call and returns its JSON-safe value, or throws for a bad call. */
83
+ inspect(call: string, args: unknown): Promise<unknown>;
84
+ private stats;
85
+ /** Lists every live object, or the objects whose name or kind holds `filter`. */
86
+ private objects;
87
+ /** The object that a call's `selector` names. */
88
+ private find;
89
+ /** The live object that `selector` names, or undefined. */
90
+ private resolve;
91
+ /** A listing's view of one object. */
92
+ private summary;
93
+ /** One object's transform, parent and material. */
94
+ private detail;
95
+ /** Changes an object's transform, flags or layers and returns its new state. */
96
+ private setObject;
97
+ /** Changes the material of the mesh that `selector` names and returns the object's new state. */
98
+ private setMaterial;
99
+ /** Applies a quality preset or settings and returns the engine's new quality. */
100
+ private setQuality;
101
+ /** Outlines the object that `selector` names, or clears the outline without one. */
102
+ private highlight;
103
+ }