@arraypress/effects-astro 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +285 -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,572 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { rotation2, declarePI } from "../shader-utils.js";
7
+ const gemSmokeMeta = {
8
+ maxColorCount: 6
9
+ };
10
+ const gemSmokeFragmentShader = `#version 300 es
11
+ precision mediump float;
12
+
13
+ in mediump vec2 v_imageUV;
14
+ in mediump vec2 v_objectUV;
15
+ in mediump vec2 v_responsiveUV;
16
+ in mediump vec2 v_responsiveBoxGivenSize;
17
+
18
+ out vec4 fragColor;
19
+
20
+ uniform sampler2D u_image;
21
+ uniform float u_shape;
22
+ uniform bool u_isImage;
23
+
24
+ uniform float u_time;
25
+ uniform vec4 u_colors[${gemSmokeMeta.maxColorCount}];
26
+ uniform float u_colorsCount;
27
+ uniform vec4 u_colorBack;
28
+ uniform vec4 u_colorInner;
29
+ uniform float u_innerDistortion;
30
+ uniform float u_outerDistortion;
31
+ uniform float u_outerGlow;
32
+ uniform float u_innerGlow;
33
+ uniform float u_offset;
34
+ uniform float u_angle;
35
+ uniform float u_size;
36
+
37
+ ${declarePI}
38
+ ${rotation2}
39
+
40
+ // 9x9 Gaussian blur on R and G channels
41
+ vec2 gaussBlur9x9RG(sampler2D tex, vec2 uv, float radius) {
42
+ vec2 texel = 1.0 / vec2(textureSize(tex, 0));
43
+ vec2 r = max(radius, 0.0) * texel;
44
+ // Pascal's row 8: sum = 256, 2D norm = 65536
45
+ const float k[9] = float[9](1.0, 8.0, 28.0, 56.0, 70.0, 56.0, 28.0, 8.0, 1.0);
46
+ vec2 sum = vec2(0.0);
47
+
48
+ for (int j = -4; j <= 4; ++j) {
49
+ float wy = k[j + 4];
50
+ for (int i = -4; i <= 4; ++i) {
51
+ float w = k[i + 4] * wy;
52
+ vec2 off = vec2(float(i) * r.x, float(j) * r.y);
53
+ sum += w * texture(tex, uv + off).rg;
54
+ }
55
+ }
56
+
57
+ return sum / 65536.0;
58
+ }
59
+
60
+ float sst(float a, float b, float x) {
61
+ return smoothstep(a, b, x);
62
+ }
63
+
64
+ void main() {
65
+ float time = u_time;
66
+
67
+ float roundness = 0.;
68
+ float imgAlpha = 0.;
69
+
70
+ if (u_isImage == true) {
71
+ // Image sampling (UV scaled inward to account for padding)
72
+ vec2 imageUV = v_imageUV;
73
+ imageUV -= .5;
74
+ imageUV *= .95;
75
+ imageUV += .5;
76
+
77
+ // Blurred image: x = roundness, y = alpha
78
+ vec2 blurred = gaussBlur9x9RG(u_image, imageUV, 10.);
79
+ roundness = 1. - blurred.x;
80
+ vec2 texelA = 1.0 / vec2(textureSize(u_image, 0));
81
+ const float k3[3] = float[3](1.0, 2.0, 1.0);
82
+ for (int j = -1; j <= 1; ++j) {
83
+ for (int i = -1; i <= 1; ++i) {
84
+ imgAlpha += k3[i + 1] * k3[j + 1] * texture(u_image, imageUV + vec2(float(i) * texelA.x, float(j) * texelA.y)).g;
85
+ }
86
+ }
87
+ imgAlpha /= 16.0;
88
+ } else {
89
+ vec2 uv = v_objectUV + .5;
90
+ uv.y = 1. - uv.y;
91
+ float edge = 0.;
92
+
93
+ if (u_shape < 1.) {
94
+ // full-fill on canvas
95
+ vec2 borderUV = v_responsiveUV + .5;
96
+ vec2 mask = min(borderUV, 1. - borderUV);
97
+ vec2 pixel_thickness = min(250. / v_responsiveBoxGivenSize, vec2(.5));
98
+ float maskX = smoothstep(0.0, pixel_thickness.x, mask.x);
99
+ float maskY = smoothstep(0.0, pixel_thickness.y, mask.y);
100
+ maskX = pow(maskX, .25);
101
+ maskY = pow(maskY, .25);
102
+ edge = clamp(1. - maskX * maskY, 0., 1.);
103
+ } else if (u_shape < 2.) {
104
+ // circle
105
+ vec2 shapeUV = uv - .5;
106
+ shapeUV *= .67;
107
+ edge = pow(clamp(3. * length(shapeUV), 0., 1.), 18.);
108
+ } else if (u_shape < 3.) {
109
+ // daisy
110
+ vec2 shapeUV = uv - .5;
111
+ shapeUV *= 1.68;
112
+
113
+ float r = length(shapeUV) * 2.;
114
+ float a = atan(shapeUV.y, shapeUV.x) + .2;
115
+ r *= (1. + .05 * sin(3. * a + 2. * time));
116
+ float f = abs(cos(a * 3.));
117
+ edge = smoothstep(f, f + .7, r);
118
+ edge *= edge;
119
+ } else if (u_shape < 4.) {
120
+ // diamond
121
+ vec2 shapeUV = uv - .5;
122
+ shapeUV = rotate(shapeUV, .25 * PI);
123
+ shapeUV *= 1.42;
124
+ shapeUV += .5;
125
+ vec2 mask = min(shapeUV, 1. - shapeUV);
126
+ vec2 pixel_thickness = vec2(.15);
127
+ float maskX = smoothstep(0.0, pixel_thickness.x, mask.x);
128
+ float maskY = smoothstep(0.0, pixel_thickness.y, mask.y);
129
+ maskX = pow(maskX, .25);
130
+ maskY = pow(maskY, .25);
131
+ edge = clamp(1. - maskX * maskY, 0., 1.);
132
+ } else if (u_shape < 5.) {
133
+ // metaballs
134
+ vec2 shapeUV = uv - .5;
135
+ shapeUV *= 1.3;
136
+ edge = 0.;
137
+ for (int i = 0; i < 5; i++) {
138
+ float fi = float(i);
139
+ float speed = 1.5 + 2./3. * sin(fi * 12.345);
140
+ float angle = -fi * 1.5;
141
+ vec2 dir1 = vec2(cos(angle), sin(angle));
142
+ vec2 dir2 = vec2(cos(angle + 1.57), sin(angle + 1.));
143
+ vec2 traj = .4 * (dir1 * sin(time * speed + fi * 1.23) + dir2 * cos(time * (speed * 0.7) + fi * 2.17));
144
+ float d = length(shapeUV + traj);
145
+ edge += pow(1.0 - clamp(d, 0.0, 1.0), 4.0);
146
+ }
147
+ edge = 1. - smoothstep(.65, .9, edge);
148
+ edge = pow(edge, 4.);
149
+ }
150
+
151
+ imgAlpha = 1. - smoothstep(.9 - 2. * fwidth(edge), .9, edge);
152
+ roundness = 1. - edge;
153
+ }
154
+
155
+ // Smoke UV setup
156
+ vec2 smokeUV = v_objectUV;
157
+ smokeUV = rotate(smokeUV, u_angle * PI / 180.);
158
+ smokeUV *= mix(4., 1., u_size);
159
+
160
+ // Two swirl paths: inner (shape-masked) and outer (free), each with independent distortion
161
+ vec2 innerUV = smokeUV;
162
+ vec2 outerUV = smokeUV;
163
+
164
+ // Vertical displacement \u2014 applied independently to inner and outer
165
+ innerUV.y += u_innerDistortion * (1. - sst(0., 1., length(.4 * innerUV)));
166
+ innerUV.y -= .4 * u_innerDistortion;
167
+ innerUV.y += .7 * u_offset * roundness;
168
+
169
+ outerUV.y += u_outerDistortion * (1. - sst(0., 1., length(.4 * outerUV)));
170
+ outerUV.y -= .4 * u_outerDistortion;
171
+
172
+ float innerSwirl = u_innerDistortion * roundness;
173
+ float outerSwirl = u_outerDistortion;
174
+
175
+ for (int i = 1; i < 5; i++) {
176
+ float fi = float(i);
177
+
178
+ float stretchIn = max(length(dFdx(innerUV)), length(dFdy(innerUV)));
179
+ float dampenIn = 1. / (1. + stretchIn * 8.);
180
+ float sIn = innerSwirl * dampenIn;
181
+ innerUV.x += sIn / fi * cos(time + fi * 2.9 * innerUV.y);
182
+ innerUV.y += sIn / fi * cos(time + fi * 1.5 * innerUV.x);
183
+
184
+ float stretchOut = max(length(dFdx(outerUV)), length(dFdy(outerUV)));
185
+ float dampenOut = 1. / (1. + stretchOut * 8.);
186
+ float sOut = outerSwirl * dampenOut;
187
+ outerUV.x += sOut / fi * cos(time + fi * 2.9 * outerUV.y);
188
+ outerUV.y += sOut / fi * cos(time + fi * 1.5 * outerUV.x);
189
+ }
190
+
191
+ // Smoke shapes from swirl fields
192
+ float innerShape = exp(-1.5 * dot(innerUV, innerUV));
193
+ float outerShape = exp(-1.5 * dot(outerUV, outerUV));
194
+
195
+ // Visibility masks
196
+ float outerMask = pow(u_outerGlow, 2.) * (1. - imgAlpha);
197
+ float innerMask = (.01 + .99 * u_innerGlow) * imgAlpha;
198
+
199
+ innerShape *= innerMask;
200
+ outerShape *= outerMask;
201
+
202
+ // Color gradient
203
+ float mixer = (innerShape + outerShape) * u_colorsCount;
204
+ vec4 gradient = u_colors[0];
205
+ gradient.rgb *= gradient.a;
206
+
207
+ float smokeMask = 0.;
208
+ for (int i = 1; i < ${gemSmokeMeta.maxColorCount + 1}; i++) {
209
+ if (i > int(u_colorsCount)) break;
210
+
211
+ float m = sst(0., 1., clamp(mixer - float(i - 1), 0., 1.));
212
+ if (i == 1) smokeMask = m;
213
+
214
+ vec4 c = u_colors[i - 1];
215
+ c.rgb *= c.a;
216
+ gradient = mix(gradient, c, m);
217
+ }
218
+
219
+ // Compositing (premultiplied alpha, front-to-back)
220
+ vec3 color = gradient.rgb * smokeMask;
221
+ float opacity = gradient.a * smokeMask;
222
+
223
+ float innerOpacity = u_colorInner.a * imgAlpha;
224
+ vec3 innerColor = u_colorInner.rgb * innerOpacity;
225
+ color += innerColor * (1.0 - opacity);
226
+ opacity += innerOpacity * (1.0 - opacity);
227
+
228
+ vec3 backColor = u_colorBack.rgb * u_colorBack.a;
229
+ color += backColor * (1.0 - opacity);
230
+ opacity += u_colorBack.a * (1.0 - opacity);
231
+
232
+ fragColor = vec4(color, opacity);
233
+ }
234
+ `;
235
+ const POISSON_CONFIG_OPTIMIZED = {
236
+ measurePerformance: false,
237
+ // Set to true to see performance metrics
238
+ workingSize: 512,
239
+ // Size to solve Poisson at (will upscale to original size)
240
+ iterations: 32
241
+ // SOR converges ~2-20x faster than standard Gauss-Seidel
242
+ };
243
+ function toProcessedGemSmoke(file) {
244
+ const canvas = document.createElement("canvas");
245
+ const ctx = canvas.getContext("2d");
246
+ const isBlob = typeof file === "string" && file.startsWith("blob:");
247
+ return new Promise((resolve, reject) => {
248
+ if (!file || !ctx) {
249
+ reject(new Error("Invalid file or canvas context"));
250
+ return;
251
+ }
252
+ const blobContentTypePromise = isBlob && fetch(file).then((res) => res.headers.get("Content-Type"));
253
+ const img = new Image();
254
+ img.crossOrigin = "anonymous";
255
+ const totalStartTime = performance.now();
256
+ img.onload = async () => {
257
+ let isSVG;
258
+ const blobContentType = await blobContentTypePromise;
259
+ if (blobContentType) {
260
+ isSVG = blobContentType === "image/svg+xml";
261
+ } else if (typeof file === "string") {
262
+ isSVG = file.endsWith(".svg") || file.startsWith("data:image/svg+xml");
263
+ } else {
264
+ isSVG = file.type === "image/svg+xml";
265
+ }
266
+ let originalWidth = img.width || img.naturalWidth;
267
+ let originalHeight = img.height || img.naturalHeight;
268
+ if (isSVG) {
269
+ const svgMaxSize = 4096;
270
+ const aspectRatio = originalWidth / originalHeight;
271
+ if (originalWidth > originalHeight) {
272
+ originalWidth = svgMaxSize;
273
+ originalHeight = svgMaxSize / aspectRatio;
274
+ } else {
275
+ originalHeight = svgMaxSize;
276
+ originalWidth = svgMaxSize * aspectRatio;
277
+ }
278
+ img.width = originalWidth;
279
+ img.height = originalHeight;
280
+ }
281
+ const minDimension = Math.min(originalWidth, originalHeight);
282
+ const targetSize = POISSON_CONFIG_OPTIMIZED.workingSize;
283
+ const scaleFactor = targetSize / minDimension;
284
+ const width = Math.round(originalWidth * scaleFactor);
285
+ const height = Math.round(originalHeight * scaleFactor);
286
+ if (POISSON_CONFIG_OPTIMIZED.measurePerformance) {
287
+ console.log(`[Processing Mode]`);
288
+ console.log(` Original: ${originalWidth}\xD7${originalHeight}`);
289
+ console.log(` Working: ${width}\xD7${height} (${(scaleFactor * 100).toFixed(1)}% scale)`);
290
+ if (scaleFactor < 1) {
291
+ console.log(` Speedup: ~${Math.round(1 / (scaleFactor * scaleFactor))}\xD7`);
292
+ }
293
+ }
294
+ canvas.width = originalWidth;
295
+ canvas.height = originalHeight;
296
+ const paddingSize = 0.025;
297
+ const padX = Math.ceil(width * paddingSize);
298
+ const padY = Math.ceil(height * paddingSize);
299
+ const imgW = width - 2 * padX;
300
+ const imgH = height - 2 * padY;
301
+ const shapeCanvas = document.createElement("canvas");
302
+ shapeCanvas.width = width;
303
+ shapeCanvas.height = height;
304
+ const shapeCtx = shapeCanvas.getContext("2d");
305
+ shapeCtx.drawImage(img, padX, padY, imgW, imgH);
306
+ const startMask = performance.now();
307
+ const shapeImageData = shapeCtx.getImageData(0, 0, width, height);
308
+ const data = shapeImageData.data;
309
+ const shapeMask = new Uint8Array(width * height);
310
+ const boundaryMask = new Uint8Array(width * height);
311
+ let shapePixelCount = 0;
312
+ for (let i = 0, idx = 0; i < data.length; i += 4, idx++) {
313
+ const a = data[i + 3];
314
+ const isShape = a === 0 ? 0 : 1;
315
+ shapeMask[idx] = isShape;
316
+ shapePixelCount += isShape;
317
+ }
318
+ const boundaryIndices = [];
319
+ const interiorIndices = [];
320
+ for (let y = 0; y < height; y++) {
321
+ for (let x = 0; x < width; x++) {
322
+ const idx = y * width + x;
323
+ if (!shapeMask[idx]) continue;
324
+ let isBoundary = false;
325
+ if (x === 0 || x === width - 1 || y === 0 || y === height - 1) {
326
+ isBoundary = true;
327
+ } else {
328
+ isBoundary = !shapeMask[idx - 1] || // left
329
+ !shapeMask[idx + 1] || // right
330
+ !shapeMask[idx - width] || // top
331
+ !shapeMask[idx + width] || // bottom
332
+ !shapeMask[idx - width - 1] || // top-left
333
+ !shapeMask[idx - width + 1] || // top-right
334
+ !shapeMask[idx + width - 1] || // bottom-left
335
+ !shapeMask[idx + width + 1];
336
+ }
337
+ if (isBoundary) {
338
+ boundaryMask[idx] = 1;
339
+ boundaryIndices.push(idx);
340
+ } else {
341
+ interiorIndices.push(idx);
342
+ }
343
+ }
344
+ }
345
+ if (POISSON_CONFIG_OPTIMIZED.measurePerformance) {
346
+ console.log(`[Mask Building] Time: ${(performance.now() - startMask).toFixed(2)}ms`);
347
+ console.log(
348
+ ` Shape pixels: ${shapePixelCount} / ${width * height} (${(shapePixelCount / (width * height) * 100).toFixed(1)}%)`
349
+ );
350
+ console.log(` Interior pixels: ${interiorIndices.length}`);
351
+ console.log(` Boundary pixels: ${boundaryIndices.length}`);
352
+ }
353
+ const sparseData = buildSparseData(
354
+ shapeMask,
355
+ boundaryMask,
356
+ new Uint32Array(interiorIndices),
357
+ new Uint32Array(boundaryIndices),
358
+ width,
359
+ height
360
+ );
361
+ const startSolve = performance.now();
362
+ const u = solvePoissonSparse(sparseData, shapeMask, boundaryMask, width, height);
363
+ if (POISSON_CONFIG_OPTIMIZED.measurePerformance) {
364
+ console.log(`[Poisson Solve] Time: ${(performance.now() - startSolve).toFixed(2)}ms`);
365
+ }
366
+ let maxVal = 0;
367
+ let finalImageData;
368
+ for (let i = 0; i < interiorIndices.length; i++) {
369
+ const idx = interiorIndices[i];
370
+ if (u[idx] > maxVal) maxVal = u[idx];
371
+ }
372
+ const tempCanvas = document.createElement("canvas");
373
+ tempCanvas.width = width;
374
+ tempCanvas.height = height;
375
+ const tempCtx = tempCanvas.getContext("2d");
376
+ const tempImg = tempCtx.createImageData(width, height);
377
+ for (let y = 0; y < height; y++) {
378
+ for (let x = 0; x < width; x++) {
379
+ const idx = y * width + x;
380
+ const px = idx * 4;
381
+ if (!shapeMask[idx]) {
382
+ tempImg.data[px] = 255;
383
+ tempImg.data[px + 1] = 255;
384
+ tempImg.data[px + 2] = 255;
385
+ tempImg.data[px + 3] = 0;
386
+ } else {
387
+ const poissonRatio = u[idx] / maxVal;
388
+ let gray = 255 * (1 - poissonRatio);
389
+ tempImg.data[px] = gray;
390
+ tempImg.data[px + 1] = gray;
391
+ tempImg.data[px + 2] = gray;
392
+ tempImg.data[px + 3] = 255;
393
+ }
394
+ }
395
+ }
396
+ tempCtx.putImageData(tempImg, 0, 0);
397
+ ctx.imageSmoothingEnabled = true;
398
+ ctx.imageSmoothingQuality = "high";
399
+ ctx.drawImage(tempCanvas, 0, 0, width, height, 0, 0, originalWidth, originalHeight);
400
+ const outImg = ctx.getImageData(0, 0, originalWidth, originalHeight);
401
+ const origPadX = Math.ceil(originalWidth * paddingSize);
402
+ const origPadY = Math.ceil(originalHeight * paddingSize);
403
+ const originalCanvas = document.createElement("canvas");
404
+ originalCanvas.width = originalWidth;
405
+ originalCanvas.height = originalHeight;
406
+ const originalCtx = originalCanvas.getContext("2d");
407
+ originalCtx.drawImage(img, origPadX, origPadY, originalWidth - 2 * origPadX, originalHeight - 2 * origPadY);
408
+ const originalData = originalCtx.getImageData(0, 0, originalWidth, originalHeight);
409
+ for (let i = 0; i < outImg.data.length; i += 4) {
410
+ const a = originalData.data[i + 3];
411
+ const upscaledAlpha = outImg.data[i + 3];
412
+ if (a === 0) {
413
+ outImg.data[i] = 255;
414
+ outImg.data[i + 1] = 0;
415
+ } else {
416
+ outImg.data[i] = upscaledAlpha === 0 ? 0 : outImg.data[i];
417
+ outImg.data[i + 1] = a;
418
+ }
419
+ outImg.data[i + 2] = 255;
420
+ outImg.data[i + 3] = 255;
421
+ }
422
+ ctx.putImageData(outImg, 0, 0);
423
+ finalImageData = outImg;
424
+ canvas.toBlob((blob) => {
425
+ if (!blob) {
426
+ reject(new Error("Failed to create PNG blob"));
427
+ return;
428
+ }
429
+ if (POISSON_CONFIG_OPTIMIZED.measurePerformance) {
430
+ const totalTime = performance.now() - totalStartTime;
431
+ console.log(`[Total Processing Time] ${totalTime.toFixed(2)}ms`);
432
+ if (scaleFactor < 1) {
433
+ const estimatedFullResTime = totalTime * Math.pow(originalWidth * originalHeight / (width * height), 1.5);
434
+ console.log(`[Estimated time at full resolution] ~${estimatedFullResTime.toFixed(0)}ms`);
435
+ console.log(
436
+ `[Time saved] ~${(estimatedFullResTime - totalTime).toFixed(0)}ms (${Math.round(estimatedFullResTime / totalTime)}\xD7 faster)`
437
+ );
438
+ }
439
+ }
440
+ resolve({
441
+ imageData: finalImageData,
442
+ pngBlob: blob
443
+ });
444
+ }, "image/png");
445
+ };
446
+ img.onerror = () => reject(new Error("Failed to load image"));
447
+ img.src = typeof file === "string" ? file : URL.createObjectURL(file);
448
+ });
449
+ }
450
+ function buildSparseData(shapeMask, boundaryMask, interiorPixels, boundaryPixels, width, height) {
451
+ const pixelCount = interiorPixels.length;
452
+ const neighborIndices = new Int32Array(pixelCount * 4);
453
+ for (let i = 0; i < pixelCount; i++) {
454
+ const idx = interiorPixels[i];
455
+ const x = idx % width;
456
+ const y = Math.floor(idx / width);
457
+ neighborIndices[i * 4 + 0] = x < width - 1 && shapeMask[idx + 1] ? idx + 1 : -1;
458
+ neighborIndices[i * 4 + 1] = x > 0 && shapeMask[idx - 1] ? idx - 1 : -1;
459
+ neighborIndices[i * 4 + 2] = y > 0 && shapeMask[idx - width] ? idx - width : -1;
460
+ neighborIndices[i * 4 + 3] = y < height - 1 && shapeMask[idx + width] ? idx + width : -1;
461
+ }
462
+ return {
463
+ interiorPixels,
464
+ boundaryPixels,
465
+ pixelCount,
466
+ neighborIndices
467
+ };
468
+ }
469
+ function solvePoissonSparse(sparseData, shapeMask, boundaryMask, width, height) {
470
+ const ITERATIONS = POISSON_CONFIG_OPTIMIZED.iterations;
471
+ const C = 0.01;
472
+ const u = new Float32Array(width * height);
473
+ const { interiorPixels, neighborIndices, pixelCount } = sparseData;
474
+ const startTime = performance.now();
475
+ const omega = 1.9;
476
+ const redPixels = [];
477
+ const blackPixels = [];
478
+ for (let i = 0; i < pixelCount; i++) {
479
+ const idx = interiorPixels[i];
480
+ const x = idx % width;
481
+ const y = Math.floor(idx / width);
482
+ if ((x + y) % 2 === 0) {
483
+ redPixels.push(i);
484
+ } else {
485
+ blackPixels.push(i);
486
+ }
487
+ }
488
+ for (let iter = 0; iter < ITERATIONS; iter++) {
489
+ for (const i of redPixels) {
490
+ const idx = interiorPixels[i];
491
+ const eastIdx = neighborIndices[i * 4 + 0];
492
+ const westIdx = neighborIndices[i * 4 + 1];
493
+ const northIdx = neighborIndices[i * 4 + 2];
494
+ const southIdx = neighborIndices[i * 4 + 3];
495
+ let sumN = 0;
496
+ if (eastIdx >= 0) sumN += u[eastIdx];
497
+ if (westIdx >= 0) sumN += u[westIdx];
498
+ if (northIdx >= 0) sumN += u[northIdx];
499
+ if (southIdx >= 0) sumN += u[southIdx];
500
+ const newValue = (C + sumN) / 4;
501
+ u[idx] = omega * newValue + (1 - omega) * u[idx];
502
+ }
503
+ for (const i of blackPixels) {
504
+ const idx = interiorPixels[i];
505
+ const eastIdx = neighborIndices[i * 4 + 0];
506
+ const westIdx = neighborIndices[i * 4 + 1];
507
+ const northIdx = neighborIndices[i * 4 + 2];
508
+ const southIdx = neighborIndices[i * 4 + 3];
509
+ let sumN = 0;
510
+ if (eastIdx >= 0) sumN += u[eastIdx];
511
+ if (westIdx >= 0) sumN += u[westIdx];
512
+ if (northIdx >= 0) sumN += u[northIdx];
513
+ if (southIdx >= 0) sumN += u[southIdx];
514
+ const newValue = (C + sumN) / 4;
515
+ u[idx] = omega * newValue + (1 - omega) * u[idx];
516
+ }
517
+ }
518
+ const tmp = new Float32Array(width * height);
519
+ for (let smooth = 0; smooth < 3; smooth++) {
520
+ tmp.set(u);
521
+ for (let i = 0; i < pixelCount; i++) {
522
+ const idx = interiorPixels[i];
523
+ const eastIdx = neighborIndices[i * 4 + 0];
524
+ const westIdx = neighborIndices[i * 4 + 1];
525
+ const northIdx = neighborIndices[i * 4 + 2];
526
+ const southIdx = neighborIndices[i * 4 + 3];
527
+ let sum = 0;
528
+ let count = 0;
529
+ if (eastIdx >= 0) {
530
+ sum += tmp[eastIdx];
531
+ count++;
532
+ }
533
+ if (westIdx >= 0) {
534
+ sum += tmp[westIdx];
535
+ count++;
536
+ }
537
+ if (northIdx >= 0) {
538
+ sum += tmp[northIdx];
539
+ count++;
540
+ }
541
+ if (southIdx >= 0) {
542
+ sum += tmp[southIdx];
543
+ count++;
544
+ }
545
+ u[idx] = count > 0 ? (tmp[idx] + sum / count) * 0.5 : tmp[idx];
546
+ }
547
+ }
548
+ if (POISSON_CONFIG_OPTIMIZED.measurePerformance) {
549
+ const elapsed = performance.now() - startTime;
550
+ console.log(`[Optimized Poisson Solver (SOR \u03C9=${omega})]`);
551
+ console.log(` Working size: ${width}\xD7${height}`);
552
+ console.log(` Iterations: ${ITERATIONS}`);
553
+ console.log(` Time: ${elapsed.toFixed(2)}ms`);
554
+ console.log(` Interior pixels processed: ${pixelCount}`);
555
+ console.log(` Speed: ${(ITERATIONS * pixelCount / (elapsed * 1e3)).toFixed(2)} Mpixels/sec`);
556
+ }
557
+ return u;
558
+ }
559
+ const GemSmokeShapes = {
560
+ none: 0,
561
+ circle: 1,
562
+ daisy: 2,
563
+ diamond: 3,
564
+ metaballs: 4
565
+ };
566
+ export {
567
+ GemSmokeShapes,
568
+ POISSON_CONFIG_OPTIMIZED,
569
+ gemSmokeFragmentShader,
570
+ gemSmokeMeta,
571
+ toProcessedGemSmoke
572
+ };
@@ -0,0 +1,132 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import {} from "../shader-sizing.js";
7
+ import { declarePI, rotation2, textureRandomizerR, colorBandingFix, proceduralHash11 } from "../shader-utils.js";
8
+ const godRaysMeta = {
9
+ maxColorCount: 5
10
+ };
11
+ const godRaysFragmentShader = `#version 300 es
12
+ precision mediump float;
13
+
14
+ uniform float u_time;
15
+
16
+ uniform sampler2D u_noiseTexture;
17
+
18
+ uniform vec4 u_colorBack;
19
+ uniform vec4 u_colorBloom;
20
+ uniform vec4 u_colors[${godRaysMeta.maxColorCount}];
21
+ uniform float u_colorsCount;
22
+
23
+ uniform float u_density;
24
+ uniform float u_spotty;
25
+ uniform float u_midSize;
26
+ uniform float u_midIntensity;
27
+ uniform float u_intensity;
28
+ uniform float u_bloom;
29
+
30
+ in vec2 v_objectUV;
31
+
32
+ out vec4 fragColor;
33
+
34
+ ${declarePI}
35
+ ${rotation2}
36
+ ${textureRandomizerR}
37
+ float valueNoise(vec2 st) {
38
+ vec2 i = floor(st);
39
+ vec2 f = fract(st);
40
+ float a = randomR(i);
41
+ float b = randomR(i + vec2(1.0, 0.0));
42
+ float c = randomR(i + vec2(0.0, 1.0));
43
+ float d = randomR(i + vec2(1.0, 1.0));
44
+ vec2 u = f * f * (3.0 - 2.0 * f);
45
+ float x1 = mix(a, b, u.x);
46
+ float x2 = mix(c, d, u.x);
47
+ return mix(x1, x2, u.y);
48
+ }
49
+
50
+ ${proceduralHash11}
51
+
52
+ float raysShape(vec2 uv, float r, float freq, float intensity, float radius) {
53
+ float a = atan(uv.y, uv.x);
54
+ vec2 left = vec2(a * freq, r);
55
+ vec2 right = vec2(fract(a / TWO_PI) * TWO_PI * freq, r);
56
+ float n_left = pow(valueNoise(left), intensity);
57
+ float n_right = pow(valueNoise(right), intensity);
58
+ float shape = mix(n_right, n_left, smoothstep(-.15, .15, uv.x));
59
+ return shape;
60
+ }
61
+
62
+ void main() {
63
+ vec2 shape_uv = v_objectUV;
64
+
65
+ float t = .2 * u_time;
66
+
67
+ float radius = length(shape_uv);
68
+ float spots = 6.5 * abs(u_spotty);
69
+
70
+ float intensity = 4. - 3. * clamp(u_intensity, 0., 1.);
71
+
72
+ float delta = 1. - smoothstep(0., 1., radius);
73
+
74
+ float midSize = 10. * abs(u_midSize);
75
+ float ms_lo = 0.02 * midSize;
76
+ float ms_hi = max(midSize, 1e-6);
77
+ float middleShape = pow(u_midIntensity, 0.3) * (1. - smoothstep(ms_lo, ms_hi, 3.0 * radius));
78
+ middleShape = pow(middleShape, 5.0);
79
+
80
+ vec3 accumColor = vec3(0.0);
81
+ float accumAlpha = 0.0;
82
+
83
+ for (int i = 0; i < ${godRaysMeta.maxColorCount}; i++) {
84
+ if (i >= int(u_colorsCount)) break;
85
+
86
+ vec2 rotatedUV = rotate(shape_uv, float(i) + 1.0);
87
+
88
+ float r1 = radius * (1.0 + 0.4 * float(i)) - 3.0 * t;
89
+ float r2 = 0.5 * radius * (1.0 + spots) - 2.0 * t;
90
+ float density = 6. * u_density + step(.5, u_density) * pow(4.5 * (u_density - .5), 4.);
91
+ float f = mix(1.0, 3.0 + 0.5 * float(i), hash11(float(i) * 15.)) * density;
92
+
93
+ float ray = raysShape(rotatedUV, r1, 5.0 * f, intensity, radius);
94
+ ray *= raysShape(rotatedUV, r2, 4.0 * f, intensity, radius);
95
+ ray += (1. + 4. * ray) * middleShape;
96
+ ray = clamp(ray, 0.0, 1.0);
97
+
98
+ float srcAlpha = u_colors[i].a * ray;
99
+ vec3 srcColor = u_colors[i].rgb * srcAlpha;
100
+
101
+ vec3 alphaBlendColor = accumColor + (1.0 - accumAlpha) * srcColor;
102
+ float alphaBlendAlpha = accumAlpha + (1.0 - accumAlpha) * srcAlpha;
103
+
104
+ vec3 addBlendColor = accumColor + srcColor;
105
+ float addBlendAlpha = accumAlpha + srcAlpha;
106
+
107
+ accumColor = mix(alphaBlendColor, addBlendColor, u_bloom);
108
+ accumAlpha = mix(alphaBlendAlpha, addBlendAlpha, u_bloom);
109
+ }
110
+
111
+ float overlayAlpha = u_colorBloom.a;
112
+ vec3 overlayColor = u_colorBloom.rgb * overlayAlpha;
113
+
114
+ vec3 colorWithOverlay = accumColor + accumAlpha * overlayColor;
115
+ accumColor = mix(accumColor, colorWithOverlay, u_bloom);
116
+
117
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
118
+
119
+ vec3 color = accumColor + (1. - accumAlpha) * bgColor;
120
+ float opacity = accumAlpha + (1. - accumAlpha) * u_colorBack.a;
121
+ color = clamp(color, 0., 1.);
122
+ opacity = clamp(opacity, 0., 1.);
123
+
124
+ ${colorBandingFix}
125
+
126
+ fragColor = vec4(color, opacity);
127
+ }
128
+ `;
129
+ export {
130
+ godRaysFragmentShader,
131
+ godRaysMeta
132
+ };