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
@@ -0,0 +1,104 @@
1
+ // KeyholeWipe — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/KeyholeWipe.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: A keyhole grows steadily from the center until the incoming image fills the frame, its bevelled rim and inner shadow making it read as a hole cut in a plate
5
+ // Tags: shape, wipe, keyhole, iris, reveal
6
+
7
+ // @param Center of the keyhole
8
+ uniform vec2 center; // = vec2(0.5, 0.5)
9
+ // @range(0, 1) Strength of the bevelled rim around the keyhole and the shadow inside it (0 for a clean cut)
10
+ uniform float rim; // = 0.6
11
+ // @range(0, 0.05) Softness of the keyhole's edge
12
+ uniform float smoothness; // = 0.002
13
+
14
+ // The keyhole, in its own units (0.85 tall, from y = -0.4 to 0.45): a round head on top of a slot
15
+ // that widens downward.
16
+ #define HEAD vec2(0.0, 0.2)
17
+ #define HEAD_R 0.25
18
+ #define SLOT_Y -0.17
19
+ const float SLOT_HE = 0.23;
20
+ const float SLOT_TOP = 0.085;
21
+ const float SLOT_BOTTOM = 0.165;
22
+ const float SLOT_ROUND = 0.025;
23
+ // height of the point the keyhole grows around, in its head
24
+ const float GROW_Y = 0.1;
25
+ // widths of the bevel and of the rim's shadows, in keyhole units
26
+ const float BEVEL = 0.028;
27
+ const float SHADE = 0.05;
28
+
29
+ float dot2(vec2 v) { return dot(v, v); }
30
+
31
+ // Signed distance to the slot, a trapezoid with rounded corners
32
+ float sdSlot(vec2 p) {
33
+ p.y -= SLOT_Y;
34
+ float r1 = SLOT_BOTTOM - SLOT_ROUND;
35
+ float r2 = SLOT_TOP - SLOT_ROUND;
36
+ float he = SLOT_HE - SLOT_ROUND;
37
+ vec2 k1 = vec2(r2, he);
38
+ vec2 k2 = vec2(r2 - r1, 2.0 * he);
39
+ p.x = abs(p.x);
40
+ vec2 ca = vec2(p.x - min(p.x, p.y < 0.0 ? r1 : r2), abs(p.y) - he);
41
+ vec2 cb = p - k1 + k2 * clamp(dot(k1 - p, k2) / dot2(k2), 0.0, 1.0);
42
+ float s = (cb.x < 0.0 && ca.y < 0.0) ? -1.0 : 1.0;
43
+ return s * sqrt(min(dot2(ca), dot2(cb))) - SLOT_ROUND;
44
+ }
45
+
46
+ float sdKeyhole(vec2 p) {
47
+ return min(length(p - HEAD) - HEAD_R, sdSlot(p));
48
+ }
49
+
50
+ // Scale at which the keyhole's head, a disk, reaches the point p (seen from the growth point):
51
+ // the root of |p - s h| = s HEAD_R, h being the head's center
52
+ float reach(vec2 p) {
53
+ vec2 h = HEAD - vec2(0.0, GROW_Y);
54
+ float k = HEAD_R * HEAD_R - dot2(h);
55
+ float b = dot(p, h);
56
+ return (sqrt(b * b + k * dot2(p)) - b) / k;
57
+ }
58
+
59
+ vec4 transition (vec2 uv) {
60
+ vec4 a = getFromColor(uv);
61
+ vec4 b = getToColor(uv);
62
+ vec2 asp = vec2(ratio, 1.0);
63
+ vec2 c = center * asp;
64
+ float sm = max(smoothness, 0.0005);
65
+
66
+ // The keyhole grows around a point of its head, at the center. It covers the frame (grown by a
67
+ // margin, so the soft edge is past it) once its head, a disk, reaches the frame's corners.
68
+ vec2 o = c;
69
+ vec2 lo = -o - 2.5 * sm;
70
+ vec2 hi = asp - o + 2.5 * sm;
71
+ float full = max(max(reach(lo), reach(hi)), max(reach(vec2(lo.x, hi.y)), reach(vec2(hi.x, lo.y))));
72
+
73
+ // The keyhole grows linearly until it fills the frame
74
+ float p = progress;
75
+ float s = full * p;
76
+ if (s <= 0.0) return a;
77
+
78
+ vec2 q = (uv * asp - o) / s + vec2(0.0, GROW_Y);
79
+ float d = sdKeyhole(q);
80
+ // the soft edge is just inside the outline, so a tiny keyhole shows nothing
81
+ float hole = 1.0 - smoothstep(-sm, sm, d * s + sm);
82
+
83
+ float fade = smoothstep(0.0, 0.08, p) * (1.0 - smoothstep(0.7, 1.0, p));
84
+ float rimA = rim * fade;
85
+ if (rimA > 0.0) {
86
+ // Plate around the hole: a bevel lit from above going down into the hole, and a soft shadow
87
+ // on its rim
88
+ vec2 e = vec2(0.002, 0.0);
89
+ vec2 n = vec2(sdKeyhole(q + e) - sdKeyhole(q - e), sdKeyhole(q + e.yx) - sdKeyhole(q - e.yx));
90
+ float lit = -dot(n / max(length(n), 1e-6), vec2(-0.35, 0.94));
91
+ float bevel = 1.0 - smoothstep(0.0, BEVEL, d);
92
+ float shade = exp(-max(d, 0.0) / SHADE);
93
+ a.rgb *= 1.0 - rimA * (0.35 * shade + bevel * 0.4 * max(-lit, 0.0));
94
+ a.rgb += rimA * bevel * bevel * 0.3 * max(lit, 0.0) * a.a;
95
+
96
+ // Inside the hole: the plate's thickness shades the incoming image under the top of the rim,
97
+ // with a softer vignette all around the edge
98
+ float wall = smoothstep(-0.03, 0.03, sdKeyhole(q + vec2(0.0, 0.05)));
99
+ float vign = exp(min(d, 0.0) / SHADE);
100
+ b.rgb *= 1.0 - rimA * (0.5 * wall + 0.3 * vign);
101
+ }
102
+
103
+ return mix(a, b, hole);
104
+ }
@@ -0,0 +1,127 @@
1
+ // LedWall — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/LedWall.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The picture zooms into a giant LED screen of round glowing diodes on a dark panel; a refresh wave sweeps across it, each diode flicking with a bright pop as it switches to the incoming image, then the diodes melt back into the plain picture
5
+ // Tags: dots, glow, grid, wave
6
+
7
+ // @range(6, 80) Number of diodes across the shorter side
8
+ uniform float cells; // = 24.0
9
+ // @range(0, 1) Strength of the glow bleeding from the diodes into the dark panel
10
+ uniform float glow; // = 0.6
11
+ // @range(0, 1) Brightness of the flash of each diode as it switches
12
+ uniform float flash; // = 0.7
13
+ // @range(0, 0.5) How much the picture zooms in while it is a screen
14
+ uniform float zoom; // = 0.15
15
+ // @param Each diode is made of red, green and blue sub-diodes
16
+ uniform bool triads; // = false
17
+ // @param Direction in which the refresh wave sweeps across the screen
18
+ uniform vec2 direction; // = vec2(1.0, 0.0)
19
+ // @color Color of the panel between the diodes
20
+ uniform vec4 panel; // = vec4(0.02, 0.02, 0.025, 1.0)
21
+
22
+ // radius of a lit diode, in cells
23
+ const float RADIUS = 0.36;
24
+ // width of the soft edge of the diodes, in cells
25
+ const float EDGE = 0.05;
26
+
27
+ float hash12(vec2 p) {
28
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
29
+ p3 += dot(p3, p3.yzx + 33.33);
30
+ return fract((p3.x + p3.y) * p3.z);
31
+ }
32
+
33
+ // folds uv back into 0..1, so the frame stays filled
34
+ vec2 mirrored(vec2 v) {
35
+ vec2 m = mod(v, 2.0);
36
+ return mix(m, 2.0 - m, step(1.0, m));
37
+ }
38
+
39
+ // 1 inside a disc of radius r, with a soft edge
40
+ float disc(float d, float r) {
41
+ return 1.0 - smoothstep(r - EDGE, r + EDGE, d);
42
+ }
43
+
44
+ vec4 transition(vec2 uv) {
45
+ // how much the picture is a screen: it resolves into diodes until 0.3, and back from 0.7
46
+ float led = smoothstep(0.0, 0.3, progress) * (1.0 - smoothstep(0.7, 1.0, progress));
47
+ float z = 1.0 + max(zoom, 0.0) * smoothstep(0.0, 0.45, progress) * (1.0 - smoothstep(0.55, 1.0, progress));
48
+ vec2 p = 0.5 + (uv - 0.5) / z;
49
+
50
+ // the grid of diodes, in cells, with a diode at the center of the frame
51
+ vec2 aspect = vec2(ratio, 1.0);
52
+ vec2 toCells = aspect * max(cells, 1.0) / min(ratio, 1.0);
53
+ vec2 q = (p - 0.5) * toCells;
54
+ vec2 id = floor(q + 0.5);
55
+ vec2 local = q - id;
56
+ vec2 side = vec2(local.x < 0.0 ? -1.0 : 1.0, local.y < 0.0 ? -1.0 : 1.0);
57
+
58
+ // the refresh wave runs along dir, from 0 to 1 across the frame
59
+ vec2 dir = length(direction) > 1e-4 ? normalize(direction) : vec2(1.0, 0.0);
60
+ float extent = abs(dir.x) * ratio + abs(dir.y);
61
+
62
+ vec4 own = vec4(0.0);
63
+ float ownSwitch = 0.0;
64
+ vec4 halo = vec4(0.0);
65
+ float haloWeight = 0.0;
66
+ // this diode and the three nearest ones, whose glow reaches this point
67
+ for (int i = 0; i < 4; i++) {
68
+ // without glow, only this diode matters
69
+ if (i > 0 && glow * led <= 0.0) break;
70
+ vec2 o = vec2(mod(float(i), 2.0), floor(float(i) / 2.0)) * side;
71
+ vec2 c = id + o;
72
+ vec2 cuv = c / toCells + 0.5;
73
+ // where the diode is seen in the frame, so that the wave crosses the visible screen
74
+ float s = clamp(dot((cuv - 0.5) * z * aspect, dir) / extent + 0.5, 0.0, 1.0);
75
+ float when = 0.2 + 0.52 * s + 0.05 * (hash12(c + 71.0) - 0.5);
76
+ float sw = smoothstep(when - 0.012, when + 0.012, progress);
77
+ // the diode blinks off just before it switches, then pops bright
78
+ float x = (progress - when) / 0.018;
79
+ float pop = exp(-x * x) - 0.5 * exp(-(x + 1.6) * (x + 1.6));
80
+ vec2 suv = mirrored(cuv);
81
+ vec4 col = mix(getFromColor(suv), getToColor(suv), sw);
82
+ col.rgb = col.rgb * (1.0 + 1.4 * flash * pop) + 0.2 * flash * max(pop, 0.0);
83
+ if (i == 0) {
84
+ own = col;
85
+ ownSwitch = sw;
86
+ }
87
+ float d = length(local - o);
88
+ float w = 0.9 * glow * exp(-6.0 * max(d - RADIUS, 0.0)) * (1.0 + 0.8 * flash * max(pop, 0.0));
89
+ // the neighbors fade out where the next ones in the other direction take over, so the glow has no seam
90
+ if (o.x != 0.0) w *= smoothstep(0.0, 0.2, abs(local.x));
91
+ if (o.y != 0.0) w *= smoothstep(0.0, 0.2, abs(local.y));
92
+ halo += w * col;
93
+ haloWeight += w;
94
+ }
95
+
96
+ // the plain picture, switched along with its diode
97
+ vec4 plain = mix(getFromColor(p), getToColor(p), ownSwitch);
98
+ float d = length(local);
99
+ // the diodes cover their whole cell with the plain picture when led = 0: the dark panel
100
+ // shows up first between them, then they light up with the color of their center
101
+ float r = mix(0.8, RADIUS, smoothstep(0.0, 0.6, led));
102
+ vec4 gap = vec4(panel.rgb, panel.a * own.a);
103
+ if (haloWeight > 0.0) {
104
+ gap = mix(gap, halo / haloWeight, clamp(haloWeight * led, 0.0, 1.0));
105
+ }
106
+ vec4 body = own;
107
+ if (triads) {
108
+ // three sub-diodes on the panel, red at the top, green and blue below
109
+ vec3 sub = vec3(
110
+ disc(length(local - vec2(0.0, 0.15)), 0.2),
111
+ disc(length(local - vec2(-0.13, -0.075)), 0.2),
112
+ disc(length(local - vec2(0.13, -0.075)), 0.2));
113
+ float m = max(sub.r, max(sub.g, sub.b));
114
+ body = vec4(gap.rgb * (1.0 - m) + own.rgb * 1.5 * sub, mix(gap.a, own.a, m));
115
+ // the sub-diodes reach out to 0.4 cells
116
+ r = max(r, 0.45);
117
+ } else {
118
+ // brighter at the core of the diode
119
+ float k = clamp(d / RADIUS, 0.0, 1.0);
120
+ body.rgb *= 0.8 + 0.45 * (1.0 - k * k);
121
+ }
122
+ // the color of the center spreads from it over the diode
123
+ float lit = smoothstep(0.0, 0.8, led);
124
+ body = mix(plain, body, lit * mix(1.0, lit, smoothstep(0.0, 0.7, d)));
125
+ vec4 color = mix(gap, body, disc(d, r));
126
+ return clamp(color, 0.0, 1.0);
127
+ }
@@ -0,0 +1,200 @@
1
+ // LightningFlash — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/LightningFlash.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: Forked lightning bolts crack down from the top of the frame, the screen flashes white in a few stuttering strobes, and the incoming image appears lit by the last flickers as they fade out
5
+ // Tags: light, flash, weather, strobe
6
+
7
+ // @range(1, 3, 1) Number of bolts: the main one strikes the ground, the others fork out higher in the sky
8
+ uniform int bolts; // = 2
9
+ // @range(0, 1) Where the main bolt strikes, from the left (0) to the right (1) of the frame
10
+ uniform float strike; // = 0.55
11
+ // @range(0, 100, 1) Changes the shape of the bolts
12
+ uniform float seed; // = 0.0
13
+ // @color Color of the light, added to the images
14
+ uniform vec3 color; // = vec3(0.75, 0.85, 1.0)
15
+ // @range(0, 1) Size and brightness of the glow around the bolts
16
+ uniform float glow; // = 0.5
17
+ // @range(1, 4, 1) Number of strobes; the images switch during the brightest one
18
+ uniform int flashes; // = 3
19
+
20
+ // the bolts crack down until this time, then the strobes start
21
+ const float LEADER = 0.3;
22
+
23
+ float hash(vec2 p) {
24
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
25
+ p3 += dot(p3, p3.yzx + 33.33);
26
+ return fract((p3.x + p3.y) * p3.z);
27
+ }
28
+
29
+ // a value noise that is linear between its cells: a jagged polyline, centered on 0
30
+ float jag(float s, float k) {
31
+ float i = floor(s);
32
+ return mix(hash(vec2(i, k)), hash(vec2(i + 1.0, k)), fract(s)) - 0.5;
33
+ }
34
+
35
+ // the zigzag of a bolt around its straight line, at height y (narrower in a portrait frame)
36
+ float zigzag(float y, float k) {
37
+ return min(ratio, 1.0) * (0.15 * jag(y * 5.0, k) + 0.06 * jag(y * 13.0, k + 1.0) + 0.03 * jag(y * 31.0, k + 2.0) + 0.012 * jag(y * 67.0, k + 3.0));
38
+ }
39
+
40
+ // the x of a bolt at height y: from x0 at the top (y = 1) to x1 at its end (y = y1),
41
+ // given z0 and z1, its zigzag at both ends
42
+ float boltX(float y, float x0, float x1, float y1, float z0, float z1, float k) {
43
+ float t = (1.0 - y) / (1.0 - y1);
44
+ return mix(x0 - z0, x1 - z1, t) + zigzag(y, k);
45
+ }
46
+
47
+ // the x of a branch at height y: it leaves its bolt at (xb, yb), where its own zigzag is zb,
48
+ // and drifts sideways by dir per unit of height
49
+ float branchX(float y, float xb, float yb, float zb, float dir, float k) {
50
+ return xb + dir * (yb - y) + 0.6 * (zigzag(y, k) - zb);
51
+ }
52
+
53
+ // distance to a curve x = f(y), knowing its x and its slope at the pixel's height,
54
+ // and how far above or below its ends the pixel is; the slope only corrects the distance
55
+ // close to the curve, so the glow farther away does not streak along the zigzags
56
+ float curveDist(vec2 q, float x, float slope, float outside) {
57
+ float dx = abs(q.x - x);
58
+ float d = dx * mix(inversesqrt(1.0 + slope * slope), 1.0, smoothstep(0.0, 0.08, dx));
59
+ return length(vec2(d, max(outside, 0.0)));
60
+ }
61
+
62
+ // a strobe at time t0: a quick rise, a plateau of length hold, then a decay
63
+ float pulse(float p, float t0, float hold, float decay) {
64
+ float x = p - t0;
65
+ if (x < 0.0) return smoothstep(-0.012, 0.0, x);
66
+ return exp(-max(x - hold, 0.0) / decay);
67
+ }
68
+
69
+ vec4 transition(vec2 uv) {
70
+ float p = progress;
71
+ vec2 q = vec2(uv.x * ratio, uv.y);
72
+ // (seeds far apart, so that neighboring seeds share no hash keys)
73
+ float k0 = floor(seed) * 61.0;
74
+ int nb = bolts < 1 ? 1 : (bolts > 3 ? 3 : bolts);
75
+ int nf = flashes < 1 ? 1 : (flashes > 4 ? 4 : flashes);
76
+ // the images switch during the brightest strobe, the second one (or the only one)
77
+ int cut = nf > 1 ? 1 : 0;
78
+
79
+ // the strobes, a bit irregular; the bolts are lit by all of them, the screen mostly by the brightest
80
+ float flash = 0.0;
81
+ float lit = 0.0;
82
+ float tCut = LEADER;
83
+ float tLast = LEADER;
84
+ float t = LEADER;
85
+ for (int i = 0; i < 4; i++) {
86
+ if (i < nf) {
87
+ bool isCut = i == cut;
88
+ float amp = isCut ? 1.0 : (i < cut ? 0.55 : 0.7 * pow(0.75, float(i - cut - 1)));
89
+ float s = amp * pulse(p, t, isCut ? 0.025 : 0.004, isCut ? 0.03 : 0.022);
90
+ flash = max(flash, s);
91
+ lit = max(lit, pulse(p, t, 0.01, 0.045));
92
+ if (isCut) tCut = t;
93
+ tLast = t;
94
+ t += (isCut ? 0.12 : 0.08) + 0.04 * hash(vec2(float(i), k0 + 5.0));
95
+ }
96
+ }
97
+ // the stutter: the light jumps from one level to another a few times per strobe
98
+ float stutter = mix(0.7, 1.0, hash(vec2(floor(p * 70.0), k0 + 9.0)));
99
+ flash *= stutter;
100
+ // the brightest strobe whites the screen out while the images switch
101
+ float whiteout = pulse(p, tCut, 0.025, 0.02);
102
+ // then a few last flickers, fading out
103
+ float tail = p > tLast ? exp(-(p - tLast) / 0.1) * smoothstep(0.03, 0.06, p - tLast) : 0.0;
104
+ flash = max(flash, 0.35 * tail * step(0.45, hash(vec2(floor(p * 40.0), k0 + 13.0))));
105
+
106
+ // the bolts crack down in a few jumps while faintly lit, then light up with the strobes and go out
107
+ float grow = clamp(p / LEADER, 0.0, 1.0);
108
+ grow = (floor(grow * 7.0) + smoothstep(0.0, 1.0, fract(grow * 7.0))) / 7.0;
109
+ float faint = 0.5 * mix(0.6, 1.0, hash(vec2(floor(p * 50.0), k0 + 11.0)));
110
+ float boltLight = p < LEADER ? faint * smoothstep(0.0, 0.06, p) : max(lit * stutter, faint * exp(-(p - LEADER) / 0.12));
111
+ boltLight = max(boltLight, 0.6 * flash * tail);
112
+ boltLight *= 1.0 - smoothstep(tLast + 0.1, tLast + 0.3, p);
113
+
114
+ // the bolts: the main one strikes the ground at strike, the others stop in the sky
115
+ float core = 0.0;
116
+ float halo = 0.0;
117
+ float near = 10.0;
118
+ bool lightsOn = boltLight > 0.0 || flash > 0.0;
119
+ for (int b = 0; b < 3; b++) {
120
+ if (b < nb && lightsOn) {
121
+ float fb = float(b);
122
+ float kb = k0 + fb * 17.0;
123
+ float x1 = strike * ratio;
124
+ float y1 = -0.05;
125
+ float bright = 1.0;
126
+ if (b > 0) {
127
+ // the second bolt goes to the roomier side, the third to the other side if there is room there
128
+ float roomy = strike < 0.5 ? 1.0 : -1.0;
129
+ bool cramped = min(strike, 1.0 - strike) < 0.25;
130
+ float side = b == 1 || cramped ? roomy : -roomy;
131
+ float dist = b == 2 && cramped ? 0.5 : 0.22;
132
+ x1 = clamp(x1 + side * ratio * (dist + 0.12 * hash(vec2(fb, kb))), 0.08 * ratio, 0.92 * ratio);
133
+ y1 = 0.25 + 0.25 * hash(vec2(fb, kb + 1.0));
134
+ bright = 0.7;
135
+ }
136
+ float x0 = clamp(x1 + (hash(vec2(fb, kb + 2.0)) - 0.5) * 0.5 * min(ratio, 1.0), 0.1 * ratio, 0.9 * ratio);
137
+ // the tip of the bolt while it cracks down
138
+ float tip = mix(1.02, y1, grow);
139
+ // (the slope is measured over a few pixels, so it changes smoothly at the corners)
140
+ float e = 0.01;
141
+ float z0 = zigzag(1.0, kb);
142
+ float z1 = zigzag(y1, kb);
143
+ float x = boltX(q.y, x0, x1, y1, z0, z1, kb);
144
+ float slope = (boltX(q.y + e, x0, x1, y1, z0, z1, kb) - boltX(q.y - e, x0, x1, y1, z0, z1, kb)) / (2.0 * e);
145
+ float d = curveDist(q, x, slope, max(max(y1, tip) - q.y, q.y - 1.05));
146
+ near = min(near, d);
147
+ float w = 0.003 * mix(1.0, 0.7, fb / 2.0);
148
+ core += bright * exp(-d * d / (w * w));
149
+ halo += bright * (0.7 * exp(-d * 24.0) + 0.25 * exp(-d * 6.0));
150
+ // three branches, leaving the bolt on either side and fading toward their ends
151
+ for (int j = 0; j < 3; j++) {
152
+ float fj = float(j);
153
+ float kj = kb + 3.0 + fj * 5.0;
154
+ float tb = 0.12 + 0.2 * fj + 0.15 * hash(vec2(fj, kj));
155
+ float yb = mix(1.0, y1, tb);
156
+ float len = (0.3 + 0.25 * hash(vec2(fj, kj + 1.0))) * (1.0 - tb) * (1.0 - y1);
157
+ float dir = (j == 1 ? -1.0 : 1.0) * (0.2 + 0.45 * hash(vec2(fj, kj + 2.0))) * min(ratio, 1.0);
158
+ float xb = boltX(yb, x0, x1, y1, z0, z1, kb);
159
+ float zb = zigzag(yb, kj);
160
+ float bx = branchX(q.y, xb, yb, zb, dir, kj);
161
+ float bs = (branchX(q.y + e, xb, yb, zb, dir, kj) - branchX(q.y - e, xb, yb, zb, dir, kj)) / (2.0 * e);
162
+ float bd = curveDist(q, bx, bs, max(max(yb - len, tip) - q.y, q.y - yb));
163
+ near = min(near, bd);
164
+ float along = clamp((yb - q.y) / len, 0.0, 1.0);
165
+ float fade = bright * (1.0 - 0.8 * along);
166
+ float bw = w * mix(0.8, 0.4, along);
167
+ core += fade * exp(-bd * bd / (bw * bw));
168
+ halo += fade * 0.6 * (0.7 * exp(-bd * 24.0) + 0.25 * exp(-bd * 6.0));
169
+ }
170
+ }
171
+ }
172
+
173
+ // the outgoing image gives way to the incoming one at the brightest strobe, hidden by it
174
+ float m = smoothstep(tCut, tCut + 0.025, p);
175
+ vec4 c = vec4(0.0);
176
+ if (m < 1.0) {
177
+ vec4 a = getFromColor(uv);
178
+ c += (1.0 - m) * vec4(a.rgb * a.a, a.a);
179
+ }
180
+ if (m > 0.0) {
181
+ vec4 a = getToColor(uv);
182
+ c += m * vec4(a.rgb * a.a, a.a);
183
+ }
184
+ if (c.a <= 0.0) return vec4(0.0);
185
+ vec3 col = c.rgb / c.a;
186
+
187
+ // the effect fades in at the start and is gone at the end
188
+ float live = smoothstep(0.0, 0.03, p) * (1.0 - smoothstep(0.85, 1.0, p));
189
+ // the sky darkens a little as the storm builds, then the strobes overexpose the image,
190
+ // more around the bolts, and the bolts glow over it
191
+ float dim = 0.4 * smoothstep(0.0, LEADER, p) * (1.0 - smoothstep(tCut, tLast + 0.15, p));
192
+ float f = flash * mix(0.6 + 0.4 * exp(-near * 4.0), 1.0, smoothstep(0.6, 1.0, flash));
193
+ col *= 1.0 - dim * live;
194
+ col = col * (1.0 + 2.5 * f * live) + color * (1.1 * f * live);
195
+ float g = 0.4 + 1.2 * glow;
196
+ vec3 light = mix(color, vec3(1.0), 0.75) * min(core, 1.5) * 1.6 + color * g * halo;
197
+ col += light * boltLight * live;
198
+ col = mix(col, vec3(1.0), 0.92 * whiteout * live);
199
+ return vec4(clamp(col, 0.0, 1.0), c.a);
200
+ }
@@ -0,0 +1,75 @@
1
+ // MoireWipe — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/MoireWipe.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: Two sets of fine concentric rings, centered on two points that drift toward each other, overlay the image and interfere into a shifting moire of wide bands; the bands open onto the incoming image and widen until it fills the frame, while the thin dark and light ring lines fade away
5
+ // Tags: moire, rings, interference, pattern, graphic, reveal
6
+
7
+ // @range(10, 80) Number of rings per frame height in each set
8
+ uniform float density; // = 36.0
9
+ // @range(1, 8) How many moire bands the rings make at the start; they get fewer and wider as the centers come together
10
+ uniform float bands; // = 3.0
11
+ // @range(-1, 1) How far the two centers turn around each other, in turns
12
+ uniform float drift; // = 0.25
13
+ // @range(0, 1) Strength of the ring lines drawn over the image
14
+ uniform float lines; // = 0.5
15
+
16
+ const float PI = 3.141592653589793;
17
+ // half width of the antialiased edges, in frame heights
18
+ const float AA = 0.0012;
19
+ // half width of a ring line, in ring spacings
20
+ const float LINE = 0.1;
21
+ // widest antialiased edge of the bands, in bands, which also sets when they start and finish
22
+ // opening
23
+ const float EDGE = 0.05;
24
+ // angle of the line between the two centers at the start, in radians
25
+ const float START = 0.35;
26
+ // strength of the ring lines at lines = 1, so the image always shows through them
27
+ const float INK = 0.7;
28
+
29
+ // coverage of the ring lines at radius r, box-filtered over the antialiasing width, and
30
+ // faded to their mean coverage when the rings get too fine to resolve
31
+ float ringLines(float r, float f) {
32
+ float q = abs(fract(r * f + 0.5) - 0.5);
33
+ float aa = AA * f;
34
+ float c = clamp((LINE - q) / (2.0 * aa) + 0.5, 0.0, 1.0);
35
+ return mix(c, 2.0 * LINE, clamp(10.0 * aa - 0.5, 0.0, 1.0));
36
+ }
37
+
38
+ vec4 transition(vec2 uv) {
39
+ vec4 a = getFromColor(uv);
40
+ vec4 b = getToColor(uv);
41
+ if (progress <= 0.0) return a;
42
+ if (progress >= 1.0) return b;
43
+
44
+ float t = progress * progress * (3.0 - 2.0 * progress);
45
+ float f = max(density, 1.0);
46
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
47
+
48
+ // the two centers turn around the middle of the frame and come together
49
+ float ang = 2.0 * PI * drift * t + START;
50
+ float k = max(bands, 1.0) * (1.0 - 0.75 * t);
51
+ vec2 axis = vec2(cos(ang), sin(ang)) * 0.5 * k / f;
52
+ float r1 = length(p - axis);
53
+ float r2 = length(p + axis);
54
+ // the second set is slightly finer than the first, which bends the bands into curves
55
+ float f2 = f + 1.2 * k;
56
+
57
+ // the beat of the two ring sets: wide bands where their rings line up, at this distance
58
+ // from the middle of the nearest band, in bands
59
+ float beat = abs(fract(f2 * r2 - f * r1 + 0.5) - 0.5);
60
+ // the bands open from their middles and widen until they cover the frame
61
+ // with an edge antialiased from the analytic gradient of the beat
62
+ vec2 grad = f2 * (p + axis) / max(r2, AA) - f * (p - axis) / max(r1, AA);
63
+ float s = min(AA * length(grad) + 0.004, EDGE);
64
+ float w = mix(-EDGE, 0.5 + EDGE, t);
65
+ float m = 1.0 - smoothstep(w - s, w + s, beat);
66
+
67
+ vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), m);
68
+
69
+ // the thin lines of both sets, dark over the outgoing image and light over the incoming
70
+ // one, fade in and out
71
+ float o = INK * clamp(lines, 0.0, 1.0) * sin(PI * t);
72
+ float l = 1.0 - (1.0 - o * ringLines(r1, f)) * (1.0 - o * ringLines(r2, f2));
73
+ c.rgb = mix(c.rgb, vec3(c.a * m), l);
74
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
75
+ }
@@ -0,0 +1,168 @@
1
+ // PaperFold — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/PaperFold.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The outgoing image is a sheet of paper that folds in half in 3D along a vertical crease, then in half again along a horizontal one, its lit and shaded faces turning to show the back of the paper, and the small folded packet flies off the frame, leaving its shadow on the incoming image underneath
5
+ // Tags: paper, fold, 3d, shadow
6
+
7
+ // @param Direction the folded packet flies off toward
8
+ uniform vec2 direction; // = vec2(1.0, 0.5)
9
+ // @range(0, 1) How much the sheet tilts and recedes while it folds, so that the folds are seen in 3D
10
+ uniform float tilt; // = 0.6
11
+ // @range(0, 1) How much the faces darken as they turn away from the light, and the shadows they cast
12
+ uniform float shading; // = 0.6
13
+ // @color Color of the back of the paper, through which the print faintly shows
14
+ uniform vec4 paper; // = vec4(0.95, 0.94, 0.9, 1.0)
15
+
16
+ const float PI = 3.141592653589793;
17
+ // width of the anti-aliased edges, as a part of the frame's height
18
+ const float EDGE = 0.0015;
19
+ // how much the print shows through the back of the paper
20
+ const float SHOW = 0.1;
21
+ // width of the shaded crease, in frame heights
22
+ const float CREASE = 0.02;
23
+ // direction of the light, from the top left and the front
24
+ const vec3 LIGHT = vec3(-0.3995, 0.4494, 0.799);
25
+
26
+ vec4 front(vec2 st) {
27
+ return getFromColor(st / vec2(ratio, 1.0));
28
+ }
29
+
30
+ vec4 back(vec2 st) {
31
+ vec4 c = front(st);
32
+ return vec4(mix(paper.rgb, c.rgb, SHOW), c.a * paper.a);
33
+ }
34
+
35
+ // the face of the packet's top layer: the image itself during the first fold, then the back
36
+ // of the right half, laid mirrored over the left half
37
+ vec4 topFace(vec2 st, bool second) {
38
+ return second ? back(vec2(ratio - st.x, st.y)) : front(st);
39
+ }
40
+
41
+ // distance inside the rectangle [0, h] x [0, k] (negative outside)
42
+ float inside(vec2 p, float h, float k) {
43
+ return min(min(p.x, h - p.x), min(p.y, k - p.y));
44
+ }
45
+
46
+ // The sheet in its own frame: a flat part [0, h] x [0, k] lying at z = 0 and a flap of the same
47
+ // size hinged on its edge x = h, turned toward the viewer so that it lies along `along`, with the
48
+ // normal n. During the second fold, x and y are swapped so that the crease is always along y.
49
+ // Where the ray o + t * v meets the flap's plane: (t, distance from the hinge, y), t < 0 if never.
50
+ vec3 hitFlap(vec3 o, vec3 v, float h, vec3 n, vec3 along) {
51
+ float den = dot(n, v);
52
+ if (abs(den) < 1e-5) return vec3(-1.0, 0.0, 0.0);
53
+ vec3 hinge = vec3(h, 0.0, 0.0);
54
+ float t = dot(n, hinge - o) / den;
55
+ vec3 q = o + t * v;
56
+ return vec3(t, dot(q - hinge, along), q.y);
57
+ }
58
+
59
+ // how much the point q is shaded, lit by l: by the flap, and by the flat part once it lifts
60
+ // above the incoming image
61
+ float shadowAt(vec3 q, vec3 l, float h, float k, vec3 n, vec3 along) {
62
+ float sh = 0.0;
63
+ if (q.z < -1e-4) {
64
+ float soft = 0.004 - 0.4 * q.z;
65
+ sh = smoothstep(-soft, soft, inside(q.xy - q.z / l.z * l.xy, h, k));
66
+ }
67
+ vec3 hit = hitFlap(q, l, h, n, along);
68
+ if (hit.x > 0.0) {
69
+ float height = hit.x * l.z;
70
+ float soft = 0.004 + 0.3 * height;
71
+ // the flap's shadow appears as it lifts and vanishes as it lands
72
+ sh = max(sh, min(4.0 * n.x * n.x, 1.0) * smoothstep(-soft, soft, inside(hit.yz, h, k)) / (1.0 + 3.0 * height));
73
+ }
74
+ return sh;
75
+ }
76
+
77
+ // a vector of the frame into the frame of the sheet, turned by yaw (around y), pitch (around x)
78
+ // and spin (around z), each given as (cos, sin)
79
+ vec3 toSheet(vec3 v, vec2 yaw, vec2 pitch, vec2 spin) {
80
+ v = vec3(yaw.x * v.x + yaw.y * v.z, v.y, yaw.x * v.z - yaw.y * v.x);
81
+ v = vec3(v.x, pitch.x * v.y + pitch.y * v.z, pitch.x * v.z - pitch.y * v.y);
82
+ return vec3(spin.x * v.x + spin.y * v.y, spin.x * v.y - spin.y * v.x, v.z);
83
+ }
84
+
85
+ vec4 transition(vec2 uv) {
86
+ float w = ratio;
87
+ float shade = clamp(shading, 0.0, 1.0);
88
+ // the two folds, one right after the other, then the flight of the packet
89
+ float s = 2.0 * smoothstep(0.0, 0.62, progress);
90
+ bool second = s > 1.0;
91
+ float x = second ? s - 1.0 : s;
92
+ float a = PI * mix(x, x * x * (3.0 - 2.0 * x), 0.6);
93
+ float f = clamp((progress - 0.5) / 0.47, 0.0, 1.0);
94
+
95
+ // the sheet tilts and recedes while it folds, so that the folds are seen in 3D, and lies flat
96
+ // again as the packet flies off
97
+ float turn = clamp(tilt, 0.0, 1.0) * (smoothstep(0.0, 0.25, progress) - smoothstep(0.4, 0.8, progress));
98
+ vec2 yaw = vec2(cos(0.45 * turn), sin(0.45 * turn));
99
+ vec2 pitch = vec2(cos(0.55 * turn), -sin(0.55 * turn));
100
+ float dist = 2.5 * max(w, 1.0);
101
+ float recede = dist * 0.35 * turn;
102
+
103
+ vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
104
+ // the point of the sheet held in the middle of the frame slides to the middle of the packet
105
+ vec2 c = vec2(0.5 * w - 0.25 * w * min(s, 1.0), 0.5 - 0.25 * max(s - 1.0, 0.0));
106
+ // far enough for the packet and its shadow to leave the frame
107
+ float reach = 0.5 * (abs(dir.x) * w + abs(dir.y)) + length(vec2(0.25 * w, 0.25)) + 0.4;
108
+ float lift = 0.3 * smoothstep(0.0, 0.5, f);
109
+ float turned = (dir.x < 0.0 ? 0.7 : -0.7) * f * f;
110
+ vec2 spin = vec2(cos(turned), sin(turned));
111
+
112
+ // the eye, the ray toward the point of the frame and the light, in the frame of the sheet,
113
+ // where the sheet lies on the plane z = 0 and the incoming image on z = -lift
114
+ vec3 center = vec3(vec2(0.5 * w, 0.5) + dir * reach * f * f, -recede);
115
+ vec3 eye = vec3(0.5 * w, 0.5, dist);
116
+ vec3 e = toSheet(eye - center, yaw, pitch, spin) + vec3(c, 0.0);
117
+ vec3 d = toSheet(vec3(uv.x * w, uv.y, 0.0) - eye, yaw, pitch, spin);
118
+ vec3 l = toSheet(LIGHT, yaw, pitch, spin);
119
+ if (second) {
120
+ e.xy = e.yx;
121
+ d.xy = d.yx;
122
+ l.xy = l.yx;
123
+ }
124
+ float h = second ? 0.5 : 0.5 * w;
125
+ float k = second ? 0.5 * w : 1.0;
126
+ float creased = sin(a);
127
+ vec3 n = vec3(-creased, 0.0, cos(a));
128
+ vec3 along = vec3(cos(a), 0.0, creased);
129
+
130
+ vec4 col = getToColor(uv);
131
+ if (d.z < 0.0) {
132
+ vec3 g = e + d * (e.z + lift) / -d.z;
133
+ // the shadow fades as the packet flies higher
134
+ col.rgb *= 1.0 - 0.7 * shade * (1.0 - f * f) * shadowAt(g, l, h, k, n, along);
135
+ }
136
+
137
+ // the flat part
138
+ float t = d.z < 0.0 ? e.z / -d.z : -1.0;
139
+ vec3 p = e + t * d;
140
+ float m = clamp(inside(p.xy, h, k) / (EDGE * t) + 1.0, 0.0, 1.0);
141
+ if (t > 0.0 && m > 0.0) {
142
+ vec4 img = topFace(second ? p.yx : p.xy, second);
143
+ float sh = shadowAt(p, l, h, k, n, along);
144
+ img.rgb *= (1.0 - 0.7 * shade * sh) * (1.0 - 0.5 * shade * creased * exp(-abs(h - p.x) / CREASE));
145
+ col = mix(col, img, m);
146
+ }
147
+
148
+ // the flap
149
+ vec3 hit = hitFlap(e, d, h, n, along);
150
+ if (hit.x > 0.0) {
151
+ float r = hit.y;
152
+ // edges seen at a grazing angle are narrower on screen
153
+ float dr = dot(along, normalize(d));
154
+ float fore = sqrt(max(1.0 - dr * dr, 0.0025));
155
+ float mf = clamp(min(min(r, h - r) * fore, min(hit.z, k - hit.z)) / (EDGE * hit.x) + 1.0, 0.0, 1.0);
156
+ if (mf > 0.0) {
157
+ bool up = dot(n, e - vec3(h, 0.0, 0.0)) > 0.0;
158
+ vec2 st = vec2(h + r, hit.z);
159
+ if (second) st = st.yx;
160
+ vec4 img = up ? topFace(st, second) : back(st);
161
+ // lit by the light, relative to the sheet lying flat
162
+ float lit = dot(up ? n : -n, l) - l.z;
163
+ img.rgb *= max(1.0 + 0.6 * shade * lit, 0.0) * (1.0 - 0.5 * shade * creased * exp(-abs(r) / CREASE));
164
+ col = mix(col, img, mf);
165
+ }
166
+ }
167
+ return col;
168
+ }