@vfx-js/effects 1.4.4 → 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 (511) 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/bloom.js +40 -106
  232. package/lib/cjs/bloom.js.map +1 -1
  233. package/lib/cjs/bubble.d.ts +284 -0
  234. package/lib/cjs/bubble.js +1820 -0
  235. package/lib/cjs/bubble.js.map +1 -0
  236. package/lib/cjs/glass.d.ts +254 -0
  237. package/lib/cjs/glass.js +981 -0
  238. package/lib/cjs/glass.js.map +1 -0
  239. package/lib/cjs/holo-static.d.ts +3 -0
  240. package/lib/cjs/holo-static.js +29 -0
  241. package/lib/cjs/holo-static.js.map +1 -0
  242. package/lib/cjs/holo.d.ts +401 -0
  243. package/lib/cjs/holo.js +1613 -0
  244. package/lib/cjs/holo.js.map +1 -0
  245. package/lib/cjs/index.d.ts +18 -9
  246. package/lib/cjs/index.js +12 -1
  247. package/lib/cjs/index.js.map +1 -1
  248. package/lib/cjs/jpeg-glitch.js +32 -29
  249. package/lib/cjs/jpeg-glitch.js.map +1 -1
  250. package/lib/cjs/matrix.d.ts +1 -1
  251. package/lib/cjs/package.json +20 -5
  252. package/lib/cjs/swirl-particle.d.ts +257 -0
  253. package/lib/cjs/swirl-particle.js +2346 -0
  254. package/lib/cjs/swirl-particle.js.map +1 -0
  255. package/lib/cjs/voronoi.js +2 -75
  256. package/lib/cjs/voronoi.js.map +1 -1
  257. package/lib/esm/_bloom-common.d.ts +31 -0
  258. package/lib/esm/_bloom-common.js +95 -0
  259. package/lib/esm/_bloom-common.js.map +1 -0
  260. package/lib/esm/_bubble-fill.d.ts +126 -0
  261. package/lib/esm/_bubble-fill.js +1039 -0
  262. package/lib/esm/_bubble-fill.js.map +1 -0
  263. package/lib/esm/_bubble-kernel-source.d.ts +2 -0
  264. package/lib/esm/_bubble-kernel-source.js +5 -0
  265. package/lib/esm/_bubble-kernel-source.js.map +1 -0
  266. package/lib/esm/_holo/data/kernels.d.ts +4 -0
  267. package/lib/esm/_holo/data/kernels.js +7 -0
  268. package/lib/esm/_holo/data/kernels.js.map +1 -0
  269. package/lib/esm/_holo/data/looks.d.ts +2 -0
  270. package/lib/esm/_holo/data/looks.js +592 -0
  271. package/lib/esm/_holo/data/looks.js.map +1 -0
  272. package/lib/esm/_holo/data/ltc.d.ts +2 -0
  273. package/lib/esm/_holo/data/ltc.js +8 -0
  274. package/lib/esm/_holo/data/ltc.js.map +1 -0
  275. package/lib/esm/_holo/data/material-presets.d.ts +3 -0
  276. package/lib/esm/_holo/data/material-presets.js +72 -0
  277. package/lib/esm/_holo/data/material-presets.js.map +1 -0
  278. package/lib/esm/_holo/data/not-ported.d.ts +5 -0
  279. package/lib/esm/_holo/data/not-ported.js +187 -0
  280. package/lib/esm/_holo/data/not-ported.js.map +1 -0
  281. package/lib/esm/_holo/data/params.d.ts +4 -0
  282. package/lib/esm/_holo/data/params.js +1638 -0
  283. package/lib/esm/_holo/data/params.js.map +1 -0
  284. package/lib/esm/_holo/data/starting-points.d.ts +199 -0
  285. package/lib/esm/_holo/data/starting-points.js +190 -0
  286. package/lib/esm/_holo/data/starting-points.js.map +1 -0
  287. package/lib/esm/_holo/data/studio-presets.d.ts +2 -0
  288. package/lib/esm/_holo/data/studio-presets.js +174 -0
  289. package/lib/esm/_holo/data/studio-presets.js.map +1 -0
  290. package/lib/esm/_holo/emboss-assets.d.ts +55 -0
  291. package/lib/esm/_holo/emboss-assets.js +150 -0
  292. package/lib/esm/_holo/emboss-assets.js.map +1 -0
  293. package/lib/esm/_holo/glare.d.ts +15 -0
  294. package/lib/esm/_holo/glare.js +117 -0
  295. package/lib/esm/_holo/glare.js.map +1 -0
  296. package/lib/esm/_holo/glsl/coat.d.ts +2 -0
  297. package/lib/esm/_holo/glsl/coat.js +30 -0
  298. package/lib/esm/_holo/glsl/coat.js.map +1 -0
  299. package/lib/esm/_holo/glsl/common.d.ts +2 -0
  300. package/lib/esm/_holo/glsl/common.js +139 -0
  301. package/lib/esm/_holo/glsl/common.js.map +1 -0
  302. package/lib/esm/_holo/glsl/emboss.d.ts +2 -0
  303. package/lib/esm/_holo/glsl/emboss.js +244 -0
  304. package/lib/esm/_holo/glsl/emboss.js.map +1 -0
  305. package/lib/esm/_holo/glsl/env.d.ts +2 -0
  306. package/lib/esm/_holo/glsl/env.js +50 -0
  307. package/lib/esm/_holo/glsl/env.js.map +1 -0
  308. package/lib/esm/_holo/glsl/glare-down.d.ts +2 -0
  309. package/lib/esm/_holo/glsl/glare-down.js +63 -0
  310. package/lib/esm/_holo/glsl/glare-down.js.map +1 -0
  311. package/lib/esm/_holo/glsl/glare-up.d.ts +2 -0
  312. package/lib/esm/_holo/glsl/glare-up.js +16 -0
  313. package/lib/esm/_holo/glsl/glare-up.js.map +1 -0
  314. package/lib/esm/_holo/glsl/glitter.d.ts +2 -0
  315. package/lib/esm/_holo/glsl/glitter.js +323 -0
  316. package/lib/esm/_holo/glsl/glitter.js.map +1 -0
  317. package/lib/esm/_holo/glsl/grating.d.ts +2 -0
  318. package/lib/esm/_holo/glsl/grating.js +238 -0
  319. package/lib/esm/_holo/glsl/grating.js.map +1 -0
  320. package/lib/esm/_holo/glsl/holo-emboss.d.ts +2 -0
  321. package/lib/esm/_holo/glsl/holo-emboss.js +294 -0
  322. package/lib/esm/_holo/glsl/holo-emboss.js.map +1 -0
  323. package/lib/esm/_holo/glsl/holo-nebula.d.ts +2 -0
  324. package/lib/esm/_holo/glsl/holo-nebula.js +184 -0
  325. package/lib/esm/_holo/glsl/holo-nebula.js.map +1 -0
  326. package/lib/esm/_holo/glsl/holo-prism.d.ts +2 -0
  327. package/lib/esm/_holo/glsl/holo-prism.js +181 -0
  328. package/lib/esm/_holo/glsl/holo-prism.js.map +1 -0
  329. package/lib/esm/_holo/glsl/holo-shatter.d.ts +2 -0
  330. package/lib/esm/_holo/glsl/holo-shatter.js +326 -0
  331. package/lib/esm/_holo/glsl/holo-shatter.js.map +1 -0
  332. package/lib/esm/_holo/glsl/holo-sparkle.d.ts +2 -0
  333. package/lib/esm/_holo/glsl/holo-sparkle.js +233 -0
  334. package/lib/esm/_holo/glsl/holo-sparkle.js.map +1 -0
  335. package/lib/esm/_holo/glsl/holo-vortex.d.ts +2 -0
  336. package/lib/esm/_holo/glsl/holo-vortex.js +199 -0
  337. package/lib/esm/_holo/glsl/holo-vortex.js.map +1 -0
  338. package/lib/esm/_holo/glsl/ibl.d.ts +2 -0
  339. package/lib/esm/_holo/glsl/ibl.js +77 -0
  340. package/lib/esm/_holo/glsl/ibl.js.map +1 -0
  341. package/lib/esm/_holo/glsl/lights.d.ts +2 -0
  342. package/lib/esm/_holo/glsl/lights.js +123 -0
  343. package/lib/esm/_holo/glsl/lights.js.map +1 -0
  344. package/lib/esm/_holo/glsl/ltc.d.ts +2 -0
  345. package/lib/esm/_holo/glsl/ltc.js +64 -0
  346. package/lib/esm/_holo/glsl/ltc.js.map +1 -0
  347. package/lib/esm/_holo/glsl/output.d.ts +2 -0
  348. package/lib/esm/_holo/glsl/output.js +111 -0
  349. package/lib/esm/_holo/glsl/output.js.map +1 -0
  350. package/lib/esm/_holo/glsl/paper.d.ts +2 -0
  351. package/lib/esm/_holo/glsl/paper.js +163 -0
  352. package/lib/esm/_holo/glsl/paper.js.map +1 -0
  353. package/lib/esm/_holo/glsl/relief.d.ts +2 -0
  354. package/lib/esm/_holo/glsl/relief.js +101 -0
  355. package/lib/esm/_holo/glsl/relief.js.map +1 -0
  356. package/lib/esm/_holo/glsl/sparkle.d.ts +2 -0
  357. package/lib/esm/_holo/glsl/sparkle.js +277 -0
  358. package/lib/esm/_holo/glsl/sparkle.js.map +1 -0
  359. package/lib/esm/_holo/glsl/spectral.d.ts +2 -0
  360. package/lib/esm/_holo/glsl/spectral.js +58 -0
  361. package/lib/esm/_holo/glsl/spectral.js.map +1 -0
  362. package/lib/esm/_holo/glsl/wear.d.ts +2 -0
  363. package/lib/esm/_holo/glsl/wear.js +105 -0
  364. package/lib/esm/_holo/glsl/wear.js.map +1 -0
  365. package/lib/esm/_holo/ltc.d.ts +9 -0
  366. package/lib/esm/_holo/ltc.js +52 -0
  367. package/lib/esm/_holo/ltc.js.map +1 -0
  368. package/lib/esm/_holo/materials/build.d.ts +32 -0
  369. package/lib/esm/_holo/materials/build.js +30 -0
  370. package/lib/esm/_holo/materials/build.js.map +1 -0
  371. package/lib/esm/_holo/materials/emboss.d.ts +22 -0
  372. package/lib/esm/_holo/materials/emboss.js +198 -0
  373. package/lib/esm/_holo/materials/emboss.js.map +1 -0
  374. package/lib/esm/_holo/materials/nebula.d.ts +4 -0
  375. package/lib/esm/_holo/materials/nebula.js +98 -0
  376. package/lib/esm/_holo/materials/nebula.js.map +1 -0
  377. package/lib/esm/_holo/materials/prism.d.ts +2 -0
  378. package/lib/esm/_holo/materials/prism.js +63 -0
  379. package/lib/esm/_holo/materials/prism.js.map +1 -0
  380. package/lib/esm/_holo/materials/registry.d.ts +11 -0
  381. package/lib/esm/_holo/materials/registry.js +48 -0
  382. package/lib/esm/_holo/materials/registry.js.map +1 -0
  383. package/lib/esm/_holo/materials/shatter.d.ts +2 -0
  384. package/lib/esm/_holo/materials/shatter.js +74 -0
  385. package/lib/esm/_holo/materials/shatter.js.map +1 -0
  386. package/lib/esm/_holo/materials/sparkle.d.ts +2 -0
  387. package/lib/esm/_holo/materials/sparkle.js +102 -0
  388. package/lib/esm/_holo/materials/sparkle.js.map +1 -0
  389. package/lib/esm/_holo/materials/vortex.d.ts +2 -0
  390. package/lib/esm/_holo/materials/vortex.js +79 -0
  391. package/lib/esm/_holo/materials/vortex.js.map +1 -0
  392. package/lib/esm/_holo/physics/emboss.d.ts +39 -0
  393. package/lib/esm/_holo/physics/emboss.js +89 -0
  394. package/lib/esm/_holo/physics/emboss.js.map +1 -0
  395. package/lib/esm/_holo/physics/geometry.d.ts +109 -0
  396. package/lib/esm/_holo/physics/geometry.js +228 -0
  397. package/lib/esm/_holo/physics/geometry.js.map +1 -0
  398. package/lib/esm/_holo/physics/grating.d.ts +86 -0
  399. package/lib/esm/_holo/physics/grating.js +313 -0
  400. package/lib/esm/_holo/physics/grating.js.map +1 -0
  401. package/lib/esm/_holo/physics/sparkle.d.ts +143 -0
  402. package/lib/esm/_holo/physics/sparkle.js +360 -0
  403. package/lib/esm/_holo/physics/sparkle.js.map +1 -0
  404. package/lib/esm/_holo/scene/env.d.ts +17 -0
  405. package/lib/esm/_holo/scene/env.js +141 -0
  406. package/lib/esm/_holo/scene/env.js.map +1 -0
  407. package/lib/esm/_holo/scene/lights.d.ts +13 -0
  408. package/lib/esm/_holo/scene/lights.js +204 -0
  409. package/lib/esm/_holo/scene/lights.js.map +1 -0
  410. package/lib/esm/_holo/scene/logo.d.ts +87 -0
  411. package/lib/esm/_holo/scene/logo.js +645 -0
  412. package/lib/esm/_holo/scene/logo.js.map +1 -0
  413. package/lib/esm/_holo/scene/paper-maps.d.ts +26 -0
  414. package/lib/esm/_holo/scene/paper-maps.js +387 -0
  415. package/lib/esm/_holo/scene/paper-maps.js.map +1 -0
  416. package/lib/esm/_holo/scene/pose.d.ts +31 -0
  417. package/lib/esm/_holo/scene/pose.js +71 -0
  418. package/lib/esm/_holo/scene/pose.js.map +1 -0
  419. package/lib/esm/_holo/scene/relief.d.ts +24 -0
  420. package/lib/esm/_holo/scene/relief.js +142 -0
  421. package/lib/esm/_holo/scene/relief.js.map +1 -0
  422. package/lib/esm/_holo/settings-types.d.ts +20 -0
  423. package/lib/esm/_holo/settings-types.js +2 -0
  424. package/lib/esm/_holo/settings-types.js.map +1 -0
  425. package/lib/esm/_holo/settings.d.ts +83 -0
  426. package/lib/esm/_holo/settings.js +358 -0
  427. package/lib/esm/_holo/settings.js.map +1 -0
  428. package/lib/esm/_holo/shader.d.ts +23 -0
  429. package/lib/esm/_holo/shader.js +211 -0
  430. package/lib/esm/_holo/shader.js.map +1 -0
  431. package/lib/esm/_holo/spectral/atlas.d.ts +36 -0
  432. package/lib/esm/_holo/spectral/atlas.js +110 -0
  433. package/lib/esm/_holo/spectral/atlas.js.map +1 -0
  434. package/lib/esm/_holo/spectral/cmf.d.ts +67 -0
  435. package/lib/esm/_holo/spectral/cmf.js +230 -0
  436. package/lib/esm/_holo/spectral/cmf.js.map +1 -0
  437. package/lib/esm/_holo/spectral/float24.d.ts +8 -0
  438. package/lib/esm/_holo/spectral/float24.js +64 -0
  439. package/lib/esm/_holo/spectral/float24.js.map +1 -0
  440. package/lib/esm/_holo/spectral/spd.d.ts +22 -0
  441. package/lib/esm/_holo/spectral/spd.js +130 -0
  442. package/lib/esm/_holo/spectral/spd.js.map +1 -0
  443. package/lib/esm/_holo/spectral/tables.d.ts +62 -0
  444. package/lib/esm/_holo/spectral/tables.js +372 -0
  445. package/lib/esm/_holo/spectral/tables.js.map +1 -0
  446. package/lib/esm/_holo/tier.d.ts +4 -0
  447. package/lib/esm/_holo/tier.js +106 -0
  448. package/lib/esm/_holo/tier.js.map +1 -0
  449. package/lib/esm/_holo/types.d.ts +148 -0
  450. package/lib/esm/_holo/types.js +11 -0
  451. package/lib/esm/_holo/types.js.map +1 -0
  452. package/lib/esm/_kernel-worker.d.ts +22 -0
  453. package/lib/esm/_kernel-worker.js +169 -0
  454. package/lib/esm/_kernel-worker.js.map +1 -0
  455. package/lib/esm/_orbit-camera.d.ts +175 -0
  456. package/lib/esm/_orbit-camera.js +360 -0
  457. package/lib/esm/_orbit-camera.js.map +1 -0
  458. package/lib/esm/_pad.d.ts +2 -0
  459. package/lib/esm/_pad.js +10 -0
  460. package/lib/esm/_pad.js.map +1 -1
  461. package/lib/esm/_scene3d.d.ts +101 -0
  462. package/lib/esm/_scene3d.js +783 -0
  463. package/lib/esm/_scene3d.js.map +1 -0
  464. package/lib/esm/_shape-kernel-source.d.ts +2 -0
  465. package/lib/esm/_shape-kernel-source.js +5 -0
  466. package/lib/esm/_shape-kernel-source.js.map +1 -0
  467. package/lib/esm/_shape-worker.d.ts +8 -0
  468. package/lib/esm/_shape-worker.js +23 -0
  469. package/lib/esm/_shape-worker.js.map +1 -0
  470. package/lib/esm/_silhouette.d.ts +88 -0
  471. package/lib/esm/_silhouette.js +436 -0
  472. package/lib/esm/_silhouette.js.map +1 -0
  473. package/lib/esm/_simplex3.d.ts +2 -0
  474. package/lib/esm/_simplex3.js +157 -0
  475. package/lib/esm/_simplex3.js.map +1 -0
  476. package/lib/esm/_source.d.ts +80 -0
  477. package/lib/esm/_source.js +187 -0
  478. package/lib/esm/_source.js.map +1 -0
  479. package/lib/esm/_sphere-foam.d.ts +34 -0
  480. package/lib/esm/_sphere-foam.js +131 -0
  481. package/lib/esm/_sphere-foam.js.map +1 -0
  482. package/lib/esm/_thin-film.d.ts +26 -0
  483. package/lib/esm/_thin-film.js +140 -0
  484. package/lib/esm/_thin-film.js.map +1 -0
  485. package/lib/esm/bloom.js +40 -106
  486. package/lib/esm/bloom.js.map +1 -1
  487. package/lib/esm/bubble.d.ts +284 -0
  488. package/lib/esm/bubble.js +1816 -0
  489. package/lib/esm/bubble.js.map +1 -0
  490. package/lib/esm/glass.d.ts +254 -0
  491. package/lib/esm/glass.js +977 -0
  492. package/lib/esm/glass.js.map +1 -0
  493. package/lib/esm/holo-static.d.ts +3 -0
  494. package/lib/esm/holo-static.js +13 -0
  495. package/lib/esm/holo-static.js.map +1 -0
  496. package/lib/esm/holo.d.ts +401 -0
  497. package/lib/esm/holo.js +1606 -0
  498. package/lib/esm/holo.js.map +1 -0
  499. package/lib/esm/index.d.ts +18 -9
  500. package/lib/esm/index.js +7 -2
  501. package/lib/esm/index.js.map +1 -1
  502. package/lib/esm/jpeg-glitch.js +32 -29
  503. package/lib/esm/jpeg-glitch.js.map +1 -1
  504. package/lib/esm/matrix.d.ts +1 -1
  505. package/lib/esm/package.json +20 -5
  506. package/lib/esm/swirl-particle.d.ts +257 -0
  507. package/lib/esm/swirl-particle.js +2342 -0
  508. package/lib/esm/swirl-particle.js.map +1 -0
  509. package/lib/esm/voronoi.js +2 -75
  510. package/lib/esm/voronoi.js.map +1 -1
  511. package/package.json +38 -11
@@ -0,0 +1,981 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlassEffect = void 0;
4
+ const _orbit_camera_js_1 = require("./_orbit-camera.js");
5
+ const _pad_js_1 = require("./_pad.js");
6
+ const _scene3d_js_1 = require("./_scene3d.js");
7
+ const _shape_worker_js_1 = require("./_shape-worker.js");
8
+ const _silhouette_js_1 = require("./_silhouette.js");
9
+ const _simplex3_js_1 = require("./_simplex3.js");
10
+ const _source_js_1 = require("./_source.js");
11
+ const DEFAULT_PARAMS = {
12
+ sourceChannel: "alpha",
13
+ depth: 0.2,
14
+ bevel: 0.03,
15
+ bevelShape: "round",
16
+ bulge: 0,
17
+ bulgeWidth: 0.15,
18
+ relief: 0,
19
+ reliefBlur: 0.006,
20
+ ior: 1.5,
21
+ dispersion: 0.12,
22
+ paths: 2,
23
+ samples: 8,
24
+ bounces: 2,
25
+ jitter: 0,
26
+ tint: "#ffffff",
27
+ absorption: 0,
28
+ reflection: 1,
29
+ bump: 0,
30
+ bumpScale: 0.15,
31
+ frost: 0,
32
+ backdrop: "stripes",
33
+ backdropVisible: false,
34
+ backdropScale: 0.25,
35
+ backdropDistance: 0.6,
36
+ backdropSpeed: 0.15,
37
+ backdropColors: "mono",
38
+ backdropRatio: 0.5,
39
+ backdropSoftness: 0.03,
40
+ lightIntensity: 1.5,
41
+ lightSoftness: 0.15,
42
+ yaw: 29,
43
+ pitch: 14,
44
+ orbitAnimation: 20,
45
+ orbitSpeed: 3.3,
46
+ fov: 30,
47
+ zoom: 0.7,
48
+ drag: false,
49
+ cameraOrigin: "element",
50
+ pointer: "none",
51
+ pointerStrength: 1,
52
+ resolution: 1,
53
+ antialias: true,
54
+ pad: 100,
55
+ debug: "off",
56
+ };
57
+ const DEBUG_VIEWS = {
58
+ off: 0,
59
+ outer: 1,
60
+ inner: 2,
61
+ total: 3,
62
+ };
63
+ const BEVEL_SHAPES = {
64
+ round: 0,
65
+ chamfer: 1,
66
+ };
67
+ const MAX_PATHS = 4;
68
+ const MAX_SAMPLES = 16;
69
+ const MAX_BOUNCES = 5;
70
+ // Noise gradient to surface slope, before it saturates.
71
+ const BUMP_SLOPE = "0.6";
72
+ // Long side of the silhouette read back from the element, in px, and the
73
+ // box blurs of the distance field built from it. Refraction magnifies
74
+ // every bump of the normals, so the glass wants a finer and smoother
75
+ // field than the pixel staircase of a small mask gives.
76
+ const GLASS_MASK_LONG = 1024;
77
+ // The mask follows the element's size in device px down to this, so a
78
+ // small element costs less; a finer mask than its pixels adds nothing.
79
+ const GLASS_MASK_MIN = 256;
80
+ const SMOOTH_RADIUS = 4;
81
+ const SMOOTH_PASSES = 3;
82
+ // Box blurs of the relief's height map: glyph edges become a short
83
+ // smooth ramp instead of a cliff, which bounds the slope too. The radius
84
+ // comes from `reliefBlur`; the default gives 3 mask px.
85
+ const RELIEF_PASSES = 3;
86
+ const RELIEF_MAX_RADIUS = 256;
87
+ // A sunk relief keeps at least this share of the glass's thickness.
88
+ const RELIEF_MIN_THICKNESS = 0.2;
89
+ // The shader compiles only the kind of backdrop in use (see GLSL_SCENE):
90
+ // a change of kind compiles a new shader on its first frame.
91
+ const fragGlass = (kind) => `#version 300 es
92
+ #define BACKDROP_KIND ${kind}
93
+ precision highp float;
94
+ in vec2 uv;
95
+ out vec4 outColor;
96
+
97
+ ${_silhouette_js_1.GLSL_SD2}
98
+
99
+ uniform int bevelShape;
100
+ uniform float bulge;
101
+ uniform float bulgeWidth;
102
+ // 1 / the Lipschitz constant of the bulged field, 1 without a bulge: the
103
+ // march steps are scaled by it so they cannot step through the caps.
104
+ uniform float stepScale;
105
+ // Relief of the front cap: \`relief\` times the height map in reliefTex
106
+ // (r = height 0..1, gb = its gradient in world units), on the SDF's grid.
107
+ uniform sampler2D reliefTex;
108
+ uniform float relief;
109
+ // The relief's share of the Lipschitz bound, <= 1: steps that may meet
110
+ // the relief are scaled by it on top of stepScale.
111
+ uniform float reliefScale;
112
+
113
+ // The extrusion of a 2D sample s (from sd2) at depth z, with a bevel and
114
+ // caps that rise by up to \`bulge\` away from the edge. hr is the relief
115
+ // sample (height, gradient) under it, only read when relief != 0.
116
+ // x = distance, yzw = unit gradient.
117
+ vec4 extrude(vec3 s, vec3 hr, float z) {
118
+ float sz = z >= 0.0 ? 1.0 : -1.0;
119
+ // The cap: b = |z| - height, and its gradient (k * grad2, sz).
120
+ float h = halfDepth;
121
+ float k = 0.0;
122
+ if (bulge > 0.0) {
123
+ // f(u) = 1 - (1 - u)^2: steepest at the edge, flat in the middle.
124
+ float u = clamp(-s.x / bulgeWidth, 0.0, 1.0);
125
+ h += bulge * (1.0 - (1.0 - u) * (1.0 - u));
126
+ k = u > 0.0 && u < 1.0 ? 2.0 * bulge * (1.0 - u) / bulgeWidth : 0.0;
127
+ }
128
+ float b = abs(z) - h;
129
+ vec3 gb = vec3(s.yz * k, sz);
130
+ bool tilted = k > 0.0;
131
+ if (relief != 0.0) {
132
+ // Only the front cap carries the relief; the nearer cap wins.
133
+ float bf = z - h - relief * hr.x;
134
+ float bb = -z - h;
135
+ b = max(bf, bb);
136
+ gb = bf >= bb
137
+ ? vec3(s.yz * k - relief * hr.yz, 1.0)
138
+ : vec3(s.yz * k, -1.0);
139
+ tilted = true;
140
+ }
141
+ if (bevelShape == 1) {
142
+ // Chamfer: a 45° plane across the corner. Hard edges on purpose.
143
+ float c = (s.x + b + rounding) * 0.7071;
144
+ if (c > s.x && c > b) {
145
+ return vec4(c, normalize(vec3(s.yz, 0.0) + gb));
146
+ }
147
+ if (s.x > b) {
148
+ return vec4(s.x, s.yz, 0.0);
149
+ }
150
+ return vec4(b, tilted ? normalize(gb) : gb);
151
+ }
152
+ vec2 w = vec2(s.x + rounding, b + rounding);
153
+ if (w.x > 0.0 && w.y > 0.0) {
154
+ float l = length(w);
155
+ vec3 g = vec3(s.yz * w.x, 0.0) + gb * w.y;
156
+ return vec4(l - rounding, tilted ? normalize(g) : g / l);
157
+ }
158
+ if (w.x > w.y) {
159
+ return vec4(w.x - rounding, s.yz, 0.0);
160
+ }
161
+ return vec4(w.y - rounding, tilted ? normalize(gb) : gb);
162
+ }
163
+
164
+ vec3 reliefAt(vec2 p) {
165
+ return texture(reliefTex, (p - sdfRect.xy) / sdfRect.zw).rgb;
166
+ }
167
+
168
+ vec4 sdf3(vec3 p) {
169
+ vec3 s = sd2(p.xy);
170
+ if (relief == 0.0) {
171
+ return extrude(s, vec3(0.0), p.z);
172
+ }
173
+ vec4 e = extrude(s, reliefAt(p.xy), p.z);
174
+ // Steep relief needs short steps, but only near it. Two lower bounds
175
+ // on the distance: the field scaled by the relief's Lipschitz share,
176
+ // and the distance to the shape with the cap at its outermost plane
177
+ // (outside) or innermost plane (inside), which has no relief slope.
178
+ // The larger one is safe; far from the relief it is the plane's.
179
+ bool out_ = e.x > 0.0;
180
+ float hEnv = out_ == (relief > 0.0) ? 1.0 : 0.0;
181
+ float env = extrude(s, vec3(hEnv, 0.0, 0.0), p.z).x;
182
+ e.x = out_ ? max(env, e.x * reliefScale) : min(env, e.x * reliefScale);
183
+ return e;
184
+ }
185
+
186
+ uniform vec2 sdfSize;
187
+ uniform vec2 shapeHalf;
188
+ // The camera (see _orbit-camera.ts): the eye in view space is
189
+ // (eye, camDist), and its axis meets the output at principalPx.
190
+ uniform mat3 viewRot;
191
+ uniform float camDist;
192
+ uniform float focalPx;
193
+ uniform vec2 eye;
194
+ uniform vec2 principalPx;
195
+ uniform vec2 bufferPx;
196
+ // Size of a pixel of the target, in output px.
197
+ uniform float pixelSize;
198
+
199
+ uniform float ior;
200
+ uniform float dispersion;
201
+ uniform int paths;
202
+ uniform int samples;
203
+ uniform int exits;
204
+ uniform float jitter;
205
+ uniform vec3 tint;
206
+ uniform float absorption;
207
+ uniform float reflection;
208
+ uniform float bump;
209
+ uniform float bumpScale;
210
+ uniform float frost;
211
+
212
+ uniform int debugView;
213
+
214
+ const int MAX_PATHS = ${MAX_PATHS};
215
+ const int MAX_SAMPLES = ${MAX_SAMPLES};
216
+ // Tries to leave the glass: one more than the reflections.
217
+ const int MAX_EXITS = ${MAX_BOUNCES + 1};
218
+ const int OUTER_STEPS = 72;
219
+ const int INNER_STEPS = 40;
220
+ const float HIT = 0.0012;
221
+
222
+ float hash12(vec2 p) {
223
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
224
+ p3 += dot(p3, p3.yzx + 33.33);
225
+ return fract((p3.x + p3.y) * p3.z);
226
+ }
227
+
228
+ ${_simplex3_js_1.GLSL_SIMPLEX3}
229
+ ${_simplex3_js_1.GLSL_SIMPLEX3_GRAD}
230
+ ${_scene3d_js_1.GLSL_SCENE}
231
+
232
+ // Unpolarised Fresnel reflectance, from a medium of index n1 into n2.
233
+ float fresnel(float cosI, float n1, float n2) {
234
+ float e = n1 / n2;
235
+ float sinT2 = e * e * (1.0 - cosI * cosI);
236
+ if (sinT2 >= 1.0) {
237
+ return 1.0;
238
+ }
239
+ float cosT = sqrt(1.0 - sinT2);
240
+ float rs = (n1 * cosI - n2 * cosT) / (n1 * cosI + n2 * cosT);
241
+ float rp = (n1 * cosT - n2 * cosI) / (n1 * cosT + n2 * cosI);
242
+ return 0.5 * (rs * rs + rp * rp);
243
+ }
244
+
245
+ // RGB response at position t of the spectrum (0 red, 1 violet): three
246
+ // triangles, so that 3 samples are exactly red, green and blue.
247
+ vec3 spectral(float t) {
248
+ return max(1.0 - abs(t - vec3(1.0, 3.0, 5.0) / 6.0) * 3.0, 0.0);
249
+ }
250
+
251
+ // A bicubic (B-spline) filtered lookup of a texture on the SDF's grid,
252
+ // in 4 bilinear taps. Stored gradients are only piecewise linear between
253
+ // texels, which shows as streaks once they bend light; these are smooth.
254
+ vec4 bicubic(sampler2D tex, vec2 uv) {
255
+ vec2 st = uv * sdfSize - 0.5;
256
+ vec2 i = floor(st);
257
+ vec2 f = st - i;
258
+ vec2 w0 = (1.0 - f) * (1.0 - f) * (1.0 - f) / 6.0;
259
+ vec2 w1 = (4.0 - 6.0 * f * f + 3.0 * f * f * f) / 6.0;
260
+ vec2 w2 = (1.0 + 3.0 * f + 3.0 * f * f - 3.0 * f * f * f) / 6.0;
261
+ vec2 w3 = f * f * f / 6.0;
262
+ vec2 g0 = w0 + w1;
263
+ vec2 g1 = w2 + w3;
264
+ vec2 h0 = (i - 0.5 + w1 / g0) / sdfSize;
265
+ vec2 h1 = (i + 1.5 + w3 / g1) / sdfSize;
266
+ return (texture(tex, vec2(h0.x, h0.y)) * g0.x
267
+ + texture(tex, vec2(h1.x, h0.y)) * g1.x) * g0.y
268
+ + (texture(tex, vec2(h0.x, h1.y)) * g0.x
269
+ + texture(tex, vec2(h1.x, h1.y)) * g1.x) * g1.y;
270
+ }
271
+
272
+ // sd2, bicubic filtered.
273
+ vec3 sd2Smooth(vec2 p) {
274
+ vec2 uv = (p - sdfRect.xy) / sdfRect.zw;
275
+ if (any(lessThan(uv, vec2(0.0))) || any(greaterThan(uv, vec2(1.0)))) {
276
+ return sd2(p);
277
+ }
278
+ vec4 s = bicubic(sdfTex, uv);
279
+ float gl = length(s.gb);
280
+ return vec3(s.r, gl > 1e-5 ? s.gb / gl : vec2(0.0, 1.0));
281
+ }
282
+
283
+ // The surface normal at p, for a ray along d that meets it there.
284
+ vec3 normalAt(vec3 p, vec3 d) {
285
+ vec3 hr = relief != 0.0
286
+ ? bicubic(reliefTex, (p.xy - sdfRect.xy) / sdfRect.zw).rgb
287
+ : vec3(0.0);
288
+ vec3 n = extrude(sd2Smooth(p.xy), hr, p.z).yzw;
289
+ if (bump <= 0.0) {
290
+ return n;
291
+ }
292
+ // Ripples: tilt the normal against the tangential part of a noise
293
+ // gradient. The noise is in object space, so it sticks to the shape.
294
+ vec3 g = snoiseD(p / bumpScale).xyz * ${BUMP_SLOPE};
295
+ g -= n * dot(g, n);
296
+ // Saturate the slope, so the tilt stays under 45°. Refraction
297
+ // through two rippled faces magnifies the tilt a lot, so the strength
298
+ // goes as bump^2 to leave room for subtle ripples.
299
+ vec3 m = normalize(n - g * (bump * bump / sqrt(1.0 + dot(g, g))));
300
+ // At grazing angles the tilt can turn the normal past the ray, which
301
+ // would refract it to the wrong side: keep the side of n.
302
+ float s = dot(d, n) < 0.0 ? -1.0 : 1.0;
303
+ float lim = min(abs(dot(d, n)), 0.1);
304
+ float c = dot(d, m) * s;
305
+ if (c < lim) {
306
+ m = normalize(m + d * (s * (lim - c)));
307
+ }
308
+ return m;
309
+ }
310
+
311
+ ${_scene3d_js_1.GLSL_HEAT}
312
+ // Slab test against the shape's bounding box. x = near, y = far.
313
+ vec2 boundsHit(vec3 ro, vec3 rd) {
314
+ vec3 b = vec3(shapeHalf + 0.01, halfDepth + bulge + max(relief, 0.0) + 0.01);
315
+ vec3 inv = 1.0 / rd;
316
+ vec3 t0 = (-b - ro) * inv;
317
+ vec3 t1 = (b - ro) * inv;
318
+ vec3 lo = min(t0, t1);
319
+ vec3 hi = max(t0, t1);
320
+ return vec2(max(max(lo.x, lo.y), lo.z), min(min(hi.x, hi.y), hi.z));
321
+ }
322
+
323
+ // The glass seen along rd at surface point p0: the reflection on the
324
+ // outside, plus the light that comes back out of the inside.
325
+ vec3 shade(vec3 p0, vec3 rd, inout float innerCount) {
326
+ vec3 n0 = normalAt(p0, rd);
327
+ float cos0 = clamp(-dot(rd, n0), 0.0, 1.0);
328
+
329
+ // Reflection on the outer surface.
330
+ float f0 = fresnel(cos0, 1.0, ior);
331
+ vec3 col = radiance(viewRot * p0, viewRot * reflect(rd, n0), frost)
332
+ * f0 * reflection;
333
+
334
+ // Trace the inside once per path, each with its own IOR.
335
+ vec3 exPos[MAX_PATHS];
336
+ vec3 exDir[MAX_PATHS];
337
+ float exLen[MAX_PATHS];
338
+ float exW[MAX_PATHS];
339
+ int exN[MAX_PATHS];
340
+ int nPaths = clamp(paths, 1, MAX_PATHS);
341
+ int nExits = clamp(exits, 1, MAX_EXITS);
342
+ for (int m = 0; m < MAX_PATHS; m++) {
343
+ if (m >= nPaths) {
344
+ break;
345
+ }
346
+ float n = ior + dispersion * ((float(m) + 0.5) / float(nPaths) - 0.5);
347
+ n = max(n, 1.0001);
348
+ vec3 d = refract(rd, n0, 1.0 / n);
349
+ vec3 p = p0 - n0 * (HIT * 3.0);
350
+ float w = 1.0 - fresnel(cos0, 1.0, n);
351
+ float len = 0.0;
352
+ int nb = 0;
353
+ for (int b = 0; b < MAX_EXITS; b++) {
354
+ float ti = 0.0;
355
+ vec4 si;
356
+ for (int i = 0; i < INNER_STEPS; i++) {
357
+ si = sdf3(p + d * ti);
358
+ innerCount += 1.0;
359
+ float di = -si.x;
360
+ // At the wall, and heading out of it.
361
+ if (di < HIT && dot(d, si.yzw) > 0.0) {
362
+ break;
363
+ }
364
+ ti += max(di * stepScale, HIT);
365
+ }
366
+ // The same Newton step onto the wall.
367
+ ti += clamp(-si.x / max(dot(d, si.yzw), 0.1), 0.0, HIT * 4.0);
368
+ p += d * ti;
369
+ len += ti;
370
+ vec3 ni = normalAt(p, d);
371
+ float cosI = clamp(dot(d, ni), 0.0, 1.0);
372
+ vec3 o = refract(d, -ni, n);
373
+ bool last = b >= nExits - 1;
374
+ if (dot(o, o) > 0.0) {
375
+ w *= 1.0 - fresnel(cosI, n, 1.0);
376
+ d = o;
377
+ break;
378
+ }
379
+ if (last) {
380
+ // Out of bounces inside: let it out along the surface
381
+ // normal's side, dimmed.
382
+ d = normalize(d + ni * 0.5);
383
+ w *= 0.5;
384
+ break;
385
+ }
386
+ d = reflect(d, ni);
387
+ p -= ni * (HIT * 3.0);
388
+ nb++;
389
+ }
390
+ exPos[m] = viewRot * p;
391
+ exDir[m] = viewRot * d;
392
+ exLen[m] = len;
393
+ exW[m] = w;
394
+ exN[m] = nb;
395
+ }
396
+
397
+ // Spectrum: each wavelength's exit ray is interpolated between the
398
+ // two nearest paths.
399
+ int nSamples = clamp(samples, 1, MAX_SAMPLES);
400
+ float j = (hash12(gl_FragCoord.xy) - 0.5) * jitter;
401
+ vec3 acc = vec3(0.0);
402
+ vec3 wsum = vec3(0.0);
403
+ vec3 absorb = absorption * (1.0 - tint);
404
+ for (int i = 0; i < MAX_SAMPLES; i++) {
405
+ if (i >= nSamples) {
406
+ break;
407
+ }
408
+ float ts = clamp((float(i) + 0.5 + j) / float(nSamples), 0.0, 1.0);
409
+ float x = ts * float(nPaths) - 0.5;
410
+ int a = clamp(int(floor(x)), 0, max(nPaths - 2, 0));
411
+ int b = min(a + 1, nPaths - 1);
412
+ float f = x - float(a);
413
+ // Paths that left through different faces can't be blended:
414
+ // snap to the nearest one.
415
+ if (a == b || exN[a] != exN[b] || dot(exDir[a], exDir[b]) < 0.9) {
416
+ f = step(0.5, f);
417
+ }
418
+ vec3 p = mix(exPos[a], exPos[b], f);
419
+ vec3 d = normalize(mix(exDir[a], exDir[b], f));
420
+ float len = mix(exLen[a], exLen[b], clamp(f, 0.0, 1.0));
421
+ float w = mix(exW[a], exW[b], clamp(f, 0.0, 1.0));
422
+ vec3 l = radiance(p, d, frost) * w * exp(-absorb * len);
423
+ vec3 sw = nSamples == 1 ? vec3(1.0) : spectral(ts);
424
+ acc += sw * l;
425
+ wsum += sw;
426
+ }
427
+ return col + acc / max(wsum, vec3(1e-4));
428
+ }
429
+
430
+ void main() {
431
+ vec2 px = uv * bufferPx;
432
+ vec3 rdV = normalize(vec3((px - principalPx) / focalPx, -1.0));
433
+ vec3 roV = vec3(eye, camDist);
434
+ // viewRot maps object to view; its transpose maps back.
435
+ vec3 ro = roV * viewRot;
436
+ vec3 rd = rdV * viewRot;
437
+
438
+ vec3 miss = vec3(0.0);
439
+ float missA = 0.0;
440
+ if (backdropVisible > 0.5) {
441
+ miss = radiance(roV, rdV, 0.0) * step(0.5, float(backdropMode));
442
+ missA = backdropMode == 0 ? 0.0 : 1.0;
443
+ }
444
+
445
+ vec2 tb = boundsHit(ro, rd);
446
+ if (tb.x > tb.y || tb.y < 0.0) {
447
+ outColor = debugView != 0 ? heat(0.0) : vec4(miss, missA);
448
+ return;
449
+ }
450
+ float outerCount = 0.0;
451
+ float innerCount = 0.0;
452
+ float t = max(tb.x, 0.0);
453
+ // Radius of the pixel's cone per unit of distance.
454
+ float cone = pixelSize / focalPx;
455
+ // Front to back: what is left to cover, and the colour so far. A ray
456
+ // that grazes an edge covers part of the pixel with it and goes on
457
+ // to what is behind, so edges are antialiased by their coverage.
458
+ float remain = 1.0;
459
+ // Up to two layers: their surface points and weights. They are
460
+ // shaded after the march, where screen-space derivatives are valid.
461
+ vec3 layerP[2];
462
+ float layerW[2];
463
+ int layers = 0;
464
+ bool leaving = false;
465
+ for (int i = 0; i < OUTER_STEPS; i++) {
466
+ vec4 s = sdf3(ro + rd * t);
467
+ outerCount += 1.0;
468
+ float r = t * cone;
469
+ float zone = max(HIT, r);
470
+ if (leaving) {
471
+ // Step away from the edge that was just grazed.
472
+ if (s.x > zone) {
473
+ leaving = false;
474
+ }
475
+ t += max(s.x * stepScale, 3.0 * r);
476
+ } else if (s.x < zone) {
477
+ // Near the surface. Step to where the ray would cross its
478
+ // tangent plane: a ray that hits gets there, one that
479
+ // grazes a convex edge ends up moving away from it.
480
+ float k = s.x / r;
481
+ bool solid = false;
482
+ for (int j = 0; j < 6; j++) {
483
+ if (s.x < 0.15 * r) {
484
+ solid = true;
485
+ break;
486
+ }
487
+ float c = dot(rd, s.yzw);
488
+ if (c > -0.02) {
489
+ break;
490
+ }
491
+ t += min(s.x / -c * stepScale, 0.05);
492
+ s = sdf3(ro + rd * t);
493
+ outerCount += 1.0;
494
+ k = min(k, s.x / (t * cone));
495
+ }
496
+ float cov = solid ? 1.0 : clamp(1.0 - k, 0.0, 1.0);
497
+ if (cov > 0.0) {
498
+ // Onto the surface: the march stops anywhere near it,
499
+ // which would show as contour lines once refracted.
500
+ vec3 p0 = ro + rd * t;
501
+ if (solid) {
502
+ p0 += rd * clamp(
503
+ s.x / max(-dot(rd, s.yzw), 0.1),
504
+ -HIT * 4.0,
505
+ HIT * 4.0
506
+ );
507
+ } else {
508
+ p0 -= s.yzw * s.x;
509
+ }
510
+ if (layers == 0) {
511
+ layerP[0] = p0;
512
+ layerW[0] = remain * cov;
513
+ } else {
514
+ layerP[1] = p0;
515
+ layerW[1] = remain * cov;
516
+ }
517
+ remain *= 1.0 - cov;
518
+ layers++;
519
+ }
520
+ if (solid || layers >= 2 || remain < 0.02) {
521
+ break;
522
+ }
523
+ leaving = true;
524
+ t += max(s.x * stepScale, 3.0 * r);
525
+ } else {
526
+ t += s.x * stepScale;
527
+ }
528
+ if (t > tb.y) {
529
+ break;
530
+ }
531
+ }
532
+
533
+ float layerA = backdropMode == 0 ? 0.0 : 1.0;
534
+ vec4 acc = remain * vec4(miss, missA);
535
+ if (layers > 0) {
536
+ acc += layerW[0] * vec4(shade(layerP[0], rd, innerCount), layerA);
537
+ }
538
+ if (layers > 1) {
539
+ acc += layerW[1] * vec4(shade(layerP[1], rd, innerCount), layerA);
540
+ }
541
+ outColor = acc;
542
+ if (debugView != 0) {
543
+ outColor = heat(
544
+ (debugView != 2 ? outerCount : 0.0)
545
+ + (debugView != 1 ? innerCount : 0.0)
546
+ );
547
+ return;
548
+ }
549
+ }
550
+ `;
551
+ // The shaders made so far, by kind of backdrop.
552
+ const FRAG_GLASS = new Map();
553
+ function fragGlassFor(kind) {
554
+ let frag = FRAG_GLASS.get(kind);
555
+ if (!frag) {
556
+ frag = fragGlass(kind);
557
+ FRAG_GLASS.set(kind, frag);
558
+ }
559
+ return frag;
560
+ }
561
+ const EMPTY = new Float32Array(0);
562
+ // Whether `relief` raises the cap. UI sliders leave remainders like
563
+ // 5e-17; those count as 0, so the default path stays exact.
564
+ function reliefOn(relief) {
565
+ return Number.isFinite(relief) && Math.abs(relief) > 1e-6;
566
+ }
567
+ // Free the big arrays once they are on the GPU. A restored context reads
568
+ // the element back again instead. The luminance stays, to rebuild the
569
+ // relief when `reliefBlur` changes.
570
+ function dropArrays(shape) {
571
+ shape.sdf = EMPTY;
572
+ shape.spawn = EMPTY;
573
+ shape.relief = EMPTY;
574
+ }
575
+ // Lipschitz constant of a field whose cap has slope up to k: the cap's
576
+ // gradient is (k * grad2, 1), k = 2 * bulge / bulgeWidth plus the
577
+ // relief's slope, and the bevel mixes it with the side's (grad2, 0). The
578
+ // worst mix is the largest singular value of [[1, k], [0, 1]], a little
579
+ // above sqrt(1 + k^2).
580
+ function capLipschitz(k) {
581
+ return Math.sqrt((2 + k * k + k * Math.sqrt(k * k + 4)) / 2);
582
+ }
583
+ /**
584
+ * Turns the element's silhouette into a block of dispersive glass: the
585
+ * alpha is extruded into 3D and ray-traced with refraction, internal
586
+ * reflections and a rainbow split of the light.
587
+ *
588
+ * ```ts
589
+ * vfx.add(img, { effect: new GlassEffect({ backdrop: "grid" }) });
590
+ * ```
591
+ *
592
+ * The silhouette is the element's alpha (or the channel
593
+ * {@link GlassParams.sourceChannel | sourceChannel} picks), read back
594
+ * when the effect starts and again when the element's aspect ratio
595
+ * changes. Call {@link GlassEffect.refresh | refresh()} after its
596
+ * content changes. An opaque photo becomes a slab. The glass shows a
597
+ * `backdrop` behind it, a procedural pattern or an image, not the page:
598
+ * the output is opaque where the backdrop is seen and premultiplied over
599
+ * transparency elsewhere.
600
+ *
601
+ * The camera ({@link OrbitCameraParams}: `yaw`, `pitch`,
602
+ * `orbitAnimation`, `fov`, …) works as in {@link SwirlParticleEffect},
603
+ * with angles in degrees. Its defaults here: the glass turned by `yaw` 29
604
+ * and `pitch` 14, a faster orbit animation (`orbitSpeed` 3.3), and
605
+ * `zoom` 0.7, so the glass is a little smaller than the element. Set `drag: true` to orbit it with
606
+ * pointer drags that start on the element, and `pointer: "tilt"` to turn
607
+ * it towards the pointer. With `cameraOrigin: "viewport"`, set
608
+ * `pad: "fullscreen"` to leave room for an off-centre element to lean out
609
+ * of its rect.
610
+ *
611
+ * All params are read every frame, so you can mutate `params` live.
612
+ */
613
+ class GlassEffect {
614
+ params;
615
+ #still;
616
+ // Reads the silhouette back: when the effect starts, on refresh(),
617
+ // and when the element's aspect ratio changes.
618
+ #source = new _source_js_1.SourceCapture({
619
+ longSide: GLASS_MASK_LONG,
620
+ minLongSide: GLASS_MASK_MIN,
621
+ onRead: (r, isCurrent) => this.#onRead(r, isCurrent),
622
+ });
623
+ // `sourceChannel` of the last shape read; a change reads it again.
624
+ #channel = null;
625
+ #pending = null;
626
+ #shape = null;
627
+ #passes = new _scene3d_js_1.ScenePasses();
628
+ #gl = null;
629
+ #sdfRaw = null;
630
+ #sdfTex = null;
631
+ #reliefRaw = null;
632
+ #reliefTex = null;
633
+ // A relief rebuilt in the worker for a new `reliefBlur`.
634
+ #reliefBusy = false;
635
+ #reliefToken = 0;
636
+ #reliefReady = null;
637
+ #backdrop = new _scene3d_js_1.SceneBackdrop(_scene3d_js_1.BACKDROP_PALETTES, DEFAULT_PARAMS);
638
+ #time = 0;
639
+ // Drags, the "tilt", and the window listeners while `drag` is on or
640
+ // `pointer` is "tilt".
641
+ #camera = new _orbit_camera_js_1.OrbitCamera(DEFAULT_PARAMS);
642
+ #unsubRestored = null;
643
+ constructor(initial = {}, opts = {}) {
644
+ this.params = { ...DEFAULT_PARAMS, ...initial };
645
+ this.#still = opts.still ?? false;
646
+ }
647
+ setParams(updates) {
648
+ Object.assign(this.params, updates);
649
+ }
650
+ init(ctx) {
651
+ this.#gl = ctx.gl;
652
+ this.#unsubRestored = ctx.onContextRestored(() => {
653
+ // The raw SDF texture is gone, and its array was freed: read
654
+ // the element back again. A readback in flight was rejected;
655
+ // start it over. The glass shows again once it is read.
656
+ this.#source.contextRestored();
657
+ this.#dropReliefJob();
658
+ if (!this.#pending) {
659
+ this.#source.refresh();
660
+ }
661
+ this.#gl = ctx.gl;
662
+ this.#sdfTex?.dispose();
663
+ this.#reliefTex?.dispose();
664
+ this.#sdfRaw = null;
665
+ this.#sdfTex = null;
666
+ this.#reliefRaw = null;
667
+ this.#reliefTex = null;
668
+ this.#backdrop.contextRestored();
669
+ this.#shape = null;
670
+ });
671
+ }
672
+ outputRect(dims) {
673
+ return (0, _pad_js_1.padOutputRect)((0, _pad_js_1.padOf)(this.params.pad, DEFAULT_PARAMS.pad), dims);
674
+ }
675
+ render(ctx) {
676
+ if (this.#source.phase === "idle" &&
677
+ this.#channel !== null &&
678
+ (0, _source_js_1.sourceChannelOf)(this.params.sourceChannel) !== this.#channel) {
679
+ this.#source.refresh();
680
+ }
681
+ this.#source.update(ctx);
682
+ // A new shape replaces the current one once it has been read back.
683
+ if (this.#pending) {
684
+ this.#upload(ctx, this.#pending);
685
+ dropArrays(this.#pending);
686
+ this.#shape = this.#pending;
687
+ this.#pending = null;
688
+ }
689
+ this.#updateRelief(ctx);
690
+ this.#backdrop.update(ctx, this.params);
691
+ if (!this.#still) {
692
+ this.#time += Math.min(ctx.deltaTime, 0.1);
693
+ }
694
+ const cam = this.#camera.update(this.params, {
695
+ time: this.#time,
696
+ dt: this.#still ? 0 : ctx.deltaTime,
697
+ dims: ctx.dims,
698
+ outputRect: (0, _pad_js_1.padOutputRect)((0, _pad_js_1.padOf)(this.params.pad, DEFAULT_PARAMS.pad), ctx.dims),
699
+ mouse: ctx.mouse,
700
+ mouseViewport: ctx.mouseViewport,
701
+ pixelRatio: ctx.pixelRatio,
702
+ live: !this.#still,
703
+ tilt: this.params.pointer === "tilt",
704
+ });
705
+ const scene = this.#drawGlass(ctx, cam);
706
+ this.#passes.output(ctx, scene, {
707
+ pad: (0, _pad_js_1.padOf)(this.params.pad, DEFAULT_PARAMS.pad),
708
+ antialias: this.params.antialias,
709
+ raw: this.#debugView() !== 0,
710
+ });
711
+ }
712
+ #debugView() {
713
+ return DEBUG_VIEWS[this.params.debug] ?? 0;
714
+ }
715
+ #drawGlass(ctx, cam) {
716
+ const shape = this.#shape;
717
+ const sdfTex = this.#sdfTex;
718
+ if (!shape || !sdfTex) {
719
+ return null;
720
+ }
721
+ const p = this.params;
722
+ const scene = this.#passes.scene(ctx, (0, _pad_js_1.padOf)(p.pad, DEFAULT_PARAMS.pad), p.resolution);
723
+ const [, , ow, oh] = (0, _pad_js_1.padOutputRect)((0, _pad_js_1.padOf)(p.pad, DEFAULT_PARAMS.pad), ctx.dims);
724
+ if (!scene || ow <= 0 || oh <= 0) {
725
+ return null;
726
+ }
727
+ const t = this.#time;
728
+ const D = DEFAULT_PARAMS;
729
+ const halfDepth = (0, _scene3d_js_1.num)(p.depth, 0.01, 100, D.depth) / 2;
730
+ const bulge = (0, _scene3d_js_1.num)(p.bulge, 0, 100, 0);
731
+ const bulgeWidth = (0, _scene3d_js_1.num)(p.bulgeWidth, 1e-3, 100, D.bulgeWidth);
732
+ const bulgeSlope = bulge > 0 ? (2 * bulge) / bulgeWidth : 0;
733
+ // A sunk relief must keep the front cap above the back one. Until
734
+ // the relief is built, the cap stays flat.
735
+ const relief = reliefOn(p.relief) && this.#reliefTex
736
+ ? Math.max(p.relief, -2 * halfDepth * (1 - RELIEF_MIN_THICKNESS))
737
+ : 0;
738
+ const reliefSlope = Math.abs(relief) * shape.reliefMaxGrad;
739
+ ctx.draw({
740
+ frag: fragGlassFor((0, _scene3d_js_1.backdropKind)(this.params.backdrop)),
741
+ uniforms: {
742
+ sdfTex,
743
+ sdfRect: shape.sdfRect,
744
+ sdfSize: [shape.sdfW, shape.sdfH],
745
+ halfDepth,
746
+ rounding: Math.min((0, _scene3d_js_1.num)(p.bevel, 0, halfDepth, D.bevel), halfDepth),
747
+ bevelShape: BEVEL_SHAPES[p.bevelShape] ?? 0,
748
+ bulge,
749
+ bulgeWidth,
750
+ stepScale: bulge > 0 ? 1 / capLipschitz(bulgeSlope) : 1,
751
+ reliefTex: this.#reliefTex ?? sdfTex,
752
+ relief,
753
+ reliefScale: capLipschitz(bulgeSlope) /
754
+ capLipschitz(bulgeSlope + reliefSlope),
755
+ shapeHalf: shape.shapeHalf,
756
+ viewRot: cam.viewRot,
757
+ camDist: cam.camDist,
758
+ focalPx: cam.focalPx,
759
+ eye: [cam.eye[0], cam.eye[1]],
760
+ principalPx: cam.principalPx,
761
+ bufferPx: [ow, oh],
762
+ pixelSize: ow / scene.width,
763
+ ior: (0, _scene3d_js_1.num)(p.ior, 1.0001, 10, D.ior),
764
+ dispersion: (0, _scene3d_js_1.num)(p.dispersion, -10, 10, D.dispersion),
765
+ paths: (0, _scene3d_js_1.clampInt)(p.paths, 1, MAX_PATHS, 2),
766
+ samples: (0, _scene3d_js_1.clampInt)(p.samples, 1, MAX_SAMPLES, 8),
767
+ exits: (0, _scene3d_js_1.clampInt)(p.bounces, 0, MAX_BOUNCES, 2) + 1,
768
+ jitter: (0, _scene3d_js_1.num)(p.jitter, 0, 1, D.jitter),
769
+ tint: (0, _scene3d_js_1.hexToRgb)(p.tint, DEFAULT_PARAMS.tint),
770
+ absorption: (0, _scene3d_js_1.num)(p.absorption, 0, 1e3, D.absorption),
771
+ reflection: (0, _scene3d_js_1.num)(p.reflection, 0, 100, D.reflection),
772
+ bump: (0, _scene3d_js_1.num)(p.bump, 0, 1, D.bump),
773
+ bumpScale: (0, _scene3d_js_1.num)(p.bumpScale, 1e-3, 100, D.bumpScale),
774
+ frost: (0, _scene3d_js_1.num)(p.frost, 0, 1, D.frost),
775
+ ...this.#backdrop.uniforms(p, t, halfDepth + bulge + Math.max(relief, 0), sdfTex),
776
+ debugView: this.#debugView(),
777
+ },
778
+ target: scene,
779
+ });
780
+ return scene;
781
+ }
782
+ /**
783
+ * Capture the element's silhouette again, for when its content
784
+ * changed: an image's `src` swapped, a text edit. For an `<img>`,
785
+ * call it after `vfx.update(img)` has reloaded the image.
786
+ *
787
+ * The glass keeps the current shape until the new one has been read
788
+ * back (a few frames later), then switches to it. A change of the
789
+ * element's aspect ratio is recaptured automatically once its size
790
+ * settles; a change of size alone needs none.
791
+ *
792
+ * Safe to call at any time and any number of times; a call while a
793
+ * capture is pending restarts it, so the latest content wins.
794
+ */
795
+ refresh() {
796
+ this.#source.refresh();
797
+ }
798
+ // Build the shape, and the relief when it is on, from the element
799
+ // read back, in the worker. False when the silhouette is empty, to
800
+ // try again later.
801
+ async #onRead(r, isCurrent) {
802
+ const channel = (0, _source_js_1.sourceChannelOf)(this.params.sourceChannel);
803
+ const withRelief = reliefOn(this.params.relief);
804
+ const built = await (0, _shape_worker_js_1.buildShapeAsync)({
805
+ pixels: r.pixels,
806
+ mw: r.width,
807
+ mh: r.height,
808
+ channel,
809
+ aspect: r.aspect,
810
+ smoothRadius: SMOOTH_RADIUS,
811
+ smoothPasses: SMOOTH_PASSES,
812
+ spawn: false,
813
+ relief: withRelief
814
+ ? {
815
+ blur: this.params.reliefBlur,
816
+ passes: RELIEF_PASSES,
817
+ maxRadius: RELIEF_MAX_RADIUS,
818
+ }
819
+ : undefined,
820
+ });
821
+ if (!built) {
822
+ return false;
823
+ }
824
+ if (!isCurrent()) {
825
+ return true; // dropped by the capture anyway
826
+ }
827
+ const { relief, ...shape } = built;
828
+ this.#pending = {
829
+ ...shape,
830
+ reliefLum: relief?.lum ?? null,
831
+ reliefRadius: relief?.radius ?? -1,
832
+ relief: relief?.map ?? EMPTY,
833
+ reliefMaxGrad: relief?.maxGrad ?? 0,
834
+ };
835
+ this.#channel = channel;
836
+ return true;
837
+ }
838
+ #upload(ctx, shape) {
839
+ const gl = ctx.gl;
840
+ this.#sdfTex?.dispose();
841
+ if (this.#sdfRaw) {
842
+ gl.deleteTexture(this.#sdfRaw);
843
+ }
844
+ this.#sdfRaw = null;
845
+ this.#sdfTex = null;
846
+ const sdf = (0, _scene3d_js_1.uploadFloatTexture)(gl, shape.sdfW, shape.sdfH, shape.sdf);
847
+ ctx.resetState();
848
+ if (sdf) {
849
+ this.#sdfRaw = sdf;
850
+ this.#sdfTex = ctx.wrapTexture(sdf, {
851
+ size: [shape.sdfW, shape.sdfH],
852
+ filter: "linear",
853
+ wrap: "clamp",
854
+ });
855
+ }
856
+ this.#uploadRelief(ctx, shape);
857
+ }
858
+ // Rebuild the relief when `reliefBlur` changes, from the luminance
859
+ // kept from the readback: no new capture, and the SDF stays. Free it
860
+ // when `relief` goes to 0; when it leaves 0, read the element again
861
+ // for its luminance.
862
+ #updateRelief(ctx) {
863
+ const shape = this.#shape;
864
+ if (!shape) {
865
+ return;
866
+ }
867
+ if (!reliefOn(this.params.relief)) {
868
+ if (shape.reliefLum) {
869
+ shape.reliefLum = null;
870
+ shape.reliefRadius = -1;
871
+ shape.reliefMaxGrad = 0;
872
+ this.#freeRelief(ctx.gl);
873
+ }
874
+ return;
875
+ }
876
+ if (!shape.reliefLum) {
877
+ if (this.#source.phase === "idle" && !this.#pending) {
878
+ this.#source.refresh();
879
+ }
880
+ return;
881
+ }
882
+ // A relief built in the worker: take it if it is for this shape.
883
+ const ready = this.#reliefReady;
884
+ if (ready) {
885
+ this.#reliefReady = null;
886
+ if (ready.shape === shape) {
887
+ shape.relief = ready.map;
888
+ shape.reliefMaxGrad = ready.maxGrad;
889
+ shape.reliefRadius = ready.radius;
890
+ this.#uploadRelief(ctx, shape);
891
+ shape.relief = EMPTY;
892
+ }
893
+ }
894
+ const radius = (0, _silhouette_js_1.reliefRadius)(this.params.reliefBlur, shape, RELIEF_MAX_RADIUS);
895
+ if (radius === shape.reliefRadius || this.#reliefBusy) {
896
+ return;
897
+ }
898
+ // One job at a time; the radius is checked again when it is back.
899
+ this.#reliefBusy = true;
900
+ const token = this.#reliefToken;
901
+ (0, _shape_worker_js_1.buildReliefAsync)({
902
+ lum: shape.reliefLum,
903
+ sdfRect: shape.sdfRect,
904
+ sdfW: shape.sdfW,
905
+ sdfH: shape.sdfH,
906
+ radius,
907
+ passes: RELIEF_PASSES,
908
+ }).then((r) => {
909
+ if (token === this.#reliefToken) {
910
+ this.#reliefBusy = false;
911
+ this.#reliefReady = { shape, radius, ...r };
912
+ }
913
+ }, (e) => {
914
+ if (token === this.#reliefToken) {
915
+ this.#reliefBusy = false;
916
+ shape.reliefRadius = radius; // not asked again
917
+ console.warn("[VFX-JS] GlassEffect could not build the relief:", e);
918
+ }
919
+ });
920
+ }
921
+ // Drop a relief job in flight (dispose, restore).
922
+ #dropReliefJob() {
923
+ this.#reliefToken++;
924
+ this.#reliefBusy = false;
925
+ this.#reliefReady = null;
926
+ }
927
+ #freeRelief(gl) {
928
+ this.#reliefTex?.dispose();
929
+ if (this.#reliefRaw) {
930
+ gl.deleteTexture(this.#reliefRaw);
931
+ }
932
+ this.#reliefRaw = null;
933
+ this.#reliefTex = null;
934
+ }
935
+ #uploadRelief(ctx, shape) {
936
+ const gl = ctx.gl;
937
+ this.#freeRelief(gl);
938
+ if (!shape.reliefLum) {
939
+ return;
940
+ }
941
+ const rel = (0, _scene3d_js_1.uploadFloatTexture)(gl, shape.sdfW, shape.sdfH, shape.relief);
942
+ ctx.resetState();
943
+ const size = [shape.sdfW, shape.sdfH];
944
+ if (rel) {
945
+ this.#reliefRaw = rel;
946
+ this.#reliefTex = ctx.wrapTexture(rel, {
947
+ size,
948
+ filter: "linear",
949
+ wrap: "clamp",
950
+ });
951
+ }
952
+ }
953
+ dispose() {
954
+ this.#camera.dispose();
955
+ this.#unsubRestored?.();
956
+ this.#unsubRestored = null;
957
+ this.#sdfTex?.dispose();
958
+ this.#reliefTex?.dispose();
959
+ if (this.#gl && this.#sdfRaw) {
960
+ this.#gl.deleteTexture(this.#sdfRaw);
961
+ }
962
+ if (this.#gl && this.#reliefRaw) {
963
+ this.#gl.deleteTexture(this.#reliefRaw);
964
+ }
965
+ this.#backdrop.dispose(this.#gl);
966
+ this.#reliefRaw = null;
967
+ this.#reliefTex = null;
968
+ this.#gl = null;
969
+ this.#sdfRaw = null;
970
+ this.#sdfTex = null;
971
+ this.#passes.dispose();
972
+ this.#shape = null;
973
+ this.#pending = null;
974
+ // Start over like a new instance if it is added again.
975
+ this.#source.reset();
976
+ this.#dropReliefJob();
977
+ this.#channel = null;
978
+ }
979
+ }
980
+ exports.GlassEffect = GlassEffect;
981
+ //# sourceMappingURL=glass.js.map