gl-transitions 2.5.0 → 3.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 (257) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +16 -1
  3. package/compatibility.json +383 -149
  4. package/gl-transitions.js +1 -1
  5. package/gl-transitions.json +1 -1
  6. package/glsl3/BandWipe.glsl +67 -0
  7. package/glsl3/BookFlip.glsl +124 -21
  8. package/glsl3/BowTie.glsl +1 -1
  9. package/glsl3/Clothesline.glsl +217 -0
  10. package/glsl3/ComicPanels.glsl +174 -0
  11. package/glsl3/Cube.glsl +105 -52
  12. package/glsl3/DirectionalWipe.glsl +1 -1
  13. package/glsl3/DominoFall.glsl +114 -0
  14. package/glsl3/Doorway.glsl +74 -38
  15. package/glsl3/Drape.glsl +186 -0
  16. package/glsl3/DuotoneFade.glsl +58 -0
  17. package/glsl3/FacetedGlass.glsl +137 -0
  18. package/glsl3/FrostWipe.glsl +176 -0
  19. package/glsl3/Funnel.glsl +71 -0
  20. package/glsl3/GlintDissolve.glsl +125 -0
  21. package/glsl3/GlitterDissolve.glsl +171 -0
  22. package/glsl3/GridFlip.glsl +151 -56
  23. package/glsl3/HeartWipe.glsl +71 -11
  24. package/glsl3/InsetWipe.glsl +58 -0
  25. package/glsl3/InsideCube.glsl +114 -0
  26. package/glsl3/KeyholeWipe.glsl +104 -0
  27. package/glsl3/LedWall.glsl +127 -0
  28. package/glsl3/LightningFlash.glsl +200 -0
  29. package/glsl3/MoireWipe.glsl +75 -0
  30. package/glsl3/PaperFold.glsl +168 -0
  31. package/glsl3/PuzzleCube.glsl +205 -0
  32. package/glsl3/RibbonTwist.glsl +53 -0
  33. package/glsl3/Shatter.glsl +231 -35
  34. package/glsl3/SketchDissolve.glsl +100 -0
  35. package/glsl3/SlotReels.glsl +118 -0
  36. package/glsl3/SplitFlap.glsl +124 -0
  37. package/glsl3/Swirl.glsl +52 -21
  38. package/glsl3/TruchetWipe.glsl +80 -0
  39. package/glsl3/Tumble.glsl +113 -0
  40. package/glsl3/WarpSpeed.glsl +120 -0
  41. package/glsl3/WaterDrop.glsl +69 -13
  42. package/glsl3/WaveWipe.glsl +154 -0
  43. package/index.js +1 -1
  44. package/layouts.json +1158 -193
  45. package/llms-full.txt +865 -540
  46. package/llms.txt +219 -204
  47. package/msl/BandWipe.metal +353 -0
  48. package/msl/BookFlip.metal +575 -114
  49. package/msl/BowTie.metal +1 -1
  50. package/msl/Clothesline.metal +828 -0
  51. package/msl/ComicPanels.metal +959 -0
  52. package/msl/Cube.metal +466 -170
  53. package/msl/DirectionalWipe.metal +1 -1
  54. package/msl/DominoFall.metal +510 -0
  55. package/msl/Doorway.metal +350 -124
  56. package/msl/Drape.metal +767 -0
  57. package/msl/DuotoneFade.metal +218 -0
  58. package/msl/FacetedGlass.metal +529 -0
  59. package/msl/FrostWipe.metal +677 -0
  60. package/msl/Funnel.metal +276 -0
  61. package/msl/GlintDissolve.metal +558 -0
  62. package/msl/GlitterDissolve.metal +637 -0
  63. package/msl/GridFlip.metal +548 -191
  64. package/msl/HeartWipe.metal +230 -58
  65. package/msl/InsetWipe.metal +232 -0
  66. package/msl/InsideCube.metal +537 -0
  67. package/msl/KeyholeWipe.metal +370 -0
  68. package/msl/LedWall.metal +437 -0
  69. package/msl/LightningFlash.metal +1038 -0
  70. package/msl/MoireWipe.metal +252 -0
  71. package/msl/PaperFold.metal +762 -0
  72. package/msl/PuzzleCube.metal +1179 -0
  73. package/msl/RibbonTwist.metal +235 -0
  74. package/msl/Shatter.metal +1136 -160
  75. package/msl/SketchDissolve.metal +446 -0
  76. package/msl/SlotReels.metal +436 -0
  77. package/msl/SplitFlap.metal +589 -0
  78. package/msl/Swirl.metal +144 -77
  79. package/msl/TruchetWipe.metal +285 -0
  80. package/msl/Tumble.metal +466 -0
  81. package/msl/WarpSpeed.metal +549 -0
  82. package/msl/WaterDrop.metal +258 -49
  83. package/msl/WaveWipe.metal +618 -0
  84. package/package.json +1 -1
  85. package/skills/gl-transitions/references/catalog.md +119 -74
  86. package/sksl/BandWipe.sksl +77 -0
  87. package/sksl/BookFlip.sksl +117 -20
  88. package/sksl/BowTie.sksl +1 -1
  89. package/sksl/Clothesline.sksl +217 -0
  90. package/sksl/ComicPanels.sksl +176 -0
  91. package/sksl/Cube.sksl +99 -46
  92. package/sksl/DirectionalWipe.sksl +1 -1
  93. package/sksl/DominoFall.sksl +122 -0
  94. package/sksl/Doorway.sksl +65 -35
  95. package/sksl/Drape.sksl +192 -0
  96. package/sksl/DuotoneFade.sksl +71 -0
  97. package/sksl/FacetedGlass.sksl +148 -0
  98. package/sksl/FrostWipe.sksl +183 -0
  99. package/sksl/Funnel.sksl +83 -0
  100. package/sksl/GlintDissolve.sksl +136 -0
  101. package/sksl/GlitterDissolve.sksl +175 -0
  102. package/sksl/GridFlip.sksl +141 -52
  103. package/sksl/HeartWipe.sksl +60 -11
  104. package/sksl/InsetWipe.sksl +70 -0
  105. package/sksl/InsideCube.sksl +123 -0
  106. package/sksl/KeyholeWipe.sksl +109 -0
  107. package/sksl/LedWall.sksl +137 -0
  108. package/sksl/LightningFlash.sksl +202 -0
  109. package/sksl/MoireWipe.sksl +85 -0
  110. package/sksl/PaperFold.sksl +170 -0
  111. package/sksl/PuzzleCube.sksl +203 -0
  112. package/sksl/RibbonTwist.sksl +66 -0
  113. package/sksl/Shatter.sksl +218 -33
  114. package/sksl/SketchDissolve.sksl +111 -0
  115. package/sksl/SlotReels.sksl +127 -0
  116. package/sksl/SplitFlap.sksl +131 -0
  117. package/sksl/Swirl.sksl +49 -20
  118. package/sksl/TruchetWipe.sksl +92 -0
  119. package/sksl/Tumble.sksl +122 -0
  120. package/sksl/WarpSpeed.sksl +131 -0
  121. package/sksl/WaterDrop.sksl +64 -10
  122. package/sksl/WaveWipe.sksl +165 -0
  123. package/sksl/index.js +1 -1
  124. package/transitions/BandWipe.glsl +66 -0
  125. package/transitions/BookFlip.glsl +124 -21
  126. package/transitions/BowTie.glsl +1 -1
  127. package/transitions/Clothesline.glsl +216 -0
  128. package/transitions/ComicPanels.glsl +173 -0
  129. package/transitions/Cube.glsl +105 -52
  130. package/transitions/DirectionalWipe.glsl +1 -1
  131. package/transitions/DominoFall.glsl +113 -0
  132. package/transitions/Doorway.glsl +74 -38
  133. package/transitions/Drape.glsl +185 -0
  134. package/transitions/DuotoneFade.glsl +57 -0
  135. package/transitions/FacetedGlass.glsl +136 -0
  136. package/transitions/FrostWipe.glsl +175 -0
  137. package/transitions/Funnel.glsl +70 -0
  138. package/transitions/GlintDissolve.glsl +124 -0
  139. package/transitions/GlitterDissolve.glsl +170 -0
  140. package/transitions/GridFlip.glsl +151 -56
  141. package/transitions/HeartWipe.glsl +71 -11
  142. package/transitions/InsetWipe.glsl +57 -0
  143. package/transitions/InsideCube.glsl +113 -0
  144. package/transitions/KeyholeWipe.glsl +103 -0
  145. package/transitions/LedWall.glsl +126 -0
  146. package/transitions/LightningFlash.glsl +199 -0
  147. package/transitions/MoireWipe.glsl +74 -0
  148. package/transitions/PaperFold.glsl +167 -0
  149. package/transitions/PuzzleCube.glsl +204 -0
  150. package/transitions/RibbonTwist.glsl +52 -0
  151. package/transitions/Shatter.glsl +231 -35
  152. package/transitions/SketchDissolve.glsl +99 -0
  153. package/transitions/SlotReels.glsl +117 -0
  154. package/transitions/SplitFlap.glsl +123 -0
  155. package/transitions/Swirl.glsl +52 -21
  156. package/transitions/TruchetWipe.glsl +79 -0
  157. package/transitions/Tumble.glsl +112 -0
  158. package/transitions/WarpSpeed.glsl +119 -0
  159. package/transitions/WaterDrop.glsl +69 -13
  160. package/transitions/WaveWipe.glsl +153 -0
  161. package/wgsl/BandWipe.wgsl +319 -0
  162. package/wgsl/BookFlip.wgsl +552 -105
  163. package/wgsl/BowTie.wgsl +1 -1
  164. package/wgsl/Clothesline.wgsl +756 -0
  165. package/wgsl/ComicPanels.wgsl +886 -0
  166. package/wgsl/Cube.wgsl +461 -156
  167. package/wgsl/DirectionalWipe.wgsl +1 -1
  168. package/wgsl/DominoFall.wgsl +461 -0
  169. package/wgsl/Doorway.wgsl +333 -117
  170. package/wgsl/Drape.wgsl +715 -0
  171. package/wgsl/DuotoneFade.wgsl +185 -0
  172. package/wgsl/FacetedGlass.wgsl +476 -0
  173. package/wgsl/FrostWipe.wgsl +617 -0
  174. package/wgsl/Funnel.wgsl +248 -0
  175. package/wgsl/GlintDissolve.wgsl +519 -0
  176. package/wgsl/GlitterDissolve.wgsl +582 -0
  177. package/wgsl/GridFlip.wgsl +523 -188
  178. package/wgsl/HeartWipe.wgsl +225 -55
  179. package/wgsl/InsetWipe.wgsl +200 -0
  180. package/wgsl/InsideCube.wgsl +496 -0
  181. package/wgsl/KeyholeWipe.wgsl +337 -0
  182. package/wgsl/LedWall.wgsl +397 -0
  183. package/wgsl/LightningFlash.wgsl +964 -0
  184. package/wgsl/MoireWipe.wgsl +222 -0
  185. package/wgsl/PaperFold.wgsl +700 -0
  186. package/wgsl/PuzzleCube.wgsl +1087 -0
  187. package/wgsl/RibbonTwist.wgsl +206 -0
  188. package/wgsl/Shatter.wgsl +1091 -148
  189. package/wgsl/SketchDissolve.wgsl +409 -0
  190. package/wgsl/SlotReels.wgsl +391 -0
  191. package/wgsl/SplitFlap.wgsl +533 -0
  192. package/wgsl/Swirl.wgsl +138 -77
  193. package/wgsl/TruchetWipe.wgsl +255 -0
  194. package/wgsl/Tumble.wgsl +424 -0
  195. package/wgsl/WarpSpeed.wgsl +497 -0
  196. package/wgsl/WaterDrop.wgsl +251 -49
  197. package/wgsl/WaveWipe.wgsl +581 -0
  198. package/glsl3/BlockDissolve.glsl +0 -16
  199. package/glsl3/BowTieVertical.glsl +0 -117
  200. package/glsl3/Box.glsl +0 -33
  201. package/glsl3/LinearBlur.glsl +0 -30
  202. package/glsl3/MosaicBlend.glsl +0 -21
  203. package/glsl3/MosaicFade.glsl +0 -20
  204. package/glsl3/RotateFade.glsl +0 -22
  205. package/glsl3/ScaleIn.glsl +0 -18
  206. package/glsl3/WipeDown.glsl +0 -12
  207. package/glsl3/WipeLeft.glsl +0 -12
  208. package/glsl3/WipeRight.glsl +0 -12
  209. package/glsl3/WipeUp.glsl +0 -12
  210. package/msl/BlockDissolve.metal +0 -108
  211. package/msl/BowTieVertical.metal +0 -375
  212. package/msl/Box.metal +0 -204
  213. package/msl/LinearBlur.metal +0 -169
  214. package/msl/MosaicBlend.metal +0 -136
  215. package/msl/MosaicFade.metal +0 -137
  216. package/msl/RotateFade.metal +0 -116
  217. package/msl/ScaleIn.metal +0 -111
  218. package/msl/WipeDown.metal +0 -105
  219. package/msl/WipeLeft.metal +0 -105
  220. package/msl/WipeRight.metal +0 -105
  221. package/msl/WipeUp.metal +0 -105
  222. package/sksl/BlockDissolve.sksl +0 -29
  223. package/sksl/BowTieVertical.sksl +0 -130
  224. package/sksl/Box.sksl +0 -47
  225. package/sksl/LinearBlur.sksl +0 -44
  226. package/sksl/MosaicBlend.sksl +0 -34
  227. package/sksl/MosaicFade.sksl +0 -33
  228. package/sksl/RotateFade.sksl +0 -34
  229. package/sksl/ScaleIn.sksl +0 -32
  230. package/sksl/WipeDown.sksl +0 -26
  231. package/sksl/WipeLeft.sksl +0 -26
  232. package/sksl/WipeRight.sksl +0 -26
  233. package/sksl/WipeUp.sksl +0 -26
  234. package/transitions/BlockDissolve.glsl +0 -15
  235. package/transitions/BowTieVertical.glsl +0 -116
  236. package/transitions/Box.glsl +0 -32
  237. package/transitions/LinearBlur.glsl +0 -29
  238. package/transitions/MosaicBlend.glsl +0 -20
  239. package/transitions/MosaicFade.glsl +0 -19
  240. package/transitions/RotateFade.glsl +0 -21
  241. package/transitions/ScaleIn.glsl +0 -17
  242. package/transitions/WipeDown.glsl +0 -11
  243. package/transitions/WipeLeft.glsl +0 -11
  244. package/transitions/WipeRight.glsl +0 -11
  245. package/transitions/WipeUp.glsl +0 -11
  246. package/wgsl/BlockDissolve.wgsl +0 -78
  247. package/wgsl/BowTieVertical.wgsl +0 -331
  248. package/wgsl/Box.wgsl +0 -176
  249. package/wgsl/LinearBlur.wgsl +0 -131
  250. package/wgsl/MosaicBlend.wgsl +0 -108
  251. package/wgsl/MosaicFade.wgsl +0 -107
  252. package/wgsl/RotateFade.wgsl +0 -85
  253. package/wgsl/ScaleIn.wgsl +0 -79
  254. package/wgsl/WipeDown.wgsl +0 -77
  255. package/wgsl/WipeLeft.wgsl +0 -77
  256. package/wgsl/WipeRight.wgsl +0 -77
  257. package/wgsl/WipeUp.wgsl +0 -77
@@ -1,21 +1,77 @@
1
1
  // WaterDrop — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/WaterDrop.glsl
2
2
  // Author: Paweł Płóciennik
3
3
  // License: MIT
4
- // Description: Ripples spread from the center like a drop falling into water, crossfading to the incoming image
5
- // Tags: ripple, water, blend
6
- // @param Frequency of the ripples
4
+ // Description: A drop falls into the image like into still water: round ripples spread out from where it hits, bending the image with glints on their slopes, the incoming image shows up inside the leading ripple, and the water calms down
5
+ // Tags: ripple, water, refraction, circle
6
+ // @range(10, 80) Frequency of the ripples: higher makes them closer together
7
7
  uniform float amplitude; // = 30
8
- // @param Speed of the ripples
8
+ // @range(0, 80) Speed of the ripples as they run outward through the spreading rings
9
9
  uniform float speed; // = 30
10
+ // @param Where the drop falls, in texture coordinates
11
+ uniform vec2 center; // = vec2(0.5, 0.5)
12
+ // @range(0, 0.08) How far the ripples bend the image, in frame heights
13
+ uniform float refraction; // = 0.015
14
+ // @range(0, 1) Brightness of the glints on the ripples
15
+ uniform float highlight; // = 0.5
10
16
 
11
- vec4 transition(vec2 p) {
12
- vec2 dir = p - vec2(.5);
13
- float dist = length(dir);
17
+ // mirror the coordinates back into the frame
18
+ vec2 mirror(vec2 v) {
19
+ return 1.0 - abs(1.0 - mod(v, 2.0));
20
+ }
21
+
22
+ // height of the water, from -1 to 1, at a distance s inside the front
23
+ float wave(float s, float k, float lambda, float t) {
24
+ // it rises just ahead of the front and dies out a few ripples behind it
25
+ float env = smoothstep(-0.3 * lambda, 0.6 * lambda, s) * exp(-s / (3.5 * lambda));
26
+ // the ripples run out through the train, faster than the train itself spreads
27
+ return env * sin(k * s + speed * t);
28
+ }
29
+
30
+ vec4 transition(vec2 uv) {
31
+ if (progress <= 0.0) return getFromColor(uv);
32
+ if (progress >= 1.0) return getToColor(uv);
33
+
34
+ float k = 2.0 * max(amplitude, 1.0);
35
+ float lambda = 6.2831853 / k;
36
+ // measured in square pixels, so the ripples are round
37
+ vec2 q = (uv - center) * vec2(ratio, 1.0);
38
+ float r = length(q);
39
+ vec2 dir = r > 0.0 ? q / r : vec2(0.0);
40
+ // the farthest corner of the frame
41
+ vec2 far = max(center, 1.0 - center) * vec2(ratio, 1.0);
42
+ float R = length(far);
43
+
44
+ // the incoming image shows from a little behind the front, with a soft edge
45
+ float edge = 0.35 * lambda;
46
+ float soft = 0.1 * lambda;
47
+ // the front spreads out, slowing down a little, from just before the drop hits until
48
+ // its revealed area is past the farthest corner
49
+ float t = progress;
50
+ float e = mix(t, 1.0 - (1.0 - t) * (1.0 - t), 0.4);
51
+ float front = mix(-0.3 * lambda, R + edge + soft + 0.01, e);
52
+ float s = front - r;
53
+
54
+ // the water calms down at the end
55
+ float calm = 1.0 - smoothstep(0.55, 1.0, t);
56
+ calm *= calm;
57
+ // slope of the water along the radius, normalized to at most about 1
58
+ // (one-sided at the very center)
59
+ float d = 0.02 * lambda;
60
+ float r0 = max(r - d, 0.0);
61
+ float slope = calm * (wave(front - r - d, k, lambda, t) - wave(front - r0, k, lambda, t)) / ((r + d - r0) * k);
62
+ vec2 offset = dir * slope * refraction / vec2(ratio, 1.0);
63
+
64
+ vec4 ca = getFromColor(mirror(uv - offset));
65
+ vec4 cb = getToColor(mirror(uv - offset));
66
+ float m = smoothstep(edge - soft, edge + soft, s);
67
+ // mixed premultiplied, so transparent images do not bleed their color
68
+ vec4 c = mix(vec4(ca.rgb * ca.a, ca.a), vec4(cb.rgb * cb.a, cb.a), m);
14
69
 
15
- if (dist > progress) {
16
- return mix(getFromColor( p), getToColor( p), progress);
17
- } else {
18
- vec2 offset = dir * sin(dist * amplitude - progress * speed);
19
- return mix(getFromColor( p + offset), getToColor( p), progress);
20
- }
70
+ // the slopes facing the light glint, the ones facing away darken a little,
71
+ // and the crests are a little brighter than the troughs
72
+ float h = calm * wave(s, k, lambda, t);
73
+ float lit = -dot(dir, normalize(vec2(-0.6, 0.8))) * slope;
74
+ float glint = highlight * (0.2 * h + 0.6 * smoothstep(0.2, 0.9, lit) - 0.3 * smoothstep(0.2, 0.9, -lit));
75
+ c.rgb = clamp(c.rgb + glint * c.a, 0.0, c.a);
76
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
21
77
  }
@@ -0,0 +1,154 @@
1
+ // WaveWipe — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/WaveWipe.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: A breaking wave crashes across the frame, its lip curling over in front of its face and throwing foam and spray ahead, its shadow darkening the outgoing image; the incoming image is left behind it, tinted and bent by the water, clearing as the wave passes
5
+ // Tags: water, wave, ocean, foam, directional, reveal
6
+
7
+ // @param Direction the wave travels toward
8
+ uniform vec2 direction; // = vec2(1.0, 0.0)
9
+ // @range(0.1, 0.45) Size of the curling lip, in wave heights: how far it overhangs ahead of the face
10
+ uniform float curl; // = 0.3
11
+ // @range(0, 1) Amount of foam on the crest and spray thrown ahead of it
12
+ uniform float foam; // = 0.6
13
+ // @range(0, 0.1) How much the water bends the incoming image behind the wave
14
+ uniform float refraction; // = 0.04
15
+ // @color Color of the water tinting the incoming image behind the wave (its alpha is its strength)
16
+ uniform vec4 water; // = vec4(0.05, 0.36, 0.46, 0.75)
17
+ // @color Color of the foam and spray (its alpha is its strength)
18
+ uniform vec4 foamColor; // = vec4(1.0, 1.0, 1.0, 1.0)
19
+
20
+ const float PI = 3.141592653589793;
21
+ // half width of the antialiased edges, in wave heights
22
+ const float AA = 0.002;
23
+ // how far the base of the face trails behind its top, in wave heights
24
+ const float TRAIL = 0.35;
25
+ // how far behind the face the water still tints the incoming image, in wave heights
26
+ const float BAND = 0.4;
27
+ // how far ahead of the lip the spray reaches, in wave heights
28
+ const float REACH = 0.25;
29
+
30
+ float hash12(vec2 v) {
31
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
32
+ v3 += dot(v3, v3.yzx + 33.33);
33
+ return fract((v3.x + v3.y) * v3.z);
34
+ }
35
+
36
+ float vnoise(vec2 v) {
37
+ vec2 i = floor(v);
38
+ vec2 f = fract(v);
39
+ f = f * f * (3.0 - 2.0 * f);
40
+ return mix(
41
+ mix(hash12(i), hash12(i + vec2(1.0, 0.0)), f.x),
42
+ mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), f.x),
43
+ f.y
44
+ );
45
+ }
46
+
47
+ // folds coordinates back into the frame, so a displaced image never shows its clamped edges
48
+ vec2 mirror(vec2 v) {
49
+ return 1.0 - abs(1.0 - mod(v, 2.0));
50
+ }
51
+
52
+ // droplets scattered in cells, one per cell at most, kept inside their cell
53
+ float droplets(vec2 q, float cell, float density, float seed) {
54
+ vec2 g = q / cell;
55
+ vec2 id = floor(g);
56
+ if (hash12(id + seed) >= density) return 0.0;
57
+ float r = 0.1 + 0.2 * hash12(id + seed + 4.7);
58
+ vec2 c = id + 0.5 + (0.45 - r) * (vec2(hash12(id + seed + 1.3), hash12(id + seed + 8.1)) * 2.0 - 1.0);
59
+ float px = AA / cell;
60
+ return 1.0 - smoothstep(r - px, r + px, length(g - c));
61
+ }
62
+
63
+ vec4 transition(vec2 uv) {
64
+ if (progress <= 0.0) return getFromColor(uv);
65
+ if (progress >= 1.0) return getToColor(uv);
66
+ float t = progress;
67
+
68
+ vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
69
+ // the crest points up the frame, or to the left when the wave travels straight up or down
70
+ vec2 up = vec2(-dir.y, dir.x);
71
+ if (up.y < 0.0 || (up.y == 0.0 && up.x > 0.0)) up = -up;
72
+ // half extents of the frame along the travel and across it, in frame heights
73
+ float e = 0.5 * (abs(dir.x) * ratio + abs(dir.y));
74
+ float w = 0.5 * (abs(up.x) * ratio + abs(up.y));
75
+ // in wave heights: u along the travel, v from the trough (0) to the crest (1)
76
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0) / (2.0 * w);
77
+ vec2 q = vec2(dot(p, dir), dot(p, up) + 0.5);
78
+ float E = e / (2.0 * w);
79
+
80
+ float R = max(curl, 0.01);
81
+ // radius of the hollow at the back of the curl, where it meets the face
82
+ float Rb = 0.5 * R;
83
+ // the lip pitches forward, then curls further down as the wave travels
84
+ float tipAngle = PI * (0.08 - 0.5 * smoothstep(0.0, 0.85, t));
85
+ // the wave sweeps from fully ahead of the frame, spray included, to fully past it, tinted water included
86
+ float travel = mix(t, t * t * (3.0 - 2.0 * t), 0.25);
87
+ vec2 C = vec2(mix(-E - R - REACH, E + Rb + TRAIL + BAND, travel), 1.02 - R);
88
+
89
+ // polar coordinates around the center of the curl
90
+ vec2 d = q - C;
91
+ // atan is undefined at the very center
92
+ if (d.x == 0.0) d.x = 1e-6;
93
+ float r = length(d);
94
+ float ang = atan(d.y, d.x);
95
+ // the inner surface of the curl spirals in from the tip of the lip (zero thickness) to the back of the hollow
96
+ float k = clamp((ang - tipAngle) / (PI - tipAngle), 0.0, 1.0);
97
+ float rIn = R - (R - Rb) * (1.0 - (1.0 - k) * (1.0 - k));
98
+ bool curled = ang >= tipAngle;
99
+ // the face below the curl: vertical where it meets the hollow, its base trailing behind
100
+ float s = 1.0 - clamp(q.y / C.y, 0.0, 1.0);
101
+ float face = C.x - Rb - TRAIL * s * s;
102
+ float behind = face - q.x; // > 0 behind the face
103
+
104
+ float wet;
105
+ if (curled) {
106
+ wet = smoothstep(-AA, AA, r - rIn) * (ang > 0.5 * PI ? 1.0 : 1.0 - smoothstep(-AA, AA, r - R));
107
+ } else {
108
+ wet = smoothstep(-AA, AA, behind);
109
+ }
110
+ // the lip: the curl in front of the top of the wave
111
+ float lip = curled ? 1.0 - smoothstep(0.5 * PI - 0.3, 0.5 * PI + 0.5, ang) : 0.0;
112
+
113
+ float n = vnoise(q * vec2(14.0, 10.0) + vec2(-9.0 * t, 3.0 * t));
114
+
115
+ // outgoing image, darkened in the hollow and in the shadow of the overhang just ahead of it
116
+ vec4 a = getFromColor(uv);
117
+ float gap = max(min(r - R, -behind), 0.0);
118
+ float shade = 0.55 * exp(-gap / 0.1) * (1.0 - smoothstep(0.0, REACH, gap)) * smoothstep(0.0, 0.6, q.y) * (1.0 - smoothstep(C.y + 0.2 * R, C.y + 1.1 * R, q.y));
119
+ shade += 0.25 * (1.0 - smoothstep(0.0, R, r));
120
+ a.rgb *= 1.0 - shade;
121
+ // spray thrown ahead of the crest, drifting forward and falling, and a mist along it
122
+ float fwd = max(r - R, 0.0);
123
+ float zone = smoothstep(tipAngle - 0.4, tipAngle + 0.2, ang) * (1.0 - smoothstep(0.0, REACH, fwd)) * step(0.0, r - R);
124
+ // stretched along the throw, so the droplets streak forward
125
+ vec2 sq = (d - t * vec2(0.5, -0.25)) * vec2(0.55, 1.0);
126
+ float thin = exp(-fwd / 0.12);
127
+ float spray = droplets(sq, 0.02, foam * thin, 1.0) + 0.6 * droplets(sq * 1.6 + 3.1, 0.02, foam * thin, 7.0);
128
+ // the mist hugs the outside of the lip only
129
+ float mist = foam * n * n * exp(-fwd / 0.06) * (1.0 - smoothstep(0.0, REACH, fwd)) * smoothstep(-AA, AA, r - R) * smoothstep(tipAngle, tipAngle + 0.3, ang);
130
+ a.rgb = mix(a.rgb, foamColor.rgb, foamColor.a * clamp(spray * zone + mist, 0.0, 1.0));
131
+
132
+ // incoming image behind the face, bent and tinted by the water, clearing further behind
133
+ float band = max(1.0 - smoothstep(0.05, BAND, behind), lip);
134
+ float bend = refraction * band * band;
135
+ vec2 off = bend * (dir * sin(17.0 * q.y + 2.0 * sin(9.0 * q.x) - 6.0 * t) + up * cos(13.0 * q.x - 5.0 * t));
136
+ vec4 b = getToColor(mirror(uv + off * 2.0 * w / vec2(ratio, 1.0)));
137
+ float luma = dot(b.rgb, vec3(0.299, 0.587, 0.114));
138
+ // lit near the top of the face and through the thin lip, darker on the underside of the lip
139
+ vec3 tinted = water.rgb * (0.4 + 0.9 * luma) * (1.0 + 0.6 * q.y);
140
+ tinted += 0.18 * lip * (1.0 - k) * vec3(0.5, 1.0, 0.9);
141
+ tinted *= 1.0 - 0.35 * lip * (1.0 - smoothstep(0.0, 0.06, r - rIn));
142
+ // a bright line along the surface of the face, fading up into the hollow
143
+ tinted += 0.35 * (curled ? k * (1.0 - smoothstep(0.0, 0.015, r - rIn)) : 1.0 - smoothstep(0.0, 0.015, behind)) * vec3(0.7, 0.95, 1.0);
144
+ b.rgb = mix(b.rgb, tinted, water.a * band);
145
+
146
+ // foam: whitewater along the outer edge of the lip, and churning at the base of the face
147
+ float crest = curled ? (1.0 - smoothstep(0.01, 0.02 + 0.12 * n, abs(R - r))) * smoothstep(tipAngle, tipAngle + 0.4, ang) * (1.0 - smoothstep(0.5 * PI + 0.2, 0.5 * PI + 0.8, ang)) : 0.0;
148
+ float churn = (1.0 - smoothstep(0.0, 0.15 + 0.1 * n, q.y)) * (1.0 - smoothstep(0.0, 0.3, abs(behind))) * smoothstep(0.3, 0.7, n);
149
+ b.rgb = mix(b.rgb, foamColor.rgb, foamColor.a * clamp(foam * 1.5 * (crest + churn), 0.0, 1.0));
150
+
151
+ // mixed premultiplied, so transparent images do not bleed their color
152
+ vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), wet);
153
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
154
+ }