@arraypress/effects-astro 0.0.0-stage → 0.1.1

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 (314) hide show
  1. package/AGENTS.md +85 -0
  2. package/COMPONENTS.md +1264 -0
  3. package/LICENSE +139 -0
  4. package/README.md +197 -2
  5. package/package.json +60 -4
  6. package/src/components/AsciiRain.astro +36 -0
  7. package/src/components/BorderSweep.astro +39 -0
  8. package/src/components/Caustics.astro +39 -0
  9. package/src/components/ColorPanels.astro +62 -0
  10. package/src/components/Cursor.astro +97 -0
  11. package/src/components/DotGrid.astro +34 -0
  12. package/src/components/DotSurface.astro +35 -0
  13. package/src/components/EffectCanvas.astro +152 -0
  14. package/src/components/FitText.astro +35 -0
  15. package/src/components/FlutedGlass.astro +36 -0
  16. package/src/components/Glass.astro +69 -0
  17. package/src/components/GlassGlyph.astro +38 -0
  18. package/src/components/GlowField.astro +177 -0
  19. package/src/components/Grain.astro +98 -0
  20. package/src/components/HaloRing.astro +38 -0
  21. package/src/components/HighlightSweep.astro +74 -0
  22. package/src/components/ImageRipple.astro +56 -0
  23. package/src/components/Ink.astro +37 -0
  24. package/src/components/InkField.astro +45 -0
  25. package/src/components/IsoCity.astro +54 -0
  26. package/src/components/LightField.astro +40 -0
  27. package/src/components/LiquidMetal.astro +41 -0
  28. package/src/components/Magnetic.astro +52 -0
  29. package/src/components/Marquee.astro +216 -0
  30. package/src/components/MosaicReveal.astro +196 -0
  31. package/src/components/NebulaLogo.astro +38 -0
  32. package/src/components/NeonSwarm.astro +38 -0
  33. package/src/components/Ocean.astro +40 -0
  34. package/src/components/OutlineWordmark.astro +222 -0
  35. package/src/components/PaperBackground.astro +40 -0
  36. package/src/components/PaperShader.astro +55 -0
  37. package/src/components/Parallax.astro +49 -0
  38. package/src/components/ParticleLogo.astro +37 -0
  39. package/src/components/PixelGlitchText.astro +70 -0
  40. package/src/components/PointCloud.astro +37 -0
  41. package/src/components/ProductStack.astro +298 -0
  42. package/src/components/PulseMark.astro +189 -0
  43. package/src/components/RadiantGlass.astro +38 -0
  44. package/src/components/RainOnGlass.astro +71 -0
  45. package/src/components/Reveal.astro +115 -0
  46. package/src/components/ScrambleText.astro +52 -0
  47. package/src/components/ScrollReveal.astro +38 -0
  48. package/src/components/ShaderBackground.astro +55 -0
  49. package/src/components/SignalLines.astro +41 -0
  50. package/src/components/SilkRibbon.astro +37 -0
  51. package/src/components/SpotlightText.astro +131 -0
  52. package/src/components/Tilt.astro +79 -0
  53. package/src/components/Topography.astro +38 -0
  54. package/src/components/Typewriter.astro +66 -0
  55. package/src/components/VariableType.astro +59 -0
  56. package/src/components/VoxelLogo.astro +46 -0
  57. package/src/components/WaveBars.astro +41 -0
  58. package/src/components/WorldRoutes.astro +41 -0
  59. package/src/components/style.js +19 -0
  60. package/src/index.d.ts +143 -0
  61. package/src/index.js +105 -0
  62. package/src/runtime/ascii-rain.d.ts +53 -0
  63. package/src/runtime/ascii-rain.js +355 -0
  64. package/src/runtime/audio-meter.d.ts +65 -0
  65. package/src/runtime/audio-meter.js +282 -0
  66. package/src/runtime/audio.d.ts +26 -0
  67. package/src/runtime/audio.js +453 -0
  68. package/src/runtime/blur.d.ts +2 -0
  69. package/src/runtime/blur.js +56 -0
  70. package/src/runtime/canvas2d.d.ts +23 -0
  71. package/src/runtime/canvas2d.js +105 -0
  72. package/src/runtime/caustics.d.ts +40 -0
  73. package/src/runtime/caustics.js +286 -0
  74. package/src/runtime/color.d.ts +33 -0
  75. package/src/runtime/color.js +213 -0
  76. package/src/runtime/curl.d.ts +5 -0
  77. package/src/runtime/curl.js +81 -0
  78. package/src/runtime/cursor.d.ts +9 -0
  79. package/src/runtime/cursor.js +80 -0
  80. package/src/runtime/device.d.ts +14 -0
  81. package/src/runtime/device.js +73 -0
  82. package/src/runtime/dot-grid.d.ts +27 -0
  83. package/src/runtime/dot-grid.js +245 -0
  84. package/src/runtime/dot-surface.d.ts +46 -0
  85. package/src/runtime/dot-surface.js +429 -0
  86. package/src/runtime/feedback.d.ts +18 -0
  87. package/src/runtime/feedback.js +131 -0
  88. package/src/runtime/fit-text.d.ts +5 -0
  89. package/src/runtime/fit-text.js +60 -0
  90. package/src/runtime/fluid.d.ts +55 -0
  91. package/src/runtime/fluid.js +504 -0
  92. package/src/runtime/fluted-glass.d.ts +27 -0
  93. package/src/runtime/fluted-glass.js +157 -0
  94. package/src/runtime/gl.d.ts +19 -0
  95. package/src/runtime/gl.js +104 -0
  96. package/src/runtime/glass-glyph.d.ts +49 -0
  97. package/src/runtime/glass-glyph.js +355 -0
  98. package/src/runtime/glass-sheen.d.ts +2 -0
  99. package/src/runtime/glass-sheen.js +30 -0
  100. package/src/runtime/glsl.d.ts +17 -0
  101. package/src/runtime/glsl.js +78 -0
  102. package/src/runtime/glyphs.d.ts +22 -0
  103. package/src/runtime/glyphs.js +107 -0
  104. package/src/runtime/halo-ring.d.ts +47 -0
  105. package/src/runtime/halo-ring.js +334 -0
  106. package/src/runtime/height-field.d.ts +50 -0
  107. package/src/runtime/height-field.js +176 -0
  108. package/src/runtime/image-ripple.d.ts +25 -0
  109. package/src/runtime/image-ripple.js +353 -0
  110. package/src/runtime/image.d.ts +11 -0
  111. package/src/runtime/image.js +81 -0
  112. package/src/runtime/in-view.d.ts +6 -0
  113. package/src/runtime/in-view.js +36 -0
  114. package/src/runtime/ink-field/shaders.js +258 -0
  115. package/src/runtime/ink-field/sim.js +582 -0
  116. package/src/runtime/ink-field.d.ts +39 -0
  117. package/src/runtime/ink-field.js +311 -0
  118. package/src/runtime/ink.d.ts +31 -0
  119. package/src/runtime/ink.js +109 -0
  120. package/src/runtime/instancing.d.ts +12 -0
  121. package/src/runtime/instancing.js +37 -0
  122. package/src/runtime/iso-camera.d.ts +35 -0
  123. package/src/runtime/iso-camera.js +85 -0
  124. package/src/runtime/iso-city/figures.d.ts +30 -0
  125. package/src/runtime/iso-city/figures.js +136 -0
  126. package/src/runtime/iso-city/look.d.ts +34 -0
  127. package/src/runtime/iso-city/look.js +105 -0
  128. package/src/runtime/iso-city/plan.d.ts +59 -0
  129. package/src/runtime/iso-city/plan.js +463 -0
  130. package/src/runtime/iso-city/roads.d.ts +64 -0
  131. package/src/runtime/iso-city/roads.js +320 -0
  132. package/src/runtime/iso-city/scene.d.ts +27 -0
  133. package/src/runtime/iso-city/scene.js +432 -0
  134. package/src/runtime/iso-city/shaders.d.ts +6 -0
  135. package/src/runtime/iso-city/shaders.js +233 -0
  136. package/src/runtime/iso-city/shadows.d.ts +13 -0
  137. package/src/runtime/iso-city/shadows.js +148 -0
  138. package/src/runtime/iso-city/traffic.d.ts +80 -0
  139. package/src/runtime/iso-city/traffic.js +457 -0
  140. package/src/runtime/iso-city.d.ts +37 -0
  141. package/src/runtime/iso-city.js +458 -0
  142. package/src/runtime/lens-map.d.ts +11 -0
  143. package/src/runtime/lens-map.js +146 -0
  144. package/src/runtime/light-field.d.ts +29 -0
  145. package/src/runtime/light-field.js +292 -0
  146. package/src/runtime/liquid-glass.d.ts +48 -0
  147. package/src/runtime/liquid-glass.js +423 -0
  148. package/src/runtime/liquid-metal/beads.js +217 -0
  149. package/src/runtime/liquid-metal/field.js +88 -0
  150. package/src/runtime/liquid-metal/look.js +64 -0
  151. package/src/runtime/liquid-metal/shaders.js +255 -0
  152. package/src/runtime/liquid-metal/wave.js +53 -0
  153. package/src/runtime/liquid-metal.d.ts +46 -0
  154. package/src/runtime/liquid-metal.js +366 -0
  155. package/src/runtime/loop.d.ts +7 -0
  156. package/src/runtime/loop.js +112 -0
  157. package/src/runtime/magnetic.d.ts +9 -0
  158. package/src/runtime/magnetic.js +46 -0
  159. package/src/runtime/marquee.d.ts +2 -0
  160. package/src/runtime/marquee.js +27 -0
  161. package/src/runtime/mesh.d.ts +30 -0
  162. package/src/runtime/mesh.js +217 -0
  163. package/src/runtime/mosaic-reveal.d.ts +34 -0
  164. package/src/runtime/mosaic-reveal.js +504 -0
  165. package/src/runtime/motion.d.ts +2 -0
  166. package/src/runtime/motion.js +21 -0
  167. package/src/runtime/mount.d.ts +13 -0
  168. package/src/runtime/mount.js +120 -0
  169. package/src/runtime/nebula-logo.d.ts +31 -0
  170. package/src/runtime/nebula-logo.js +282 -0
  171. package/src/runtime/neon-swarm.d.ts +31 -0
  172. package/src/runtime/neon-swarm.js +258 -0
  173. package/src/runtime/ocean/presets.d.ts +54 -0
  174. package/src/runtime/ocean/presets.js +184 -0
  175. package/src/runtime/ocean/shader.d.ts +14 -0
  176. package/src/runtime/ocean/shader.js +389 -0
  177. package/src/runtime/ocean/view.d.ts +24 -0
  178. package/src/runtime/ocean/view.js +98 -0
  179. package/src/runtime/ocean/waves.d.ts +29 -0
  180. package/src/runtime/ocean/waves.js +119 -0
  181. package/src/runtime/ocean.d.ts +31 -0
  182. package/src/runtime/ocean.js +173 -0
  183. package/src/runtime/palettes.d.ts +37 -0
  184. package/src/runtime/palettes.js +75 -0
  185. package/src/runtime/paper-look.d.ts +42 -0
  186. package/src/runtime/paper-look.js +91 -0
  187. package/src/runtime/paper-looks.d.ts +17 -0
  188. package/src/runtime/paper-looks.js +21 -0
  189. package/src/runtime/paper.d.ts +37 -0
  190. package/src/runtime/paper.js +303 -0
  191. package/src/runtime/particle-logo.d.ts +31 -0
  192. package/src/runtime/particle-logo.js +196 -0
  193. package/src/runtime/ping-pong.d.ts +43 -0
  194. package/src/runtime/ping-pong.js +175 -0
  195. package/src/runtime/pixel-glitch.d.ts +17 -0
  196. package/src/runtime/pixel-glitch.js +287 -0
  197. package/src/runtime/point-cloud.d.ts +33 -0
  198. package/src/runtime/point-cloud.js +287 -0
  199. package/src/runtime/pointer.d.ts +27 -0
  200. package/src/runtime/pointer.js +128 -0
  201. package/src/runtime/points.d.ts +25 -0
  202. package/src/runtime/points.js +130 -0
  203. package/src/runtime/pools.d.ts +2 -0
  204. package/src/runtime/pools.js +25 -0
  205. package/src/runtime/product-stack.d.ts +24 -0
  206. package/src/runtime/product-stack.js +210 -0
  207. package/src/runtime/radiant-glass.d.ts +29 -0
  208. package/src/runtime/radiant-glass.js +282 -0
  209. package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
  210. package/src/runtime/rain-on-glass/backdrop.js +185 -0
  211. package/src/runtime/rain-on-glass/shader.d.ts +2 -0
  212. package/src/runtime/rain-on-glass/shader.js +168 -0
  213. package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
  214. package/src/runtime/rain-on-glass/wipe.js +65 -0
  215. package/src/runtime/rain-on-glass.d.ts +27 -0
  216. package/src/runtime/rain-on-glass.js +210 -0
  217. package/src/runtime/ramp.d.ts +2 -0
  218. package/src/runtime/ramp.js +30 -0
  219. package/src/runtime/random.d.ts +2 -0
  220. package/src/runtime/random.js +22 -0
  221. package/src/runtime/scroll-reveal.d.ts +22 -0
  222. package/src/runtime/scroll-reveal.js +73 -0
  223. package/src/runtime/shader-background.d.ts +42 -0
  224. package/src/runtime/shader-background.js +261 -0
  225. package/src/runtime/shader-backgrounds/band-lens.js +72 -0
  226. package/src/runtime/shader-backgrounds/common.js +53 -0
  227. package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
  228. package/src/runtime/shader-backgrounds/grid.js +33 -0
  229. package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
  230. package/src/runtime/shader-backgrounds/silk.js +57 -0
  231. package/src/runtime/shader-backgrounds/waves.js +31 -0
  232. package/src/runtime/shape.d.ts +42 -0
  233. package/src/runtime/shape.js +313 -0
  234. package/src/runtime/silk-ribbon.d.ts +23 -0
  235. package/src/runtime/silk-ribbon.js +206 -0
  236. package/src/runtime/slideshow.d.ts +27 -0
  237. package/src/runtime/slideshow.js +234 -0
  238. package/src/runtime/spotlight.d.ts +9 -0
  239. package/src/runtime/spotlight.js +97 -0
  240. package/src/runtime/stack-poses.d.ts +53 -0
  241. package/src/runtime/stack-poses.js +273 -0
  242. package/src/runtime/stage.d.ts +47 -0
  243. package/src/runtime/stage.js +187 -0
  244. package/src/runtime/swarm.d.ts +49 -0
  245. package/src/runtime/swarm.js +199 -0
  246. package/src/runtime/text-motion.d.ts +41 -0
  247. package/src/runtime/text-motion.js +165 -0
  248. package/src/runtime/text.d.ts +11 -0
  249. package/src/runtime/text.js +90 -0
  250. package/src/runtime/tilt.d.ts +19 -0
  251. package/src/runtime/tilt.js +116 -0
  252. package/src/runtime/topography.d.ts +71 -0
  253. package/src/runtime/topography.js +650 -0
  254. package/src/runtime/trackers.d.ts +21 -0
  255. package/src/runtime/trackers.js +76 -0
  256. package/src/runtime/variable-type.d.ts +43 -0
  257. package/src/runtime/variable-type.js +358 -0
  258. package/src/runtime/voxel-logo.d.ts +31 -0
  259. package/src/runtime/voxel-logo.js +237 -0
  260. package/src/runtime/waves.d.ts +70 -0
  261. package/src/runtime/waves.js +799 -0
  262. package/src/runtime/world-labels.d.ts +29 -0
  263. package/src/runtime/world-labels.js +59 -0
  264. package/src/runtime/world-land.d.ts +8 -0
  265. package/src/runtime/world-land.js +105 -0
  266. package/src/runtime/world-map.d.ts +69 -0
  267. package/src/runtime/world-map.js +308 -0
  268. package/src/runtime/world-plan.d.ts +101 -0
  269. package/src/runtime/world-plan.js +333 -0
  270. package/src/runtime/world-routes.d.ts +75 -0
  271. package/src/runtime/world-routes.js +673 -0
  272. package/src/styles/border-sweep.css +82 -0
  273. package/src/styles/glass.css +104 -0
  274. package/src/styles/motion.css +218 -0
  275. package/src/styles/reveal.css +51 -0
  276. package/src/vendor/paper/LICENSE +201 -0
  277. package/src/vendor/paper/NOTICE +5 -0
  278. package/src/vendor/paper/README.md +8 -0
  279. package/src/vendor/paper/get-shader-color-from-string.js +100 -0
  280. package/src/vendor/paper/get-shader-noise-texture.js +17 -0
  281. package/src/vendor/paper/presets.js +3678 -0
  282. package/src/vendor/paper/shader-sizing.js +37 -0
  283. package/src/vendor/paper/shader-utils.js +130 -0
  284. package/src/vendor/paper/shaders/color-panels.js +223 -0
  285. package/src/vendor/paper/shaders/dithering.js +270 -0
  286. package/src/vendor/paper/shaders/dot-grid.js +109 -0
  287. package/src/vendor/paper/shaders/dot-orbit.js +122 -0
  288. package/src/vendor/paper/shaders/fluted-glass.js +360 -0
  289. package/src/vendor/paper/shaders/gem-smoke.js +572 -0
  290. package/src/vendor/paper/shaders/god-rays.js +132 -0
  291. package/src/vendor/paper/shaders/grain-gradient.js +300 -0
  292. package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
  293. package/src/vendor/paper/shaders/halftone-dots.js +320 -0
  294. package/src/vendor/paper/shaders/heatmap.js +383 -0
  295. package/src/vendor/paper/shaders/image-dithering.js +198 -0
  296. package/src/vendor/paper/shaders/lens-distortion.js +275 -0
  297. package/src/vendor/paper/shaders/liquid-metal.js +632 -0
  298. package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
  299. package/src/vendor/paper/shaders/metaballs.js +110 -0
  300. package/src/vendor/paper/shaders/neuro-noise.js +76 -0
  301. package/src/vendor/paper/shaders/paper-texture.js +526 -0
  302. package/src/vendor/paper/shaders/perlin-noise.js +166 -0
  303. package/src/vendor/paper/shaders/pulsing-border.js +238 -0
  304. package/src/vendor/paper/shaders/simplex-noise.js +91 -0
  305. package/src/vendor/paper/shaders/smoke-ring.js +132 -0
  306. package/src/vendor/paper/shaders/spiral.js +82 -0
  307. package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
  308. package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
  309. package/src/vendor/paper/shaders/swirl.js +103 -0
  310. package/src/vendor/paper/shaders/voronoi.js +138 -0
  311. package/src/vendor/paper/shaders/warp.js +129 -0
  312. package/src/vendor/paper/shaders/water.js +121 -0
  313. package/src/vendor/paper/shaders/waves.js +65 -0
  314. package/src/vendor/paper/vertex-shader.js +159 -0
@@ -0,0 +1,320 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import {} from "../shader-sizing.js";
7
+ import { declarePI, rotation2, proceduralHash21 } from "../shader-utils.js";
8
+ const halftoneDotsFragmentShader = `#version 300 es
9
+ precision mediump float;
10
+
11
+ uniform vec4 u_colorFront;
12
+ uniform vec4 u_colorBack;
13
+ uniform float u_radius;
14
+ uniform float u_contrast;
15
+
16
+ uniform sampler2D u_image;
17
+ uniform float u_imageAspectRatio;
18
+
19
+ uniform float u_size;
20
+ uniform float u_grainMixer;
21
+ uniform float u_grainOverlay;
22
+ uniform float u_grainSize;
23
+ uniform float u_grid;
24
+ uniform bool u_originalColors;
25
+ uniform bool u_inverted;
26
+ uniform float u_type;
27
+
28
+ in vec2 v_imageUV;
29
+
30
+ out vec4 fragColor;
31
+
32
+ ${declarePI}
33
+ ${rotation2}
34
+ ${proceduralHash21}
35
+
36
+ float valueNoise(vec2 st) {
37
+ vec2 i = floor(st);
38
+ vec2 f = fract(st);
39
+ float a = hash21(i);
40
+ float b = hash21(i + vec2(1.0, 0.0));
41
+ float c = hash21(i + vec2(0.0, 1.0));
42
+ float d = hash21(i + vec2(1.0, 1.0));
43
+ vec2 u = f * f * (3.0 - 2.0 * f);
44
+ float x1 = mix(a, b, u.x);
45
+ float x2 = mix(c, d, u.x);
46
+ return mix(x1, x2, u.y);
47
+ }
48
+
49
+ float lst(float edge0, float edge1, float x) {
50
+ return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
51
+ }
52
+
53
+ float sst(float edge0, float edge1, float x) {
54
+ return smoothstep(edge0, edge1, x);
55
+ }
56
+
57
+ float getCircle(vec2 uv, float r, float baseR) {
58
+ r = mix(.25 * baseR, 0., r);
59
+ float d = length(uv - .5);
60
+ float aa = fwidth(d);
61
+ return 1. - smoothstep(r - aa, r + aa, d);
62
+ }
63
+
64
+ float getCell(vec2 uv) {
65
+ float insideX = step(0.0, uv.x) * (1.0 - step(1.0, uv.x));
66
+ float insideY = step(0.0, uv.y) * (1.0 - step(1.0, uv.y));
67
+ return insideX * insideY;
68
+ }
69
+
70
+ float getCircleWithHole(vec2 uv, float r, float baseR) {
71
+ float cell = getCell(uv);
72
+
73
+ r = mix(.75 * baseR, 0., r);
74
+ float rMod = mod(r, .5);
75
+
76
+ float d = length(uv - .5);
77
+ float aa = fwidth(d);
78
+ float circle = 1. - smoothstep(rMod - aa, rMod + aa, d);
79
+ if (r < .5) {
80
+ return circle;
81
+ } else {
82
+ return cell - circle;
83
+ }
84
+ }
85
+
86
+ float getGooeyBall(vec2 uv, float r, float baseR) {
87
+ float d = length(uv - .5);
88
+ float sizeRadius = .3;
89
+ if (u_grid == 1.) {
90
+ sizeRadius = .42;
91
+ }
92
+ sizeRadius = mix(sizeRadius * baseR, 0., r);
93
+ d = 1. - sst(0., sizeRadius, d);
94
+
95
+ d = pow(d, 2. + baseR);
96
+ return d;
97
+ }
98
+
99
+ float getSoftBall(vec2 uv, float r, float baseR) {
100
+ float d = length(uv - .5);
101
+ float sizeRadius = clamp(baseR, 0., 1.);
102
+ sizeRadius = mix(.5 * sizeRadius, 0., r);
103
+ d = 1. - lst(0., sizeRadius, d);
104
+ float powRadius = 1. - lst(0., 2., baseR);
105
+ d = pow(d, 4. + 3. * powRadius);
106
+ return d;
107
+ }
108
+
109
+ float getUvFrame(vec2 uv, vec2 pad) {
110
+ float aa = 0.0001;
111
+
112
+ float left = smoothstep(-pad.x, -pad.x + aa, uv.x);
113
+ float right = smoothstep(1.0 + pad.x, 1.0 + pad.x - aa, uv.x);
114
+ float bottom = smoothstep(-pad.y, -pad.y + aa, uv.y);
115
+ float top = smoothstep(1.0 + pad.y, 1.0 + pad.y - aa, uv.y);
116
+
117
+ return left * right * bottom * top;
118
+ }
119
+
120
+ float sigmoid(float x, float k) {
121
+ return 1.0 / (1.0 + exp(-k * (x - 0.5)));
122
+ }
123
+
124
+ float getLumAtPx(vec2 uv, float contrast) {
125
+ vec4 tex = texture(u_image, uv);
126
+ vec3 color = vec3(
127
+ sigmoid(tex.r, contrast),
128
+ sigmoid(tex.g, contrast),
129
+ sigmoid(tex.b, contrast)
130
+ );
131
+ float lum = dot(vec3(0.2126, 0.7152, 0.0722), color);
132
+ lum = mix(1., lum, tex.a);
133
+ lum = u_inverted ? (1. - lum) : lum;
134
+ return lum;
135
+ }
136
+
137
+ float getLumBall(vec2 p, vec2 pad, vec2 inCellOffset, float contrast, float baseR, float stepSize, out vec4 ballColor) {
138
+ p += inCellOffset;
139
+ vec2 uv_i = floor(p);
140
+ vec2 uv_f = fract(p);
141
+ vec2 samplingUV = (uv_i + .5 - inCellOffset) * pad + vec2(.5);
142
+ float outOfFrame = getUvFrame(samplingUV, pad * stepSize);
143
+
144
+ float lum = getLumAtPx(samplingUV, contrast);
145
+ ballColor = texture(u_image, samplingUV);
146
+ ballColor.rgb *= ballColor.a;
147
+ ballColor *= outOfFrame;
148
+
149
+ float ball = 0.;
150
+ if (u_type == 0.) {
151
+ // classic
152
+ ball = getCircle(uv_f, lum, baseR);
153
+ } else if (u_type == 1.) {
154
+ // gooey
155
+ ball = getGooeyBall(uv_f, lum, baseR);
156
+ } else if (u_type == 2.) {
157
+ // holes
158
+ ball = getCircleWithHole(uv_f, lum, baseR);
159
+ } else if (u_type == 3.) {
160
+ // soft
161
+ ball = getSoftBall(uv_f, lum, baseR);
162
+ }
163
+
164
+ return ball * outOfFrame;
165
+ }
166
+
167
+
168
+ void main() {
169
+
170
+ float stepMultiplier = 1.;
171
+ if (u_type == 0.) {
172
+ // classic
173
+ stepMultiplier = 2.;
174
+ } else if (u_type == 1. || u_type == 3.) {
175
+ // gooey & soft
176
+ stepMultiplier = 6.;
177
+ }
178
+
179
+ float cellsPerSide = mix(300., 7., pow(u_size, .7));
180
+ cellsPerSide /= stepMultiplier;
181
+ float cellSizeY = 1. / cellsPerSide;
182
+ vec2 pad = cellSizeY * vec2(1. / u_imageAspectRatio, 1.);
183
+ if (u_type == 1. && u_grid == 1.) {
184
+ // gooey diagonal grid works differently
185
+ pad *= .7;
186
+ }
187
+
188
+ vec2 uv = v_imageUV;
189
+ uv -= vec2(.5);
190
+ uv /= pad;
191
+
192
+ float contrast = mix(0., 15., pow(u_contrast, 1.5));
193
+ float baseRadius = u_radius;
194
+ if (u_originalColors == true) {
195
+ contrast = mix(.1, 4., pow(u_contrast, 2.));
196
+ baseRadius = 2. * pow(.5 * u_radius, .3);
197
+ }
198
+
199
+ float totalShape = 0.;
200
+ vec3 totalColor = vec3(0.);
201
+ float totalOpacity = 0.;
202
+
203
+ vec4 ballColor;
204
+ float shape;
205
+ float stepSize = 1. / stepMultiplier;
206
+ for (float x = -0.5; x < 0.5; x += stepSize) {
207
+ for (float y = -0.5; y < 0.5; y += stepSize) {
208
+ vec2 offset = vec2(x, y);
209
+
210
+ if (u_grid == 1.) {
211
+ float rowIndex = floor((y + .5) / stepSize);
212
+ float colIndex = floor((x + .5) / stepSize);
213
+ if (stepSize == 1.) {
214
+ rowIndex = floor(uv.y + y + 1.);
215
+ if (u_type == 1.) {
216
+ colIndex = floor(uv.x + x + 1.);
217
+ }
218
+ }
219
+ if (u_type == 1.) {
220
+ if (mod(rowIndex + colIndex, 2.) == 1.) {
221
+ continue;
222
+ }
223
+ } else {
224
+ if (mod(rowIndex, 2.) == 1.) {
225
+ offset.x += .5 * stepSize;
226
+ }
227
+ }
228
+ }
229
+
230
+ shape = getLumBall(uv, pad, offset, contrast, baseRadius, stepSize, ballColor);
231
+ totalColor += ballColor.rgb * shape;
232
+ totalShape += shape;
233
+ totalOpacity += shape;
234
+ }
235
+ }
236
+
237
+ const float eps = 1e-4;
238
+
239
+ totalColor /= max(totalShape, eps);
240
+ totalOpacity /= max(totalShape, eps);
241
+
242
+ float finalShape = 0.;
243
+ if (u_type == 0.) {
244
+ finalShape = min(1., totalShape);
245
+ } else if (u_type == 1.) {
246
+ float aa = fwidth(totalShape);
247
+ float th = .5;
248
+ finalShape = smoothstep(th - aa, th + aa, totalShape);
249
+ } else if (u_type == 2.) {
250
+ finalShape = min(1., totalShape);
251
+ } else if (u_type == 3.) {
252
+ finalShape = totalShape;
253
+ }
254
+
255
+ vec2 grainSize = mix(2000., 200., u_grainSize) * vec2(1., 1. / u_imageAspectRatio);
256
+ vec2 grainUV = v_imageUV - .5;
257
+ grainUV *= grainSize;
258
+ grainUV += .5;
259
+ if (u_grainMixer > 0.) {
260
+ float grain = valueNoise(grainUV);
261
+ grain = smoothstep(.55, .7 + .2 * u_grainMixer, grain);
262
+ grain *= u_grainMixer;
263
+ finalShape = mix(finalShape, 0., grain);
264
+ }
265
+
266
+ vec3 color = vec3(0.);
267
+ float opacity = 0.;
268
+
269
+ if (u_originalColors == true) {
270
+ color = totalColor * finalShape;
271
+ opacity = totalOpacity * finalShape;
272
+
273
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
274
+ color = color + bgColor * (1. - opacity);
275
+ opacity = opacity + u_colorBack.a * (1. - opacity);
276
+ } else {
277
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
278
+ float fgOpacity = u_colorFront.a;
279
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
280
+ float bgOpacity = u_colorBack.a;
281
+
282
+ color = fgColor * finalShape;
283
+ opacity = fgOpacity * finalShape;
284
+ color += bgColor * (1. - opacity);
285
+ opacity += bgOpacity * (1. - opacity);
286
+ }
287
+
288
+ if (u_grainOverlay > 0.) {
289
+ float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));
290
+ grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);
291
+ grainOverlay = pow(grainOverlay, 1.3);
292
+
293
+ float grainOverlayV = grainOverlay * 2. - 1.;
294
+ vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
295
+ float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
296
+ grainOverlayStrength = pow(grainOverlayStrength, .8);
297
+ color = mix(color, grainOverlayColor, .5 * grainOverlayStrength);
298
+
299
+ opacity += .5 * grainOverlayStrength;
300
+ }
301
+ opacity = clamp(opacity, 0., 1.);
302
+
303
+ fragColor = vec4(color, opacity);
304
+ }
305
+ `;
306
+ const HalftoneDotsTypes = {
307
+ classic: 0,
308
+ gooey: 1,
309
+ holes: 2,
310
+ soft: 3
311
+ };
312
+ const HalftoneDotsGrids = {
313
+ square: 0,
314
+ hex: 1
315
+ };
316
+ export {
317
+ HalftoneDotsGrids,
318
+ HalftoneDotsTypes,
319
+ halftoneDotsFragmentShader
320
+ };
@@ -0,0 +1,383 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ const heatmapMeta = {
7
+ maxColorCount: 10
8
+ };
9
+ const heatmapFragmentShader = `#version 300 es
10
+ precision highp float;
11
+
12
+ in mediump vec2 v_imageUV;
13
+ in mediump vec2 v_objectUV;
14
+ out vec4 fragColor;
15
+
16
+ uniform sampler2D u_image;
17
+ uniform float u_time;
18
+
19
+ uniform vec4 u_colorBack;
20
+ uniform vec4 u_colors[${heatmapMeta.maxColorCount}];
21
+ uniform float u_colorsCount;
22
+
23
+ uniform float u_angle;
24
+ uniform float u_noise;
25
+ uniform float u_innerGlow;
26
+ uniform float u_outerGlow;
27
+ uniform float u_contour;
28
+
29
+ #define TWO_PI 6.28318530718
30
+ #define PI 3.14159265358979323846
31
+
32
+ float getImgFrame(vec2 uv, float th) {
33
+ float frame = 1.;
34
+ frame *= smoothstep(0., th, uv.y);
35
+ frame *= 1. - smoothstep(1. - th, 1., uv.y);
36
+ frame *= smoothstep(0., th, uv.x);
37
+ frame *= 1. - smoothstep(1. - th, 1., uv.x);
38
+ return frame;
39
+ }
40
+
41
+ float circle(vec2 uv, vec2 c, vec2 r) {
42
+ return 1. - smoothstep(r[0], r[1], length(uv - c));
43
+ }
44
+
45
+ float lst(float edge0, float edge1, float x) {
46
+ return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
47
+ }
48
+
49
+ float sst(float edge0, float edge1, float x) {
50
+ return smoothstep(edge0, edge1, x);
51
+ }
52
+
53
+ float shadowShape(vec2 uv, float t, float contour) {
54
+ vec2 scaledUV = uv;
55
+
56
+ // base shape tranjectory
57
+ float posY = mix(-1., 2., t);
58
+
59
+ // scaleX when it's moving down
60
+ scaledUV.y -= .5;
61
+ float mainCircleScale = sst(0., .8, posY) * lst(1.4, .9, posY);
62
+ scaledUV *= vec2(1., 1. + 1.5 * mainCircleScale);
63
+ scaledUV.y += .5;
64
+
65
+ // base shape
66
+ float innerR = .4;
67
+ float outerR = 1. - .3 * (sst(.1, .2, t) * (1. - sst(.2, .5, t)));
68
+ float s = circle(scaledUV, vec2(.5, posY - .2), vec2(innerR, outerR));
69
+ float shapeSizing = sst(.2, .3, t) * sst(.6, .3, t);
70
+ s = pow(s, 1.4);
71
+ s *= 1.2;
72
+
73
+ // flat gradient to take over the shadow shape
74
+ float topFlattener = 0.;
75
+ {
76
+ float pos = posY - uv.y;
77
+ float edge = 1.2;
78
+ topFlattener = lst(-.4, 0., pos) * (1. - sst(.0, edge, pos));
79
+ topFlattener = pow(topFlattener, 3.);
80
+ float topFlattenerMixer = (1. - sst(.0, .3, pos));
81
+ s = mix(topFlattener, s, topFlattenerMixer);
82
+ }
83
+
84
+ // apple right circle
85
+ {
86
+ float visibility = sst(.6, .7, t) * (1. - sst(.8, .9, t));
87
+ float angle = -2. -t * TWO_PI;
88
+ float rightCircle = circle(uv, vec2(.95 - .2 * cos(angle), .4 - .1 * sin(angle)), vec2(.15, .3));
89
+ rightCircle *= visibility;
90
+ s = mix(s, 0., rightCircle);
91
+ }
92
+
93
+ // apple top circle
94
+ {
95
+ float topCircle = circle(uv, vec2(.5, .19), vec2(.05, .25));
96
+ topCircle += 2. * contour * circle(uv, vec2(.5, .19), vec2(.2, .5));
97
+ float visibility = .55 * sst(.2, .3, t) * (1. - sst(.3, .45, t));
98
+ topCircle *= visibility;
99
+ s = mix(s, 0., topCircle);
100
+ }
101
+
102
+ float leafMask = circle(uv, vec2(.53, .13), vec2(.08, .19));
103
+ leafMask = mix(leafMask, 0., 1. - sst(.4, .54, uv.x));
104
+ leafMask = mix(0., leafMask, sst(.0, .2, uv.y));
105
+ leafMask *= (sst(.5, 1.1, posY) * sst(1.5, 1.3, posY));
106
+ s += leafMask;
107
+
108
+ // apple bottom circle
109
+ {
110
+ float visibility = sst(.0, .4, t) * (1. - sst(.6, .8, t));
111
+ s = mix(s, 0., visibility * circle(uv, vec2(.52, .92), vec2(.09, .25)));
112
+ }
113
+
114
+ // random balls that are invisible if apple logo is selected
115
+ {
116
+ float pos = sst(.0, .6, t) * (1. - sst(.6, 1., t));
117
+ s = mix(s, .5, circle(uv, vec2(.0, 1.2 - .5 * pos), vec2(.1, .3)));
118
+ s = mix(s, .0, circle(uv, vec2(1., .5 + .5 * pos), vec2(.1, .3)));
119
+
120
+ s = mix(s, 1., circle(uv, vec2(.95, .2 + .2 * sst(.3, .4, t) * sst(.7, .5, t)), vec2(.07, .22)));
121
+ s = mix(s, 1., circle(uv, vec2(.95, .2 + .2 * sst(.3, .4, t) * (1. - sst(.5, .7, t))), vec2(.07, .22)));
122
+ s /= max(1e-4, sst(1., .85, uv.y));
123
+ }
124
+
125
+ s = clamp(0., 1., s);
126
+ return s;
127
+ }
128
+
129
+ float blurEdge3x3(sampler2D tex, vec2 uv, vec2 dudx, vec2 dudy, float radius, float centerSample) {
130
+ vec2 texel = 1.0 / vec2(textureSize(tex, 0));
131
+ vec2 r = radius * texel;
132
+
133
+ float w1 = 1.0, w2 = 2.0, w4 = 4.0;
134
+ float norm = 16.0;
135
+ float sum = w4 * centerSample;
136
+
137
+ sum += w2 * textureGrad(tex, uv + vec2(0.0, -r.y), dudx, dudy).g;
138
+ sum += w2 * textureGrad(tex, uv + vec2(0.0, r.y), dudx, dudy).g;
139
+ sum += w2 * textureGrad(tex, uv + vec2(-r.x, 0.0), dudx, dudy).g;
140
+ sum += w2 * textureGrad(tex, uv + vec2(r.x, 0.0), dudx, dudy).g;
141
+
142
+ sum += w1 * textureGrad(tex, uv + vec2(-r.x, -r.y), dudx, dudy).g;
143
+ sum += w1 * textureGrad(tex, uv + vec2(r.x, -r.y), dudx, dudy).g;
144
+ sum += w1 * textureGrad(tex, uv + vec2(-r.x, r.y), dudx, dudy).g;
145
+ sum += w1 * textureGrad(tex, uv + vec2(r.x, r.y), dudx, dudy).g;
146
+
147
+ return sum / norm;
148
+ }
149
+
150
+ void main() {
151
+ vec2 uv = v_objectUV + .5;
152
+ uv.y = 1. - uv.y;
153
+
154
+ vec2 imgUV = v_imageUV;
155
+ imgUV -= .5;
156
+ imgUV *= 0.5714285714285714;
157
+ imgUV += .5;
158
+ float imgSoftFrame = getImgFrame(imgUV, .03);
159
+
160
+ vec4 img = texture(u_image, imgUV);
161
+ vec2 dudx = dFdx(imgUV);
162
+ vec2 dudy = dFdy(imgUV);
163
+
164
+ if (img.a == 0.) {
165
+ fragColor = u_colorBack;
166
+ return;
167
+ }
168
+
169
+ float t = .1 * u_time;
170
+ t -= .3;
171
+
172
+ float tCopy = t + 1. / 3.;
173
+ float tCopy2 = t + 2. / 3.;
174
+
175
+ t = mod(t, 1.);
176
+ tCopy = mod(tCopy, 1.);
177
+ tCopy2 = mod(tCopy2, 1.);
178
+
179
+ vec2 animationUV = imgUV - vec2(.5);
180
+ float angle = -u_angle * PI / 180.;
181
+ float cosA = cos(angle);
182
+ float sinA = sin(angle);
183
+ animationUV = vec2(
184
+ animationUV.x * cosA - animationUV.y * sinA,
185
+ animationUV.x * sinA + animationUV.y * cosA
186
+ ) + vec2(.5);
187
+
188
+ float shape = img[0];
189
+
190
+ img[1] = blurEdge3x3(u_image, imgUV, dudx, dudy, 8., img[1]);
191
+
192
+ float outerBlur = 1. - mix(1., img[1], shape);
193
+ float innerBlur = mix(img[1], 0., shape);
194
+ float contour = mix(img[2], 0., shape);
195
+
196
+ outerBlur *= imgSoftFrame;
197
+
198
+ float shadow = shadowShape(animationUV, t, innerBlur);
199
+ float shadowCopy = shadowShape(animationUV, tCopy, innerBlur);
200
+ float shadowCopy2 = shadowShape(animationUV, tCopy2, innerBlur);
201
+
202
+ float inner = .8 + .8 * innerBlur;
203
+ inner = mix(inner, 0., shadow);
204
+ inner = mix(inner, 0., shadowCopy);
205
+ inner = mix(inner, 0., shadowCopy2);
206
+
207
+ inner *= mix(0., 2., u_innerGlow);
208
+
209
+ inner += (u_contour * 2.) * contour;
210
+ inner = min(1., inner);
211
+ inner *= (1. - shape);
212
+
213
+ float outer = 0.;
214
+ {
215
+ t *= 3.;
216
+ t = mod(t - .1, 1.);
217
+
218
+ outer = .9 * pow(outerBlur, .8);
219
+ float y = mod(animationUV.y - t, 1.);
220
+ float animatedMask = sst(.3, .65, y) * (1. - sst(.65, 1., y));
221
+ animatedMask = .5 + animatedMask;
222
+ outer *= animatedMask;
223
+ outer *= mix(0., 5., pow(u_outerGlow, 2.));
224
+ outer *= imgSoftFrame;
225
+ }
226
+
227
+ inner = pow(inner, 1.2);
228
+ float heat = clamp(inner + outer, 0., 1.);
229
+
230
+ heat += (.005 + .35 * u_noise) * (fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123) - .5);
231
+
232
+ float mixer = heat * u_colorsCount;
233
+ vec4 gradient = u_colors[0];
234
+ gradient.rgb *= gradient.a;
235
+ float outerShape = 0.;
236
+ for (int i = 1; i < ${heatmapMeta.maxColorCount + 1}; i++) {
237
+ if (i > int(u_colorsCount)) break;
238
+ float m = clamp(mixer - float(i - 1), 0., 1.);
239
+ if (i == 1) {
240
+ outerShape = m;
241
+ }
242
+ vec4 c = u_colors[i - 1];
243
+ c.rgb *= c.a;
244
+ gradient = mix(gradient, c, m);
245
+ }
246
+
247
+ vec3 color = gradient.rgb * outerShape;
248
+ float opacity = gradient.a * outerShape;
249
+
250
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
251
+ color = color + bgColor * (1.0 - opacity);
252
+ opacity = opacity + u_colorBack.a * (1.0 - opacity);
253
+
254
+ color += .02 * (fract(sin(dot(uv + 1., vec2(12.9898, 78.233))) * 43758.5453123) - .5);
255
+
256
+ fragColor = vec4(color, opacity);
257
+ }
258
+ `;
259
+ function toProcessedHeatmap(file) {
260
+ const canvas = document.createElement("canvas");
261
+ const canvasSize = 1e3;
262
+ return new Promise((resolve, reject) => {
263
+ const image = new Image();
264
+ image.crossOrigin = "anonymous";
265
+ image.addEventListener("load", () => {
266
+ if (typeof file === "string" ? file.endsWith(".svg") : file.type === "image/svg+xml") {
267
+ image.width = canvasSize;
268
+ image.height = canvasSize;
269
+ }
270
+ const ratio = image.naturalWidth / image.naturalHeight;
271
+ const maxBlur = Math.floor(canvasSize * 0.15);
272
+ const padding = Math.ceil(maxBlur * 2.5);
273
+ let imgWidth = canvasSize;
274
+ let imgHeight = canvasSize;
275
+ if (ratio > 1) {
276
+ imgHeight = Math.floor(canvasSize / ratio);
277
+ } else {
278
+ imgWidth = Math.floor(canvasSize * ratio);
279
+ }
280
+ canvas.width = imgWidth + 2 * padding;
281
+ canvas.height = imgHeight + 2 * padding;
282
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
283
+ if (!ctx) {
284
+ throw new Error("Failed to get canvas 2d context");
285
+ }
286
+ ctx.fillStyle = "white";
287
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
288
+ ctx.drawImage(image, padding, padding, imgWidth, imgHeight);
289
+ const { width, height } = canvas;
290
+ const srcImageData = ctx.getImageData(0, 0, width, height);
291
+ const src = srcImageData.data;
292
+ const totalPixels = width * height;
293
+ const gray = new Uint8ClampedArray(totalPixels);
294
+ for (let i = 0; i < totalPixels; i++) {
295
+ const px = i * 4;
296
+ const r = src[px] ?? 0;
297
+ const g = src[px + 1] ?? 0;
298
+ const b = src[px + 2] ?? 0;
299
+ gray[i] = 0.299 * r + 0.587 * g + 0.114 * b | 0;
300
+ }
301
+ const bigBlurRadius = maxBlur;
302
+ const innerBlurRadius = Math.max(1, Math.round(0.12 * maxBlur));
303
+ const contourRadius = 5;
304
+ const bigBlurGray = multiPassBlurGray(gray, width, height, bigBlurRadius, 3);
305
+ const innerBlurGray = multiPassBlurGray(gray, width, height, innerBlurRadius, 3);
306
+ const contourGray = multiPassBlurGray(gray, width, height, contourRadius, 1);
307
+ const processedImageData = ctx.createImageData(width, height);
308
+ const dst = processedImageData.data;
309
+ for (let i = 0; i < totalPixels; i++) {
310
+ const px = i * 4;
311
+ dst[px] = contourGray[i] ?? 0;
312
+ dst[px + 1] = bigBlurGray[i] ?? 0;
313
+ dst[px + 2] = innerBlurGray[i] ?? 0;
314
+ dst[px + 3] = 255;
315
+ }
316
+ ctx.putImageData(processedImageData, 0, 0);
317
+ canvas.toBlob((blob) => {
318
+ if (!blob) {
319
+ reject(new Error("Failed to create PNG blob"));
320
+ return;
321
+ }
322
+ resolve({ blob });
323
+ }, "image/png");
324
+ });
325
+ image.addEventListener("error", () => {
326
+ reject(new Error("Failed to load image"));
327
+ });
328
+ image.src = typeof file === "string" ? file : URL.createObjectURL(file);
329
+ });
330
+ }
331
+ function blurGray(gray, width, height, radius) {
332
+ if (radius <= 0) {
333
+ return gray.slice();
334
+ }
335
+ const out = new Uint8ClampedArray(width * height);
336
+ const integral = new Uint32Array(width * height);
337
+ for (let y = 0; y < height; y++) {
338
+ let rowSum = 0;
339
+ for (let x = 0; x < width; x++) {
340
+ const idx = y * width + x;
341
+ const v = gray[idx] ?? 0;
342
+ rowSum += v;
343
+ integral[idx] = rowSum + (y > 0 ? integral[idx - width] ?? 0 : 0);
344
+ }
345
+ }
346
+ for (let y = 0; y < height; y++) {
347
+ const y1 = Math.max(0, y - radius);
348
+ const y2 = Math.min(height - 1, y + radius);
349
+ for (let x = 0; x < width; x++) {
350
+ const x1 = Math.max(0, x - radius);
351
+ const x2 = Math.min(width - 1, x + radius);
352
+ const idxA = y2 * width + x2;
353
+ const idxB = y2 * width + (x1 - 1);
354
+ const idxC = (y1 - 1) * width + x2;
355
+ const idxD = (y1 - 1) * width + (x1 - 1);
356
+ const A = integral[idxA] ?? 0;
357
+ const B = x1 > 0 ? integral[idxB] ?? 0 : 0;
358
+ const C = y1 > 0 ? integral[idxC] ?? 0 : 0;
359
+ const D = x1 > 0 && y1 > 0 ? integral[idxD] ?? 0 : 0;
360
+ const sum = A - B - C + D;
361
+ const area = (x2 - x1 + 1) * (y2 - y1 + 1);
362
+ out[y * width + x] = Math.round(sum / area);
363
+ }
364
+ }
365
+ return out;
366
+ }
367
+ function multiPassBlurGray(gray, width, height, radius, passes) {
368
+ if (radius <= 0 || passes <= 1) {
369
+ return blurGray(gray, width, height, radius);
370
+ }
371
+ let input = gray;
372
+ let tmp = gray;
373
+ for (let p = 0; p < passes; p++) {
374
+ tmp = blurGray(input, width, height, radius);
375
+ input = tmp;
376
+ }
377
+ return tmp;
378
+ }
379
+ export {
380
+ heatmapFragmentShader,
381
+ heatmapMeta,
382
+ toProcessedHeatmap
383
+ };