@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,1606 @@
1
+ import { captureContent } from "./_capture.js";
2
+ import { LOOKS } from "./_holo/data/looks.js";
3
+ import { MATERIAL_PRESETS } from "./_holo/data/material-presets.js";
4
+ import { PARAM_SPECS } from "./_holo/data/params.js";
5
+ import { STARTING_POINTS, } from "./_holo/data/starting-points.js";
6
+ import { STUDIO_PRESETS } from "./_holo/data/studio-presets.js";
7
+ import { HoloGlare } from "./_holo/glare.js";
8
+ import outputFrag from "./_holo/glsl/output.js";
9
+ import { FRAG_DECODE_RGBA_MAIN, LTC_IMAGE, LTC_SIZE, ltcImageBytes, } from "./_holo/ltc.js";
10
+ import { isMaterialName, loadedMaterial, loadMaterial, MATERIAL_NAMES, } from "./_holo/materials/registry.js";
11
+ import { envLevels, eulerXYZ, framingDistance, } from "./_holo/physics/geometry.js";
12
+ import { etaFrame } from "./_holo/physics/grating.js";
13
+ import { cameraSideBlobs, ENV_LEVELS, ENV_SIZE, envRotation, FRAG_ENV_PREFILTER, sameLevels, } from "./_holo/scene/env.js";
14
+ import { computeLights, emptyLightSet } from "./_holo/scene/lights.js";
15
+ import { inversePoseQuat, PoseSpring, wobbleOffset, } from "./_holo/scene/pose.js";
16
+ import { buildWaves } from "./_holo/scene/relief.js";
17
+ import { backgroundTone, exposureMultiplier, isCopyBlob, resolveSettings, sceneStateFrom, warnOnce, } from "./_holo/settings.js";
18
+ import { assembleMaterial, CARD_VERT, FRAG_CARD_BASE, FRAG_PREFIX, GLSL_COMMON, PLAIN_VERT, } from "./_holo/shader.js";
19
+ import { ATLAS, SpectralAtlas } from "./_holo/spectral/atlas.js";
20
+ import { GLSL_DECODE_FLOAT24 } from "./_holo/spectral/float24.js";
21
+ import { detectTier, TIERS } from "./_holo/tier.js";
22
+ import { SPD_IDS, } from "./_holo/types.js";
23
+ const DEFAULT_COMPOSED = {
24
+ material: "prism",
25
+ settings: {},
26
+ quality: "medium",
27
+ structureScale: 1,
28
+ };
29
+ const DEFAULT_PARAMS = {
30
+ holo: [],
31
+ sourceChannel: "alpha",
32
+ ink: 0,
33
+ flat: false,
34
+ sizeMm: null,
35
+ antialias: true,
36
+ };
37
+ const COMPOSED_KEYS = new Set(["material", "quality", "structureScale"]);
38
+ // Keys that are not params, e.g. `pointer` given as in the other effects:
39
+ // it goes in `holo`.
40
+ function warnUnknownParams(p) {
41
+ for (const k of Object.keys(p)) {
42
+ if (Object.hasOwn(DEFAULT_PARAMS, k)) {
43
+ continue;
44
+ }
45
+ warnOnce(COMPOSED_KEYS.has(k) || SCENE_KEYS.has(k) || k === "settings"
46
+ ? `HoloEffect: "${k}" goes in \`holo\`: { holo: { ${k} } }; ignored.`
47
+ : `HoloEffect: unknown param "${k}"; ignored.`);
48
+ }
49
+ }
50
+ const SCENE_KEYS = new Set([
51
+ "exposure",
52
+ "tone",
53
+ "glare",
54
+ "grain",
55
+ "studio",
56
+ "background",
57
+ "bow",
58
+ "pose",
59
+ "lens",
60
+ "pointer",
61
+ "tiltRange",
62
+ "wobble",
63
+ "wobbleAmp",
64
+ ]);
65
+ /** Composes `holo` over holo.spot's parameter defaults. */
66
+ function compose(holo) {
67
+ const st = { ...DEFAULT_COMPOSED };
68
+ const list = (Array.isArray(holo) ? holo : holo ? [holo] : []);
69
+ for (const input of list) {
70
+ if (input && typeof input === "object") {
71
+ applyInput(st, input);
72
+ }
73
+ }
74
+ return st;
75
+ }
76
+ /** holo.spot entities whose blobs HoloEffect draws as they are meant (the rest are drawn as the flat card). */
77
+ const BLOB_ENTITIES = new Set(["card", "object", "image", "plain"]);
78
+ /** The emboss logo's placement: CSS px here, mm on holo.spot's card in a Copy settings blob. */
79
+ const MM_PLACEMENT = new Set(["emboss.x", "emboss.y", "emboss.width"]);
80
+ /** The ids a scene shorthand writes (`null` for each removes it). */
81
+ function sceneWrites(p) {
82
+ const o = {};
83
+ const set = (v, ...ids) => {
84
+ if (v !== undefined) {
85
+ for (const id of ids) {
86
+ o[id] = v;
87
+ }
88
+ }
89
+ };
90
+ set(p.exposure, "display.ev");
91
+ set(p.tone, "display.tone");
92
+ set(p.glare, "display.glare");
93
+ if (p.grain !== undefined) {
94
+ o["grain.amount"] = p.grain;
95
+ o["grain.on"] = p.grain === null ? null : p.grain > 0;
96
+ }
97
+ set(p.studio, "studio.preset");
98
+ if (p.background !== undefined) {
99
+ const b = p.background?.trim() ?? null;
100
+ if (b === null || b === "black" || b === "white") {
101
+ o["scene.background"] = b;
102
+ o["scene.bgColor"] = null;
103
+ }
104
+ else {
105
+ o["scene.background"] = "colour";
106
+ o["scene.bgColor"] = b;
107
+ }
108
+ }
109
+ set(p.bow, "card.bow");
110
+ set(p.pose && { x: p.pose.x, y: p.pose.y }, "motion.pose");
111
+ set(p.lens, "dof.lens");
112
+ set(p.pointer, "motion.pointer");
113
+ set(p.tiltRange, "motion.tiltRange");
114
+ set(p.wobble, "motion.wobble");
115
+ set(p.wobbleAmp, "motion.wobbleAmp");
116
+ return o;
117
+ }
118
+ /** FNV-1a hash of bytes (32 bit, hex). */
119
+ function fnv1a(b) {
120
+ let h = 0x811c9dc5;
121
+ for (let i = 0; i < b.length; i++) {
122
+ h ^= b[i];
123
+ h = Math.imul(h, 0x01000193);
124
+ }
125
+ return (h >>> 0).toString(16);
126
+ }
127
+ /** An <img> (false where the DOM has none, such as a worker or a test). */
128
+ const isImgElement = (v) => typeof HTMLImageElement !== "undefined" && v instanceof HTMLImageElement;
129
+ /** An image setting that is set: a non-empty URL, or an image object. */
130
+ const givenImage = (v) => (typeof v === "string" && v.trim() !== "") ||
131
+ (!!v && typeof v === "object");
132
+ const isSettingValue = (v) => typeof v === "number" ||
133
+ typeof v === "boolean" ||
134
+ typeof v === "string" ||
135
+ (!!v &&
136
+ typeof v === "object" &&
137
+ typeof v.x === "number" &&
138
+ typeof v.y === "number");
139
+ /**
140
+ * Applies one input of `holo`, in place. A Copy settings blob replaces the settings (it is a whole scene) and brings
141
+ * its material, pose and structure scale; settings by id merge by id. A light rig (`studio.preset`) or a material
142
+ * preset select (`emboss.stock`) writes its values where it is given, so ids given after it win and ids given before
143
+ * it lose.
144
+ */
145
+ function applyInput(st, input) {
146
+ const writes = {};
147
+ let next = { ...st.settings };
148
+ if (isCopyBlob(input)) {
149
+ next = {};
150
+ const m = input.material;
151
+ if (m !== undefined) {
152
+ if (isMaterialName(m)) {
153
+ st.material = m;
154
+ }
155
+ else {
156
+ warnOnce(`HoloEffect: the Copy settings' material "${m}" is not supported (one of ${MATERIAL_NAMES.join(", ")}); keeping "${st.material}".`);
157
+ }
158
+ }
159
+ const entity = input.entity;
160
+ if (entity !== undefined && !BLOB_ENTITIES.has(String(entity))) {
161
+ warnOnce(`HoloEffect: a holo.spot Copy settings of the "${String(entity)}" object is drawn as a flat card (HoloEffect draws holo.spot's card, 3D object look and paper card, not its cloth, stickers or flag).`);
162
+ }
163
+ for (const [id, v] of Object.entries(input.values)) {
164
+ if ((id === "emboss.logo" || id === "emboss.print") &&
165
+ typeof v === "string" &&
166
+ /^(\/logos\/|asset:)/.test(v.trim())) {
167
+ // holo.spot's own logo marks and its uploaded images do not come with a blob
168
+ warnOnce(`HoloEffect: ${id} "${v}" of a holo.spot Copy settings is holo.spot's own image, which HoloEffect does not include; ignored. Set ${id} to an image or a URL.`);
169
+ }
170
+ else if (MM_PLACEMENT.has(id)) {
171
+ // mm on holo.spot's 63 × 88 mm card; the port's are px of the element
172
+ warnOnce(`HoloEffect: ${id} of a holo.spot Copy settings is in mm on holo.spot's card; ignored (HoloEffect's is in CSS px).`);
173
+ }
174
+ else if (isSettingValue(v)) {
175
+ writes[id] = v;
176
+ }
177
+ }
178
+ const pose = input.pose;
179
+ if (pose &&
180
+ typeof pose.rx === "number" &&
181
+ typeof pose.ry === "number") {
182
+ writes["motion.pose"] = { x: pose.ry, y: pose.rx };
183
+ }
184
+ const ss = input.values["object.structureScale"];
185
+ if (typeof ss === "number") {
186
+ st.structureScale = ss;
187
+ }
188
+ }
189
+ else {
190
+ const { settings, ...rest } = input;
191
+ if (isCopyBlob(settings)) {
192
+ warnOnce("HoloEffect: a holo.spot Copy settings blob goes in `holo` itself (`holo: blob`, or an element of the list), not in `settings`; ignored.");
193
+ }
194
+ else if (settings) {
195
+ Object.assign(writes, settings);
196
+ }
197
+ Object.assign(writes, sceneWrites(rest));
198
+ for (const [k, v] of Object.entries(rest)) {
199
+ if (COMPOSED_KEYS.has(k)) {
200
+ if (k === "material" && v !== undefined && !isMaterialName(v)) {
201
+ warnOnce(`HoloEffect: unknown material "${String(v)}" (one of ${MATERIAL_NAMES.join(", ")}); keeping "${st.material}".`);
202
+ }
203
+ else if (v !== undefined) {
204
+ st[k] = v;
205
+ }
206
+ }
207
+ else if (!SCENE_KEYS.has(k)) {
208
+ warnOnce(`HoloEffect: unknown key "${k}" in holo; ignored.${k in DEFAULT_PARAMS ? ` ${k} is a param of its own: { holo, ${k} }.` : ""}`);
209
+ }
210
+ }
211
+ }
212
+ // presets first, so the ids given with them win
213
+ const rig = writes["studio.preset"];
214
+ if (typeof rig === "string" && STUDIO_PRESETS[rig]) {
215
+ Object.assign(next, STUDIO_PRESETS[rig]);
216
+ }
217
+ for (const [id, options] of Object.entries(MATERIAL_PRESETS)) {
218
+ const choice = writes[id];
219
+ if (typeof choice === "string" && options[choice]) {
220
+ Object.assign(next, options[choice]);
221
+ }
222
+ }
223
+ for (const [id, v] of Object.entries(writes)) {
224
+ if (v === null) {
225
+ delete next[id];
226
+ }
227
+ else if (v !== undefined) {
228
+ next[id] = v;
229
+ }
230
+ }
231
+ st.settings = Object.freeze(next);
232
+ }
233
+ /**
234
+ * A look holo.spot ships, as params: all of it in `settings` (lights `studio.*`, exposure, glare, grain, card finish,
235
+ * pose, material values) plus its quality, so whatever comes after it wins.
236
+ */
237
+ function lookParams(entries, quality, material) {
238
+ const values = {};
239
+ for (const [, e] of entries) {
240
+ Object.assign(values, e.values);
241
+ }
242
+ // the look's rest pose as holo.spot's motion.pose (x = ry, y = rx)
243
+ const pose = entries[0][1].pose;
244
+ values["motion.pose"] = { x: pose.ry, y: pose.rx };
245
+ return Object.freeze({
246
+ ...(material ? { material } : {}),
247
+ quality,
248
+ settings: Object.freeze(values),
249
+ });
250
+ }
251
+ /** A look's entries: the foils share its scene values, each adds its own material values. */
252
+ const lookEntries = (name) => Object.entries(LOOKS[name]).filter(([m]) => m !== "emboss");
253
+ const MM_PER_CSS_PX = 25.4 / 96;
254
+ const MATERIAL_PREFIXES = new Set(MATERIAL_NAMES);
255
+ /** holospot's framing: the card at rest fills this share of the view (camera FOV 22°). */
256
+ const FRAMING = 0.7;
257
+ /** Vertical field of view [deg] of a focal length (holospot physics/lens.ts lensFovDeg: exactly 22° at 62 mm). */
258
+ function lensFovDeg(fMm) {
259
+ if (!(fMm > 0) || fMm === 62) {
260
+ return 22;
261
+ }
262
+ return (2 * Math.atan(12 / fMm) * 180) / Math.PI;
263
+ }
264
+ /** Perspective-mode margin [physical px] on each side of the element. */
265
+ function perspectiveMargin(w, h) {
266
+ const k = (1 / FRAMING - 1) / 2;
267
+ return [Math.ceil(w * k), Math.ceil(h * k)];
268
+ }
269
+ const SOURCE_CHANNELS = {
270
+ alpha: 0,
271
+ luminance: 1,
272
+ none: 2,
273
+ };
274
+ /** uWave without relief waves. */
275
+ const NO_WAVES = new Float32Array(128);
276
+ const TONES = { neutral: 0, agx: 1, clamp: 2 };
277
+ /** The output pass's grain uniforms (holospot render/grain.ts): off at amount 0. */
278
+ function grainUniforms(g, dpr, timeS) {
279
+ if (!g.on || !(g.amount > 0)) {
280
+ return {
281
+ uGrain: 0,
282
+ uGrainCell: 1,
283
+ uGrainSeed: 0,
284
+ uGrainRgb: 0,
285
+ uGrainBg: 0,
286
+ };
287
+ }
288
+ const seed = g.animated ? (((timeS * 120) % 512) + 512) % 512 : 0;
289
+ return {
290
+ uGrain: g.amount,
291
+ uGrainCell: Math.max(g.sizePx * (dpr > 0 ? dpr : 1), 1),
292
+ uGrainSeed: Number.isFinite(seed) ? seed : 0,
293
+ uGrainRgb: g.colour === "rgb" ? 1 : 0,
294
+ uGrainBg: g.onBackground ? 1 : 0,
295
+ };
296
+ }
297
+ /** Row-major Mat3 → column-major Float32Array (GLSL mat3). */
298
+ function colMajor(m, out = new Float32Array(9)) {
299
+ out[0] = m[0];
300
+ out[1] = m[3];
301
+ out[2] = m[6];
302
+ out[3] = m[1];
303
+ out[4] = m[4];
304
+ out[5] = m[7];
305
+ out[6] = m[2];
306
+ out[7] = m[5];
307
+ out[8] = m[8];
308
+ return out;
309
+ }
310
+ const FRAG_DECODE = `#version 300 es
311
+ precision highp float;
312
+ precision highp int;
313
+ precision highp sampler2D;
314
+ uniform sampler2D uBytes;
315
+ uniform int uRowOffset;
316
+ out vec4 outColor;
317
+ ${GLSL_DECODE_FLOAT24}
318
+ void main() {
319
+ ivec2 t = ivec2(gl_FragCoord.xy);
320
+ int y = t.y + uRowOffset;
321
+ outColor = vec4(
322
+ decodeFloat24(texelFetch(uBytes, ivec2(3 * t.x, y), 0).rgb),
323
+ decodeFloat24(texelFetch(uBytes, ivec2(3 * t.x + 1, y), 0).rgb),
324
+ decodeFloat24(texelFetch(uBytes, ivec2(3 * t.x + 2, y), 0).rgb),
325
+ 1.0);
326
+ }
327
+ `;
328
+ /** Decodes a float24 byte image (4 values per output texel) into an RGBA float target: the LTC tables, the logo and the paper maps. */
329
+ const FRAG_DECODE_RGBA = `#version 300 es
330
+ precision highp float;
331
+ precision highp int;
332
+ precision highp sampler2D;
333
+ ${GLSL_DECODE_FLOAT24}
334
+ ${FRAG_DECODE_RGBA_MAIN}`;
335
+ const FRAG_ZERO = `#version 300 es
336
+ precision highp float;
337
+ out vec4 outColor;
338
+ void main() { outColor = vec4(0.0); }
339
+ `;
340
+ // output.frag's helpers (tone curves, gamut map, sRGB transfer, dither, grain) with a main for the element: decode
341
+ // the card target, expose, tone-map, encode, then composite with the element by the foil mask.
342
+ const OUTPUT_HELPERS = outputFrag
343
+ .slice(0, outputFrag.indexOf("void main()"))
344
+ .replace("varying vec2 vUv;\n", "");
345
+ const FRAG_OUTPUT = `${FRAG_PREFIX}
346
+ ${GLSL_COMMON}
347
+ ${OUTPUT_HELPERS}
348
+ in vec2 uv;
349
+ in vec2 uvContent;
350
+ in vec2 uvSrc;
351
+ uniform sampler2D src;
352
+ uniform sampler2D uBase; // 3d view: the element mapped onto the card
353
+ uniform int uMask;
354
+ uniform int uPersp;
355
+ void main() {
356
+ // flat view: the card target covers the element; 3d view: the whole (grown) output
357
+ vec2 hu = uPersp == 1 ? uv : uvContent;
358
+ vec4 s = uPersp == 1 ? (uMask == 1 ? texture(uBase, uv) : vec4(0.0)) : texture(src, uvSrc);
359
+ if (uPersp == 0 && (uvContent.x < 0.0 || uvContent.x > 1.0 || uvContent.y < 0.0 || uvContent.y > 1.0)) {
360
+ gl_FragColor = s;
361
+ return;
362
+ }
363
+ vec4 P = textureLod(tHdr, clamp(hu, 0.0, 1.0), 0.0);
364
+ float a = clamp(P.a, 0.0, 1.0); vec3 c = vec3(0.0);
365
+ if (a > 1e-5) { vec3 cu = P.rgb / a; c = cu / (ENC_S * max(1.0 - max(max3(cu), 0.0), 1e-4)); }
366
+ vec3 G = uGW0 * textureLod(tG0, hu * uG0Scale, 0.0).rgb; // premultiplied linear glare
367
+ vec3 card = toDisplay(((1.0 - uGlare) * c + uGlare * G) * uExposure);
368
+ vec3 spill = toDisplay(uGlare * G * uExposure);
369
+ // The foil's coverage (the mask, applied by the material pass) is the card target's alpha, then the foil goes over
370
+ // what is left of the element (luma mask) with the glare spill on it. holospot screens the spill onto the page: in
371
+ // premultiplied output that is the spill with alpha = its largest channel (exact on black, invisible on white).
372
+ float cov = a;
373
+ vec4 base = uMask == 1 ? s : vec4(0.0);
374
+ vec3 se = srgbOETF(spill);
375
+ vec4 spillP = vec4(se, max3(se));
376
+ base = spillP + (1.0 - spillP.a) * base;
377
+ vec3 enc = srgbOETF(card);
378
+ // A4.1 film grain in display space, after the tone curve and before the dither (output.frag).
379
+ if (uGrain > 0.0) {
380
+ vec2 fc = gl_FragCoord.xy;
381
+ vec3 n = uGrainRgb == 1
382
+ ? vec3(grainNoise(fc, uGrainSeed), grainNoise(fc, uGrainSeed + 171.0), grainNoise(fc, uGrainSeed + 342.0))
383
+ : vec3(grainNoise(fc, uGrainSeed));
384
+ enc += uGrain * n;
385
+ if (uGrainBg == 1) base.rgb = clamp(base.rgb + uGrain * n * base.a, 0.0, 1.0);
386
+ }
387
+ if (cov > 0.0 || max3(spill) > 1e-4) enc += triangularDither(gl_FragCoord.xy) / 255.0;
388
+ gl_FragColor = vec4(clamp(enc, 0.0, 1.0), 1.0) * cov + base * (1.0 - cov);
389
+ }
390
+ `;
391
+ /**
392
+ * Holographic foil: the diffraction foils of holo.spot (Prism Rainbow and friends) on an element, ported from
393
+ * [holospot](https://github.com/dmitrykurash/holospot) (MIT). The element is lit as a card by holo.spot's spectral
394
+ * studio lights and tilts toward the pointer. Settings use holo.spot's ids, so a look copied from holo.spot carries
395
+ * over.
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * vfx.add(el, {
400
+ * effect: new HoloEffect({
401
+ * holo: [
402
+ * HoloEffect.looks.card,
403
+ * { material: "prism", settings: { "prism.pitch": 1200, "prism.pattern": "radial" } },
404
+ * ],
405
+ * }),
406
+ * });
407
+ * ```
408
+ *
409
+ * @remarks
410
+ * ### The model
411
+ *
412
+ * The element is a card of real size (`sizeMm`, else its CSS size at 96 dpi), lit by holo.spot's studio rig and
413
+ * seen by holospot's camera (`lens`). By default the card turns in 3D with the pose (pointer tilt, idle wobble,
414
+ * `pose`), and the output grows by about 21 % per side so the turned card and its glare fit. With `flat: true` the
415
+ * card stays in place and the light rig turns the other way instead.
416
+ *
417
+ * holospot's physics is kept: the grating equation, order efficiencies, η renormalisation, material- and
418
+ * SPD-convolved spectral tables, LTC rect lights, the studio environment, coat, wear, glare, grain and tone curves.
419
+ * Its GLSL is used as is, without comments. What differs:
420
+ *
421
+ * - The environment is a prefiltered octahedral atlas (an importance-sampled GGX lobe per level) instead of three's
422
+ * PMREM.
423
+ * - The pose is the port's: a spring toward the rest pose plus the pointer tilt, and an idle wobble.
424
+ * - The foil's shape comes from the element (`sourceChannel`), and `ink` tints the foil with its colours.
425
+ *
426
+ * ### Params
427
+ *
428
+ * The params are the holo.spot side, `holo`, and how the element becomes the card: `sourceChannel`, `ink`, `flat`,
429
+ * `sizeMm` and `antialias`. `setParams` assigns params as other effects do, and so does writing `effect.params`
430
+ * (`effect.params.flat = true`); a new `holo` (not one changed in place) applies on the next frame.
431
+ *
432
+ * `holo` takes what holo.spot's "Copy settings" button copies, holo.spot settings by id with the kit's options and
433
+ * the scene shorthands, or a list of them: `{ holo: [HoloEffect.looks.card, { exposure: 1 }], flat: true }`. A list
434
+ * applies in order over holo.spot's parameter defaults, and later values win. `settings` are holo.spot ids
435
+ * (`HoloSettingId`), merged by id. `null` removes an id, so the default or the look's value applies again.
436
+ *
437
+ * - **Looks:** `HoloEffect.looks` are the looks holo.spot ships: their scene in `settings`, and the quality holospot
438
+ * ships each with. Put a look in the list as its own element, not spread into an object that has its own
439
+ * `settings`.
440
+ * - **Starting points:** `HoloEffect.startingPoints` are holospot's material starting points.
441
+ * - **Presets:** a light rig (`studio.preset`) or `emboss.stock` writes its values where it is given. Ids given
442
+ * after it win; ids given before it lose.
443
+ * - **Copy settings:** a holo.spot "Copy settings" blob (`HoloCopyBlob`) replaces the settings given before it and
444
+ * brings its material, pose and structure scale.
445
+ * - **Checks:** values are checked against holo.spot's ranges. Out-of-range values are clamped, and bad values
446
+ * and unknown ids are dropped, each with one console warning. holo.spot ids the port does not render (depth of
447
+ * field blur, bump maps, card borders) warn when set away from holospot's default.
448
+ *
449
+ * The scene shorthands write holo.spot ids with holospot's units and ranges:
450
+ *
451
+ * | Shorthand | holo.spot id |
452
+ * | --- | --- |
453
+ * | `exposure` (EV, ±3), `tone` | `display.ev`, `display.tone` |
454
+ * | `glare` (0–0.1), `grain` (0–0.6, 0 = off) | `display.glare`, `grain.amount` |
455
+ * | `studio` | `studio.preset` |
456
+ * | `background` (`black`, `white`, `#rgb`, `#rrggbb`) | `scene.background`, `scene.bgColor` |
457
+ * | `bow` (mm, 0–2), `pose` (±35°) | `card.bow`, `motion.pose` |
458
+ * | `lens` (mm, 24–200: the field of view, no blur) | `dof.lens` |
459
+ * | `pointer`, `tiltRange` (5–35°) | `motion.pointer`, `motion.tiltRange` |
460
+ * | `wobble`, `wobbleAmp` (0–25°) | `motion.wobble`, `motion.wobbleAmp` |
461
+ *
462
+ * ### Foil Emboss
463
+ *
464
+ * `material: "emboss"` is a paper card with a foil logo pressed into it, and the whole element is the paper.
465
+ *
466
+ * - **Logo:** `emboss.logo` takes a URL, an `<img>`, a canvas or an `ImageBitmap`. Without one there is no logo.
467
+ * The logo is cut into foil / no foil: `sourceChannel` picks how the image is read (`"alpha"` or `"luminance"`), and
468
+ * `emboss.threshold` sets where it is cut. A photo becomes a one-tone stamp.
469
+ * - **Placement:** in CSS px of the element. `emboss.x` and `emboss.y` are the logo's centre from the top left,
470
+ * and `emboss.width` its width. Unset, the logo is centred at 36/63 of the element's width.
471
+ * - **Print:** by default the element is printed on the paper. `emboss.print` prints an image instead, fitted like
472
+ * `background-size: cover`. While it loads, and if it fails, the paper is plain.
473
+ * - **The element as the logo:** `"emboss.logo": "element"` presses the element itself in foil, 1:1. It is read
474
+ * back once, and again on a resize or when `holo` is set again, so it suits a still element. The ground
475
+ * is `emboss.print` or `emboss.paperColour`, and transparent without both, so CSS can show what is behind.
476
+ * - **Loading:** the logo, paper and print load in the background. `ready` resolves after a frame with them, and
477
+ * `errors` lists what failed (a cross-origin image needs CORS).
478
+ *
479
+ * ### Code loading
480
+ *
481
+ * Each material's code (its shaders; for `emboss` also the logo and paper builders) is a separate chunk, loaded
482
+ * when the material is first used. `init` waits for it. After `holo` changes the material, the effect keeps drawing
483
+ * the previous material until the new one has loaded, and `ready` waits for it. `HoloEffect.preload(...)` loads
484
+ * materials ahead. `@vfx-js/effects/holo/static` exports the same class with every material built in: one file,
485
+ * and a material change never waits for code.
486
+ *
487
+ * ### Differences from holo.spot
488
+ *
489
+ * - **Port-only:** `sourceChannel`, `ink`, `flat`, `sizeMm`, `antialias`, the `"none"` pointer,
490
+ * `emboss.threshold` and the element as the emboss logo.
491
+ * - **Changed defaults:** grain is 0.07 (the value holo.spot's looks use), and there is no default emboss logo
492
+ * (holo.spot's marks are not included). A blob's references to holo.spot's marks or uploaded images
493
+ * (`emboss.logo`, `emboss.print`) are ignored with a warning.
494
+ * - **Changed units:** the emboss placement is in px, not mm on holo.spot's 63 × 88 mm card. A blob's mm placement
495
+ * is ignored.
496
+ * - **Different names:** `studio` instead of `lights`, `startingPoints`, and `flat`, because holospot uses
497
+ * `lights` and `View` for other things.
498
+ * - **Not ported:** the Volume Hologram and the emboss hologram stickers, multi-element emboss cards
499
+ * (`emboss.doc`), depth of field blur, bump maps, and card borders and thickness. holo.spot's cloth, stickers and
500
+ * flag objects are not either: a Copy settings blob of one is drawn as the flat card, with a warning.
501
+ *
502
+ * Rendered next to holospot in Chromium, the foils differ by about 1 per channel (0–255) on average. Glitter
503
+ * glints differ per pixel, but match within 1 after a slight blur. holospot's and three.js's MIT notices ship in
504
+ * the package's `THIRD_PARTY_NOTICES.md`.
505
+ */
506
+ export class HoloEffect {
507
+ /** The params; see `HoloParams`. */
508
+ params;
509
+ /** `params.holo` composed, and what it was composed from. */
510
+ #p = { ...DEFAULT_COMPOSED };
511
+ #holoSeen = Symbol("unseen");
512
+ #channelSeen = null;
513
+ #resolved = null;
514
+ #scene = null;
515
+ #dirty = true;
516
+ #atlas = null;
517
+ #atlasUploaded = -1;
518
+ #bytesCanvas = null;
519
+ #bytesTex = null;
520
+ #conv = null;
521
+ #cum = null;
522
+ #hdr = null;
523
+ #base = null;
524
+ #viewProj = new Float32Array(16);
525
+ #black = null;
526
+ #env = null;
527
+ #ltcTex = null;
528
+ #ltc1 = null;
529
+ #ltc2 = null;
530
+ #ltcReady = false;
531
+ #glare = new HoloGlare();
532
+ // Foil Emboss: the logo distance field and the paper maps (built on demand)
533
+ #emboss = null;
534
+ #logoRt = null;
535
+ #logoMap = [1.28, 1.28, 1 / 800, 1];
536
+ #logoUp = -1;
537
+ #paperRt = null;
538
+ #paperUp = -1;
539
+ #envDrawn = null;
540
+ #blobs = cameraSideBlobs();
541
+ #waves = null;
542
+ #blackReady = false;
543
+ #pose = new PoseSpring();
544
+ #lights = emptyLightSet();
545
+ #prevLightPos = new Float32Array(12);
546
+ #cardRot = new Float32Array(9);
547
+ #prevCardRot = new Float32Array(9);
548
+ #camPos = [0, 0, 0.4];
549
+ #cardSizeMm = [63, 88];
550
+ /** The element's CSS size [px] (the emboss logo's placement frame). */
551
+ #elemCss = [238, 333];
552
+ /** The card's surface domain [mm]: its size × `structureScale` (the structure's frame, not the geometry's). */
553
+ #domainMm = [63, 88];
554
+ /** The drawn card's rotation (3d view: the pose; flat: identity). */
555
+ #visRot = new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
556
+ /** Flat view: the inverse of the light rig's rotation (= the pose), row-major; null in 3d. */
557
+ #rigInv = null;
558
+ #eta = null;
559
+ #matUniforms = {};
560
+ /** Per-frame uniform buffers, reused. */
561
+ #binLam = new Float32Array(8);
562
+ #binW = new Float32Array(72);
563
+ #frag = "";
564
+ #mouseStart = null;
565
+ #pointerSeen = false;
566
+ #started = false;
567
+ /**
568
+ * @example
569
+ * ```ts
570
+ * new HoloEffect({ holo: copiedFromHoloSpot });
571
+ * new HoloEffect({
572
+ * holo: [HoloEffect.looks.card, HoloEffect.startingPoints.prism.compactDisc, { exposure: 1 }],
573
+ * flat: true,
574
+ * });
575
+ * ```
576
+ */
577
+ constructor(initial = {}) {
578
+ warnUnknownParams(initial);
579
+ this.params = { ...DEFAULT_PARAMS, ...initial };
580
+ this.#sync(); // check holo now, so its warnings point here
581
+ }
582
+ /** Assigns params, as other effects do. A new `holo` replaces the whole holo.spot side. */
583
+ setParams(updates) {
584
+ warnUnknownParams(updates);
585
+ Object.assign(this.params, updates);
586
+ this.#sync();
587
+ }
588
+ /** The material in effect: the last one `holo` sets, else `"prism"`. */
589
+ get material() {
590
+ this.#sync();
591
+ return this.#p.material;
592
+ }
593
+ /** Takes up a new `params.holo` or `params.sourceChannel`: composes `holo` again, and resolves again. */
594
+ #sync() {
595
+ const holo = this.params.holo;
596
+ if (holo !== this.#holoSeen) {
597
+ this.#holoSeen = holo;
598
+ this.#p = compose(holo);
599
+ this.#dirty = true;
600
+ this.#defFailed = null; // a material that failed to load is tried again
601
+ this.#defError = null;
602
+ this.#capGen++; // the element as the logo is read again (it may have changed)
603
+ }
604
+ if (this.params.sourceChannel !== this.#channelSeen) {
605
+ this.#channelSeen = this.params.sourceChannel;
606
+ this.#dirty = true; // the emboss logo is read again
607
+ }
608
+ }
609
+ /**
610
+ * Resolves once the effect has drawn a frame with everything it loads in place: the material's code, and for
611
+ * `emboss` the logo, the paper maps and `emboss.print`, which load in the background (until then the card is
612
+ * drawn without them). A load that fails does not reject it; see `errors`. It also resolves when the effect is
613
+ * disposed.
614
+ */
615
+ get ready() {
616
+ this.#sync();
617
+ if (this.#readyNow()) {
618
+ return Promise.resolve();
619
+ }
620
+ return new Promise((resolve) => this.#readyWaiters.push(resolve));
621
+ }
622
+ /** Loading errors (a logo that could not be fetched or read, …), newest last; cleared when the input changes. */
623
+ get errors() {
624
+ return [
625
+ ...(this.#defError ? [this.#defError] : []),
626
+ ...(this.#emboss?.errors ?? []),
627
+ ...(this.#printError ? [this.#printError] : []),
628
+ ];
629
+ }
630
+ #readyWaiters = [];
631
+ #drawnOnce = false;
632
+ #disposed = false;
633
+ #readyNow() {
634
+ if (this.#disposed) {
635
+ return true;
636
+ }
637
+ if (this.#defFailed === this.#p.material && !this.#renderDef) {
638
+ return true; // nothing to draw: the first material failed to load
639
+ }
640
+ return (this.#drawnOnce &&
641
+ !this.#dirty &&
642
+ // the material asked for is drawn, or failed to load (see errors)
643
+ (this.#renderDef?.id === this.#p.material ||
644
+ this.#defFailed === this.#p.material) &&
645
+ (this.#p.material !== "emboss" ||
646
+ (!this.#emboss?.busy && !this.#printBusy && !this.#capPending)));
647
+ }
648
+ #settleReady() {
649
+ if (this.#readyWaiters.length > 0 && this.#readyNow()) {
650
+ const w = this.#readyWaiters;
651
+ this.#readyWaiters = [];
652
+ for (const f of w) {
653
+ f();
654
+ }
655
+ }
656
+ }
657
+ /**
658
+ * The looks holo.spot ships, as inputs: `card` (its holographic card), `object` (its 3D object), `image` (its
659
+ * Foil Emboss paper card; sets `material: "emboss"`). Each sets the scene (lights, pose, exposure, …, all in
660
+ * `settings`) and the `quality` holospot ships it with. Without one, the effect starts from holo.spot's parameter
661
+ * defaults. Put a look in `holo` as its own element, not spread, so the `settings` after it merge by id.
662
+ *
663
+ * @example
664
+ * ```ts
665
+ * new HoloEffect({ holo: [HoloEffect.looks.card, { material: "shatter", studio: "softbox" }] });
666
+ * ```
667
+ */
668
+ static looks = Object.freeze({
669
+ card: lookParams(lookEntries("card"), "medium"),
670
+ object: lookParams(lookEntries("object"), "low"),
671
+ image: lookParams([
672
+ [
673
+ "emboss",
674
+ LOOKS.card.emboss,
675
+ ],
676
+ ], "medium", "emboss"),
677
+ });
678
+ /**
679
+ * The "Starting points" of holospot's material docs, as inputs (`material` and `settings`). They set the material
680
+ * only, not the lights or the pose, so combine them with a look:
681
+ * `new HoloEffect({ holo: [HoloEffect.looks.card, HoloEffect.startingPoints.prism.compactDisc] })`.
682
+ */
683
+ static startingPoints = Object.freeze(Object.fromEntries(Object.entries(STARTING_POINTS).map(([m, ps]) => [
684
+ m,
685
+ Object.freeze(Object.fromEntries(Object.entries(ps).map(([name, settings]) => [
686
+ name,
687
+ Object.freeze({
688
+ material: m,
689
+ settings: Object.freeze({
690
+ ...settings,
691
+ }),
692
+ }),
693
+ ]))),
694
+ ])));
695
+ /**
696
+ * The holo.spot settings a material understands (its own ids, then the scene's), for building controls. Ids, ranges
697
+ * and meanings follow holospot's docs (`docs/materials/<material>.md`, `docs/scene-settings.md`).
698
+ */
699
+ static settingSpecs(material) {
700
+ const own = (id) => id.startsWith(`${material}.`);
701
+ const scene = (id) => !MATERIAL_PREFIXES.has(id.split(".")[0]);
702
+ const specs = PARAM_SPECS.filter((p) => own(p.id) || scene(p.id));
703
+ return [
704
+ ...specs.filter((p) => own(p.id)),
705
+ ...specs.filter((p) => !own(p.id)),
706
+ ];
707
+ }
708
+ /**
709
+ * The settings in effect, by holo.spot id: holo.spot's defaults with `settings` over them, checked (clamped to
710
+ * the ranges, invalid values dropped). Useful to show a control's current value.
711
+ */
712
+ resolvedSettings() {
713
+ // the settings alone: no material code is needed (it may not be loaded yet)
714
+ this.#sync();
715
+ const r = resolveSettings(this.#p.material, "plain", this.#p.settings);
716
+ // the rest pose in effect (motion.pose / pose when given): x = ry, y = rx
717
+ return { ...r.values, "motion.pose": { x: r.pose.ry, y: r.pose.rx } };
718
+ }
719
+ /** The tier `quality: "auto"` picks, detected once from the GL context. */
720
+ #autoTier = null;
721
+ #tier() {
722
+ const q = this.#p.quality;
723
+ const t = q === "auto" ? (this.#autoTier ?? "medium") : q;
724
+ return TIERS[t] ?? TIERS.medium;
725
+ }
726
+ #restoreUnsub = null;
727
+ /**
728
+ * Loads materials' code ahead of use, so switching `material` later draws at once. HoloEffect loads a material's
729
+ * code (its shaders, and for `emboss` the logo and paper builders) when it is first used; `@vfx-js/effects/holo/static`
730
+ * has every material built in instead.
731
+ */
732
+ static preload(...materials) {
733
+ return Promise.all(materials.map(loadMaterial)).then(() => { });
734
+ }
735
+ /** Counts init / dispose, so an init that awaited across a dispose stops. */
736
+ #life = 0;
737
+ async init(ctx) {
738
+ const life = ++this.#life;
739
+ this.#disposed = false;
740
+ this.#sync();
741
+ // the material's code, before the first frame
742
+ await this.#requestDef(this.#p.material);
743
+ if (life !== this.#life) {
744
+ return; // disposed (or initialised again) while loading
745
+ }
746
+ // after a context loss the render targets come back empty (wrapped canvases are re-uploaded): fill them
747
+ // again from the CPU-side data, which survives
748
+ this.#restoreUnsub = ctx.onContextRestored(() => {
749
+ this.#autoTier = detectTier(ctx.gl);
750
+ this.#atlasUploaded = -1;
751
+ this.#ltcReady = false;
752
+ this.#blackReady = false;
753
+ this.#envDrawn = null;
754
+ this.#logoUp = this.#paperUp = -1;
755
+ this.#capKey = "";
756
+ this.#capInFlight = false;
757
+ this.#capToken++;
758
+ });
759
+ this.#setup(ctx);
760
+ }
761
+ #setup(ctx) {
762
+ this.#autoTier = detectTier(ctx.gl);
763
+ this.#dirty = true; // resolve again: the new atlas takes the material's tint
764
+ this.#atlas = new SpectralAtlas();
765
+ const canvas = this.#makeCanvas(ATLAS.imageWidth, ATLAS.imageHeight);
766
+ this.#bytesCanvas = canvas;
767
+ this.#bytesTex = ctx.wrapTexture(canvas, {
768
+ autoUpdate: false,
769
+ filter: "nearest",
770
+ });
771
+ const tableOpts = {
772
+ size: [ATLAS.width, ATLAS.height],
773
+ float: true,
774
+ filter: "linear",
775
+ };
776
+ this.#conv = ctx.createRenderTarget(tableOpts);
777
+ this.#cum = ctx.createRenderTarget(tableOpts);
778
+ this.#ensureHdr(ctx);
779
+ this.#black = ctx.createRenderTarget({ size: [1, 1], float: true });
780
+ const ltcCanvas = this.#makeCanvas(LTC_IMAGE.width, LTC_IMAGE.height);
781
+ this.#ctx2d(ltcCanvas)?.putImageData(new ImageData(ltcImageBytes(), LTC_IMAGE.width, LTC_IMAGE.height), 0, 0);
782
+ this.#ltcTex = ctx.wrapTexture(ltcCanvas, {
783
+ autoUpdate: false,
784
+ filter: "nearest",
785
+ });
786
+ const ltcOpts = {
787
+ size: [LTC_SIZE, LTC_SIZE],
788
+ float: true,
789
+ filter: "linear",
790
+ };
791
+ this.#ltc1 = ctx.createRenderTarget(ltcOpts);
792
+ this.#ltc2 = ctx.createRenderTarget(ltcOpts);
793
+ this.#env = ctx.createRenderTarget({
794
+ size: [ENV_SIZE, ENV_SIZE * ENV_LEVELS],
795
+ float: true,
796
+ filter: "linear",
797
+ });
798
+ }
799
+ #samples = 1;
800
+ /** The card target (float, the output's size) and the 3d view's base layer, with `antialias` (4× half float). */
801
+ #ensureHdr(ctx) {
802
+ const samples = this.params.antialias ? 4 : 1;
803
+ if (this.#hdr && this.#samples === samples) {
804
+ return;
805
+ }
806
+ this.#hdr?.dispose();
807
+ this.#base?.dispose();
808
+ this.#base = null;
809
+ this.#hdr = ctx.createRenderTarget({
810
+ float: true,
811
+ filter: "nearest",
812
+ samples,
813
+ });
814
+ this.#samples = samples;
815
+ }
816
+ #ensureBase(ctx) {
817
+ this.#base ??= ctx.createRenderTarget({ samples: this.#samples });
818
+ return this.#base;
819
+ }
820
+ /** Perspective mode grows the output so the tilted card and its glare fit. */
821
+ outputRect(dims) {
822
+ if (this.params.flat) {
823
+ return undefined;
824
+ }
825
+ const [w, h] = dims.elementPixel;
826
+ const [mx, my] = perspectiveMargin(w, h);
827
+ return [-mx, -my, w + 2 * mx, h + 2 * my];
828
+ }
829
+ #makeCanvas(w, h) {
830
+ const c = typeof document !== "undefined"
831
+ ? document.createElement("canvas")
832
+ : new OffscreenCanvas(w, h);
833
+ c.width = w;
834
+ c.height = h;
835
+ return c;
836
+ }
837
+ #ctx2d(c) {
838
+ return c.getContext("2d");
839
+ }
840
+ /** The material code the current render state was built with. */
841
+ #renderDef = null;
842
+ #defError = null;
843
+ /** The material whose code is loading, and the one that failed to load (tried again when `holo` changes). */
844
+ #defPending = null;
845
+ #defFailed = null;
846
+ /** Loads a material's code once; a failure warns once, is listed in `errors`, and the effect keeps drawing what it drew. */
847
+ #requestDef(m) {
848
+ if (this.#defPending?.m === m) {
849
+ return this.#defPending.p;
850
+ }
851
+ const p = loadMaterial(m)
852
+ .then(() => {
853
+ this.#defError = null;
854
+ this.#defFailed = null;
855
+ }, (e) => {
856
+ this.#defFailed = m;
857
+ this.#defError = `HoloEffect: could not load the "${m}" material: ${e instanceof Error ? e.message : String(e)}`;
858
+ console.warn(this.#defError);
859
+ })
860
+ .finally(() => {
861
+ if (this.#defPending?.p === p) {
862
+ this.#defPending = null;
863
+ }
864
+ this.#dirty = true; // resolve again: with the new material, or settle on the failure
865
+ this.#settleReady();
866
+ });
867
+ this.#defPending = { m, p };
868
+ return p;
869
+ }
870
+ #resolve() {
871
+ const p = this.#p;
872
+ let def = loadedMaterial(p.material);
873
+ if (!def) {
874
+ // not loaded yet (or failed): load it, and meanwhile draw the material drawn so far with the current settings
875
+ if (this.#defFailed !== p.material) {
876
+ void this.#requestDef(p.material);
877
+ }
878
+ def = this.#renderDef ?? undefined;
879
+ if (!def) {
880
+ return; // nothing drawn yet
881
+ }
882
+ }
883
+ this.#renderDef = def;
884
+ this.#resolved = resolveSettings(def.id, "plain", p.settings);
885
+ this.#scene = sceneStateFrom(this.#resolved.values);
886
+ this.#matUniforms = def.uniforms(this.#resolved.values);
887
+ this.#atlas?.setTint(def.gratingSummary(this.#resolved.values).tint);
888
+ const tier = this.#tier();
889
+ const c = this.#scene.card;
890
+ this.#waves = buildWaves(def.relief(this.#resolved.values), {
891
+ emboss: c.emboss,
892
+ pitchMm: c.embossPitchMm,
893
+ heightUm: c.embossHeightUm,
894
+ layer: c.embossLayer,
895
+ }, tier.waves);
896
+ this.#frag = assembleMaterial({
897
+ ...tier.defines,
898
+ ...def.defines(tier),
899
+ [`MATERIAL_${def.id.toUpperCase()}`]: 1,
900
+ ...(this.#clearPaper() ? { HOLO_CLEAR_PAPER: 1 } : {}),
901
+ NSPD: 5,
902
+ MAX_LIGHTS: 4,
903
+ DEBUG_VIEW: 0,
904
+ }, def.extraChunks, def.fragmentMain);
905
+ this.#dirty = false;
906
+ }
907
+ /** holospot's camera: vertical FOV from the lens, at (0, 0, D) looking down −Z (column-major projection × view). */
908
+ #setViewProj(aspect, D, tanHalf) {
909
+ const f = 1 / tanHalf;
910
+ const near = 0.1 * D;
911
+ const far = 10 * D;
912
+ const a = (far + near) / (near - far);
913
+ const b = (2 * far * near) / (near - far);
914
+ const m = this.#viewProj;
915
+ m.fill(0);
916
+ m[0] = f / aspect;
917
+ m[5] = f;
918
+ m[10] = a;
919
+ m[11] = -1;
920
+ m[14] = a * -D + b; // view = translate(0, 0, −D)
921
+ m[15] = D;
922
+ }
923
+ update(ctx) {
924
+ this.#sync();
925
+ if (this.#dirty || !this.#resolved) {
926
+ this.#resolve();
927
+ }
928
+ const r = this.#resolved;
929
+ const s = this.#scene;
930
+ if (!r || !s) {
931
+ return;
932
+ }
933
+ const [ew, eh] = ctx.dims.element;
934
+ // a zero-size element (not laid out yet, display: none) is treated as 1 px, so the geometry stays finite
935
+ const pw = Math.max(ctx.dims.elementPixel[0], 1);
936
+ const ph = Math.max(ctx.dims.elementPixel[1], 1);
937
+ const w = Math.max(ew, 1);
938
+ const h = Math.max(eh, 1);
939
+ const given = this.params.sizeMm;
940
+ const largest = given !== null && Number.isFinite(given) && given > 0
941
+ ? given
942
+ : Math.max(w, h) * MM_PER_CSS_PX;
943
+ const k = largest / Math.max(w, h);
944
+ this.#cardSizeMm = [w * k, h * k];
945
+ this.#elemCss = [w, h];
946
+ // the surface's domain, as holospot's models.ts: size × structureScale (a larger one lays more structure over the card)
947
+ const ss = Math.min(Math.max(this.#p.structureScale || 1, 0.25), 4);
948
+ this.#domainMm = [w * k * ss, h * k * ss];
949
+ const fov = lensFovDeg(s.lensMm);
950
+ const tanHalf = Math.tan((fov * Math.PI) / 360);
951
+ const view3d = !this.params.flat;
952
+ let D = framingDistance(w / h, this.#cardSizeMm[0] / 2000, this.#cardSizeMm[1] / 2000, fov);
953
+ if (view3d) {
954
+ // the card at rest maps exactly onto the element inside the grown output
955
+ const [mx, my] = perspectiveMargin(pw, ph);
956
+ const oh = ph + 2 * my;
957
+ D = (this.#cardSizeMm[1] / 2000 / tanHalf) * (oh / Math.max(ph, 1));
958
+ this.#setViewProj((pw + 2 * mx) / Math.max(oh, 1), D, tanHalf);
959
+ }
960
+ this.#camPos = [0, 0, D];
961
+ // pointer: normalised element position, active once the pointer has moved and while it is over the element
962
+ if (!this.#mouseStart) {
963
+ this.#mouseStart = ctx.mouseViewport;
964
+ }
965
+ else if (ctx.mouseViewport[0] !== this.#mouseStart[0] ||
966
+ ctx.mouseViewport[1] !== this.#mouseStart[1]) {
967
+ this.#pointerSeen = true;
968
+ }
969
+ const nx = (ctx.mouse[0] / Math.max(pw, 1)) * 2 - 1;
970
+ const ny = (ctx.mouse[1] / Math.max(ph, 1)) * 2 - 1;
971
+ const over = this.#pointerSeen && Math.abs(nx) <= 1 && Math.abs(ny) <= 1;
972
+ const m = s.motion;
973
+ const dt = Math.min(Math.max(ctx.deltaTime, 0), 0.1);
974
+ let target = { rx: r.pose.rx, ry: r.pose.ry };
975
+ if (m.pointer === "tilt" && over) {
976
+ target = {
977
+ rx: r.pose.rx - ny * m.tiltRangeDeg,
978
+ ry: r.pose.ry + nx * m.tiltRangeDeg,
979
+ };
980
+ }
981
+ else if (m.wobble) {
982
+ const o = wobbleOffset(ctx.time, m.wobbleAmpDeg);
983
+ target = { rx: r.pose.rx + o.rx, ry: r.pose.ry + o.ry };
984
+ }
985
+ this.#pose.step(target, dt);
986
+ // 3d: the card turns. flat: the card stays and the light rig turns the other way (holospot's Q_L).
987
+ const pose = eulerXYZ(this.#pose.rx, this.#pose.ry, 0);
988
+ const rot = view3d ? pose : [1, 0, 0, 0, 1, 0, 0, 0, 1];
989
+ const rig = view3d
990
+ ? { x: 0, y: 0, z: 0, w: 1 }
991
+ : inversePoseQuat(this.#pose.rx, this.#pose.ry);
992
+ this.#rigInv = view3d ? null : pose; // mat3(conj(Q_L)) for the environment
993
+ if (this.#started) {
994
+ this.#prevCardRot.set(this.#cardRot);
995
+ this.#prevLightPos.set(this.#lights.pos);
996
+ }
997
+ colMajor(rot, this.#cardRot);
998
+ colMajor(rot, this.#visRot);
999
+ const pad = over ? { x: nx, y: ny } : { x: 0, y: 0 };
1000
+ computeLights(s.studio, {
1001
+ mode: m.pointer === "none" ? "tilt" : m.pointer,
1002
+ pad,
1003
+ }, s.background, rig, this.#camPos, this.#lights);
1004
+ for (let i = 0; i < 4; i++) {
1005
+ if (this.#lights.type[i] !== 0) {
1006
+ this.#atlas?.ensureLayer(SPD_IDS[this.#lights.spd[i]] ?? "equal");
1007
+ }
1008
+ }
1009
+ if (!this.#started) {
1010
+ this.#prevCardRot.set(this.#cardRot);
1011
+ this.#prevLightPos.set(this.#lights.pos);
1012
+ this.#started = true;
1013
+ }
1014
+ const embossDef = this.#renderDef?.emboss;
1015
+ if (embossDef) {
1016
+ this.#emboss ??= embossDef.createAssets();
1017
+ // a URL, or an image given in settings (kept by reference); "element" is read back in render
1018
+ const logo = r.values["emboss.logo"];
1019
+ if (logo !== "element") {
1020
+ this.#capHash = ""; // the next element readback installs its logo again
1021
+ if (this.#capPending || this.#capInFlight) {
1022
+ // a readback of the element (still blank, or on its way) is no longer wanted
1023
+ this.#capPending = false;
1024
+ this.#capInFlight = false;
1025
+ this.#capToken++;
1026
+ this.#capKey = "";
1027
+ this.#capTries = 0;
1028
+ }
1029
+ this.#emboss.setLogo(logo, this.#logoReadOpts("ink"));
1030
+ }
1031
+ this.#emboss.setPaper(embossDef.paperKey(r.values));
1032
+ }
1033
+ else if (this.#emboss || this.#printTex || this.#capRt) {
1034
+ this.#releaseEmboss(); // switched away from emboss
1035
+ }
1036
+ this.#eta = etaFrame(this.#renderDef.gratingSummary(r.values), this.#lights, rot, this.#camPos);
1037
+ }
1038
+ render(ctx) {
1039
+ const atlas = this.#atlas;
1040
+ const s = this.#scene;
1041
+ if (!atlas ||
1042
+ !s ||
1043
+ !this.#hdr ||
1044
+ !this.#conv ||
1045
+ !this.#cum ||
1046
+ !this.#black ||
1047
+ !this.#bytesTex ||
1048
+ !this.#eta) {
1049
+ ctx.blit(ctx.src, ctx.target);
1050
+ return;
1051
+ }
1052
+ this.#ensureHdr(ctx);
1053
+ if (!this.#blackReady) {
1054
+ ctx.draw({
1055
+ frag: FRAG_ZERO,
1056
+ vert: PLAIN_VERT,
1057
+ target: this.#black,
1058
+ });
1059
+ this.#blackReady = true;
1060
+ }
1061
+ if (!this.#ltcReady && this.#ltcTex && this.#ltc1 && this.#ltc2) {
1062
+ for (const [target, row] of [
1063
+ [this.#ltc1, 0],
1064
+ [this.#ltc2, LTC_SIZE],
1065
+ ]) {
1066
+ ctx.draw({
1067
+ frag: FRAG_DECODE_RGBA,
1068
+ vert: PLAIN_VERT,
1069
+ target,
1070
+ uniforms: { uBytes: this.#ltcTex, uRowOffset: row },
1071
+ });
1072
+ }
1073
+ this.#ltcReady = true;
1074
+ }
1075
+ if (this.#atlasUploaded !== atlas.version) {
1076
+ this.#uploadAtlas(ctx, atlas);
1077
+ }
1078
+ const tone = backgroundTone(s.background, s.bgColor);
1079
+ const levels = envLevels(s.studio.ambient, tone);
1080
+ if (this.#env && !sameLevels(this.#envDrawn, levels)) {
1081
+ ctx.draw({
1082
+ frag: FRAG_ENV_PREFILTER,
1083
+ vert: PLAIN_VERT,
1084
+ target: this.#env,
1085
+ uniforms: {
1086
+ uRims: levels.rims,
1087
+ uFill: levels.fill,
1088
+ uScrim: levels.scrim,
1089
+ uCameraSide: levels.cameraSide,
1090
+ uCameraTexture: levels.cameraTexture,
1091
+ uBehind: levels.behind,
1092
+ uBlobs: this.#blobs.blobs,
1093
+ uBlobNorm: this.#blobs.norm,
1094
+ },
1095
+ });
1096
+ this.#envDrawn = levels;
1097
+ }
1098
+ const waves = this.#waves;
1099
+ const tier = this.#tier();
1100
+ const tr = tier.trips;
1101
+ const L = this.#lights;
1102
+ const bins = atlas.bins[tier.defines.NB === 6 ? 6 : 8];
1103
+ // the uniforms take 8 bins; the low tier's 6 leave the rest zero
1104
+ const binLam = this.#binLam.fill(0);
1105
+ binLam.set(bins.lambda);
1106
+ const binW = this.#binW.fill(0);
1107
+ binW.set(bins.W);
1108
+ const emb = this.#renderDef?.emboss ? this.#embossUniforms(ctx) : {};
1109
+ const persp = !this.params.flat;
1110
+ const card = {
1111
+ uCardRot: this.#cardRot,
1112
+ uPrevCardRot: this.#prevCardRot,
1113
+ uCardSizeMm: this.#domainMm,
1114
+ uCardWorldMm: this.#cardSizeMm,
1115
+ uVisRot: this.#visRot,
1116
+ uViewProj: this.#viewProj,
1117
+ uPersp: persp ? 1 : 0,
1118
+ };
1119
+ // the emboss paper is the whole card
1120
+ const mask = this.#renderDef?.id === "emboss"
1121
+ ? SOURCE_CHANNELS.none
1122
+ : (SOURCE_CHANNELS[this.params.sourceChannel] ?? 0);
1123
+ if (persp) {
1124
+ ctx.clear(this.#hdr);
1125
+ if (mask === 1) {
1126
+ const base = this.#ensureBase(ctx);
1127
+ ctx.clear(base);
1128
+ ctx.draw({
1129
+ frag: FRAG_CARD_BASE,
1130
+ vert: CARD_VERT,
1131
+ target: base,
1132
+ uniforms: { ...card, src: ctx.src },
1133
+ });
1134
+ }
1135
+ }
1136
+ ctx.draw({
1137
+ frag: this.#frag,
1138
+ vert: CARD_VERT,
1139
+ target: this.#hdr,
1140
+ uniforms: {
1141
+ ...this.#matUniforms,
1142
+ ...emb,
1143
+ ...card,
1144
+ cameraPosition: [...this.#camPos],
1145
+ uWrapMm: [0, 0],
1146
+ uBowMm: s.card.bowMm,
1147
+ uBowAxis: s.card.bowAxis === "along" ? 1 : 0,
1148
+ uLightType: L.type,
1149
+ uLightOrder: L.order,
1150
+ uLightPos: L.pos,
1151
+ uPrevLightPos: this.#prevLightPos,
1152
+ uLightU: L.u,
1153
+ uLightW: L.w,
1154
+ uLightRadius: L.radius,
1155
+ uLightRad: L.rad,
1156
+ uLightSpd: L.spd,
1157
+ uLightRGB: L.rgb,
1158
+ uEtaOrd: this.#eta.ord,
1159
+ uEtaMir: this.#eta.mir,
1160
+ uEtaEnv: this.#eta.env,
1161
+ uKeyLight: L.key,
1162
+ uMaxOrder: tr.maxOrder,
1163
+ uGhB: tr.ghB,
1164
+ uVorR: tr.vorR,
1165
+ uFlakeR: tr.flakeR,
1166
+ uBCells: tr.bCells,
1167
+ uBBins: tr.bBins,
1168
+ uBLevels: tr.bLevels,
1169
+ uEnv: this.#env ?? this.#black,
1170
+ uEnvMaxLod: ENV_LEVELS - 1,
1171
+ uEnvIntensity: 1,
1172
+ uEnvRot: envRotation(s.studio.ambient.rotationDeg, this.#rigInv ?? undefined),
1173
+ uEnvUniform: 0,
1174
+ uCmfConv: this.#conv,
1175
+ uCmfCum: this.#cum,
1176
+ uSpecProj: atlas.specProj,
1177
+ uBinLam: binLam,
1178
+ uBinW: binW,
1179
+ uBinWidth: bins.width,
1180
+ uLtc1: this.#ltc1 ?? this.#black,
1181
+ uLtc2: this.#ltc2 ?? this.#black,
1182
+ uWave: waves?.data ?? NO_WAVES,
1183
+ uWaveBoard: waves?.board ?? [0, 0],
1184
+ uWaveCoat: waves?.coat ?? [0, 0],
1185
+ uBumpMode: 0,
1186
+ uBumpMom: this.#black,
1187
+ uBumpCross: this.#black,
1188
+ uBumpScale: [1, 1],
1189
+ uBumpK: [0, 0],
1190
+ uWear: s.card.wear,
1191
+ uDebugLight: 1,
1192
+ uPrintSrc: ctx.src,
1193
+ uMask: mask,
1194
+ uInk: Math.min(Math.max(this.params.ink, 0), 1),
1195
+ },
1196
+ });
1197
+ const hw = this.#hdr.width;
1198
+ const hh = this.#hdr.height;
1199
+ const div = tier.glareStartDiv;
1200
+ let gw0 = 0;
1201
+ const glare = s.display.glare;
1202
+ if (glare > 0) {
1203
+ this.#glare.ensure(ctx, hw, hh, tier.glareLevels, div);
1204
+ gw0 = this.#glare.render(ctx, this.#hdr, hw, hh, div, s.display.glareRadiusPx, ctx.pixelRatio);
1205
+ }
1206
+ const g0 = glare > 0 ? this.#glare.level0 : null;
1207
+ ctx.draw({
1208
+ frag: FRAG_OUTPUT,
1209
+ target: ctx.target,
1210
+ uniforms: {
1211
+ tHdr: this.#hdr,
1212
+ src: ctx.src,
1213
+ uExposure: exposureMultiplier(s.display.ev, tone),
1214
+ uTone: TONES[s.display.tone],
1215
+ uP3: 0,
1216
+ uMask: mask,
1217
+ uPersp: persp ? 1 : 0,
1218
+ uBase: (persp && mask === 1 && this.#base) || this.#black,
1219
+ tG0: g0 ?? this.#black,
1220
+ uGW0: gw0,
1221
+ uGlare: g0 ? glare : 0,
1222
+ uG0Scale: g0 ? this.#glare.outputScale(hw, hh, div) : [1, 1],
1223
+ ...grainUniforms(s.grain, ctx.pixelRatio, ctx.time),
1224
+ },
1225
+ });
1226
+ this.#drawnOnce = true;
1227
+ this.#settleReady();
1228
+ }
1229
+ /**
1230
+ * The logo's placement in the card's surface frame [mm]: `emboss.x` / `emboss.y` / `emboss.width` are CSS px of the
1231
+ * element (centre and 36/63 of the width when unset), converted with the frame's mm per px.
1232
+ */
1233
+ #logoPlacement() {
1234
+ const v = this.#resolved?.values ?? {};
1235
+ const px = (id) => {
1236
+ const x = v[id];
1237
+ return typeof x === "number" && Number.isFinite(x) ? x : null;
1238
+ };
1239
+ const [ew, eh] = this.#elemCss;
1240
+ const mmPerPx = this.#domainMm[0] / Math.max(ew, 1);
1241
+ const x = px("emboss.x") ?? ew / 2;
1242
+ const y = px("emboss.y") ?? eh / 2;
1243
+ // the element as the logo fills the element; an image logo is 36/63 of its width (holo.spot's proportion)
1244
+ const w = px("emboss.width") ??
1245
+ (v["emboss.logo"] === "element" ? ew : (ew * 36) / 63);
1246
+ const rot = ((px("emboss.rotation") ?? 0) * Math.PI) / 180;
1247
+ return {
1248
+ uLogoXf: [
1249
+ (x - ew / 2) * mmPerPx,
1250
+ (eh / 2 - y) * mmPerPx, // CSS y runs down, the card frame's up
1251
+ Math.cos(rot),
1252
+ Math.sin(rot),
1253
+ ],
1254
+ uLogoW: Math.max(w, 1) * mmPerPx,
1255
+ };
1256
+ }
1257
+ /** How the logo image is read: `sourceChannel` picks alpha (holospot's coverage) or luminance, `emboss.threshold` the cut. */
1258
+ #logoReadOpts(frame) {
1259
+ const t = this.#resolved?.values["emboss.threshold"];
1260
+ return {
1261
+ frame,
1262
+ read: this.params.sourceChannel === "luminance" ? "luma" : "auto",
1263
+ threshold: typeof t === "number" ? t : 0.5,
1264
+ };
1265
+ }
1266
+ /** What decides how the element logo is read (its cache key). */
1267
+ #readOptsKey() {
1268
+ const o = this.#logoReadOpts("full");
1269
+ return `${o.read}|${o.threshold}`;
1270
+ }
1271
+ /** emboss with the element as its logo, and neither `emboss.print` nor `emboss.paperColour`: no ground. */
1272
+ #clearPaper() {
1273
+ const v = this.#resolved?.values;
1274
+ return (this.#renderDef?.id === "emboss" &&
1275
+ v?.["emboss.logo"] === "element" &&
1276
+ !givenImage(v["emboss.print"]) &&
1277
+ this.#p.settings["emboss.paperColour"] === undefined);
1278
+ }
1279
+ // ---- the element as the logo: read back once per size / `holo` (a still element)
1280
+ #capRt = null;
1281
+ #capKey = "";
1282
+ #capGen = 0;
1283
+ #capTries = 0;
1284
+ #capPending = false;
1285
+ /** A readback is on its way; the token drops one that arrives after #release or a restore. */
1286
+ #capInFlight = false;
1287
+ #capToken = 0;
1288
+ /** Hash of the last pixels read back, so an unchanged element does not rebuild the logo. */
1289
+ #capHash = "";
1290
+ #captureElementLogo(ctx) {
1291
+ const [pw, ph] = ctx.dims.elementPixel;
1292
+ const k = Math.min(1, 1024 / Math.max(pw, ph, 1));
1293
+ const w = Math.max(1, Math.round(pw * k));
1294
+ const h = Math.max(1, Math.round(ph * k));
1295
+ const key = `${w}x${h}|${this.#capGen}|${this.#readOptsKey()}`;
1296
+ if (key === this.#capKey || this.#capInFlight) {
1297
+ return;
1298
+ }
1299
+ this.#capPending = true;
1300
+ if (!this.#capRt ||
1301
+ this.#capRt.width !== w ||
1302
+ this.#capRt.height !== h) {
1303
+ this.#capRt?.dispose();
1304
+ this.#capRt = ctx.createRenderTarget({ size: [w, h] });
1305
+ }
1306
+ captureContent(ctx, this.#capRt);
1307
+ // read back without stalling the GPU: 8 bit, premultiplied, rows top-down; it resolves a frame or so later
1308
+ this.#capInFlight = true;
1309
+ const token = this.#capToken;
1310
+ ctx.readPixels(this.#capRt, { flipY: true }).then((raw) => {
1311
+ if (token === this.#capToken) {
1312
+ this.#capInFlight = false;
1313
+ this.#useElementLogo(raw, w, h, key);
1314
+ }
1315
+ }, () => {
1316
+ // disposed or context lost: #release / the restore start over
1317
+ if (token === this.#capToken) {
1318
+ this.#capInFlight = false;
1319
+ }
1320
+ });
1321
+ }
1322
+ /** Turns the element read back (premultiplied, top-down) into the logo. */
1323
+ #useElementLogo(raw, w, h, key) {
1324
+ const px = new Uint8ClampedArray(w * h * 4);
1325
+ let visible = false;
1326
+ for (let i = 0; i < w * h * 4; i += 4) {
1327
+ const al = raw[i + 3];
1328
+ const u = al > 0 ? 255 / al : 0;
1329
+ px[i] = raw[i] * u;
1330
+ px[i + 1] = raw[i + 1] * u;
1331
+ px[i + 2] = raw[i + 2] * u;
1332
+ px[i + 3] = al;
1333
+ visible ||= al > 8;
1334
+ }
1335
+ // the element may not be drawn yet on the first frames: read it again for a while
1336
+ if (!visible && ++this.#capTries < 120) {
1337
+ return;
1338
+ }
1339
+ this.#capKey = key;
1340
+ this.#capTries = 0;
1341
+ this.#capPending = false;
1342
+ const hash = `${w}x${h}|${this.#readOptsKey()}|${fnv1a(px)}`;
1343
+ const a = this.#emboss;
1344
+ if (!a || hash === this.#capHash) {
1345
+ return;
1346
+ }
1347
+ this.#capHash = hash;
1348
+ const canvas = this.#makeCanvas(w, h);
1349
+ this.#ctx2d(canvas)?.putImageData(new ImageData(px, w, h), 0, 0);
1350
+ a.setLogo(visible ? canvas : "", this.#logoReadOpts("full"));
1351
+ }
1352
+ // ---- emboss.print: an image printed on the paper instead of the element
1353
+ #printWant = "";
1354
+ #printImg = null;
1355
+ #printTex = null;
1356
+ #printBusy = false;
1357
+ #printError = null;
1358
+ #printToken = 0;
1359
+ #printUniforms(ctx) {
1360
+ const want = this.#resolved?.values["emboss.print"] ?? "";
1361
+ if (want !== this.#printWant) {
1362
+ this.#printWant = want;
1363
+ const token = ++this.#printToken;
1364
+ this.#printTex?.dispose();
1365
+ this.#printTex = null;
1366
+ this.#printImg = null;
1367
+ this.#printError = null;
1368
+ this.#printBusy = false;
1369
+ // a URL, or an <img> that has not loaded yet: decode it first (a texture of an unloaded image would stay
1370
+ // 0 × 0); a loaded image, a canvas or an ImageBitmap is used at once
1371
+ let pending = null;
1372
+ if (typeof want === "string" && want.trim() !== "") {
1373
+ pending = new Image();
1374
+ pending.crossOrigin = "anonymous";
1375
+ pending.src = want.trim();
1376
+ }
1377
+ else if (isImgElement(want) &&
1378
+ !(want.complete && want.naturalWidth > 0)) {
1379
+ pending = want;
1380
+ }
1381
+ else if (givenImage(want)) {
1382
+ this.#printImg = want;
1383
+ }
1384
+ if (pending) {
1385
+ const img = pending;
1386
+ const label = typeof want === "string" ? ` ${want}` : "";
1387
+ this.#printBusy = true;
1388
+ img.decode().then(() => {
1389
+ if (token === this.#printToken) {
1390
+ this.#printImg = img;
1391
+ this.#printBusy = false;
1392
+ }
1393
+ }, (e) => {
1394
+ if (token === this.#printToken) {
1395
+ this.#printError = `HoloEffect: could not load emboss.print${label}: ${(e instanceof Error ? e.message : String(e)).replace(/\.$/, "")}. A cross-origin image needs CORS.`;
1396
+ console.warn(this.#printError);
1397
+ this.#printBusy = false;
1398
+ }
1399
+ });
1400
+ }
1401
+ }
1402
+ const img = this.#printImg;
1403
+ if (img && !this.#printTex) {
1404
+ this.#printTex = ctx.wrapTexture(img, { autoUpdate: false });
1405
+ }
1406
+ // the print: emboss.print once it is loaded (none while it loads or after it fails, not the element), else
1407
+ // the element, unless the element is the logo
1408
+ const v = this.#resolved?.values ?? {};
1409
+ const ink = typeof v["emboss.printInk"] === "number" ? v["emboss.printInk"] : 1;
1410
+ const printOn = givenImage(want)
1411
+ ? !!this.#printTex
1412
+ : v["emboss.logo"] !== "element";
1413
+ const uPrintK = [printOn ? 1 : 0, Math.min(Math.max(ink, 0), 1), 0, 0];
1414
+ if (!img || !this.#printTex) {
1415
+ return {
1416
+ uPrintK,
1417
+ uPrintOwn: 0,
1418
+ uPrintImg: this.#black ?? ctx.src,
1419
+ uPrintRect: [0, 0, 1, 1],
1420
+ };
1421
+ }
1422
+ // cover the element, as CSS background-size: cover
1423
+ const iw = isImgElement(img) ? img.naturalWidth : img.width;
1424
+ const ih = isImgElement(img) ? img.naturalHeight : img.height;
1425
+ const ae = this.#elemCss[0] / Math.max(this.#elemCss[1], 1);
1426
+ const ai = iw / Math.max(ih, 1);
1427
+ const sx = ai > ae ? ae / ai : 1;
1428
+ const sy = ai > ae ? 1 : ai / ae;
1429
+ return {
1430
+ uPrintK,
1431
+ uPrintOwn: 1,
1432
+ uPrintImg: this.#printTex,
1433
+ uPrintRect: [(1 - sx) / 2, (1 - sy) / 2, sx, sy],
1434
+ };
1435
+ }
1436
+ /** Uploads the Foil Emboss textures when they change and returns their uniforms. */
1437
+ #embossUniforms(ctx) {
1438
+ const a = this.#emboss;
1439
+ const black = this.#black;
1440
+ if (!a || !black) {
1441
+ return {};
1442
+ }
1443
+ if (this.#resolved?.values["emboss.logo"] === "element") {
1444
+ this.#captureElementLogo(ctx);
1445
+ }
1446
+ const print = this.#printUniforms(ctx);
1447
+ if (a.logoVersion !== this.#logoUp) {
1448
+ this.#logoUp = a.logoVersion;
1449
+ const l = a.logo;
1450
+ if (l) {
1451
+ const { w, h } = l.image;
1452
+ if (!this.#logoRt ||
1453
+ this.#logoRt.width !== w ||
1454
+ this.#logoRt.height !== h) {
1455
+ this.#logoRt?.dispose();
1456
+ this.#logoRt = ctx.createRenderTarget({
1457
+ size: [w, h],
1458
+ float: true,
1459
+ filter: "linear",
1460
+ mipmap: true,
1461
+ wrap: "clamp",
1462
+ });
1463
+ }
1464
+ this.#upload(ctx, l.image, this.#logoRt);
1465
+ this.#logoMap = l.map;
1466
+ }
1467
+ else {
1468
+ this.#logoRt?.dispose();
1469
+ this.#logoRt = null;
1470
+ }
1471
+ }
1472
+ if (a.paperVersion !== this.#paperUp && a.paper) {
1473
+ this.#paperUp = a.paperVersion;
1474
+ const n = a.paper.mom.w;
1475
+ const opts = {
1476
+ size: [n, n],
1477
+ float: true,
1478
+ filter: "linear",
1479
+ mipmap: true,
1480
+ wrap: "repeat",
1481
+ };
1482
+ this.#paperRt ??= {
1483
+ mom: ctx.createRenderTarget(opts),
1484
+ aux: ctx.createRenderTarget(opts),
1485
+ };
1486
+ this.#upload(ctx, a.paper.mom, this.#paperRt.mom);
1487
+ this.#upload(ctx, a.paper.aux, this.#paperRt.aux);
1488
+ }
1489
+ return {
1490
+ ...print,
1491
+ ...this.#logoPlacement(),
1492
+ uLogoTex: this.#logoRt ?? black,
1493
+ uLogoOn: this.#logoRt ? 1 : 0,
1494
+ uLogoMap: this.#logoMap,
1495
+ uPaperMom: this.#paperRt?.mom ?? black,
1496
+ uPaperAux: this.#paperRt?.aux ?? black,
1497
+ uPaperOn: this.#paperRt ? 1 : 0,
1498
+ };
1499
+ }
1500
+ /** One float RGBA byte image (emboss-assets.ts) → a float target, through a canvas and the decode pass. */
1501
+ #upload(ctx, img, target) {
1502
+ const canvas = this.#makeCanvas(4 * img.w, img.h);
1503
+ this.#ctx2d(canvas)?.putImageData(new ImageData(img.bytes, 4 * img.w, img.h), 0, 0);
1504
+ const tex = ctx.wrapTexture(canvas, {
1505
+ autoUpdate: false,
1506
+ filter: "nearest",
1507
+ });
1508
+ ctx.draw({
1509
+ frag: FRAG_DECODE_RGBA,
1510
+ vert: PLAIN_VERT,
1511
+ target,
1512
+ uniforms: { uBytes: tex, uRowOffset: 0 },
1513
+ });
1514
+ tex.dispose();
1515
+ }
1516
+ dispose() {
1517
+ this.#life++;
1518
+ this.#restoreUnsub?.();
1519
+ this.#restoreUnsub = null;
1520
+ this.#release();
1521
+ // a pending ready resolves: nothing more is drawn until the next init
1522
+ this.#drawnOnce = false;
1523
+ this.#disposed = true;
1524
+ const w = this.#readyWaiters;
1525
+ this.#readyWaiters = [];
1526
+ for (const f of w) {
1527
+ f();
1528
+ }
1529
+ }
1530
+ /** Frees the GPU resources and forgets what was drawn into them (dispose, and a restored context). */
1531
+ #release() {
1532
+ for (const rt of [
1533
+ this.#conv,
1534
+ this.#cum,
1535
+ this.#hdr,
1536
+ this.#base,
1537
+ this.#black,
1538
+ this.#env,
1539
+ this.#ltc1,
1540
+ this.#ltc2,
1541
+ ]) {
1542
+ rt?.dispose();
1543
+ }
1544
+ this.#bytesTex?.dispose();
1545
+ this.#ltcTex?.dispose();
1546
+ this.#glare.dispose();
1547
+ this.#releaseEmboss();
1548
+ this.#conv = this.#cum = this.#hdr = this.#black = this.#env = null;
1549
+ this.#base = null;
1550
+ this.#ltc1 = this.#ltc2 = null;
1551
+ this.#bytesTex = this.#ltcTex = null;
1552
+ this.#atlasUploaded = -1;
1553
+ this.#ltcReady = false;
1554
+ this.#blackReady = false;
1555
+ this.#envDrawn = null;
1556
+ }
1557
+ /** Frees what only `emboss` uses: its workers, logo and paper maps, the element read back as the logo, and `emboss.print`. */
1558
+ #releaseEmboss() {
1559
+ this.#emboss?.dispose();
1560
+ this.#emboss = null;
1561
+ this.#logoRt?.dispose();
1562
+ this.#logoRt = null;
1563
+ this.#paperRt?.mom.dispose();
1564
+ this.#paperRt?.aux.dispose();
1565
+ this.#paperRt = null;
1566
+ this.#logoUp = this.#paperUp = -1;
1567
+ this.#capRt?.dispose();
1568
+ this.#capRt = null;
1569
+ this.#capKey = "";
1570
+ this.#capHash = "";
1571
+ this.#capTries = 0;
1572
+ this.#capPending = false;
1573
+ this.#capInFlight = false;
1574
+ this.#capToken++;
1575
+ this.#printTex?.dispose();
1576
+ this.#printTex = null;
1577
+ this.#printImg = null;
1578
+ this.#printWant = "";
1579
+ this.#printToken++;
1580
+ this.#printBusy = false;
1581
+ this.#printError = null;
1582
+ }
1583
+ #uploadAtlas(ctx, atlas) {
1584
+ const canvas = this.#bytesCanvas;
1585
+ const c2d = canvas ? this.#ctx2d(canvas) : null;
1586
+ if (!c2d || !this.#bytesTex || !this.#conv || !this.#cum) {
1587
+ return;
1588
+ }
1589
+ c2d.putImageData(new ImageData(atlas.bytes, ATLAS.imageWidth, ATLAS.imageHeight), 0, 0);
1590
+ this.#bytesTex.update();
1591
+ ctx.draw({
1592
+ frag: FRAG_DECODE,
1593
+ vert: PLAIN_VERT,
1594
+ target: this.#conv,
1595
+ uniforms: { uBytes: this.#bytesTex, uRowOffset: 0 },
1596
+ });
1597
+ ctx.draw({
1598
+ frag: FRAG_DECODE,
1599
+ vert: PLAIN_VERT,
1600
+ target: this.#cum,
1601
+ uniforms: { uBytes: this.#bytesTex, uRowOffset: ATLAS.height },
1602
+ });
1603
+ this.#atlasUploaded = atlas.version;
1604
+ }
1605
+ }
1606
+ //# sourceMappingURL=holo.js.map