@vfx-js/effects 1.4.3 → 1.5.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 (631) hide show
  1. package/README.md +4 -0
  2. package/THIRD_PARTY_NOTICES.md +61 -0
  3. package/lib/cjs/_bloom-common.d.ts +31 -0
  4. package/lib/cjs/_bloom-common.js +101 -0
  5. package/lib/cjs/_bloom-common.js.map +1 -0
  6. package/lib/cjs/_bubble-fill.d.ts +126 -0
  7. package/lib/cjs/_bubble-fill.js +1044 -0
  8. package/lib/cjs/_bubble-fill.js.map +1 -0
  9. package/lib/cjs/_bubble-kernel-source.d.ts +2 -0
  10. package/lib/cjs/_bubble-kernel-source.js +8 -0
  11. package/lib/cjs/_bubble-kernel-source.js.map +1 -0
  12. package/lib/cjs/_holo/data/kernels.d.ts +4 -0
  13. package/lib/cjs/_holo/data/kernels.js +10 -0
  14. package/lib/cjs/_holo/data/kernels.js.map +1 -0
  15. package/lib/cjs/_holo/data/looks.d.ts +2 -0
  16. package/lib/cjs/_holo/data/looks.js +595 -0
  17. package/lib/cjs/_holo/data/looks.js.map +1 -0
  18. package/lib/cjs/_holo/data/ltc.d.ts +2 -0
  19. package/lib/cjs/_holo/data/ltc.js +11 -0
  20. package/lib/cjs/_holo/data/ltc.js.map +1 -0
  21. package/lib/cjs/_holo/data/material-presets.d.ts +3 -0
  22. package/lib/cjs/_holo/data/material-presets.js +75 -0
  23. package/lib/cjs/_holo/data/material-presets.js.map +1 -0
  24. package/lib/cjs/_holo/data/not-ported.d.ts +5 -0
  25. package/lib/cjs/_holo/data/not-ported.js +190 -0
  26. package/lib/cjs/_holo/data/not-ported.js.map +1 -0
  27. package/lib/cjs/_holo/data/params.d.ts +4 -0
  28. package/lib/cjs/_holo/data/params.js +1641 -0
  29. package/lib/cjs/_holo/data/params.js.map +1 -0
  30. package/lib/cjs/_holo/data/starting-points.d.ts +199 -0
  31. package/lib/cjs/_holo/data/starting-points.js +193 -0
  32. package/lib/cjs/_holo/data/starting-points.js.map +1 -0
  33. package/lib/cjs/_holo/data/studio-presets.d.ts +2 -0
  34. package/lib/cjs/_holo/data/studio-presets.js +177 -0
  35. package/lib/cjs/_holo/data/studio-presets.js.map +1 -0
  36. package/lib/cjs/_holo/emboss-assets.d.ts +55 -0
  37. package/lib/cjs/_holo/emboss-assets.js +155 -0
  38. package/lib/cjs/_holo/emboss-assets.js.map +1 -0
  39. package/lib/cjs/_holo/glare.d.ts +15 -0
  40. package/lib/cjs/_holo/glare.js +125 -0
  41. package/lib/cjs/_holo/glare.js.map +1 -0
  42. package/lib/cjs/_holo/glsl/coat.d.ts +2 -0
  43. package/lib/cjs/_holo/glsl/coat.js +32 -0
  44. package/lib/cjs/_holo/glsl/coat.js.map +1 -0
  45. package/lib/cjs/_holo/glsl/common.d.ts +2 -0
  46. package/lib/cjs/_holo/glsl/common.js +141 -0
  47. package/lib/cjs/_holo/glsl/common.js.map +1 -0
  48. package/lib/cjs/_holo/glsl/emboss.d.ts +2 -0
  49. package/lib/cjs/_holo/glsl/emboss.js +246 -0
  50. package/lib/cjs/_holo/glsl/emboss.js.map +1 -0
  51. package/lib/cjs/_holo/glsl/env.d.ts +2 -0
  52. package/lib/cjs/_holo/glsl/env.js +52 -0
  53. package/lib/cjs/_holo/glsl/env.js.map +1 -0
  54. package/lib/cjs/_holo/glsl/glare-down.d.ts +2 -0
  55. package/lib/cjs/_holo/glsl/glare-down.js +65 -0
  56. package/lib/cjs/_holo/glsl/glare-down.js.map +1 -0
  57. package/lib/cjs/_holo/glsl/glare-up.d.ts +2 -0
  58. package/lib/cjs/_holo/glsl/glare-up.js +18 -0
  59. package/lib/cjs/_holo/glsl/glare-up.js.map +1 -0
  60. package/lib/cjs/_holo/glsl/glitter.d.ts +2 -0
  61. package/lib/cjs/_holo/glsl/glitter.js +325 -0
  62. package/lib/cjs/_holo/glsl/glitter.js.map +1 -0
  63. package/lib/cjs/_holo/glsl/grating.d.ts +2 -0
  64. package/lib/cjs/_holo/glsl/grating.js +240 -0
  65. package/lib/cjs/_holo/glsl/grating.js.map +1 -0
  66. package/lib/cjs/_holo/glsl/holo-emboss.d.ts +2 -0
  67. package/lib/cjs/_holo/glsl/holo-emboss.js +296 -0
  68. package/lib/cjs/_holo/glsl/holo-emboss.js.map +1 -0
  69. package/lib/cjs/_holo/glsl/holo-nebula.d.ts +2 -0
  70. package/lib/cjs/_holo/glsl/holo-nebula.js +186 -0
  71. package/lib/cjs/_holo/glsl/holo-nebula.js.map +1 -0
  72. package/lib/cjs/_holo/glsl/holo-prism.d.ts +2 -0
  73. package/lib/cjs/_holo/glsl/holo-prism.js +183 -0
  74. package/lib/cjs/_holo/glsl/holo-prism.js.map +1 -0
  75. package/lib/cjs/_holo/glsl/holo-shatter.d.ts +2 -0
  76. package/lib/cjs/_holo/glsl/holo-shatter.js +328 -0
  77. package/lib/cjs/_holo/glsl/holo-shatter.js.map +1 -0
  78. package/lib/cjs/_holo/glsl/holo-sparkle.d.ts +2 -0
  79. package/lib/cjs/_holo/glsl/holo-sparkle.js +235 -0
  80. package/lib/cjs/_holo/glsl/holo-sparkle.js.map +1 -0
  81. package/lib/cjs/_holo/glsl/holo-vortex.d.ts +2 -0
  82. package/lib/cjs/_holo/glsl/holo-vortex.js +201 -0
  83. package/lib/cjs/_holo/glsl/holo-vortex.js.map +1 -0
  84. package/lib/cjs/_holo/glsl/ibl.d.ts +2 -0
  85. package/lib/cjs/_holo/glsl/ibl.js +79 -0
  86. package/lib/cjs/_holo/glsl/ibl.js.map +1 -0
  87. package/lib/cjs/_holo/glsl/lights.d.ts +2 -0
  88. package/lib/cjs/_holo/glsl/lights.js +125 -0
  89. package/lib/cjs/_holo/glsl/lights.js.map +1 -0
  90. package/lib/cjs/_holo/glsl/ltc.d.ts +2 -0
  91. package/lib/cjs/_holo/glsl/ltc.js +66 -0
  92. package/lib/cjs/_holo/glsl/ltc.js.map +1 -0
  93. package/lib/cjs/_holo/glsl/output.d.ts +2 -0
  94. package/lib/cjs/_holo/glsl/output.js +113 -0
  95. package/lib/cjs/_holo/glsl/output.js.map +1 -0
  96. package/lib/cjs/_holo/glsl/paper.d.ts +2 -0
  97. package/lib/cjs/_holo/glsl/paper.js +165 -0
  98. package/lib/cjs/_holo/glsl/paper.js.map +1 -0
  99. package/lib/cjs/_holo/glsl/relief.d.ts +2 -0
  100. package/lib/cjs/_holo/glsl/relief.js +103 -0
  101. package/lib/cjs/_holo/glsl/relief.js.map +1 -0
  102. package/lib/cjs/_holo/glsl/sparkle.d.ts +2 -0
  103. package/lib/cjs/_holo/glsl/sparkle.js +279 -0
  104. package/lib/cjs/_holo/glsl/sparkle.js.map +1 -0
  105. package/lib/cjs/_holo/glsl/spectral.d.ts +2 -0
  106. package/lib/cjs/_holo/glsl/spectral.js +60 -0
  107. package/lib/cjs/_holo/glsl/spectral.js.map +1 -0
  108. package/lib/cjs/_holo/glsl/wear.d.ts +2 -0
  109. package/lib/cjs/_holo/glsl/wear.js +107 -0
  110. package/lib/cjs/_holo/glsl/wear.js.map +1 -0
  111. package/lib/cjs/_holo/ltc.d.ts +9 -0
  112. package/lib/cjs/_holo/ltc.js +56 -0
  113. package/lib/cjs/_holo/ltc.js.map +1 -0
  114. package/lib/cjs/_holo/materials/build.d.ts +32 -0
  115. package/lib/cjs/_holo/materials/build.js +36 -0
  116. package/lib/cjs/_holo/materials/build.js.map +1 -0
  117. package/lib/cjs/_holo/materials/emboss.d.ts +22 -0
  118. package/lib/cjs/_holo/materials/emboss.js +205 -0
  119. package/lib/cjs/_holo/materials/emboss.js.map +1 -0
  120. package/lib/cjs/_holo/materials/nebula.d.ts +4 -0
  121. package/lib/cjs/_holo/materials/nebula.js +105 -0
  122. package/lib/cjs/_holo/materials/nebula.js.map +1 -0
  123. package/lib/cjs/_holo/materials/prism.d.ts +2 -0
  124. package/lib/cjs/_holo/materials/prism.js +69 -0
  125. package/lib/cjs/_holo/materials/prism.js.map +1 -0
  126. package/lib/cjs/_holo/materials/registry.d.ts +11 -0
  127. package/lib/cjs/_holo/materials/registry.js +88 -0
  128. package/lib/cjs/_holo/materials/registry.js.map +1 -0
  129. package/lib/cjs/_holo/materials/shatter.d.ts +2 -0
  130. package/lib/cjs/_holo/materials/shatter.js +80 -0
  131. package/lib/cjs/_holo/materials/shatter.js.map +1 -0
  132. package/lib/cjs/_holo/materials/sparkle.d.ts +2 -0
  133. package/lib/cjs/_holo/materials/sparkle.js +108 -0
  134. package/lib/cjs/_holo/materials/sparkle.js.map +1 -0
  135. package/lib/cjs/_holo/materials/vortex.d.ts +2 -0
  136. package/lib/cjs/_holo/materials/vortex.js +85 -0
  137. package/lib/cjs/_holo/materials/vortex.js.map +1 -0
  138. package/lib/cjs/_holo/physics/emboss.d.ts +39 -0
  139. package/lib/cjs/_holo/physics/emboss.js +95 -0
  140. package/lib/cjs/_holo/physics/emboss.js.map +1 -0
  141. package/lib/cjs/_holo/physics/geometry.d.ts +109 -0
  142. package/lib/cjs/_holo/physics/geometry.js +252 -0
  143. package/lib/cjs/_holo/physics/geometry.js.map +1 -0
  144. package/lib/cjs/_holo/physics/grating.d.ts +86 -0
  145. package/lib/cjs/_holo/physics/grating.js +328 -0
  146. package/lib/cjs/_holo/physics/grating.js.map +1 -0
  147. package/lib/cjs/_holo/physics/sparkle.d.ts +143 -0
  148. package/lib/cjs/_holo/physics/sparkle.js +388 -0
  149. package/lib/cjs/_holo/physics/sparkle.js.map +1 -0
  150. package/lib/cjs/_holo/scene/env.d.ts +17 -0
  151. package/lib/cjs/_holo/scene/env.js +151 -0
  152. package/lib/cjs/_holo/scene/env.js.map +1 -0
  153. package/lib/cjs/_holo/scene/lights.d.ts +13 -0
  154. package/lib/cjs/_holo/scene/lights.js +211 -0
  155. package/lib/cjs/_holo/scene/lights.js.map +1 -0
  156. package/lib/cjs/_holo/scene/logo.d.ts +87 -0
  157. package/lib/cjs/_holo/scene/logo.js +655 -0
  158. package/lib/cjs/_holo/scene/logo.js.map +1 -0
  159. package/lib/cjs/_holo/scene/paper-maps.d.ts +26 -0
  160. package/lib/cjs/_holo/scene/paper-maps.js +391 -0
  161. package/lib/cjs/_holo/scene/paper-maps.js.map +1 -0
  162. package/lib/cjs/_holo/scene/pose.d.ts +31 -0
  163. package/lib/cjs/_holo/scene/pose.js +77 -0
  164. package/lib/cjs/_holo/scene/pose.js.map +1 -0
  165. package/lib/cjs/_holo/scene/relief.d.ts +24 -0
  166. package/lib/cjs/_holo/scene/relief.js +148 -0
  167. package/lib/cjs/_holo/scene/relief.js.map +1 -0
  168. package/lib/cjs/_holo/settings-types.d.ts +20 -0
  169. package/lib/cjs/_holo/settings-types.js +3 -0
  170. package/lib/cjs/_holo/settings-types.js.map +1 -0
  171. package/lib/cjs/_holo/settings.d.ts +83 -0
  172. package/lib/cjs/_holo/settings.js +375 -0
  173. package/lib/cjs/_holo/settings.js.map +1 -0
  174. package/lib/cjs/_holo/shader.d.ts +23 -0
  175. package/lib/cjs/_holo/shader.js +219 -0
  176. package/lib/cjs/_holo/shader.js.map +1 -0
  177. package/lib/cjs/_holo/spectral/atlas.d.ts +36 -0
  178. package/lib/cjs/_holo/spectral/atlas.js +114 -0
  179. package/lib/cjs/_holo/spectral/atlas.js.map +1 -0
  180. package/lib/cjs/_holo/spectral/cmf.d.ts +67 -0
  181. package/lib/cjs/_holo/spectral/cmf.js +244 -0
  182. package/lib/cjs/_holo/spectral/cmf.js.map +1 -0
  183. package/lib/cjs/_holo/spectral/float24.d.ts +8 -0
  184. package/lib/cjs/_holo/spectral/float24.js +70 -0
  185. package/lib/cjs/_holo/spectral/float24.js.map +1 -0
  186. package/lib/cjs/_holo/spectral/spd.d.ts +22 -0
  187. package/lib/cjs/_holo/spectral/spd.js +139 -0
  188. package/lib/cjs/_holo/spectral/spd.js.map +1 -0
  189. package/lib/cjs/_holo/spectral/tables.d.ts +62 -0
  190. package/lib/cjs/_holo/spectral/tables.js +386 -0
  191. package/lib/cjs/_holo/spectral/tables.js.map +1 -0
  192. package/lib/cjs/_holo/tier.d.ts +4 -0
  193. package/lib/cjs/_holo/tier.js +110 -0
  194. package/lib/cjs/_holo/tier.js.map +1 -0
  195. package/lib/cjs/_holo/types.d.ts +148 -0
  196. package/lib/cjs/_holo/types.js +14 -0
  197. package/lib/cjs/_holo/types.js.map +1 -0
  198. package/lib/cjs/_kernel-worker.d.ts +22 -0
  199. package/lib/cjs/_kernel-worker.js +174 -0
  200. package/lib/cjs/_kernel-worker.js.map +1 -0
  201. package/lib/cjs/_orbit-camera.d.ts +175 -0
  202. package/lib/cjs/_orbit-camera.js +366 -0
  203. package/lib/cjs/_orbit-camera.js.map +1 -0
  204. package/lib/cjs/_pad.d.ts +2 -0
  205. package/lib/cjs/_pad.js +11 -0
  206. package/lib/cjs/_pad.js.map +1 -1
  207. package/lib/cjs/_scene3d.d.ts +101 -0
  208. package/lib/cjs/_scene3d.js +794 -0
  209. package/lib/cjs/_scene3d.js.map +1 -0
  210. package/lib/cjs/_shape-kernel-source.d.ts +2 -0
  211. package/lib/cjs/_shape-kernel-source.js +8 -0
  212. package/lib/cjs/_shape-kernel-source.js.map +1 -0
  213. package/lib/cjs/_shape-worker.d.ts +8 -0
  214. package/lib/cjs/_shape-worker.js +27 -0
  215. package/lib/cjs/_shape-worker.js.map +1 -0
  216. package/lib/cjs/_silhouette.d.ts +88 -0
  217. package/lib/cjs/_silhouette.js +441 -0
  218. package/lib/cjs/_silhouette.js.map +1 -0
  219. package/lib/cjs/_simplex3.d.ts +2 -0
  220. package/lib/cjs/_simplex3.js +160 -0
  221. package/lib/cjs/_simplex3.js.map +1 -0
  222. package/lib/cjs/_source.d.ts +80 -0
  223. package/lib/cjs/_source.js +192 -0
  224. package/lib/cjs/_source.js.map +1 -0
  225. package/lib/cjs/_sphere-foam.d.ts +34 -0
  226. package/lib/cjs/_sphere-foam.js +135 -0
  227. package/lib/cjs/_sphere-foam.js.map +1 -0
  228. package/lib/cjs/_thin-film.d.ts +26 -0
  229. package/lib/cjs/_thin-film.js +146 -0
  230. package/lib/cjs/_thin-film.js.map +1 -0
  231. package/lib/cjs/ascii.js +63 -73
  232. package/lib/cjs/ascii.js.map +1 -1
  233. package/lib/cjs/bad-jpeg.js +7 -5
  234. package/lib/cjs/bad-jpeg.js.map +1 -1
  235. package/lib/cjs/bloom.js +59 -135
  236. package/lib/cjs/bloom.js.map +1 -1
  237. package/lib/cjs/bubble.d.ts +284 -0
  238. package/lib/cjs/bubble.js +1820 -0
  239. package/lib/cjs/bubble.js.map +1 -0
  240. package/lib/cjs/chromatic.js +1 -0
  241. package/lib/cjs/chromatic.js.map +1 -1
  242. package/lib/cjs/colored-edges.js +1 -0
  243. package/lib/cjs/colored-edges.js.map +1 -1
  244. package/lib/cjs/datamosh.js +173 -183
  245. package/lib/cjs/datamosh.js.map +1 -1
  246. package/lib/cjs/dither.js +6 -3
  247. package/lib/cjs/dither.js.map +1 -1
  248. package/lib/cjs/duotone.js +4 -2
  249. package/lib/cjs/duotone.js.map +1 -1
  250. package/lib/cjs/fluid.js +62 -74
  251. package/lib/cjs/fluid.js.map +1 -1
  252. package/lib/cjs/glass.d.ts +254 -0
  253. package/lib/cjs/glass.js +981 -0
  254. package/lib/cjs/glass.js.map +1 -0
  255. package/lib/cjs/glitch.js +1 -0
  256. package/lib/cjs/glitch.js.map +1 -1
  257. package/lib/cjs/gradient-map.js +4 -1
  258. package/lib/cjs/gradient-map.js.map +1 -1
  259. package/lib/cjs/halftone.js +3 -0
  260. package/lib/cjs/halftone.js.map +1 -1
  261. package/lib/cjs/holo-static.d.ts +3 -0
  262. package/lib/cjs/holo-static.js +29 -0
  263. package/lib/cjs/holo-static.js.map +1 -0
  264. package/lib/cjs/holo.d.ts +401 -0
  265. package/lib/cjs/holo.js +1613 -0
  266. package/lib/cjs/holo.js.map +1 -0
  267. package/lib/cjs/hue-shift.js +1 -0
  268. package/lib/cjs/hue-shift.js.map +1 -1
  269. package/lib/cjs/index.d.ts +18 -9
  270. package/lib/cjs/index.js +12 -1
  271. package/lib/cjs/index.js.map +1 -1
  272. package/lib/cjs/jpeg-glitch.js +275 -276
  273. package/lib/cjs/jpeg-glitch.js.map +1 -1
  274. package/lib/cjs/light-streak.js +34 -47
  275. package/lib/cjs/light-streak.js.map +1 -1
  276. package/lib/cjs/matrix.d.ts +1 -1
  277. package/lib/cjs/matrix.js +48 -59
  278. package/lib/cjs/matrix.js.map +1 -1
  279. package/lib/cjs/package.json +20 -4
  280. package/lib/cjs/particle-explode.js +122 -128
  281. package/lib/cjs/particle-explode.js.map +1 -1
  282. package/lib/cjs/particle.js +253 -258
  283. package/lib/cjs/particle.js.map +1 -1
  284. package/lib/cjs/pattern-refraction.js +1 -0
  285. package/lib/cjs/pattern-refraction.js.map +1 -1
  286. package/lib/cjs/pixel-stretch.js +1 -0
  287. package/lib/cjs/pixel-stretch.js.map +1 -1
  288. package/lib/cjs/pixelate.js +1 -0
  289. package/lib/cjs/pixelate.js.map +1 -1
  290. package/lib/cjs/pixelsort.js +102 -121
  291. package/lib/cjs/pixelsort.js.map +1 -1
  292. package/lib/cjs/rainbow.js +1 -0
  293. package/lib/cjs/rainbow.js.map +1 -1
  294. package/lib/cjs/rgb-glitch.js +1 -0
  295. package/lib/cjs/rgb-glitch.js.map +1 -1
  296. package/lib/cjs/rgb-shift.js +1 -0
  297. package/lib/cjs/rgb-shift.js.map +1 -1
  298. package/lib/cjs/scanline.js +1 -0
  299. package/lib/cjs/scanline.js.map +1 -1
  300. package/lib/cjs/sinewave.js +1 -0
  301. package/lib/cjs/sinewave.js.map +1 -1
  302. package/lib/cjs/slice-shift.js +1 -0
  303. package/lib/cjs/slice-shift.js.map +1 -1
  304. package/lib/cjs/swirl-particle.d.ts +257 -0
  305. package/lib/cjs/swirl-particle.js +2346 -0
  306. package/lib/cjs/swirl-particle.js.map +1 -0
  307. package/lib/cjs/tile-pixelate.js +4 -1
  308. package/lib/cjs/tile-pixelate.js.map +1 -1
  309. package/lib/cjs/tritone.js +5 -2
  310. package/lib/cjs/tritone.js.map +1 -1
  311. package/lib/cjs/vignette.js +1 -0
  312. package/lib/cjs/vignette.js.map +1 -1
  313. package/lib/cjs/voronoi.js +6 -76
  314. package/lib/cjs/voronoi.js.map +1 -1
  315. package/lib/cjs/warp.js +1 -0
  316. package/lib/cjs/warp.js.map +1 -1
  317. package/lib/esm/_bloom-common.d.ts +31 -0
  318. package/lib/esm/_bloom-common.js +95 -0
  319. package/lib/esm/_bloom-common.js.map +1 -0
  320. package/lib/esm/_bubble-fill.d.ts +126 -0
  321. package/lib/esm/_bubble-fill.js +1039 -0
  322. package/lib/esm/_bubble-fill.js.map +1 -0
  323. package/lib/esm/_bubble-kernel-source.d.ts +2 -0
  324. package/lib/esm/_bubble-kernel-source.js +5 -0
  325. package/lib/esm/_bubble-kernel-source.js.map +1 -0
  326. package/lib/esm/_holo/data/kernels.d.ts +4 -0
  327. package/lib/esm/_holo/data/kernels.js +7 -0
  328. package/lib/esm/_holo/data/kernels.js.map +1 -0
  329. package/lib/esm/_holo/data/looks.d.ts +2 -0
  330. package/lib/esm/_holo/data/looks.js +592 -0
  331. package/lib/esm/_holo/data/looks.js.map +1 -0
  332. package/lib/esm/_holo/data/ltc.d.ts +2 -0
  333. package/lib/esm/_holo/data/ltc.js +8 -0
  334. package/lib/esm/_holo/data/ltc.js.map +1 -0
  335. package/lib/esm/_holo/data/material-presets.d.ts +3 -0
  336. package/lib/esm/_holo/data/material-presets.js +72 -0
  337. package/lib/esm/_holo/data/material-presets.js.map +1 -0
  338. package/lib/esm/_holo/data/not-ported.d.ts +5 -0
  339. package/lib/esm/_holo/data/not-ported.js +187 -0
  340. package/lib/esm/_holo/data/not-ported.js.map +1 -0
  341. package/lib/esm/_holo/data/params.d.ts +4 -0
  342. package/lib/esm/_holo/data/params.js +1638 -0
  343. package/lib/esm/_holo/data/params.js.map +1 -0
  344. package/lib/esm/_holo/data/starting-points.d.ts +199 -0
  345. package/lib/esm/_holo/data/starting-points.js +190 -0
  346. package/lib/esm/_holo/data/starting-points.js.map +1 -0
  347. package/lib/esm/_holo/data/studio-presets.d.ts +2 -0
  348. package/lib/esm/_holo/data/studio-presets.js +174 -0
  349. package/lib/esm/_holo/data/studio-presets.js.map +1 -0
  350. package/lib/esm/_holo/emboss-assets.d.ts +55 -0
  351. package/lib/esm/_holo/emboss-assets.js +150 -0
  352. package/lib/esm/_holo/emboss-assets.js.map +1 -0
  353. package/lib/esm/_holo/glare.d.ts +15 -0
  354. package/lib/esm/_holo/glare.js +117 -0
  355. package/lib/esm/_holo/glare.js.map +1 -0
  356. package/lib/esm/_holo/glsl/coat.d.ts +2 -0
  357. package/lib/esm/_holo/glsl/coat.js +30 -0
  358. package/lib/esm/_holo/glsl/coat.js.map +1 -0
  359. package/lib/esm/_holo/glsl/common.d.ts +2 -0
  360. package/lib/esm/_holo/glsl/common.js +139 -0
  361. package/lib/esm/_holo/glsl/common.js.map +1 -0
  362. package/lib/esm/_holo/glsl/emboss.d.ts +2 -0
  363. package/lib/esm/_holo/glsl/emboss.js +244 -0
  364. package/lib/esm/_holo/glsl/emboss.js.map +1 -0
  365. package/lib/esm/_holo/glsl/env.d.ts +2 -0
  366. package/lib/esm/_holo/glsl/env.js +50 -0
  367. package/lib/esm/_holo/glsl/env.js.map +1 -0
  368. package/lib/esm/_holo/glsl/glare-down.d.ts +2 -0
  369. package/lib/esm/_holo/glsl/glare-down.js +63 -0
  370. package/lib/esm/_holo/glsl/glare-down.js.map +1 -0
  371. package/lib/esm/_holo/glsl/glare-up.d.ts +2 -0
  372. package/lib/esm/_holo/glsl/glare-up.js +16 -0
  373. package/lib/esm/_holo/glsl/glare-up.js.map +1 -0
  374. package/lib/esm/_holo/glsl/glitter.d.ts +2 -0
  375. package/lib/esm/_holo/glsl/glitter.js +323 -0
  376. package/lib/esm/_holo/glsl/glitter.js.map +1 -0
  377. package/lib/esm/_holo/glsl/grating.d.ts +2 -0
  378. package/lib/esm/_holo/glsl/grating.js +238 -0
  379. package/lib/esm/_holo/glsl/grating.js.map +1 -0
  380. package/lib/esm/_holo/glsl/holo-emboss.d.ts +2 -0
  381. package/lib/esm/_holo/glsl/holo-emboss.js +294 -0
  382. package/lib/esm/_holo/glsl/holo-emboss.js.map +1 -0
  383. package/lib/esm/_holo/glsl/holo-nebula.d.ts +2 -0
  384. package/lib/esm/_holo/glsl/holo-nebula.js +184 -0
  385. package/lib/esm/_holo/glsl/holo-nebula.js.map +1 -0
  386. package/lib/esm/_holo/glsl/holo-prism.d.ts +2 -0
  387. package/lib/esm/_holo/glsl/holo-prism.js +181 -0
  388. package/lib/esm/_holo/glsl/holo-prism.js.map +1 -0
  389. package/lib/esm/_holo/glsl/holo-shatter.d.ts +2 -0
  390. package/lib/esm/_holo/glsl/holo-shatter.js +326 -0
  391. package/lib/esm/_holo/glsl/holo-shatter.js.map +1 -0
  392. package/lib/esm/_holo/glsl/holo-sparkle.d.ts +2 -0
  393. package/lib/esm/_holo/glsl/holo-sparkle.js +233 -0
  394. package/lib/esm/_holo/glsl/holo-sparkle.js.map +1 -0
  395. package/lib/esm/_holo/glsl/holo-vortex.d.ts +2 -0
  396. package/lib/esm/_holo/glsl/holo-vortex.js +199 -0
  397. package/lib/esm/_holo/glsl/holo-vortex.js.map +1 -0
  398. package/lib/esm/_holo/glsl/ibl.d.ts +2 -0
  399. package/lib/esm/_holo/glsl/ibl.js +77 -0
  400. package/lib/esm/_holo/glsl/ibl.js.map +1 -0
  401. package/lib/esm/_holo/glsl/lights.d.ts +2 -0
  402. package/lib/esm/_holo/glsl/lights.js +123 -0
  403. package/lib/esm/_holo/glsl/lights.js.map +1 -0
  404. package/lib/esm/_holo/glsl/ltc.d.ts +2 -0
  405. package/lib/esm/_holo/glsl/ltc.js +64 -0
  406. package/lib/esm/_holo/glsl/ltc.js.map +1 -0
  407. package/lib/esm/_holo/glsl/output.d.ts +2 -0
  408. package/lib/esm/_holo/glsl/output.js +111 -0
  409. package/lib/esm/_holo/glsl/output.js.map +1 -0
  410. package/lib/esm/_holo/glsl/paper.d.ts +2 -0
  411. package/lib/esm/_holo/glsl/paper.js +163 -0
  412. package/lib/esm/_holo/glsl/paper.js.map +1 -0
  413. package/lib/esm/_holo/glsl/relief.d.ts +2 -0
  414. package/lib/esm/_holo/glsl/relief.js +101 -0
  415. package/lib/esm/_holo/glsl/relief.js.map +1 -0
  416. package/lib/esm/_holo/glsl/sparkle.d.ts +2 -0
  417. package/lib/esm/_holo/glsl/sparkle.js +277 -0
  418. package/lib/esm/_holo/glsl/sparkle.js.map +1 -0
  419. package/lib/esm/_holo/glsl/spectral.d.ts +2 -0
  420. package/lib/esm/_holo/glsl/spectral.js +58 -0
  421. package/lib/esm/_holo/glsl/spectral.js.map +1 -0
  422. package/lib/esm/_holo/glsl/wear.d.ts +2 -0
  423. package/lib/esm/_holo/glsl/wear.js +105 -0
  424. package/lib/esm/_holo/glsl/wear.js.map +1 -0
  425. package/lib/esm/_holo/ltc.d.ts +9 -0
  426. package/lib/esm/_holo/ltc.js +52 -0
  427. package/lib/esm/_holo/ltc.js.map +1 -0
  428. package/lib/esm/_holo/materials/build.d.ts +32 -0
  429. package/lib/esm/_holo/materials/build.js +30 -0
  430. package/lib/esm/_holo/materials/build.js.map +1 -0
  431. package/lib/esm/_holo/materials/emboss.d.ts +22 -0
  432. package/lib/esm/_holo/materials/emboss.js +198 -0
  433. package/lib/esm/_holo/materials/emboss.js.map +1 -0
  434. package/lib/esm/_holo/materials/nebula.d.ts +4 -0
  435. package/lib/esm/_holo/materials/nebula.js +98 -0
  436. package/lib/esm/_holo/materials/nebula.js.map +1 -0
  437. package/lib/esm/_holo/materials/prism.d.ts +2 -0
  438. package/lib/esm/_holo/materials/prism.js +63 -0
  439. package/lib/esm/_holo/materials/prism.js.map +1 -0
  440. package/lib/esm/_holo/materials/registry.d.ts +11 -0
  441. package/lib/esm/_holo/materials/registry.js +48 -0
  442. package/lib/esm/_holo/materials/registry.js.map +1 -0
  443. package/lib/esm/_holo/materials/shatter.d.ts +2 -0
  444. package/lib/esm/_holo/materials/shatter.js +74 -0
  445. package/lib/esm/_holo/materials/shatter.js.map +1 -0
  446. package/lib/esm/_holo/materials/sparkle.d.ts +2 -0
  447. package/lib/esm/_holo/materials/sparkle.js +102 -0
  448. package/lib/esm/_holo/materials/sparkle.js.map +1 -0
  449. package/lib/esm/_holo/materials/vortex.d.ts +2 -0
  450. package/lib/esm/_holo/materials/vortex.js +79 -0
  451. package/lib/esm/_holo/materials/vortex.js.map +1 -0
  452. package/lib/esm/_holo/physics/emboss.d.ts +39 -0
  453. package/lib/esm/_holo/physics/emboss.js +89 -0
  454. package/lib/esm/_holo/physics/emboss.js.map +1 -0
  455. package/lib/esm/_holo/physics/geometry.d.ts +109 -0
  456. package/lib/esm/_holo/physics/geometry.js +228 -0
  457. package/lib/esm/_holo/physics/geometry.js.map +1 -0
  458. package/lib/esm/_holo/physics/grating.d.ts +86 -0
  459. package/lib/esm/_holo/physics/grating.js +313 -0
  460. package/lib/esm/_holo/physics/grating.js.map +1 -0
  461. package/lib/esm/_holo/physics/sparkle.d.ts +143 -0
  462. package/lib/esm/_holo/physics/sparkle.js +360 -0
  463. package/lib/esm/_holo/physics/sparkle.js.map +1 -0
  464. package/lib/esm/_holo/scene/env.d.ts +17 -0
  465. package/lib/esm/_holo/scene/env.js +141 -0
  466. package/lib/esm/_holo/scene/env.js.map +1 -0
  467. package/lib/esm/_holo/scene/lights.d.ts +13 -0
  468. package/lib/esm/_holo/scene/lights.js +204 -0
  469. package/lib/esm/_holo/scene/lights.js.map +1 -0
  470. package/lib/esm/_holo/scene/logo.d.ts +87 -0
  471. package/lib/esm/_holo/scene/logo.js +645 -0
  472. package/lib/esm/_holo/scene/logo.js.map +1 -0
  473. package/lib/esm/_holo/scene/paper-maps.d.ts +26 -0
  474. package/lib/esm/_holo/scene/paper-maps.js +387 -0
  475. package/lib/esm/_holo/scene/paper-maps.js.map +1 -0
  476. package/lib/esm/_holo/scene/pose.d.ts +31 -0
  477. package/lib/esm/_holo/scene/pose.js +71 -0
  478. package/lib/esm/_holo/scene/pose.js.map +1 -0
  479. package/lib/esm/_holo/scene/relief.d.ts +24 -0
  480. package/lib/esm/_holo/scene/relief.js +142 -0
  481. package/lib/esm/_holo/scene/relief.js.map +1 -0
  482. package/lib/esm/_holo/settings-types.d.ts +20 -0
  483. package/lib/esm/_holo/settings-types.js +2 -0
  484. package/lib/esm/_holo/settings-types.js.map +1 -0
  485. package/lib/esm/_holo/settings.d.ts +83 -0
  486. package/lib/esm/_holo/settings.js +358 -0
  487. package/lib/esm/_holo/settings.js.map +1 -0
  488. package/lib/esm/_holo/shader.d.ts +23 -0
  489. package/lib/esm/_holo/shader.js +211 -0
  490. package/lib/esm/_holo/shader.js.map +1 -0
  491. package/lib/esm/_holo/spectral/atlas.d.ts +36 -0
  492. package/lib/esm/_holo/spectral/atlas.js +110 -0
  493. package/lib/esm/_holo/spectral/atlas.js.map +1 -0
  494. package/lib/esm/_holo/spectral/cmf.d.ts +67 -0
  495. package/lib/esm/_holo/spectral/cmf.js +230 -0
  496. package/lib/esm/_holo/spectral/cmf.js.map +1 -0
  497. package/lib/esm/_holo/spectral/float24.d.ts +8 -0
  498. package/lib/esm/_holo/spectral/float24.js +64 -0
  499. package/lib/esm/_holo/spectral/float24.js.map +1 -0
  500. package/lib/esm/_holo/spectral/spd.d.ts +22 -0
  501. package/lib/esm/_holo/spectral/spd.js +130 -0
  502. package/lib/esm/_holo/spectral/spd.js.map +1 -0
  503. package/lib/esm/_holo/spectral/tables.d.ts +62 -0
  504. package/lib/esm/_holo/spectral/tables.js +372 -0
  505. package/lib/esm/_holo/spectral/tables.js.map +1 -0
  506. package/lib/esm/_holo/tier.d.ts +4 -0
  507. package/lib/esm/_holo/tier.js +106 -0
  508. package/lib/esm/_holo/tier.js.map +1 -0
  509. package/lib/esm/_holo/types.d.ts +148 -0
  510. package/lib/esm/_holo/types.js +11 -0
  511. package/lib/esm/_holo/types.js.map +1 -0
  512. package/lib/esm/_kernel-worker.d.ts +22 -0
  513. package/lib/esm/_kernel-worker.js +169 -0
  514. package/lib/esm/_kernel-worker.js.map +1 -0
  515. package/lib/esm/_orbit-camera.d.ts +175 -0
  516. package/lib/esm/_orbit-camera.js +360 -0
  517. package/lib/esm/_orbit-camera.js.map +1 -0
  518. package/lib/esm/_pad.d.ts +2 -0
  519. package/lib/esm/_pad.js +10 -0
  520. package/lib/esm/_pad.js.map +1 -1
  521. package/lib/esm/_scene3d.d.ts +101 -0
  522. package/lib/esm/_scene3d.js +783 -0
  523. package/lib/esm/_scene3d.js.map +1 -0
  524. package/lib/esm/_shape-kernel-source.d.ts +2 -0
  525. package/lib/esm/_shape-kernel-source.js +5 -0
  526. package/lib/esm/_shape-kernel-source.js.map +1 -0
  527. package/lib/esm/_shape-worker.d.ts +8 -0
  528. package/lib/esm/_shape-worker.js +23 -0
  529. package/lib/esm/_shape-worker.js.map +1 -0
  530. package/lib/esm/_silhouette.d.ts +88 -0
  531. package/lib/esm/_silhouette.js +436 -0
  532. package/lib/esm/_silhouette.js.map +1 -0
  533. package/lib/esm/_simplex3.d.ts +2 -0
  534. package/lib/esm/_simplex3.js +157 -0
  535. package/lib/esm/_simplex3.js.map +1 -0
  536. package/lib/esm/_source.d.ts +80 -0
  537. package/lib/esm/_source.js +187 -0
  538. package/lib/esm/_source.js.map +1 -0
  539. package/lib/esm/_sphere-foam.d.ts +34 -0
  540. package/lib/esm/_sphere-foam.js +131 -0
  541. package/lib/esm/_sphere-foam.js.map +1 -0
  542. package/lib/esm/_thin-film.d.ts +26 -0
  543. package/lib/esm/_thin-film.js +140 -0
  544. package/lib/esm/_thin-film.js.map +1 -0
  545. package/lib/esm/ascii.js +63 -73
  546. package/lib/esm/ascii.js.map +1 -1
  547. package/lib/esm/bad-jpeg.js +7 -5
  548. package/lib/esm/bad-jpeg.js.map +1 -1
  549. package/lib/esm/bloom.js +59 -135
  550. package/lib/esm/bloom.js.map +1 -1
  551. package/lib/esm/bubble.d.ts +284 -0
  552. package/lib/esm/bubble.js +1816 -0
  553. package/lib/esm/bubble.js.map +1 -0
  554. package/lib/esm/chromatic.js +1 -0
  555. package/lib/esm/chromatic.js.map +1 -1
  556. package/lib/esm/colored-edges.js +1 -0
  557. package/lib/esm/colored-edges.js.map +1 -1
  558. package/lib/esm/datamosh.js +172 -182
  559. package/lib/esm/datamosh.js.map +1 -1
  560. package/lib/esm/dither.js +6 -3
  561. package/lib/esm/dither.js.map +1 -1
  562. package/lib/esm/duotone.js +4 -2
  563. package/lib/esm/duotone.js.map +1 -1
  564. package/lib/esm/fluid.js +62 -74
  565. package/lib/esm/fluid.js.map +1 -1
  566. package/lib/esm/glass.d.ts +254 -0
  567. package/lib/esm/glass.js +977 -0
  568. package/lib/esm/glass.js.map +1 -0
  569. package/lib/esm/glitch.js +1 -0
  570. package/lib/esm/glitch.js.map +1 -1
  571. package/lib/esm/gradient-map.js +4 -1
  572. package/lib/esm/gradient-map.js.map +1 -1
  573. package/lib/esm/halftone.js +3 -0
  574. package/lib/esm/halftone.js.map +1 -1
  575. package/lib/esm/holo-static.d.ts +3 -0
  576. package/lib/esm/holo-static.js +13 -0
  577. package/lib/esm/holo-static.js.map +1 -0
  578. package/lib/esm/holo.d.ts +401 -0
  579. package/lib/esm/holo.js +1606 -0
  580. package/lib/esm/holo.js.map +1 -0
  581. package/lib/esm/hue-shift.js +1 -0
  582. package/lib/esm/hue-shift.js.map +1 -1
  583. package/lib/esm/index.d.ts +18 -9
  584. package/lib/esm/index.js +7 -2
  585. package/lib/esm/index.js.map +1 -1
  586. package/lib/esm/jpeg-glitch.js +274 -275
  587. package/lib/esm/jpeg-glitch.js.map +1 -1
  588. package/lib/esm/light-streak.js +34 -47
  589. package/lib/esm/light-streak.js.map +1 -1
  590. package/lib/esm/matrix.d.ts +1 -1
  591. package/lib/esm/matrix.js +48 -59
  592. package/lib/esm/matrix.js.map +1 -1
  593. package/lib/esm/package.json +20 -4
  594. package/lib/esm/particle-explode.js +122 -128
  595. package/lib/esm/particle-explode.js.map +1 -1
  596. package/lib/esm/particle.js +253 -258
  597. package/lib/esm/particle.js.map +1 -1
  598. package/lib/esm/pattern-refraction.js +1 -0
  599. package/lib/esm/pattern-refraction.js.map +1 -1
  600. package/lib/esm/pixel-stretch.js +1 -0
  601. package/lib/esm/pixel-stretch.js.map +1 -1
  602. package/lib/esm/pixelate.js +1 -0
  603. package/lib/esm/pixelate.js.map +1 -1
  604. package/lib/esm/pixelsort.js +102 -121
  605. package/lib/esm/pixelsort.js.map +1 -1
  606. package/lib/esm/rainbow.js +1 -0
  607. package/lib/esm/rainbow.js.map +1 -1
  608. package/lib/esm/rgb-glitch.js +1 -0
  609. package/lib/esm/rgb-glitch.js.map +1 -1
  610. package/lib/esm/rgb-shift.js +1 -0
  611. package/lib/esm/rgb-shift.js.map +1 -1
  612. package/lib/esm/scanline.js +1 -0
  613. package/lib/esm/scanline.js.map +1 -1
  614. package/lib/esm/sinewave.js +1 -0
  615. package/lib/esm/sinewave.js.map +1 -1
  616. package/lib/esm/slice-shift.js +1 -0
  617. package/lib/esm/slice-shift.js.map +1 -1
  618. package/lib/esm/swirl-particle.d.ts +257 -0
  619. package/lib/esm/swirl-particle.js +2342 -0
  620. package/lib/esm/swirl-particle.js.map +1 -0
  621. package/lib/esm/tile-pixelate.js +4 -1
  622. package/lib/esm/tile-pixelate.js.map +1 -1
  623. package/lib/esm/tritone.js +5 -2
  624. package/lib/esm/tritone.js.map +1 -1
  625. package/lib/esm/vignette.js +1 -0
  626. package/lib/esm/vignette.js.map +1 -1
  627. package/lib/esm/voronoi.js +6 -76
  628. package/lib/esm/voronoi.js.map +1 -1
  629. package/lib/esm/warp.js +1 -0
  630. package/lib/esm/warp.js.map +1 -1
  631. package/package.json +38 -10
@@ -0,0 +1,1816 @@
1
+ import { BUBBLE_LIST_MAX, BUBBLE_TEX_W, bubbleKernel, } from "./_bubble-fill.js";
2
+ import { BUBBLE_KERNEL_SOURCE } from "./_bubble-kernel-source.js";
3
+ import { KernelWorker } from "./_kernel-worker.js";
4
+ import { OrbitCamera, } from "./_orbit-camera.js";
5
+ import { padOf, padOutputRect } from "./_pad.js";
6
+ import { BACKDROP_PALETTES, backdropKind, clampInt, GLSL_HEAT, GLSL_SCENE, hexToRgb, SceneBackdrop, ScenePasses, uploadFloatTexture, } from "./_scene3d.js";
7
+ import { buildShapeAsync } from "./_shape-worker.js";
8
+ import { GLSL_SDF } from "./_silhouette.js";
9
+ import { GLSL_SIMPLEX3, GLSL_SIMPLEX3_GRAD } from "./_simplex3.js";
10
+ import { SourceCapture, sourceChannelOf, } from "./_source.js";
11
+ import { THIN_FILM_LUT_H, THIN_FILM_LUT_W, THIN_FILM_THICKNESS_MAX, thinFilmLut, } from "./_thin-film.js";
12
+ // How much thicker the film gets at a border, in nm per unit of
13
+ // borderWidth.
14
+ const BORDER_NM_PER_WIDTH = 10000;
15
+ const DEFAULT_PARAMS = {
16
+ sourceChannel: "alpha",
17
+ depth: 0.1,
18
+ bevel: 0.02,
19
+ cellSize: 0.1,
20
+ cellSizeRandomness: 0.25,
21
+ roundness: 0.3,
22
+ seed: 1,
23
+ minSize: 0.25,
24
+ containment: 0,
25
+ wobble: 0.06,
26
+ speed: 0.15,
27
+ maxLayers: 6,
28
+ iridescence: 0.5,
29
+ thickness: 420,
30
+ thicknessVariation: 0.35,
31
+ drain: 0.5,
32
+ swirlScale: 1.2,
33
+ swirlSpeed: 0.12,
34
+ reflection: 1.4,
35
+ rim: 1,
36
+ tint: "#6d8ee8",
37
+ tintStrength: 0.3,
38
+ opacity: 0,
39
+ color: "#2f7fe0",
40
+ borderWidth: 0.06,
41
+ borderHighlight: 0.35,
42
+ backdrop: "none",
43
+ backdropVisible: false,
44
+ backdropAround: false,
45
+ backdropScale: 0.25,
46
+ backdropDistance: 0.6,
47
+ backdropSpeed: 0.15,
48
+ backdropColors: "mono",
49
+ backdropRatio: 0.5,
50
+ backdropSoftness: 0.03,
51
+ lightIntensity: 1.2,
52
+ lightSoftness: 0.8,
53
+ yaw: 20,
54
+ pitch: 11.5,
55
+ orbitAnimation: 11.5,
56
+ orbitSpeed: 3.3,
57
+ fov: 30,
58
+ zoom: 0.75,
59
+ drag: false,
60
+ cameraOrigin: "element",
61
+ pointer: "none",
62
+ pointerStrength: 1,
63
+ resolution: 1,
64
+ antialias: true,
65
+ pad: 100,
66
+ debug: "off",
67
+ };
68
+ const DEBUG_VIEWS = {
69
+ off: 0,
70
+ cost: 1,
71
+ layers: 2,
72
+ cells: 3,
73
+ };
74
+ const MAX_LAYERS = 16;
75
+ // The depth the fill inside the shape takes to reach its full size, per
76
+ // cell size.
77
+ const FILL_DEPTH = 0.5;
78
+ const WOBBLE_MAX = 0.15;
79
+ // The cosine the films' angle is held at with `rim` 0.
80
+ const RIM_COS = 0.6;
81
+ // Long side of the silhouette read back from the element, in px, and
82
+ // the smoothing of its field. The field only places the bubbles, so it
83
+ // can be coarser than GlassEffect's.
84
+ const BUBBLE_MASK_LONG = 512;
85
+ const SMOOTH_RADIUS = 2;
86
+ const SMOOTH_PASSES = 2;
87
+ // The shader per containment mode: 0 none, 1 the shape cuts the foam
88
+ // flat, 2 the foam out of the shape is squashed. Each mode compiles only
89
+ // its own path, which keeps the others light on registers.
90
+ // It also compiles only the kind of backdrop in use (see GLSL_SCENE): a
91
+ // change of either compiles a new shader on its first frame.
92
+ const fragBubble = (mode, kind) => `#version 300 es
93
+ #define CONTAIN ${mode}
94
+ #define BACKDROP_KIND ${kind}
95
+ precision highp float;
96
+ precision highp int;
97
+ precision highp sampler2D;
98
+ in vec2 uv;
99
+ out vec4 outColor;
100
+
101
+ ${GLSL_SDF}
102
+
103
+ uniform vec2 shapeHalf;
104
+ uniform float boxMargin;
105
+ uniform mat3 viewRot;
106
+ uniform float camDist;
107
+ uniform float focalPx;
108
+ // The camera (see _orbit-camera.ts): the eye in view space is
109
+ // (eye, camDist), and its axis meets the output at principalPx.
110
+ uniform vec2 eye;
111
+ uniform vec2 principalPx;
112
+ uniform vec2 bufferPx;
113
+ uniform float pixelSize;
114
+
115
+ uniform int maxLayers;
116
+ uniform uint seed;
117
+ uniform float cellSize;
118
+
119
+ // The spheres (x, y, z, r per texel, drifted for this frame) and the grid
120
+ // over them: per cell an offset into the index list and a count; the
121
+ // index list holds four sphere indices per texel. All in rows of
122
+ // BUBBLE_TEX_W texels.
123
+ uniform highp sampler2D sphereTex;
124
+ uniform highp sampler2D cellTex;
125
+ uniform highp sampler2D indexTex;
126
+ uniform vec3 gridOrigin;
127
+ uniform float gridCell;
128
+ uniform ivec3 gridDims;
129
+ // The grid the borders are found with: the spheres listed by their own
130
+ // radii. In a container the grid above lists them as far as the fill
131
+ // blows them up, which the foam's outside does not need.
132
+ uniform highp sampler2D edgeCellTex;
133
+ uniform highp sampler2D edgeIndexTex;
134
+ uniform vec3 edgeOrigin;
135
+ uniform float edgeCell;
136
+ uniform ivec3 edgeDims;
137
+ // How far any sphere can reach out of the shape, drift included.
138
+ uniform float reachMax;
139
+ // The container: the foam ends where the shape's field reaches clipOff
140
+ // (0: the shape itself).
141
+ uniform float clipOff;
142
+ // Below containment 1 the part of the foam outside the shape is not cut
143
+ // but squashed towards it: a point at distance S from the shape shows
144
+ // the foam at S / (1 - containment). warpK = containment / (1 -
145
+ // containment). At 1 (WALL_ON) it is cut flat instead.
146
+ uniform float warpK;
147
+ // In a container the bubbles inside the shape are blown up with depth,
148
+ // by up to fillG on r², reached fillDepth in: the gaps left between them
149
+ // deep inside close, and the shape reads as full of foam.
150
+ uniform float fillG;
151
+ uniform float fillDepth;
152
+ #define WALL_ON (CONTAIN == 1)
153
+
154
+ uniform sampler2D filmLut;
155
+ uniform float iridescence;
156
+ uniform float thickness;
157
+ uniform float thicknessVariation;
158
+ uniform float drain;
159
+ uniform float swirlScale;
160
+ uniform float swirlOffset;
161
+ uniform float reflection;
162
+ // The films reflect as if seen no more grazing than this cosine.
163
+ uniform float rimCos;
164
+ // The backdrop is reflected all around (1), or only behind (0).
165
+ uniform float backdropAround;
166
+ uniform vec3 tint;
167
+ uniform float tintStrength;
168
+ uniform float opacity;
169
+ uniform vec3 bodyColor;
170
+ // The borders on the foam's outside: their width in world units (0: off,
171
+ // none of their work is done), the white line, the film's thickening.
172
+ uniform float borderWidth;
173
+ uniform float borderHighlight;
174
+ uniform float borderThickness;
175
+ uniform int debugView;
176
+
177
+ // Spheres a grid cell lists, at most: the ray passes through some of them.
178
+ const int MAX_CAND = ${BUBBLE_LIST_MAX};
179
+ const int TEX_W = ${BUBBLE_TEX_W};
180
+ const int MAX_LAYERS = ${MAX_LAYERS};
181
+ const float THICKNESS_MAX = ${THIN_FILM_THICKNESS_MAX.toFixed(1)};
182
+ const float TAU = 6.2831853;
183
+ // Brightness of the lights in reflections, the most a film reflects, and
184
+ // how much of that the walls inside the foam keep.
185
+ const float LIGHT_GAIN = 8.0;
186
+ const float RIM_MAX = 0.2;
187
+ const float WALL_DIM = 0.35;
188
+ // Half the white line's core, as a share of the border's width.
189
+ const float BORDER_LINE = 0.22;
190
+ const float NO_EDGE = 1e30;
191
+
192
+ ${GLSL_SIMPLEX3}
193
+ ${GLSL_SIMPLEX3_GRAD}
194
+ ${GLSL_SCENE}
195
+ ${GLSL_HEAT}
196
+
197
+ vec3 ro;
198
+ vec3 rd;
199
+ // Radius of the pixel's cone per unit of distance.
200
+ float pixCone;
201
+ float cost = 0.0;
202
+
203
+ uvec3 pcg3d(uvec3 v) {
204
+ v = v * 1664525u + 1013904223u;
205
+ v.x += v.y * v.z;
206
+ v.y += v.z * v.x;
207
+ v.z += v.x * v.y;
208
+ v ^= v >> 16u;
209
+ v.x += v.y * v.z;
210
+ v.y += v.z * v.x;
211
+ v.z += v.x * v.y;
212
+ return v;
213
+ }
214
+
215
+ vec4 hash4(uvec3 v) {
216
+ uvec3 a = pcg3d(v ^ uvec3(seed, seed * 7u, seed * 13u));
217
+ uint w = (a.x ^ (a.y >> 11u) ^ (a.z << 7u)) * 747796405u;
218
+ return vec4(a, w ^ (w >> 16u)) * (1.0 / 4294967295.0);
219
+ }
220
+
221
+ // The id of sphere i, which seeds its film's swirls.
222
+ float sphereId(int i) {
223
+ return hash4(uvec3(uint(i), 977u, 31u)).w * 251.0;
224
+ }
225
+
226
+ // ---- shading ----
227
+
228
+ vec3 col = vec3(0.0);
229
+ vec3 remain = vec3(1.0);
230
+ int films = 0;
231
+ float firstId = -1.0;
232
+
233
+ // Film thickness in nm at l (from the cell's seed, per cell size):
234
+ // thinner at the top, with slow swirls flowing down.
235
+ float filmThickness(vec3 l, float id) {
236
+ float g = max(1.0 - drain * l.y, 0.05);
237
+ vec3 q = l * swirlScale + vec3(id * 1.37, id * 0.71 - swirlOffset, id * 2.13);
238
+ float n = 0.7 * snoise(q + vec3(0.0, 0.0, swirlOffset * 0.5))
239
+ + 0.3 * snoise(q * 2.3 + 11.7);
240
+ return thickness * g * max(1.0 + thicknessVariation * n, 0.05);
241
+ }
242
+
243
+ // Reflectance of a film without interference: both faces' Fresnel
244
+ // (water, Schlick), summed incoherently.
245
+ float plainFilm(float c) {
246
+ float f = 0.02 + 0.98 * pow(1.0 - c, 5.0);
247
+ return 2.0 * f / (1.0 + f);
248
+ }
249
+
250
+ // The light a film of reflectance R reflects: a soft studio sky, and the
251
+ // scene's lights (or the backdrop). The lights are much brighter than
252
+ // their surroundings, as studio lights are, so a cap facing one shows a
253
+ // highlight at the few percent a film reflects head on; past that, a
254
+ // grazing film reflects them no more, so rims stay soft.
255
+ vec3 reflected(vec3 R, vec3 pV, vec3 dV) {
256
+ // The backdrop is behind, and with backdropAround on a plane as far
257
+ // in front too: towards the side both planes blur to its mean.
258
+ // It is sampled in one place: each call site is compiled apart, and
259
+ // the patterns are the largest part of the shader.
260
+ bool behind = backdropMode != 0 && dV.z < -1e-4;
261
+ bool front = backdropAround > 0.5 && backdropMode != 0 && !behind;
262
+ float t = behind
263
+ ? (-backdropDistance - pV.z) / dV.z
264
+ : (backdropDistance - pV.z) / max(dV.z, 1e-4);
265
+ vec2 q = pV.xy + dV.xy * t;
266
+ bool hit = front || (behind && t > 0.0);
267
+ vec3 env = vec3(0.0);
268
+ if (hit) {
269
+ env = backdrop(q, length(fwidth(q)));
270
+ }
271
+ vec3 lit = lights(dV, lightSoftness);
272
+ vec3 glint = min(R, vec3(0.05)) * LIGHT_GAIN * lit;
273
+ if (front) {
274
+ return R * env + glint;
275
+ }
276
+ float sky = lightIntensity * 0.35 * (0.3 + 0.7 * smoothstep(-0.7, 0.9, dV.y));
277
+ if (behind) {
278
+ return R * (hit ? env : lit) + R * sky;
279
+ }
280
+ return glint + R * sky;
281
+ }
282
+
283
+ // The white line across a border, at distance e from it: a flat core
284
+ // with a short falloff, spread over the pixel's footprint fp when it is
285
+ // thinner, so it keeps its brightness per length instead of breaking up.
286
+ float borderLine(float e, float fp) {
287
+ float c = borderWidth * BORDER_LINE;
288
+ float w = max(c, 0.5 * fp);
289
+ float s = max(0.4 * c, 0.5 * fp);
290
+ return c / w * (1.0 - smoothstep(w - s, w + s, e));
291
+ }
292
+
293
+ // The shell's warp along a piece of the ray, where it is linear: with
294
+ // warpOn, ro and rd are the piece in the unsquashed foam (t scaled by
295
+ // warpL), roReal and rdReal the ray seen. The push is along warpG (out of
296
+ // the side walls) and warpZ (out of the front or back), each when active.
297
+ // The outline is taken as straight: its field is warpA0 + warpGrad . xy.
298
+ bool warpOn = false;
299
+ vec3 roReal;
300
+ vec3 rdReal;
301
+ float warpL;
302
+ vec3 warpG;
303
+ vec3 warpZ;
304
+ vec2 warpGrad;
305
+ float warpA0;
306
+ // A flat film the first cell of the next walk starts with (a bubble cut
307
+ // at the middle of a gap), and its normal.
308
+ bool capOn = false;
309
+ vec3 capN;
310
+
311
+ // A film found along the ray, kept to be shaded a little later: the
312
+ // point and normal as seen, the point in its cell (per cell size), and
313
+ // the rest as addFilm takes them.
314
+ struct Film {
315
+ vec3 p;
316
+ vec3 n;
317
+ vec3 l;
318
+ float id;
319
+ float outer;
320
+ float cover;
321
+ float edge;
322
+ bool entering;
323
+ };
324
+ // The films not shaded yet. A few are enough: segmentFilms shades them
325
+ // on every step, and at most FOUND_MAX are found between two. The list is
326
+ // kept short, since every pixel pays for its size.
327
+ const int FOUND_MAX = 4;
328
+ Film found[FOUND_MAX];
329
+ int nFound = 0;
330
+ // The share of light that passes the opaque bodies found so far: the
331
+ // walk stops when none is left.
332
+ float through = 1.0;
333
+
334
+ // Keep a film at p with normal n, of the cell round \`center\` with id
335
+ // \`id\`: \`outer\` is 1 on the foam's outside, 0 on a wall inside it;
336
+ // \`cover\` is how much of the pixel it covers; \`edge\` the distance to
337
+ // the nearest border on the outside (NO_EDGE: none).
338
+ // The films are shaded apart, in as few places as can be (shadeFilms):
339
+ // each call site of the shading is compiled apart, and it is most of
340
+ // the shader.
341
+ void addFilm(vec3 p, vec3 n, vec3 center, float id, float outer, bool entering, float cover, float edge) {
342
+ vec3 l = (p - center) / cellSize;
343
+ if (warpOn) {
344
+ // In the warped shell, keep the point and normal as seen.
345
+ p = roReal + rdReal * (dot(p - ro, rd) / warpL);
346
+ n = normalize(n + warpK * (warpG * dot(warpG, n) + warpZ * dot(warpZ, n)));
347
+ }
348
+ if (nFound < FOUND_MAX) {
349
+ found[nFound] = Film(p, n, l, id, outer, cover, edge, entering);
350
+ nFound++;
351
+ }
352
+ if (films == 0) {
353
+ firstId = id;
354
+ }
355
+ if (entering) {
356
+ through *= 1.0 - opacity * cover;
357
+ }
358
+ films++;
359
+ }
360
+
361
+ // Shade a film, in front of those shaded before.
362
+ void shadeFilm(Film film) {
363
+ vec3 p = film.p;
364
+ vec3 n = film.n;
365
+ float cover = film.cover;
366
+ float edge = film.edge;
367
+ float th = filmThickness(film.l, film.id);
368
+ vec3 nf = dot(n, rd) > 0.0 ? -n : n;
369
+ float cosI = clamp(-dot(rd, nf), 0.0, 1.0);
370
+ // White light scattered by the water along the borders.
371
+ float white = 0.0;
372
+ if (edge < borderWidth) {
373
+ // The border: the water gathered where two bubbles meet. The
374
+ // film thickens towards it, and a narrow line of it scatters.
375
+ // The pixel's footprint on the film is longer at a grazing angle.
376
+ float fp = pixCone * length(p - ro) / max(cosI, 0.25);
377
+ float f = 1.0 - edge / borderWidth;
378
+ th = min(th + borderThickness * f * f, THICKNESS_MAX);
379
+ white = borderHighlight * borderLine(edge, fp);
380
+ }
381
+ float cosR = max(cosI, rimCos);
382
+ vec3 R = mix(
383
+ vec3(plainFilm(cosR)),
384
+ textureLod(filmLut, vec2(th / THICKNESS_MAX, cosR), 0.0).rgb,
385
+ iridescence
386
+ );
387
+ // Grazing films reflect most, but a foam is mostly grazing films:
388
+ // their reflectance is held down, more for the walls inside it.
389
+ R = min(R, vec3(RIM_MAX)) * mix(WALL_DIM, 1.0, film.outer) * cover;
390
+ vec3 rv = viewRot * reflect(rd, nf);
391
+ vec3 refl = reflected(R, viewRot * p, rv) * reflection;
392
+ col += remain * refl / (1.0 + refl);
393
+ // The light that passes: some of it scattered in the tint, more at a
394
+ // grazing angle, where the path through the film is longer.
395
+ vec3 T = 1.0 - R;
396
+ float k = (1.0 - exp(-tintStrength * 0.03 / max(cosI * cosI, 0.1))) * cover;
397
+ col += remain * T * k * tint;
398
+ remain *= T * (1.0 - k);
399
+ if (white > 0.0) {
400
+ // An even white, lit like the sky the films reflect: it takes
401
+ // from what passes, and shows on the body too.
402
+ float a = clamp(white, 0.0, 1.0) * cover;
403
+ col += remain * a * (0.3 + 0.55 * lightIntensity);
404
+ remain *= 1.0 - a;
405
+ }
406
+ if (film.entering && opacity > 0.0) {
407
+ // A matte, softly lit body: wrapped diffuse from the upper left,
408
+ // a little rim light.
409
+ vec3 nV = viewRot * n;
410
+ float wrap = clamp((dot(nV, normalize(vec3(-0.5, 0.75, 0.6))) + 0.5) / 1.5, 0.0, 1.0);
411
+ float rim = pow(1.0 - cosI, 3.0);
412
+ float li = 0.35 + 0.5 * lightIntensity;
413
+ vec3 body = bodyColor * li * (0.25 + 0.85 * wrap * wrap)
414
+ + rim * 0.2 * li * vec3(0.8, 0.9, 1.0);
415
+ float o = opacity * cover;
416
+ col += remain * o * body;
417
+ remain *= 1.0 - o;
418
+ }
419
+ }
420
+
421
+ // Shade the films found since the last call, front to back.
422
+ void shadeFilms() {
423
+ // The films are kept as seen: shade them along the ray seen, also
424
+ // from inside the warped shell.
425
+ vec3 roWalk = ro;
426
+ vec3 rdWalk = rd;
427
+ if (warpOn) {
428
+ ro = roReal;
429
+ rd = rdReal;
430
+ }
431
+ for (int i = 0; i < FOUND_MAX; i++) {
432
+ if (i >= nFound) {
433
+ break;
434
+ }
435
+ shadeFilm(found[i]);
436
+ }
437
+ nFound = 0;
438
+ ro = roWalk;
439
+ rd = rdWalk;
440
+ }
441
+
442
+ // ---- the foam: a power diagram of spheres, found through a grid ----
443
+
444
+ // The spheres of the grid cell the ray is in that it passes through on
445
+ // the segment: centre (drifted) and radius, id, and the ray's power line
446
+ // b t + k for each.
447
+ vec4 cand[MAX_CAND];
448
+ float candId[MAX_CAND];
449
+ vec2 candBK[MAX_CAND];
450
+ int nCand = 0;
451
+
452
+ // The fill along the current stretch inside the shape: the outline's
453
+ // field and gradient there, sampled at even steps of fillDt from fillT0
454
+ // and taken as straight between them.
455
+ #define FILL_STEPS 8
456
+ bool fillOn = false;
457
+ float fillT0;
458
+ float fillDt;
459
+ vec3 fillKnot[FILL_STEPS + 1];
460
+
461
+ vec3 fillOutline(float t) {
462
+ float u = clamp((t - fillT0) / fillDt, 0.0, float(FILL_STEPS));
463
+ int i = min(int(u), FILL_STEPS - 1);
464
+ return mix(fillKnot[i], fillKnot[i + 1], u - float(i));
465
+ }
466
+
467
+ ivec2 texel(int i) {
468
+ return ivec2(i % TEX_W, i / TEX_W);
469
+ }
470
+
471
+ // Load the spheres of grid cell C that the ray passes through on
472
+ // [t0, t1]. The cell's list holds every sphere that can reach into it,
473
+ // drift included, so none that owns a point of the segment is missed.
474
+ // With \`all\`, every sphere of the list is loaded instead.
475
+ void loadCell(ivec3 C, float t0, float t1, bool all) {
476
+ nCand = 0;
477
+ if (any(lessThan(C, ivec3(0))) || any(greaterThanEqual(C, gridDims))) {
478
+ return;
479
+ }
480
+ vec4 head = texelFetch(cellTex, texel(C.x + gridDims.x * (C.y + gridDims.y * C.z)), 0);
481
+ cost += 1.0;
482
+ int off = int(head.x);
483
+ int count = min(int(head.y), MAX_CAND);
484
+ vec4 idx = vec4(0.0);
485
+ for (int j = 0; j < MAX_CAND; j++) {
486
+ if (j >= count) {
487
+ break;
488
+ }
489
+ int e = off + j;
490
+ if (j == 0 || (e & 3) == 0) {
491
+ idx = texelFetch(indexTex, texel(e >> 2), 0);
492
+ cost += 1.0;
493
+ }
494
+ int i = int(idx[e & 3]);
495
+ vec4 sph = texelFetch(sphereTex, texel(i), 0);
496
+ cost += 1.0;
497
+ // In the shell, only the bubbles poking out through this side.
498
+ if (warpOn && warpA0 + dot(warpGrad, sph.xy) > 0.5 * sph.w) {
499
+ continue;
500
+ }
501
+ vec3 oc = ro - sph.xyz;
502
+ vec2 bk = vec2(2.0 * dot(rd, oc), dot(oc, oc) - sph.w * sph.w);
503
+ if (all) {
504
+ cand[nCand] = sph;
505
+ candId[nCand] = sphereId(i);
506
+ candBK[nCand] = bk;
507
+ nCand++;
508
+ continue;
509
+ }
510
+ // With the fill a sphere owns points beyond its radius: keep it
511
+ // as far as it reaches with the fill.
512
+ float disc = bk.x * bk.x - 4.0 * (bk.y - (fillOn ? fillG : 0.0));
513
+ if (disc <= 0.0) {
514
+ continue;
515
+ }
516
+ vec2 hit = 0.5 * (-bk.x + vec2(-1.0, 1.0) * sqrt(disc));
517
+ // Only spheres the ray passes through on the segment can own a
518
+ // point inside the foam; the others are left out of the envelope.
519
+ if (hit.x < t1 && hit.y > t0) {
520
+ cand[nCand] = sph;
521
+ candId[nCand] = sphereId(i);
522
+ candBK[nCand] = bk;
523
+ nCand++;
524
+ }
525
+ }
526
+ }
527
+
528
+ // ---- borders: where two bubbles meet ----
529
+
530
+ // The distance from q, in the cell of sphere \`own\` (whose power at q is
531
+ // powI), to the wall it shares with sphere s: walls lie on radical
532
+ // planes, so it is exact. Keeps the nearer of it and e; the owner itself
533
+ // is skipped.
534
+ void nearWall(inout float e, vec3 q, vec4 own, float powI, vec4 s) {
535
+ vec3 dc = s.xyz - own.xyz;
536
+ float d2 = dot(dc, dc);
537
+ if (d2 < 1e-12) {
538
+ return;
539
+ }
540
+ vec3 m = q - s.xyz;
541
+ float ri = inversesqrt(d2);
542
+ e = min(e, (dot(m, m) - s.w * s.w - powI) * 0.5 * ri);
543
+ }
544
+
545
+ // The distance from q to the nearest wall of its owner's cell, over
546
+ // every sphere the border grid's cell of q lists (as
547
+ // \`_sphere-foam.ts\`'s borderDist). A sphere that could bound the cell at q contains q or is
548
+ // close to it, so it reaches into that grid cell and is listed. The list
549
+ // is read again here: the one loaded for the ray keeps only the spheres
550
+ // the ray passes through.
551
+ float borderDist(vec3 q, vec4 own) {
552
+ ivec3 C = ivec3(floor((q - edgeOrigin) / edgeCell));
553
+ if (any(lessThan(C, ivec3(0))) || any(greaterThanEqual(C, edgeDims))) {
554
+ return NO_EDGE;
555
+ }
556
+ vec4 head = texelFetch(edgeCellTex, texel(C.x + edgeDims.x * (C.y + edgeDims.y * C.z)), 0);
557
+ cost += 1.0;
558
+ int off = int(head.x);
559
+ int count = min(int(head.y), MAX_CAND);
560
+ vec3 mo = q - own.xyz;
561
+ float powI = dot(mo, mo) - own.w * own.w;
562
+ float e = NO_EDGE;
563
+ vec4 idx = vec4(0.0);
564
+ for (int j = 0; j < MAX_CAND; j++) {
565
+ if (j >= count) {
566
+ break;
567
+ }
568
+ int k = off + j;
569
+ if (j == 0 || (k & 3) == 0) {
570
+ idx = texelFetch(edgeIndexTex, texel(k >> 2), 0);
571
+ cost += 1.0;
572
+ }
573
+ int i = int(idx[k & 3]);
574
+ vec4 sph = texelFetch(sphereTex, texel(i), 0);
575
+ cost += 1.0;
576
+ if (warpOn && warpA0 + dot(warpGrad, sph.xy) > 0.5 * sph.w) {
577
+ continue;
578
+ }
579
+ nearWall(e, q, own, powI, sph);
580
+ }
581
+ return max(e, 0.0);
582
+ }
583
+
584
+ bool sphereInside = false;
585
+
586
+ // The shape's field at t on the stretch, and its gradient.
587
+ float fillField(float t, out vec3 grad) {
588
+ float zt = ro.z + rd.z * t;
589
+ float dz = abs(zt) - halfDepth;
590
+ vec3 o = fillOutline(t);
591
+ grad = o.x > dz ? vec3(o.yz, 0.0) : vec3(0.0, 0.0, zt >= 0.0 ? 1.0 : -1.0);
592
+ return max(o.x, dz);
593
+ }
594
+
595
+ // What the fill adds to r² at t.
596
+ float fillAt(float t) {
597
+ vec3 grad;
598
+ return fillG * smoothstep(0.0, 1.0, -fillField(t, grad) / fillDepth);
599
+ }
600
+ // The cell that owns the end of the last segment (an index into cand).
601
+ int segOwn = 0;
602
+ // Whether the last grid walk ended inside a bubble, and that bubble.
603
+ bool endInside = false;
604
+ vec4 endSph;
605
+ float endId;
606
+
607
+ // The film on the container's wall at t, where it cuts the cell of sphere i.
608
+ void wallFilm(int i, float t, bool entering) {
609
+ vec3 p = ro + rd * t;
610
+ vec4 s = sdf3(p);
611
+ cost += 1.0;
612
+ float edge = NO_EDGE;
613
+ if (borderWidth > 0.0) {
614
+ edge = borderDist(p, cand[i]);
615
+ }
616
+ addFilm(p, s.yzw, cand[i].xyz, candId[i], 1.0, entering, 1.0, edge);
617
+ }
618
+
619
+ // The film on a sphere's own surface at t.
620
+ void sphereFilm(int i, float t, bool entering, float cover) {
621
+ vec3 p = ro + rd * t;
622
+ vec3 n = (p - cand[i].xyz) / cand[i].w;
623
+ if (fillOn) {
624
+ // The surface is |p - c|² - r² = fill: its gradient bends with
625
+ // the fill's.
626
+ vec3 grad;
627
+ float sf = fillField(t, grad);
628
+ if (sf < 0.0 && sf > -fillDepth) {
629
+ float q = -sf / fillDepth;
630
+ n = normalize(p - cand[i].xyz + 3.0 * q * (1.0 - q) * fillG / fillDepth * grad);
631
+ }
632
+ }
633
+ float edge = NO_EDGE;
634
+ if (borderWidth > 0.0) {
635
+ edge = borderDist(p, cand[i]);
636
+ }
637
+ addFilm(p, n, cand[i].xyz, candId[i], 1.0, entering, cover, edge);
638
+ }
639
+
640
+ // The films of the foam on [t0, t1] with the spheres loaded: the lower
641
+ // envelope of the power lines, as in \`_sphere-foam.ts\`.
642
+ // \`first\`: t0 is where the ray enters the container, so a cell that
643
+ // holds that point starts with a film on the container's wall.
644
+ void segmentFilms(float t0, float t1, float cone, int layers, bool first) {
645
+ int n = nCand;
646
+ int own = 0;
647
+ float lo = candBK[0].x * t0 + candBK[0].y;
648
+ for (int i = 1; i < MAX_CAND; i++) {
649
+ if (i >= n) {
650
+ break;
651
+ }
652
+ float l = candBK[i].x * t0 + candBK[i].y;
653
+ if (l < lo || (l == lo && candBK[i].x < candBK[own].x)) {
654
+ lo = l;
655
+ own = i;
656
+ }
657
+ }
658
+ segOwn = own;
659
+ // The fill over the segment, a line there: g0 + gB (t - t0).
660
+ float g0 = 0.0;
661
+ float gB = 0.0;
662
+ if (fillOn && n > 0) {
663
+ g0 = fillAt(t0);
664
+ gB = (fillAt(t1) - g0) / max(t1 - t0, 1e-6);
665
+ }
666
+ float ta = t0;
667
+ for (int guard = 0; guard <= MAX_CAND; guard++) {
668
+ // The one place in the walk where films are shaded, in every
669
+ // cell, empty ones too. A step finds two films at most, and the
670
+ // walkers add two more between calls.
671
+ shadeFilms();
672
+ if (n == 0) {
673
+ sphereInside = false;
674
+ return;
675
+ }
676
+ if (first && guard == 0) {
677
+ sphereInside = t0 * t0 + lo - g0 < 0.0;
678
+ if (sphereInside && WALL_ON) {
679
+ wallFilm(own, t0, true);
680
+ } else if (sphereInside && capOn) {
681
+ addFilm(ro + rd * t0, capN, cand[own].xyz, candId[own], 1.0, true, 1.0, NO_EDGE);
682
+ }
683
+ }
684
+ if (films >= layers) {
685
+ return;
686
+ }
687
+ vec2 bo = candBK[own];
688
+ float ts = 1e30;
689
+ int next = -1;
690
+ for (int j = 0; j < MAX_CAND; j++) {
691
+ if (j >= n) {
692
+ break;
693
+ }
694
+ vec2 bj = candBK[j];
695
+ if (bj.x < bo.x) {
696
+ float tj = max((bj.y - bo.y) / (bo.x - bj.x), ta);
697
+ if (tj < ts) {
698
+ ts = tj;
699
+ next = j;
700
+ }
701
+ }
702
+ }
703
+ float tb = min(ts, t1);
704
+ // The owner's power less the fill: t² + bf.x t + bf.y.
705
+ vec2 bf = bo - vec2(gB, g0 - gB * t0);
706
+ float disc = bf.x * bf.x - 4.0 * bf.y;
707
+ if (disc > 0.0) {
708
+ float hh = sqrt(disc);
709
+ float tIn = 0.5 * (-bf.x - hh);
710
+ float tOut = 0.5 * (-bf.x + hh);
711
+ // Edge antialiasing: a chord shorter than the pixel's
712
+ // footprint covers part of it.
713
+ float cover = clamp(0.5 * hh / max(cone * tIn, 1e-6), 0.0, 1.0);
714
+ if (!sphereInside && tIn > ta && tIn <= tb && tIn > 0.0) {
715
+ sphereFilm(own, tIn, true, cover);
716
+ sphereInside = true;
717
+ }
718
+ if (sphereInside && tOut > ta && tOut <= tb && films < layers) {
719
+ sphereFilm(own, tOut, false, cover);
720
+ sphereInside = false;
721
+ }
722
+ }
723
+ if (next < 0 || ts >= t1) {
724
+ return;
725
+ }
726
+ if (sphereInside && films < layers) {
727
+ // One flat wall on the radical plane, shared by both cells.
728
+ vec3 p = ro + rd * ts;
729
+ vec3 c = 0.5 * (cand[own].xyz + cand[next].xyz);
730
+ addFilm(p, normalize(cand[next].xyz - cand[own].xyz), c, candId[own] + candId[next], 0.0, false, 1.0, NO_EDGE);
731
+ }
732
+ own = next;
733
+ segOwn = own;
734
+ ta = ts;
735
+ }
736
+ }
737
+
738
+ float fillCut(float num, float den) {
739
+ return abs(den) > 1e-7 ? num / den : 1e30;
740
+ }
741
+
742
+ // The films on [t0, t1]. With the fill, the stretch is split where the
743
+ // fill bends along the ray, so it is close to a line on each part.
744
+ void sphereSegment(float t0, float t1, float cone, int layers, bool first) {
745
+ // Without the fill, the whole stretch in one part.
746
+ bool split = fillOn && nCand > 0;
747
+ // The middle plane, and where the fill is full along z.
748
+ float zFull = halfDepth - fillDepth;
749
+ vec3 cut = vec3(
750
+ fillCut(-ro.z, rd.z),
751
+ fillCut(zFull - ro.z, rd.z),
752
+ fillCut(-zFull - ro.z, rd.z)
753
+ );
754
+ float ta = t0;
755
+ for (int k = 0; k < FILL_STEPS + 4; k++) {
756
+ // The next sample of the outline's field.
757
+ float tn = t1;
758
+ if (split) {
759
+ tn = min(t1, fillT0 + fillDt * (floor((ta - fillT0) / fillDt + 1e-3) + 1.0));
760
+ for (int c = 0; c < 3; c++) {
761
+ if (cut[c] > ta + 1e-5 && cut[c] < tn) {
762
+ tn = cut[c];
763
+ }
764
+ }
765
+ }
766
+ segmentFilms(ta, tn, cone, layers, first && k == 0);
767
+ if (tn >= t1 || films >= layers) {
768
+ return;
769
+ }
770
+ ta = tn;
771
+ }
772
+ }
773
+
774
+ // The container's field along the ray (negative inside).
775
+ float clipField(float t) {
776
+ cost += 1.0;
777
+ return sdf3(ro + rd * t).x - clipOff;
778
+ }
779
+
780
+ // Walk the grid on [a, b], a stretch of the ray inside the shape (or,
781
+ // with WALL_ON, inside the container): the foam's films there. With
782
+ // WALL_ON, a cell cut by the container gets a film on its wall.
783
+ void walkGrid(float a, float b, float cone, int layers) {
784
+ vec3 d = mix(rd, vec3(1e-7), lessThan(abs(rd), vec3(1e-7)));
785
+ vec3 inv = 1.0 / d;
786
+ ivec3 stp = ivec3(sign(d));
787
+ vec3 tDelta = gridCell * abs(inv);
788
+ vec3 q = (ro + rd * a - gridOrigin) / gridCell;
789
+ ivec3 C = clamp(ivec3(floor(q)), ivec3(0), gridDims - 1);
790
+ vec3 tMax = a + (vec3(C) + step(0.0, d) - q) * gridCell * inv;
791
+ float tw = a;
792
+ bool first = true;
793
+ sphereInside = false;
794
+ for (int i = 0; i < 128; i++) {
795
+ if (films >= layers || through < 0.02) {
796
+ return;
797
+ }
798
+ float tn = min(tMax.x, min(tMax.y, tMax.z));
799
+ float te = min(tn, b);
800
+ loadCell(C, tw, te, false);
801
+ sphereSegment(tw, te, cone, layers, first);
802
+ first = false;
803
+ if (tn >= b) {
804
+ if (sphereInside && films < layers && nCand > 0 && WALL_ON) {
805
+ wallFilm(segOwn, b, false);
806
+ }
807
+ break;
808
+ }
809
+ tw = tn;
810
+ int axis = tMax.x <= tMax.y && tMax.x <= tMax.z ? 0 : (tMax.y <= tMax.z ? 1 : 2);
811
+ C[axis] += stp[axis];
812
+ tMax[axis] += tDelta[axis];
813
+ if (C[axis] < 0 || C[axis] >= gridDims[axis]) {
814
+ break;
815
+ }
816
+ }
817
+ endInside = sphereInside && nCand > 0;
818
+ if (endInside) {
819
+ endSph = cand[segOwn];
820
+ endId = candId[segOwn];
821
+ }
822
+ sphereInside = false;
823
+ }
824
+
825
+ // Walk [ta, tb] of the shell. Out of an extruded shape the push along
826
+ // its field splits into one out of the side walls (by the outline's
827
+ // field) and one out of the front or back (by |z| - halfDepth), even
828
+ // round its edges. With the outline taken as straight near the ray, both
829
+ // are linear in t between the points where each starts, so the ray is
830
+ // straight in the unsquashed foam on each piece, and the pieces join.
831
+ void shellWalk(float ta, float tb, float cone, int layers) {
832
+ roReal = ro;
833
+ rdReal = rd;
834
+ vec3 pm = ro + rd * (0.5 * (ta + tb));
835
+ vec3 s2 = sd2(pm.xy);
836
+ cost += 1.0;
837
+ vec2 g = s2.yz;
838
+ warpGrad = g;
839
+ warpA0 = s2.x - dot(g, pm.xy);
840
+ // The outline's field along the ray, a + b t.
841
+ float a = warpA0 + dot(g, ro.xy);
842
+ float b = dot(g, rd.xy);
843
+ float bp[3];
844
+ bp[0] = abs(b) > 1e-6 ? -a / b : 1e30;
845
+ bp[1] = abs(rd.z) > 1e-6 ? (halfDepth - ro.z) / rd.z : 1e30;
846
+ bp[2] = abs(rd.z) > 1e-6 ? (-halfDepth - ro.z) / rd.z : 1e30;
847
+ for (int i = 0; i < 2; i++) {
848
+ for (int j = 0; j < 2 - i; j++) {
849
+ if (bp[j] > bp[j + 1]) {
850
+ float x = bp[j];
851
+ bp[j] = bp[j + 1];
852
+ bp[j + 1] = x;
853
+ }
854
+ }
855
+ }
856
+ float t0 = ta;
857
+ for (int i = 0; i <= 3; i++) {
858
+ float t1 = i < 3 ? clamp(bp[i], ta, tb) : tb;
859
+ if (t1 > t0 + 1e-6) {
860
+ float tc = 0.5 * (t0 + t1);
861
+ float zc = roReal.z + rdReal.z * tc;
862
+ float sz = zc >= 0.0 ? 1.0 : -1.0;
863
+ float xy = a + b * tc > 0.0 ? 1.0 : 0.0;
864
+ float zz = abs(zc) > halfDepth ? 1.0 : 0.0;
865
+ vec3 G = vec3(g, 0.0) * xy;
866
+ vec3 Z = vec3(0.0, 0.0, sz) * zz;
867
+ vec3 q0 = roReal + warpK * (a * G + (sz * roReal.z - halfDepth) * Z);
868
+ vec3 dq = rdReal + warpK * (b * G + sz * rdReal.z * Z);
869
+ float L = length(dq);
870
+ ro = q0;
871
+ rd = dq / L;
872
+ warpL = L;
873
+ warpG = G;
874
+ warpZ = Z;
875
+ warpOn = true;
876
+ walkGrid(t0 * L, t1 * L, cone / L, layers);
877
+ warpOn = false;
878
+ capOn = false;
879
+ ro = roReal;
880
+ rd = rdReal;
881
+ if (films >= layers) {
882
+ return;
883
+ }
884
+ }
885
+ t0 = max(t0, t1);
886
+ }
887
+ }
888
+
889
+
890
+ // ---- the squashed shell outside the shape ----
891
+
892
+ // The squashed shell from t, where the ray is outside the shape and in
893
+ // the container. Its stretch is found by tracing the shape's field, then
894
+ // walked by shellWalk. True when the ray enters the shape (t there).
895
+ bool shellStretch(inout float t, float tEnd, float cone, int layers) {
896
+ float stepMin = max(clipOff / 16.0, 2e-4);
897
+ for (int part = 0; part < 3; part++) {
898
+ float ta = t;
899
+ vec4 s = sdf3(ro + rd * t);
900
+ cost += 1.0;
901
+ if (s.x < 0.0) {
902
+ return true;
903
+ }
904
+ vec3 n0 = s.yzw;
905
+ int how = 0;
906
+ for (int i = 0; i < 48; i++) {
907
+ float tp = t;
908
+ float sp = s.x;
909
+ t += max(s.x, stepMin);
910
+ if (t >= tEnd) {
911
+ t = tEnd;
912
+ break;
913
+ }
914
+ s = sdf3(ro + rd * t);
915
+ cost += 1.0;
916
+ if (s.x < 0.0) {
917
+ // Into the shape.
918
+ t = tp + (t - tp) * sp / (sp - s.x);
919
+ how = 1;
920
+ break;
921
+ }
922
+ if (s.x > clipOff) {
923
+ // Out of the container.
924
+ t = tp + (t - tp) * (clipOff - sp) / (s.x - sp);
925
+ break;
926
+ }
927
+ if (dot(s.yzw, n0) < 0.0) {
928
+ // A crease: the middle of a gap, the nearest side changes.
929
+ t = 0.5 * (tp + t);
930
+ how = 2;
931
+ break;
932
+ }
933
+ }
934
+ if (t > ta) {
935
+ shellWalk(ta, t, cone, layers);
936
+ }
937
+ if (how == 1) {
938
+ return true;
939
+ }
940
+ if (how != 2 || films >= layers) {
941
+ return false;
942
+ }
943
+ // The near bubble ends flat at the crease; the far side starts
944
+ // with one.
945
+ vec3 nc = normalize(n0 - s.yzw + 1e-5 * rd);
946
+ if (endInside) {
947
+ addFilm(ro + rd * t, nc, endSph.xyz, endId, 1.0, false, 1.0, NO_EDGE);
948
+ }
949
+ capOn = true;
950
+ capN = nc;
951
+ t += 1e-4;
952
+ }
953
+ return false;
954
+ }
955
+
956
+ // The foam inside the container. The ray's stretches inside it are
957
+ // found by tracing the shape's field. With WALL_ON each is walked through
958
+ // the grid and cut flat by the container. Otherwise the stretches inside
959
+ // the shape are walked the same way, and those between the shape and the
960
+ // container, where the foam is squashed, by shellStretch.
961
+ void traceContained(vec2 tb, float cone, int layers) {
962
+ float t = max(tb.x, 0.0);
963
+ float eps = 1e-3;
964
+ for (int iv = 0; iv < 6; iv++) {
965
+ // Into the container. A ray that only grazes it is not in it: it
966
+ // goes on, so a run of grazing points does not use up the stretches.
967
+ float g = clipField(t);
968
+ for (int i = 0; i < 64 && g > 0.0 && t <= tb.y; i++) {
969
+ t += max(g, eps);
970
+ g = clipField(t);
971
+ }
972
+ if (t > tb.y || films >= layers) {
973
+ return;
974
+ }
975
+ if (g > 0.0) {
976
+ // Out of steps: go on from here.
977
+ continue;
978
+ }
979
+ for (int k = 0; k < 4; k++) {
980
+ #if CONTAIN == 2
981
+ if (!shellStretch(t, tb.y, cone, layers)) {
982
+ break;
983
+ }
984
+ #endif
985
+ // Through the container (WALL_ON) or the shape, to where the
986
+ // ray leaves it.
987
+ float off = WALL_ON ? clipOff : 0.0;
988
+ float a = t;
989
+ float tp = t;
990
+ float gp = 0.0;
991
+ g = sdf3(ro + rd * t).x - off;
992
+ float b = tb.y;
993
+ for (int i = 0; i < 96; i++) {
994
+ tp = t;
995
+ gp = g;
996
+ t += max(-g, 2.0 * eps);
997
+ if (t >= tb.y) {
998
+ break;
999
+ }
1000
+ g = sdf3(ro + rd * t).x - off;
1001
+ cost += 1.0;
1002
+ if (g > 0.0) {
1003
+ b = gp < 0.0 ? tp + (t - tp) * gp / (gp - g) : tp;
1004
+ break;
1005
+ }
1006
+ }
1007
+ // Inside the shape: the fill.
1008
+ fillOn = fillG > 0.0;
1009
+ if (fillOn) {
1010
+ fillT0 = a;
1011
+ fillDt = max(b - a, 1e-5) / float(FILL_STEPS);
1012
+ for (int i = 0; i <= FILL_STEPS; i++) {
1013
+ fillKnot[i] = sd2((ro + rd * (a + fillDt * float(i))).xy);
1014
+ }
1015
+ cost += float(FILL_STEPS + 1);
1016
+ }
1017
+ walkGrid(a, b, cone, layers);
1018
+ fillOn = false;
1019
+ t = b + (WALL_ON ? 4.0 * eps : 1e-4);
1020
+ if (WALL_ON || films >= layers || t >= tb.y) {
1021
+ break;
1022
+ }
1023
+ }
1024
+ if (films >= layers || t >= tb.y) {
1025
+ return;
1026
+ }
1027
+ t += 4.0 * eps;
1028
+ }
1029
+ }
1030
+
1031
+ void traceSpheres(vec2 tb, float cone, int layers) {
1032
+ float t = max(tb.x, 0.0);
1033
+ bool walking = false;
1034
+ ivec3 C = ivec3(0);
1035
+ vec3 tMax = vec3(0.0);
1036
+ vec3 tDelta = vec3(0.0);
1037
+ ivec3 stp = ivec3(0);
1038
+ for (int i = 0; i < 256; i++) {
1039
+ if (t > tb.y || films >= layers || through < 0.02) {
1040
+ break;
1041
+ }
1042
+ if (!walking) {
1043
+ // Empty space: no sphere reaches farther than this out of the
1044
+ // shape.
1045
+ float s = sdf3(ro + rd * t).x;
1046
+ cost += 1.0;
1047
+ if (s > reachMax + 1e-4) {
1048
+ t += s - reachMax;
1049
+ continue;
1050
+ }
1051
+ vec3 q = (ro + rd * t - gridOrigin) / gridCell;
1052
+ C = clamp(ivec3(floor(q)), ivec3(0), gridDims - 1);
1053
+ vec3 d = mix(rd, vec3(1e-7), lessThan(abs(rd), vec3(1e-7)));
1054
+ vec3 inv = 1.0 / d;
1055
+ stp = ivec3(sign(d));
1056
+ tMax = t + (vec3(C) + step(0.0, d) - q) * gridCell * inv;
1057
+ tDelta = gridCell * abs(inv);
1058
+ sphereInside = false;
1059
+ walking = true;
1060
+ }
1061
+ float tn = min(tMax.x, min(tMax.y, tMax.z));
1062
+ float te = min(tn, tb.y);
1063
+ loadCell(C, t, te, false);
1064
+ sphereSegment(t, te, cone, layers, false);
1065
+ t = tn;
1066
+ int axis = tMax.x <= tMax.y && tMax.x <= tMax.z ? 0 : (tMax.y <= tMax.z ? 1 : 2);
1067
+ C[axis] += stp[axis];
1068
+ tMax[axis] += tDelta[axis];
1069
+ if (C[axis] < 0 || C[axis] >= gridDims[axis]) {
1070
+ // Out of the grid: no sphere is left ahead.
1071
+ break;
1072
+ }
1073
+ // Out of every sphere and well away from the shape: back to
1074
+ // tracing, which skips the empty cells faster than stepping.
1075
+ if (!sphereInside) {
1076
+ float s = sdf3(ro + rd * t).x;
1077
+ cost += 1.0;
1078
+ if (s > reachMax + 2.0 * gridCell) {
1079
+ walking = false;
1080
+ }
1081
+ }
1082
+ }
1083
+ }
1084
+
1085
+ // Slab test against the shape's bounding box. x = near, y = far.
1086
+ vec2 boundsHit() {
1087
+ vec3 b = vec3(shapeHalf, halfDepth) + boxMargin + 0.01;
1088
+ vec3 inv = 1.0 / rd;
1089
+ vec3 t0 = (-b - ro) * inv;
1090
+ vec3 t1 = (b - ro) * inv;
1091
+ vec3 lo = min(t0, t1);
1092
+ vec3 hi = max(t0, t1);
1093
+ return vec2(max(max(lo.x, lo.y), lo.z), min(min(hi.x, hi.y), hi.z));
1094
+ }
1095
+
1096
+ void main() {
1097
+ vec2 px = uv * bufferPx;
1098
+ vec3 rdV = normalize(vec3((px - principalPx) / focalPx, -1.0));
1099
+ vec3 roV = vec3(eye, camDist);
1100
+ // viewRot maps object to view; its transpose maps back.
1101
+ ro = roV * viewRot;
1102
+ rd = rdV * viewRot;
1103
+
1104
+ vec3 miss = vec3(0.0);
1105
+ float missA = 0.0;
1106
+ if (backdropVisible > 0.5 && backdropMode != 0) {
1107
+ miss = radiance(roV, rdV, 0.0);
1108
+ missA = 1.0;
1109
+ }
1110
+
1111
+ vec2 tb = boundsHit();
1112
+ // Every sphere, drift included, is inside the grid's box.
1113
+ vec3 gInv = 1.0 / mix(rd, vec3(1e-7), lessThan(abs(rd), vec3(1e-7)));
1114
+ vec3 g0 = (gridOrigin - ro) * gInv;
1115
+ vec3 g1 = (gridOrigin + vec3(gridDims) * gridCell - ro) * gInv;
1116
+ vec3 gLo = min(g0, g1);
1117
+ vec3 gHi = max(g0, g1);
1118
+ tb.x = max(tb.x, max(max(gLo.x, gLo.y), gLo.z));
1119
+ tb.y = min(tb.y, min(min(gHi.x, gHi.y), gHi.z));
1120
+ if (tb.x > tb.y || tb.y < 0.0) {
1121
+ outColor = debugView != 0 ? (debugView == 3 ? vec4(0.0, 0.0, 0.0, 1.0) : heat(0.0)) : vec4(miss, missA);
1122
+ return;
1123
+ }
1124
+ // Radius of the pixel's cone per unit of distance.
1125
+ float cone = pixelSize / focalPx;
1126
+ pixCone = cone;
1127
+ #if CONTAIN == 0
1128
+ traceSpheres(tb, cone, clamp(maxLayers, 1, MAX_LAYERS));
1129
+ #else
1130
+ traceContained(tb, cone, clamp(maxLayers, 1, MAX_LAYERS));
1131
+ #endif
1132
+ shadeFilms();
1133
+
1134
+ if (debugView == 1) {
1135
+ outColor = heat(cost);
1136
+ return;
1137
+ }
1138
+ if (debugView == 2) {
1139
+ outColor = heat(float(films) * 40.0);
1140
+ return;
1141
+ }
1142
+ if (debugView == 3) {
1143
+ vec3 c = firstId < 0.0
1144
+ ? vec3(0.0)
1145
+ : 0.25 + 0.75 * hash4(uvec3(uint(firstId * 7.0 + 3.0), 11u, 3u)).rgb;
1146
+ outColor = vec4(c, 1.0);
1147
+ return;
1148
+ }
1149
+ // What is behind: the backdrop when it is drawn, otherwise the page,
1150
+ // dimmed by what the films take from it.
1151
+ if (missA > 0.0) {
1152
+ outColor = vec4(col + remain * miss, 1.0);
1153
+ } else {
1154
+ float a = 1.0 - (remain.r + remain.g + remain.b) / 3.0;
1155
+ outColor = vec4(col, a);
1156
+ }
1157
+ }
1158
+ `;
1159
+ // The shaders made so far, by containment mode and kind of backdrop.
1160
+ const FRAG_BUBBLES = new Map();
1161
+ function fragBubbleFor(mode, kind) {
1162
+ const key = `${mode}:${kind}`;
1163
+ let frag = FRAG_BUBBLES.get(key);
1164
+ if (!frag) {
1165
+ frag = fragBubble(mode, kind);
1166
+ FRAG_BUBBLES.set(key, frag);
1167
+ }
1168
+ return frag;
1169
+ }
1170
+ function finite(v, fallback) {
1171
+ return Number.isFinite(v) ? v : fallback;
1172
+ }
1173
+ function clamp(v, lo, hi, fallback) {
1174
+ return Math.min(Math.max(finite(v, fallback), lo), hi);
1175
+ }
1176
+ function colorOf(hex, fallback) {
1177
+ return hexToRgb(hex, fallback);
1178
+ }
1179
+ // A data texture read with texelFetch: RGBA32F, nearest.
1180
+ function uploadDataTexture(gl, w, h, data) {
1181
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
1182
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
1183
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
1184
+ const tex = gl.createTexture();
1185
+ gl.bindTexture(gl.TEXTURE_2D, tex);
1186
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, w, h, 0, gl.RGBA, gl.FLOAT, data);
1187
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
1188
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
1189
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
1190
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
1191
+ gl.bindTexture(gl.TEXTURE_2D, null);
1192
+ return tex;
1193
+ }
1194
+ function maxRadius(grid) {
1195
+ let maxR = 0;
1196
+ for (let i = 0; i < grid.count; i++) {
1197
+ maxR = Math.max(maxR, grid.spheres[i * 4 + 3]);
1198
+ }
1199
+ return maxR;
1200
+ }
1201
+ /**
1202
+ * Fills the element's silhouette, extruded into 3D, with a foam of
1203
+ * transparent soap bubbles in thin-film colours.
1204
+ *
1205
+ * ```ts
1206
+ * vfx.add(img, { effect: new BubbleEffect({ roundness: 0.7 }) });
1207
+ * ```
1208
+ *
1209
+ * The volume is filled with big spheres spread at random but evenly
1210
+ * (`cellSize`), and the gaps they leave, between them and along the
1211
+ * outline, with smaller ones down to `minSize`. Where spheres overlap,
1212
+ * they are cut by a flat wall they share (a power diagram); where they
1213
+ * are exposed, they keep their round outside. `roundness` goes from a
1214
+ * flat-walled foam to nearly separate spheres. The films are found
1215
+ * exactly along each ray.
1216
+ *
1217
+ * The silhouette is the element's alpha (or the channel
1218
+ * {@link BubbleParams.sourceChannel | sourceChannel} picks), read back
1219
+ * when the effect starts and again when the element's aspect ratio
1220
+ * changes. Call {@link BubbleEffect.refresh | refresh()} after its
1221
+ * content changes. Films do not bend
1222
+ * light, so the page shows through the foam, dimmed by what the films
1223
+ * reflect; the output is premultiplied over it. With `backdropVisible`,
1224
+ * a backdrop is drawn behind the foam instead.
1225
+ *
1226
+ * The camera ({@link OrbitCameraParams}: `yaw`, `pitch`,
1227
+ * `orbitAnimation`, `fov`, …) works as in {@link GlassEffect}, with
1228
+ * angles in degrees. Set `drag: true` to orbit it with pointer drags that
1229
+ * start on the element, and `pointer: "tilt"` to turn it towards the
1230
+ * pointer.
1231
+ *
1232
+ * All params are read every frame, so you can mutate `params` live. The
1233
+ * bubbles are placed on the CPU, again whenever a placement param
1234
+ * changes (see {@link BubbleParams}).
1235
+ */
1236
+ export class BubbleEffect {
1237
+ params;
1238
+ #still;
1239
+ // Reads the silhouette back: when the effect starts, on refresh(),
1240
+ // and when the element's aspect ratio changes.
1241
+ #source = new SourceCapture({
1242
+ longSide: BUBBLE_MASK_LONG,
1243
+ onRead: (r, isCurrent) => this.#onRead(r, isCurrent),
1244
+ });
1245
+ // `sourceChannel` of the last shape read; a change reads it again.
1246
+ #channel = null;
1247
+ #pending = null;
1248
+ #shape = null;
1249
+ // The latest shape read. It takes over once its foam is placed.
1250
+ #next = null;
1251
+ #passes = new ScenePasses();
1252
+ #gl = null;
1253
+ #sdfRaw = null;
1254
+ #lutRaw = null;
1255
+ #sdfTex = null;
1256
+ #lutTex = null;
1257
+ #foamData = null;
1258
+ // Places the bubbles off the page's thread, where it can. Made when
1259
+ // first needed (again after dispose()).
1260
+ #kernel = null;
1261
+ // One job at a time: while it runs, param changes wait, and when it
1262
+ // comes back the next frame asks for the foam of the params then. A
1263
+ // reply is drawn even if the params moved on (a step closer), unless
1264
+ // the shape changed under it. The token drops replies after dispose().
1265
+ #foamBusy = false;
1266
+ #foamReady = null;
1267
+ // The key whose job or upload failed, so it is not asked again every
1268
+ // frame.
1269
+ #foamFailed = null;
1270
+ #foamToken = 0;
1271
+ // The shape and fill the kernel placed bubbles for last: it keeps that
1272
+ // placement, so the next job with the same pair need not send the SDF.
1273
+ #placedKey = null;
1274
+ // Bumped by each new shape, so its foam is placed again.
1275
+ #shapeVersion = 0;
1276
+ #backdrop = new SceneBackdrop(BACKDROP_PALETTES, DEFAULT_PARAMS);
1277
+ #time = 0;
1278
+ // The drift and the swirl so far: a change of speed only changes
1279
+ // their rate from then on.
1280
+ #driftTurns = 0;
1281
+ #swirlOffset = 0;
1282
+ // Drags, the "tilt", and the window listeners while `drag` is on or
1283
+ // `pointer` is "tilt".
1284
+ #camera = new OrbitCamera(DEFAULT_PARAMS);
1285
+ #unsubRestored = null;
1286
+ constructor(initial = {}, opts = {}) {
1287
+ this.params = { ...DEFAULT_PARAMS, ...initial };
1288
+ this.#still = opts.still ?? false;
1289
+ }
1290
+ setParams(updates) {
1291
+ Object.assign(this.params, updates);
1292
+ }
1293
+ init(ctx) {
1294
+ this.#gl = ctx.gl;
1295
+ this.#unsubRestored = ctx.onContextRestored(() => {
1296
+ // The raw textures are gone; upload them again. A readback in
1297
+ // flight was rejected; start it over.
1298
+ this.#source.contextRestored();
1299
+ this.#gl = ctx.gl;
1300
+ const foam = this.#foamData;
1301
+ this.#sdfTex?.dispose();
1302
+ this.#lutTex?.dispose();
1303
+ for (const tex of foam?.textures ?? []) {
1304
+ tex.dispose();
1305
+ }
1306
+ this.#sdfRaw = null;
1307
+ this.#lutRaw = null;
1308
+ this.#sdfTex = null;
1309
+ this.#lutTex = null;
1310
+ this.#foamData = null;
1311
+ this.#foamFailed = null;
1312
+ this.#backdrop.contextRestored();
1313
+ if (this.#next) {
1314
+ // A placement is in flight; it uploads the new shape.
1315
+ return;
1316
+ }
1317
+ if (foam && this.#shape) {
1318
+ // Upload the last placement again, without placing anew.
1319
+ this.#next = this.#shape;
1320
+ this.#foamReady = {
1321
+ key: foam.key,
1322
+ version: this.#shapeVersion,
1323
+ data: foam,
1324
+ params: foam.params,
1325
+ };
1326
+ return;
1327
+ }
1328
+ this.#pending = this.#pending ?? this.#shape;
1329
+ });
1330
+ }
1331
+ outputRect(dims) {
1332
+ return padOutputRect(padOf(this.params.pad, DEFAULT_PARAMS.pad), dims);
1333
+ }
1334
+ render(ctx) {
1335
+ if (this.#source.phase === "idle" &&
1336
+ this.#channel !== null &&
1337
+ sourceChannelOf(this.params.sourceChannel) !== this.#channel) {
1338
+ this.#source.refresh();
1339
+ }
1340
+ this.#source.update(ctx);
1341
+ // A new shape waits for its foam, then replaces the current one.
1342
+ if (this.#pending) {
1343
+ this.#next = this.#pending;
1344
+ this.#pending = null;
1345
+ this.#shapeVersion++;
1346
+ }
1347
+ this.#backdrop.update(ctx, this.params);
1348
+ if (!this.#still) {
1349
+ const dt = Math.min(ctx.deltaTime, 0.1);
1350
+ const p = this.params;
1351
+ const d = DEFAULT_PARAMS;
1352
+ this.#time += dt;
1353
+ this.#driftTurns += dt * Math.max(finite(p.speed, d.speed), 0);
1354
+ this.#swirlOffset += dt * finite(p.swirlSpeed, d.swirlSpeed);
1355
+ }
1356
+ const cam = this.#camera.update(this.params, {
1357
+ time: this.#time,
1358
+ dt: this.#still ? 0 : ctx.deltaTime,
1359
+ dims: ctx.dims,
1360
+ outputRect: padOutputRect(padOf(this.params.pad, DEFAULT_PARAMS.pad), ctx.dims),
1361
+ mouse: ctx.mouse,
1362
+ mouseViewport: ctx.mouseViewport,
1363
+ pixelRatio: ctx.pixelRatio,
1364
+ live: !this.#still,
1365
+ tilt: this.params.pointer === "tilt",
1366
+ });
1367
+ const scene = this.#draw(ctx, cam);
1368
+ this.#passes.output(ctx, scene, {
1369
+ pad: padOf(this.params.pad, DEFAULT_PARAMS.pad),
1370
+ antialias: this.params.antialias,
1371
+ raw: this.#debugView() !== 0,
1372
+ });
1373
+ }
1374
+ #debugView() {
1375
+ return DEBUG_VIEWS[this.params.debug] ?? 0;
1376
+ }
1377
+ // The params, clamped to what the shader can take, and what follows
1378
+ // from them.
1379
+ // The resolved params and their keys, made again only when an input
1380
+ // changes, so a still frame allocates nothing.
1381
+ #keyIn = new Float64Array(10);
1382
+ #keyLast = new Float64Array(10).fill(Number.NaN);
1383
+ #keys = null;
1384
+ #foamKeys() {
1385
+ const p = this.params;
1386
+ const a = this.#keyIn;
1387
+ a[0] = this.#shapeVersion;
1388
+ a[1] = p.depth;
1389
+ a[2] = p.bevel;
1390
+ a[3] = p.cellSize;
1391
+ a[4] = p.roundness;
1392
+ a[5] = p.cellSizeRandomness;
1393
+ a[6] = p.seed;
1394
+ a[7] = p.minSize;
1395
+ a[8] = p.wobble;
1396
+ a[9] = p.containment;
1397
+ const last = this.#keyLast;
1398
+ let same = this.#keys !== null;
1399
+ for (let i = 0; same && i < a.length; i++) {
1400
+ same = Object.is(a[i], last[i]);
1401
+ }
1402
+ if (same && this.#keys) {
1403
+ return this.#keys;
1404
+ }
1405
+ last.set(a);
1406
+ const r = this.#resolved();
1407
+ const f = r.fill;
1408
+ const placeKey = `${this.#shapeVersion}|${f.halfDepth}|${f.bevel}|${f.cellSize}|${f.roundness}|${f.cellSizeRandomness}|${f.seed}|${f.minSize}`;
1409
+ this.#keys = {
1410
+ r,
1411
+ placeKey,
1412
+ key: `${placeKey}|${r.wobble}|${r.containment}`,
1413
+ };
1414
+ return this.#keys;
1415
+ }
1416
+ #resolved() {
1417
+ const p = this.params;
1418
+ const d = DEFAULT_PARAMS;
1419
+ const halfDepth = clamp(p.depth / 2, 0.005, 1, d.depth / 2);
1420
+ const cellSize = Math.max(finite(p.cellSize, d.cellSize), 0.02);
1421
+ const fill = {
1422
+ halfDepth,
1423
+ bevel: clamp(p.bevel, 0, halfDepth, Math.min(d.bevel, halfDepth)),
1424
+ cellSize,
1425
+ roundness: clamp(p.roundness, 0, 1, d.roundness),
1426
+ cellSizeRandomness: clamp(p.cellSizeRandomness, 0, 1, d.cellSizeRandomness),
1427
+ seed: clampInt(p.seed, 0, 0x7fffffff, d.seed),
1428
+ minSize: clamp(p.minSize, 0.05, 1, d.minSize),
1429
+ };
1430
+ const wobble = clamp(p.wobble, 0, WOBBLE_MAX, d.wobble);
1431
+ return {
1432
+ halfDepth,
1433
+ cellSize,
1434
+ fill,
1435
+ wobble,
1436
+ containment: clamp(p.containment, 0, 1, d.containment),
1437
+ };
1438
+ }
1439
+ // The borders, in world units; a width of 0 skips them in the shader.
1440
+ #borderUniforms(cellSize) {
1441
+ const p = this.params;
1442
+ const d = DEFAULT_PARAMS;
1443
+ const highlight = clamp(p.borderHighlight, 0, 2, d.borderHighlight);
1444
+ const share = clamp(p.borderWidth, 0, 0.5, d.borderWidth);
1445
+ return {
1446
+ borderWidth: share * cellSize,
1447
+ borderHighlight: highlight,
1448
+ // More water: a wider border and a thicker film at it.
1449
+ borderThickness: share * BORDER_NM_PER_WIDTH,
1450
+ };
1451
+ }
1452
+ // The bubbles for the params, placed by the kernel (in a worker where
1453
+ // it can) whenever the shape or a param it depends on changes. Until
1454
+ // the new foam comes back, the last one is drawn.
1455
+ #foam(ctx) {
1456
+ const ready = this.#foamReady;
1457
+ if (ready) {
1458
+ this.#foamReady = null;
1459
+ if (ready.version === this.#shapeVersion &&
1460
+ !this.#adopt(ctx, ready)) {
1461
+ this.#foamFailed = ready.key;
1462
+ }
1463
+ }
1464
+ const shape = this.#next ?? this.#shape;
1465
+ if (!shape) {
1466
+ return null;
1467
+ }
1468
+ const { r, placeKey, key } = this.#foamKeys();
1469
+ const version = this.#shapeVersion;
1470
+ if (!this.#foamBusy &&
1471
+ this.#foamData?.key !== key &&
1472
+ this.#foamFailed !== key) {
1473
+ this.#foamBusy = true;
1474
+ const token = this.#foamToken;
1475
+ this.#kernel ??= new KernelWorker(bubbleKernel, BUBBLE_KERNEL_SOURCE);
1476
+ const sendShape = placeKey !== this.#placedKey;
1477
+ this.#kernel
1478
+ .run("buildFoam", {
1479
+ shape: sendShape
1480
+ ? {
1481
+ sdf: shape.sdf,
1482
+ sdfW: shape.sdfW,
1483
+ sdfH: shape.sdfH,
1484
+ sdfRect: shape.sdfRect,
1485
+ }
1486
+ : undefined,
1487
+ shapeKey: version,
1488
+ fill: r.fill,
1489
+ wobble: r.wobble,
1490
+ containment: r.containment,
1491
+ })
1492
+ .then((data) => {
1493
+ if (token === this.#foamToken) {
1494
+ this.#foamBusy = false;
1495
+ this.#placedKey = placeKey;
1496
+ this.#foamReady = { key, version, data, params: r };
1497
+ }
1498
+ }, (e) => {
1499
+ if (token === this.#foamToken) {
1500
+ this.#foamBusy = false;
1501
+ this.#placedKey = null;
1502
+ if (!sendShape) {
1503
+ // The kernel lost its placement (its worker
1504
+ // died): send the shape next frame.
1505
+ return;
1506
+ }
1507
+ this.#foamFailed = key;
1508
+ console.warn("[VFX-JS] BubbleEffect could not place its bubbles:", e);
1509
+ }
1510
+ });
1511
+ }
1512
+ return this.#foamData;
1513
+ }
1514
+ // Switch to a foam that came back, and to the shape it was placed in.
1515
+ // False when a texture could not be made; the last foam stays.
1516
+ #adopt(ctx, ready) {
1517
+ const gl = ctx.gl;
1518
+ const next = this.#next;
1519
+ let sdf = null;
1520
+ if (next) {
1521
+ sdf = uploadFloatTexture(gl, next.sdfW, next.sdfH, next.sdf);
1522
+ ctx.resetState();
1523
+ if (!sdf) {
1524
+ return false;
1525
+ }
1526
+ }
1527
+ const foam = this.#uploadFoam(ctx, ready.key, ready.data, ready.params);
1528
+ if (!foam) {
1529
+ gl.deleteTexture(sdf);
1530
+ return false;
1531
+ }
1532
+ this.#freeFoam();
1533
+ this.#foamData = foam;
1534
+ if (next && sdf) {
1535
+ this.#sdfTex?.dispose();
1536
+ gl.deleteTexture(this.#sdfRaw);
1537
+ this.#sdfRaw = sdf;
1538
+ this.#sdfTex = ctx.wrapTexture(sdf, {
1539
+ size: [next.sdfW, next.sdfH],
1540
+ filter: "linear",
1541
+ wrap: "clamp",
1542
+ });
1543
+ this.#shape = next;
1544
+ this.#next = null;
1545
+ }
1546
+ return true;
1547
+ }
1548
+ #uploadFoam(ctx, key, data, params) {
1549
+ const { grid } = data;
1550
+ const edgeGrid = data.edgeGrid ?? grid;
1551
+ const gl = ctx.gl;
1552
+ const raw = [];
1553
+ const textures = [];
1554
+ const layers = [
1555
+ [grid.sphereData, grid.sphereTexH],
1556
+ [grid.cellData, grid.cellTexH],
1557
+ [grid.index, grid.indexTexH],
1558
+ ];
1559
+ if (edgeGrid !== grid) {
1560
+ layers.push([edgeGrid.cellData, edgeGrid.cellTexH], [edgeGrid.index, edgeGrid.indexTexH]);
1561
+ }
1562
+ for (const [data, h] of layers) {
1563
+ const tex = uploadDataTexture(gl, BUBBLE_TEX_W, h, data);
1564
+ if (!tex) {
1565
+ break;
1566
+ }
1567
+ raw.push(tex);
1568
+ textures.push(ctx.wrapTexture(tex, {
1569
+ size: [BUBBLE_TEX_W, h],
1570
+ filter: "nearest",
1571
+ wrap: "clamp",
1572
+ }));
1573
+ }
1574
+ ctx.resetState();
1575
+ if (textures.length < layers.length) {
1576
+ for (const tex of textures) {
1577
+ tex.dispose();
1578
+ }
1579
+ for (const tex of raw) {
1580
+ gl.deleteTexture(tex);
1581
+ }
1582
+ return null;
1583
+ }
1584
+ return {
1585
+ ...data,
1586
+ key,
1587
+ raw,
1588
+ textures,
1589
+ sphereTex: textures[0],
1590
+ cellTex: textures[1],
1591
+ indexTex: textures[2],
1592
+ edgeCellTex: textures[edgeGrid === grid ? 1 : 3],
1593
+ edgeIndexTex: textures[edgeGrid === grid ? 2 : 4],
1594
+ params,
1595
+ moved: grid.sphereData.slice(),
1596
+ movedTurns: Number.NaN,
1597
+ maxR: maxRadius(grid),
1598
+ };
1599
+ }
1600
+ // Drift the spheres and upload them: a slow wander of length <= wobble
1601
+ // times the radius, from a random phase per sphere.
1602
+ #move(ctx, foam) {
1603
+ const wobble = foam.params.wobble;
1604
+ // Without wobble the spheres stay as uploaded.
1605
+ if (wobble <= 0 || foam.movedTurns === this.#driftTurns) {
1606
+ return;
1607
+ }
1608
+ foam.movedTurns = this.#driftTurns;
1609
+ const src = foam.grid.sphereData;
1610
+ const out = foam.moved;
1611
+ const f = foam.drift;
1612
+ const w = Math.PI * 2 * this.#driftTurns;
1613
+ for (let i = 0; i < foam.grid.count; i++) {
1614
+ const amp = wobble * src[i * 4 + 3] * 0.5774;
1615
+ for (let a = 0; a < 3; a++) {
1616
+ const phase = w * f[i * 6 + a] + Math.PI * 2 * f[i * 6 + 3 + a];
1617
+ out[i * 4 + a] = src[i * 4 + a] + amp * Math.sin(phase);
1618
+ }
1619
+ }
1620
+ const gl = ctx.gl;
1621
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
1622
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
1623
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
1624
+ gl.bindTexture(gl.TEXTURE_2D, foam.raw[0]);
1625
+ gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, BUBBLE_TEX_W, foam.grid.sphereTexH, gl.RGBA, gl.FLOAT, out);
1626
+ gl.bindTexture(gl.TEXTURE_2D, null);
1627
+ ctx.resetState();
1628
+ }
1629
+ // The thin-film colours, uploaded when first needed.
1630
+ #lut(ctx) {
1631
+ if (!this.#lutTex) {
1632
+ const lut = uploadFloatTexture(ctx.gl, THIN_FILM_LUT_W, THIN_FILM_LUT_H, thinFilmLut());
1633
+ ctx.resetState();
1634
+ if (lut) {
1635
+ this.#lutRaw = lut;
1636
+ this.#lutTex = ctx.wrapTexture(lut, {
1637
+ size: [THIN_FILM_LUT_W, THIN_FILM_LUT_H],
1638
+ filter: "linear",
1639
+ wrap: "clamp",
1640
+ });
1641
+ }
1642
+ }
1643
+ return this.#lutTex;
1644
+ }
1645
+ #freeFoam() {
1646
+ const f = this.#foamData;
1647
+ for (const tex of f?.textures ?? []) {
1648
+ tex.dispose();
1649
+ }
1650
+ if (f && this.#gl) {
1651
+ for (const tex of f.raw) {
1652
+ this.#gl.deleteTexture(tex);
1653
+ }
1654
+ }
1655
+ this.#foamData = null;
1656
+ }
1657
+ #draw(ctx, cam) {
1658
+ const foam = this.#foam(ctx);
1659
+ const shape = this.#shape;
1660
+ const sdfTex = this.#sdfTex;
1661
+ const lutTex = this.#lut(ctx);
1662
+ if (!foam || !shape || !sdfTex || !lutTex) {
1663
+ return null;
1664
+ }
1665
+ const p = this.params;
1666
+ const d = DEFAULT_PARAMS;
1667
+ const scene = this.#passes.scene(ctx, padOf(p.pad, DEFAULT_PARAMS.pad), p.resolution);
1668
+ const [, , ow, oh] = padOutputRect(padOf(p.pad, DEFAULT_PARAMS.pad), ctx.dims);
1669
+ if (!scene || ow <= 0 || oh <= 0) {
1670
+ return null;
1671
+ }
1672
+ const t = this.#time;
1673
+ const r = foam.params;
1674
+ // The cells may be larger than asked, to fit the shape.
1675
+ const cellSize = foam.fill.cellSize;
1676
+ const grid = foam.grid;
1677
+ const maxR = foam.maxR;
1678
+ // How far any sphere reaches out of the shape, drift included,
1679
+ // with a margin for the field's filtering.
1680
+ const reach = foam.fill.reach + foam.grow + r.wobble * maxR + 0.02 * cellSize;
1681
+ this.#move(ctx, foam);
1682
+ const containment = r.containment;
1683
+ const mode = containment <= 0 ? 0 : containment >= 0.995 ? 1 : 2;
1684
+ const backdrop = this.#backdrop.uniforms(p, t, r.halfDepth + reach, sdfTex);
1685
+ ctx.draw({
1686
+ frag: fragBubbleFor(mode, backdropKind(p.backdrop)),
1687
+ uniforms: {
1688
+ sdfTex,
1689
+ sdfRect: shape.sdfRect,
1690
+ halfDepth: r.halfDepth,
1691
+ rounding: r.fill.bevel ?? 0,
1692
+ shapeHalf: shape.shapeHalf,
1693
+ boxMargin: reach,
1694
+ viewRot: cam.viewRot,
1695
+ camDist: cam.camDist,
1696
+ focalPx: cam.focalPx,
1697
+ eye: [cam.eye[0], cam.eye[1]],
1698
+ principalPx: cam.principalPx,
1699
+ bufferPx: [ow, oh],
1700
+ pixelSize: ow / scene.width,
1701
+ maxLayers: clampInt(p.maxLayers, 1, MAX_LAYERS, d.maxLayers),
1702
+ seed: r.fill.seed,
1703
+ cellSize,
1704
+ sphereTex: foam.sphereTex,
1705
+ cellTex: foam.cellTex,
1706
+ indexTex: foam.indexTex,
1707
+ gridOrigin: grid.origin,
1708
+ gridCell: grid.cell,
1709
+ gridDims: grid.dims,
1710
+ edgeCellTex: foam.edgeCellTex,
1711
+ edgeIndexTex: foam.edgeIndexTex,
1712
+ edgeOrigin: (foam.edgeGrid ?? grid).origin,
1713
+ edgeCell: (foam.edgeGrid ?? grid).cell,
1714
+ edgeDims: (foam.edgeGrid ?? grid).dims,
1715
+ reachMax: reach,
1716
+ clipOff: (1 - containment) * reach,
1717
+ warpK: containment / Math.max(1 - containment, 1e-3),
1718
+ fillG: foam.fillG,
1719
+ fillDepth: FILL_DEPTH * cellSize,
1720
+ filmLut: lutTex,
1721
+ iridescence: clamp(p.iridescence, 0, 1, d.iridescence),
1722
+ thickness: Math.max(finite(p.thickness, d.thickness), 0),
1723
+ thicknessVariation: clamp(p.thicknessVariation, 0, 1, d.thicknessVariation),
1724
+ drain: clamp(p.drain, 0, 1, d.drain),
1725
+ swirlScale: Math.max(finite(p.swirlScale, d.swirlScale), 0),
1726
+ swirlOffset: this.#swirlOffset,
1727
+ reflection: Math.max(finite(p.reflection, d.reflection), 0),
1728
+ backdropAround: p.backdropAround ? 1 : 0,
1729
+ rimCos: RIM_COS * (1 - clamp(p.rim, 0, 1, d.rim)),
1730
+ tint: colorOf(p.tint, d.tint),
1731
+ tintStrength: clamp(p.tintStrength, 0, 1, d.tintStrength),
1732
+ opacity: clamp(p.opacity, 0, 1, d.opacity),
1733
+ bodyColor: colorOf(p.color, d.color),
1734
+ ...this.#borderUniforms(cellSize),
1735
+ ...backdrop,
1736
+ debugView: this.#debugView(),
1737
+ },
1738
+ target: scene,
1739
+ });
1740
+ return scene;
1741
+ }
1742
+ /**
1743
+ * Capture the element's silhouette again, for when its content
1744
+ * changed: an image's `src` swapped, a text edit. For an `<img>`,
1745
+ * call it after `vfx.update(img)` has reloaded the image.
1746
+ *
1747
+ * The foam keeps the current shape until the new one has been read
1748
+ * back (a few frames later), then switches to it and places its
1749
+ * bubbles again. A change of the element's aspect ratio is
1750
+ * recaptured automatically once its size settles; a change of size
1751
+ * alone needs none.
1752
+ *
1753
+ * Safe to call at any time and any number of times; a call while a
1754
+ * capture is pending restarts it, so the latest content wins.
1755
+ */
1756
+ refresh() {
1757
+ this.#source.refresh();
1758
+ }
1759
+ // Build the shape from the element read back. False when the
1760
+ // silhouette is empty, to try again later.
1761
+ // Build the shape from the element read back, in the worker. False
1762
+ // when the silhouette is empty, to try again later.
1763
+ async #onRead(r, isCurrent) {
1764
+ const channel = sourceChannelOf(this.params.sourceChannel);
1765
+ const built = await buildShapeAsync({
1766
+ pixels: r.pixels,
1767
+ mw: r.width,
1768
+ mh: r.height,
1769
+ channel,
1770
+ aspect: r.aspect,
1771
+ smoothRadius: SMOOTH_RADIUS,
1772
+ smoothPasses: SMOOTH_PASSES,
1773
+ spawn: false,
1774
+ });
1775
+ if (!built) {
1776
+ return false;
1777
+ }
1778
+ if (!isCurrent()) {
1779
+ return true; // dropped by the capture anyway
1780
+ }
1781
+ this.#pending = built;
1782
+ this.#channel = channel;
1783
+ return true;
1784
+ }
1785
+ dispose() {
1786
+ this.#camera.dispose();
1787
+ this.#unsubRestored?.();
1788
+ this.#unsubRestored = null;
1789
+ this.#sdfTex?.dispose();
1790
+ this.#lutTex?.dispose();
1791
+ this.#gl?.deleteTexture(this.#sdfRaw);
1792
+ this.#gl?.deleteTexture(this.#lutRaw);
1793
+ this.#sdfRaw = null;
1794
+ this.#lutRaw = null;
1795
+ this.#sdfTex = null;
1796
+ this.#lutTex = null;
1797
+ this.#freeFoam();
1798
+ this.#kernel?.dispose();
1799
+ this.#kernel = null;
1800
+ this.#foamToken++;
1801
+ this.#foamBusy = false;
1802
+ this.#placedKey = null;
1803
+ this.#foamReady = null;
1804
+ this.#foamFailed = null;
1805
+ this.#backdrop.dispose(this.#gl);
1806
+ this.#gl = null;
1807
+ this.#passes.dispose();
1808
+ this.#shape = null;
1809
+ this.#next = null;
1810
+ this.#pending = null;
1811
+ // Start over like a new instance if it is added again.
1812
+ this.#source.reset();
1813
+ this.#channel = null;
1814
+ }
1815
+ }
1816
+ //# sourceMappingURL=bubble.js.map