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,205 @@
1
+ // PuzzleCube — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/PuzzleCube.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The frame becomes the face of a twisty cube puzzle: dark gaps open between its cubies, then whole columns and rows of cubies turn a quarter turn around the cube one after another in 3D, each bringing the incoming image from the cube's side to the front, until the gaps close on the incoming image
5
+ // Tags: 3d, rotate, grid
6
+
7
+ // @range(2, 8, 1) Number of cubies along each side of the face
8
+ uniform int size; // = 3
9
+ // @range(0, 0.05) Width of the gaps between the cubies, as a part of the frame's height
10
+ uniform float gap; // = 0.012
11
+ // @range(0, 1) How much the turning sides darken away from the light, and the shadows inside the cube
12
+ uniform float shading; // = 0.6
13
+ // @color Color of the cubies' body, seen in the gaps, on their inner sides and around the cube
14
+ uniform vec4 background; // = vec4(0.04, 0.04, 0.05, 1.0)
15
+
16
+ const float PI = 3.141592653589793;
17
+ // delay between the turns of a group, as a part of a turn
18
+ const float STAGGER = 0.45;
19
+ // width of the anti-aliased edges, in frame heights
20
+ const float EDGE = 0.0012;
21
+
22
+ float gridSize() {
23
+ return float(size < 2 ? 2 : (size > 8 ? 8 : size));
24
+ }
25
+
26
+ // the turns run in 3 groups, one after the other: the even columns, the even rows (counted from the top),
27
+ // then the odd columns; the turns of a group overlap
28
+ float groupLength(float m) {
29
+ return m > 0.0 ? 1.0 + (m - 1.0) * STAGGER : 0.0;
30
+ }
31
+
32
+ // the time in turn units, and the length of the groups of even and odd slices
33
+ vec3 timeline(float n) {
34
+ float lenEven = groupLength(floor((n + 1.0) * 0.5));
35
+ float lenOdd = groupLength(floor(n * 0.5));
36
+ float u = clamp((progress - 0.05) / 0.85, 0.0, 1.0) * (2.0 * lenEven + lenOdd);
37
+ return vec3(u, lenEven, lenOdd);
38
+ }
39
+
40
+ // the turn of a column (isCol) or of a row, 0 at rest to 1 turned
41
+ float turnTime(vec3 tl, bool isCol, float idx, float n) {
42
+ // rows are counted from the top
43
+ float k = isCol ? idx : n - 1.0 - idx;
44
+ bool odd = mod(k, 2.0) > 0.5;
45
+ // the odd rows never turn: the columns already brought the incoming image there
46
+ if (odd && !isCol) return 0.0;
47
+ float start = (odd ? 2.0 * tl.y : (isCol ? 0.0 : tl.y)) + floor(k * 0.5) * STAGGER;
48
+ return clamp(tl.x - start, 0.0, 1.0);
49
+ }
50
+
51
+ // the turn's direction: +1 brings the side of the cube at higher coordinates to the front
52
+ float turnDir(bool isCol, float idx) {
53
+ return mod(idx + (isCol ? 0.0 : 1.0), 2.0) < 0.5 ? 1.0 : -1.0;
54
+ }
55
+
56
+ // eased angle, landing with a little speed left like a click
57
+ float turnAngle(float t) {
58
+ return 0.5 * PI * mix(t, t * t * (3.0 - 2.0 * t), 0.8);
59
+ }
60
+
61
+ // 1 on the cubies' faces, 0 in the gaps, at the point fp of the face (frame heights)
62
+ float faceMask(vec2 fp, float n, float g) {
63
+ if (g <= 0.0) return 1.0;
64
+ vec2 cell = vec2(ratio, 1.0) / n;
65
+ vec2 c = fp / cell;
66
+ vec2 r = floor(c + 0.5);
67
+ // distance to the nearest cubie edge inside the face (the face's own border has no gap)
68
+ vec2 d = abs(c - r) * cell;
69
+ d.x = (r.x < 0.5 || r.x > n - 0.5) ? 1.0 : d.x;
70
+ d.y = (r.y < 0.5 || r.y > n - 0.5) ? 1.0 : d.y;
71
+ float e = min(EDGE, 0.5 * g);
72
+ return smoothstep(0.5 * g - e, 0.5 * g + e, min(d.x, d.y));
73
+ }
74
+
75
+ // does the cubie of the face at fp show the incoming image, from the turns done so far
76
+ bool isDone(vec3 tl, vec2 fp, float n) {
77
+ vec2 cell = clamp(floor(fp / (vec2(ratio, 1.0) / n)), 0.0, n - 1.0);
78
+ return turnTime(tl, true, cell.x, n) >= 1.0 || turnTime(tl, false, cell.y, n) >= 1.0;
79
+ }
80
+
81
+ vec4 sticker(vec2 fp, bool incoming, float light, float n, float g) {
82
+ vec2 uv = clamp(fp / vec2(ratio, 1.0), 0.0, 1.0);
83
+ vec4 img = incoming ? getToColor(uv) : getFromColor(uv);
84
+ vec4 body = vec4(background.rgb * light, background.a);
85
+ return mix(body, vec4(img.rgb * light, img.a), faceMask(fp, n, g));
86
+ }
87
+
88
+ // brightness of a face of normal nrm (across the slices, along the turn, depth) in the turn's space, 1 facing the viewer
89
+ float lighting(vec3 nrm, bool isCol) {
90
+ vec3 l = normalize(vec3(-0.35, 0.55, 1.0));
91
+ if (isCol) l = l.yxz;
92
+ return 1.0 - shading * (1.0 - clamp(dot(nrm, l) / l.z, 0.0, 1.0));
93
+ }
94
+
95
+ vec2 rot(vec2 v, float a) {
96
+ float c = cos(a), s = sin(a);
97
+ return vec2(c * v.x - s * v.y, s * v.x + c * v.y);
98
+ }
99
+
100
+ // casts the ray (o, d), in the turn's space (across the slices, along the turn, depth), onto the slice
101
+ // [a0, a0 + w] turned by the angle a around the middle of the cube (a square section of side S):
102
+ // returns the ray's parameter at the hit (or -1), the face hit (0 front, 1 back, 2 and 3 the sides
103
+ // at higher and lower coordinates along the turn at rest, 4 the slice's ends), and the point hit
104
+ // (across the slices, and across the face, -1 to 1)
105
+ vec4 sliceHit(vec3 o, vec3 d, float a0, float w, float S, float a) {
106
+ vec2 lo = rot(o.yz - vec2(0.5 * S, -0.5 * S), -a);
107
+ vec2 ld = rot(d.yz, -a);
108
+ ld = vec2(abs(ld.x) < 1e-6 ? 1e-6 : ld.x, abs(ld.y) < 1e-6 ? 1e-6 : ld.y);
109
+ float dx = abs(d.x) < 1e-6 ? 1e-6 : d.x;
110
+ vec3 t1 = vec3((a0 - o.x) / dx, (-0.5 * S - lo) / ld);
111
+ vec3 t2 = vec3((a0 + w - o.x) / dx, (0.5 * S - lo) / ld);
112
+ vec3 tn = min(t1, t2);
113
+ vec3 tf = max(t1, t2);
114
+ float tNear = max(tn.x, max(tn.y, tn.z));
115
+ float tFar = min(tf.x, min(tf.y, tf.z));
116
+ if (tNear > tFar || tNear <= 0.0) return vec4(-1.0);
117
+ vec2 q = (lo + tNear * ld) / (0.5 * S);
118
+ float across = o.x + tNear * d.x;
119
+ if (tn.x >= tn.y && tn.x >= tn.z) return vec4(tNear, 4.0, across, sign(-dx));
120
+ if (tn.y > tn.z) return vec4(tNear, ld.x < 0.0 ? 2.0 : 3.0, across, q.y);
121
+ return vec4(tNear, ld.y < 0.0 ? 0.0 : 1.0, across, q.x);
122
+ }
123
+
124
+ // the color of a turning slice at its hit
125
+ vec4 sliceColor(vec4 hit, vec3 tl, bool isCol, float a, float dir, float S, float n, float g) {
126
+ float f = hit.y;
127
+ if (f > 3.5) return vec4(background.rgb * lighting(vec3(hit.w, 0.0, 0.0), isCol), background.a);
128
+ vec2 nl = f < 0.5 ? vec2(0.0, 1.0) : f < 1.5 ? vec2(0.0, -1.0) : f < 2.5 ? vec2(1.0, 0.0) : vec2(-1.0, 0.0);
129
+ float light = lighting(vec3(0.0, rot(nl, a)), isCol);
130
+ // the front shows what the cubies showed before this turn, the side that comes to the front
131
+ // shows the incoming image where it lands
132
+ bool front = f < 0.5;
133
+ bool coming = nl.x * dir > 0.5;
134
+ if (!front && !coming) return vec4(background.rgb * light, background.a);
135
+ // on the side coming to the front, the point across lands at -dir times its depth
136
+ float r = 0.5 * S * (1.0 + (front ? hit.w : -dir * hit.w));
137
+ vec2 fp = isCol ? vec2(hit.z, r) : vec2(r, hit.z);
138
+ return sticker(fp, coming || isDone(tl, fp, n), light, n, g);
139
+ }
140
+
141
+ vec4 transition(vec2 uv) {
142
+ float n = gridSize();
143
+ vec3 tl = timeline(n);
144
+ // the gaps open at the start and close at the end, after the last turn
145
+ float g = gap * smoothstep(0.0, 0.1, progress) * (1.0 - smoothstep(0.9, 1.0, progress));
146
+ vec2 P = vec2(uv.x * ratio, uv.y);
147
+
148
+ // the turns going on are of columns or of rows, never both
149
+ bool isCol = tl.x < tl.y || tl.x >= 2.0 * tl.y;
150
+ // the turn's space: (across the slices, along the turn, depth toward the viewer);
151
+ // a column turns around the horizontal axis through the middle of the cube, a row around the vertical one
152
+ float w = (isCol ? ratio : 1.0) / n;
153
+ float S = isCol ? 1.0 : ratio;
154
+ vec2 pp = isCol ? P : P.yx;
155
+ vec3 o = vec3(isCol ? vec2(0.5 * ratio, 0.5) : vec2(0.5, 0.5 * ratio), 1.2 + 0.6 * max(ratio, 1.0));
156
+ // the ray reaches the face (z = 0) at t = 1
157
+ vec3 d = vec3(pp, 0.0) - o;
158
+
159
+ float k0 = clamp(floor(pp.x / w), 0.0, n - 1.0);
160
+ float t0 = turnTime(tl, isCol, k0, n);
161
+
162
+ float nearest = 1.0;
163
+ vec4 color;
164
+ if (t0 <= 0.0 || t0 >= 1.0) {
165
+ // the face at rest: the exact image
166
+ color = isDone(tl, P, n) ? getToColor(uv) : getFromColor(uv);
167
+ color = mix(background, color, faceMask(P, n, g));
168
+ // the shade of the turning slices next to this one, deepest mid-turn
169
+ for (int j = -1; j <= 1; j += 2) {
170
+ float k = k0 + float(j);
171
+ if (k < 0.0 || k > n - 1.0) continue;
172
+ float tk = turnTime(tl, isCol, k, n);
173
+ if (tk <= 0.0 || tk >= 1.0) continue;
174
+ float dist = abs(pp.x - (k + 0.5) * w) - 0.5 * w;
175
+ color.rgb *= 1.0 - 0.5 * shading * sin(2.0 * turnAngle(tk)) * exp(-dist / (0.2 * w));
176
+ }
177
+ } else {
178
+ // inside the hollow left by the turning slice: the sides of the slices next to it and the cube's inside, in the dark
179
+ float tw = abs(d.x) < 1e-6 ? 1e6 : (d.x < 0.0 ? k0 * w - o.x : (k0 + 1.0) * w - o.x) / d.x;
180
+ float tb = (o.z + S) / -d.z;
181
+ nearest = min(tw, tb);
182
+ float along = o.y + nearest * d.y;
183
+ float depth = (o.z + nearest * d.z) / -S;
184
+ float light = tw < tb ? lighting(vec3(-sign(d.x), 0.0, 0.0), isCol) : 1.0;
185
+ light *= 1.0 - shading * (0.5 + 0.4 * clamp(depth, 0.0, 1.0));
186
+ // beyond the cube's edges: the background
187
+ color = along < 0.0 || along > S ? background : vec4(background.rgb * light, background.a);
188
+ }
189
+
190
+ // the turning slices, which come out in front of the face as they turn
191
+ for (int j = -1; j <= 1; j++) {
192
+ float k = k0 + float(j);
193
+ if (k < 0.0 || k > n - 1.0) continue;
194
+ float tk = turnTime(tl, isCol, k, n);
195
+ if (tk <= 0.0 || tk >= 1.0) continue;
196
+ float dir = turnDir(isCol, k);
197
+ float a = dir * turnAngle(tk);
198
+ vec4 hit = sliceHit(o, d, k * w, w, S, a);
199
+ if (hit.x > 0.0 && hit.x < nearest) {
200
+ nearest = hit.x;
201
+ color = sliceColor(hit, tl, isCol, a, dir, S, n, g);
202
+ }
203
+ }
204
+ return color;
205
+ }
@@ -0,0 +1,53 @@
1
+ // RibbonTwist — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/RibbonTwist.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The image twists like a ribbon around its horizontal center line, the twist travelling smoothly across its width, the outgoing image on its front and the incoming one on its back
5
+ // Tags: 3d, flip, rotate
6
+
7
+ // @range(0.1, 2) Length of the twisted section, as a part of the frame's width
8
+ uniform float spread; // = 0.8
9
+ // @range(0, 0.8) Amount of perspective: the edge turning toward the viewer grows
10
+ uniform float perspective; // = 0.4
11
+ // @range(0, 1) How much the ribbon darkens as it turns away
12
+ uniform float shading; // = 0.6
13
+ // @param Twist around the vertical center line instead, travelling from top to bottom
14
+ uniform bool vertical; // = false
15
+ // @color Color seen where the twisting ribbon leaves the frame uncovered
16
+ uniform vec4 backColor; // = vec4(0.0, 0.0, 0.0, 1.0)
17
+
18
+ const float PI = 3.141592653589793;
19
+ // width of the anti-aliased edges, in frame heights
20
+ const float EDGE = 0.002;
21
+
22
+ vec4 transition (vec2 uv) {
23
+ // q.x: along the ribbon, the way the twist travels; q.y: across the ribbon
24
+ vec2 q = vertical ? vec2(1.0 - uv.y, uv.x) : uv;
25
+ // the ribbon's half width across, in frame heights
26
+ float halfSize = vertical ? 0.5 * ratio : 0.5;
27
+ // each line across the ribbon turns half a turn, a little later than the one before
28
+ float t = smoothstep(0.0, 1.0, (progress * (1.0 + spread) - q.x) / spread);
29
+ // the visible face (outgoing front, incoming back) and its angle from its rest position
30
+ bool front = t < 0.5;
31
+ float angle = PI * (front ? t : t - 1.0);
32
+ float c = cos(angle);
33
+ float s = sin(angle);
34
+ // w: screen position across the ribbon, -1 to 1 at rest; v: the matching position on the face
35
+ // a point v of the face goes to v * c across and v * s in depth, nearer points look bigger
36
+ float w = 2.0 * q.y - 1.0;
37
+ float den = c + perspective * w * s;
38
+ if (den <= 0.0) return backColor;
39
+ float v = w / den;
40
+ if (abs(v) >= 1.0) return backColor;
41
+ // soft edges while twisting (sharp at rest, to keep the first and last frames exact)
42
+ float edge = max(EDGE * min(1.0, 20.0 * abs(s)), 1e-4);
43
+ float top = c / (1.0 - perspective * s);
44
+ float bottom = -c / (1.0 + perspective * s);
45
+ float cover = clamp(min(top - w, w - bottom) * halfSize / edge, 0.0, 1.0);
46
+ vec2 p = vec2(q.x, 0.5 + 0.5 * v);
47
+ p = vertical ? vec2(p.y, 1.0 - p.x) : p;
48
+ vec4 img = front ? getFromColor(p) : getToColor(p);
49
+ // lit from the front and slightly from one side of the axis
50
+ float lambert = clamp(c - 0.25 * s, 0.0, 1.0);
51
+ vec4 color = vec4(img.rgb * mix(1.0 - shading, 1.0, lambert), img.a);
52
+ return mix(backColor, color, cover);
53
+ }
@@ -1,54 +1,250 @@
1
1
  // Shatter — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/Shatter.glsl
2
2
  // Author: lbl
3
3
  // License: MIT
4
- // Description: The outgoing image shatters into fragments that fly away
5
- // Tags: shatter, fragments
4
+ // Description: The outgoing image cracks like a pane of glass from an impact point, then its shards break loose from the impact outward, tumbling in 3D and falling away with gravity to reveal the incoming image behind
5
+ // Tags: shatter, fragments, glass, 3d
6
6
 
7
- #define POINTS 10
7
+ // @param Impact point where the cracks start, from (0, 0) at the bottom left to (1, 1) at the top right
8
+ uniform vec2 center; // = vec2(0.5, 0.5)
9
+ // @range(3, 8) Approximate number of rows of shards across the height of the frame
10
+ uniform float shards; // = 6.0
11
+ // @range(0.5, 3) Strength of the gravity: the shards fall faster, and break loose over a longer time
12
+ uniform float gravity; // = 1.0
13
+ // @param Random seed: another value gives other shards, tumbling another way
14
+ uniform float seed; // = 0.0
8
15
 
9
- float random(vec2 par) {
10
- return fract(sin(dot(par.xy, vec2(12.9898, 78.233))) * 43758.5453);
16
+ // distance from the camera to the pane, as a part of the frame's height
17
+ const float EYE = 2.5;
18
+ // how far the corners of the shards are moved from a regular grid, as a part of a cell
19
+ const float JITTER = 0.32;
20
+ // width of the anti-aliased edges, the crack lines and the bevels, as a part of the frame's height
21
+ const float EDGE = 0.0012;
22
+ const float CRACK_WIDTH = 0.0025;
23
+ const float BEVEL = 0.006;
24
+
25
+ vec3 hash32(vec2 p) {
26
+ vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
27
+ p3 += dot(p3, p3.yxz + 33.33);
28
+ return fract((p3.xxy + p3.yzz) * p3.zyx);
11
29
  }
12
30
 
13
- vec2 random2(vec2 par) {
14
- float rand = random(par);
15
- return vec2(rand, random(par + rand));
31
+ float cellSize() {
32
+ return 1.0 / clamp(shards, 3.0, 8.0);
16
33
  }
17
34
 
18
- vec4 transition (vec2 uv) {
19
- if (progress <= 0.0) return getFromColor(uv);
20
- if (progress >= 1.0) return getToColor(uv);
35
+ vec2 seedOffset() {
36
+ return vec2(37.0, 17.0) * floor(seed);
37
+ }
21
38
 
22
- const float duration = 8.0;
23
- float time = progress * duration;
24
- vec2 point[POINTS];
25
- for (int i = 0; i < POINTS; i++) {
26
- point[i] = random2(vec2(float(i)));
27
- }
39
+ // a corner of the cracks: the point p of a grid, moved at random
40
+ vec2 corner(vec2 p) {
41
+ return (p + JITTER * (2.0 * hash32(p + seedOffset()).xy - 1.0)) * cellSize();
42
+ }
43
+
44
+ // signed distance from q to the line a -> b, positive on its left
45
+ float side(vec2 q, vec2 a, vec2 b) {
46
+ vec2 d = b - a;
47
+ return (d.x * (q.y - a.y) - d.y * (q.x - a.x)) / length(d);
48
+ }
49
+
50
+ // the cell c is cut into two triangular shards along one of its diagonals, picked at random
51
+ bool diagonalUp(vec2 c) {
52
+ return hash32(c + seedOffset() + 0.5).z > 0.5;
53
+ }
54
+
55
+ // distance from q to the edges of the triangle p0 p1 p2 (counterclockwise), positive inside
56
+ float triangleDist(vec2 q, vec2 p0, vec2 p1, vec2 p2) {
57
+ return min(min(side(q, p0, p1), side(q, p1, p2)), side(q, p2, p0));
58
+ }
59
+
60
+ // the shard that contains q on the unbroken pane: (its cell, its triangle, the distance from q to its nearest crack)
61
+ vec4 locate(vec2 q) {
62
+ vec2 c = floor(q / cellSize());
63
+ // the cells' sides are not straight: step to the neighbor cell when q is beyond one of them
64
+ vec2 a, b, cc, d;
65
+ for (int i = 0; i < 2; i++) {
66
+ a = corner(c);
67
+ b = corner(c + vec2(1.0, 0.0));
68
+ cc = corner(c + 1.0);
69
+ d = corner(c + vec2(0.0, 1.0));
70
+ c.x += side(q, d, a) < 0.0 ? -1.0 : (side(q, b, cc) < 0.0 ? 1.0 : 0.0);
71
+ a = corner(c);
72
+ b = corner(c + vec2(1.0, 0.0));
73
+ cc = corner(c + 1.0);
74
+ d = corner(c + vec2(0.0, 1.0));
75
+ c.y += side(q, a, b) < 0.0 ? -1.0 : (side(q, cc, d) < 0.0 ? 1.0 : 0.0);
76
+ }
77
+ a = corner(c);
78
+ b = corner(c + vec2(1.0, 0.0));
79
+ cc = corner(c + 1.0);
80
+ d = corner(c + vec2(0.0, 1.0));
81
+ bool up = diagonalUp(c);
82
+ float d0 = up ? triangleDist(q, a, b, cc) : triangleDist(q, a, b, d);
83
+ float d1 = up ? triangleDist(q, a, cc, d) : triangleDist(q, b, cc, d);
84
+ return vec4(c, d1 > d0 ? 1.0 : 0.0, abs(max(d0, d1)));
85
+ }
86
+
87
+ // Rodrigues' rotation of v around the unit axis k
88
+ vec3 rotate(vec3 v, vec3 k, float angle) {
89
+ float c = cos(angle), s = sin(angle);
90
+ return v * c + cross(k, v) * s + k * dot(k, v) * (1.0 - c);
91
+ }
28
92
 
29
- vec4 col = getToColor(uv);
93
+ vec2 impact() {
94
+ return clamp(center, 0.0, 1.0) * vec2(ratio, 1.0);
95
+ }
30
96
 
31
- for (int i = 0; i < POINTS; i++) {
32
- vec2 dir = normalize(random2(vec2(float(i), float(i) + 11.)));
33
- float v = (1.0 + random(dir) * 0.5) * 0.2;
34
- vec2 ofst = dir * clamp(time - 0.5, 0.0, duration) * v;
35
- vec2 U = uv - ofst;
97
+ // distance from the impact to the farthest corner of the frame
98
+ float reach() {
99
+ vec2 c = impact();
100
+ return length(max(c, vec2(ratio, 1.0) - c));
101
+ }
36
102
 
37
- if (U.x < 0.0 || U.x > 1.0 || U.y < 0.0 || U.y > 1.0) continue;
103
+ // how far below its center a shard must fall to leave the frame
104
+ float fallMargin() {
105
+ return 0.1 + 1.5 * cellSize();
106
+ }
38
107
 
39
- float dist_i = distance(U, point[i]);
40
- bool closest = true;
41
- for (int j = 0; j < POINTS; j++) {
42
- if (distance(U, point[j]) < dist_i) {
43
- closest = false;
44
- break;
45
- }
108
+ // the time a shard breaks loose: the nearer the impact the sooner, and late enough to fall out of the frame by the end
109
+ // (dn: its distance to the impact, as a part of the reach)
110
+ float releaseTime(vec2 mid, float dn, float h, float g, float margin) {
111
+ float latest = max(0.98 - sqrt(2.0 * (mid.y + margin) / g), 0.04);
112
+ return 0.04 + (latest - 0.04) * (0.8 * pow(dn, 0.8) + 0.2 * h);
113
+ }
114
+
115
+ // a flash at the impact, at the start
116
+ float flash(vec2 q) {
117
+ float f = sin(3.141592653589793 * clamp(progress / 0.12, 0.0, 1.0));
118
+ vec2 d = q - impact();
119
+ return 0.6 * f * exp(-dot(d, d) / (0.004 + 0.02 * progress));
120
+ }
121
+
122
+ vec4 transition(vec2 uv) {
123
+ if (progress <= 0.0) return getFromColor(uv);
124
+ if (progress >= 1.0) return getToColor(uv);
125
+ float s = cellSize();
126
+ vec2 a = vec2(uv.x * ratio, uv.y);
127
+ vec3 eye = vec3(0.5 * ratio, 0.5, -EYE);
128
+ vec3 ray = vec3(a, 0.0) - eye;
129
+ vec3 light = normalize(vec3(-0.35, 0.55, -1.0));
130
+ vec3 halfway = normalize(light - normalize(ray));
131
+ float g = 12.0 * clamp(gravity, 0.5, 3.0);
132
+ vec2 imp = impact();
133
+ float rch = reach();
134
+ float margin = fallMargin();
135
+ // the cracks run from the impact to the farthest corner, before the last shards break loose
136
+ float crackTime = clamp(0.6 * (0.94 - sqrt(2.0 * (1.0 + margin) / g)), 0.05, 0.22);
137
+
138
+ // the part of the pane still in place, behind the loose shards
139
+ vec4 pane = vec4(0.0);
140
+ float paneDepth = 1e9;
141
+ vec4 here = locate(a);
142
+ vec2 hc = here.xy;
143
+ vec2 ha = corner(hc), hb = corner(hc + vec2(1.0, 0.0)), hcc = corner(hc + 1.0), hd = corner(hc + vec2(0.0, 1.0));
144
+ bool hup = diagonalUp(hc);
145
+ vec2 hcenter = here.z < 0.5 ? (hup ? ha + hb + hcc : ha + hb + hd) : (hup ? ha + hcc + hd : hb + hcc + hd);
146
+ vec3 hh = hash32(hc + vec2(0.31, 0.57) * (here.z + 1.0) + seedOffset());
147
+ hcenter /= 3.0;
148
+ if (progress < releaseTime(hcenter, clamp(length(hcenter - imp) / rch, 0.0, 1.0), hh.x, g, margin)) {
149
+ vec4 col = getFromColor(uv);
150
+ float crack = clamp((progress - crackTime * length(a - imp) / rch) / 0.03, 0.0, 1.0);
151
+ // cracked shards settle at slightly different angles (no change while flat: dot(n, light) = -light.z)
152
+ vec3 n = rotate(vec3(0.0, 0.0, -1.0), normalize(vec3(hh.yz - 0.5, 0.0) + 1e-4), 0.06 * crack * (hh.x - 0.5));
153
+ col.rgb *= 1.0 + 1.2 * (dot(n, light) + light.z);
154
+ col.rgb += crack * 0.35 * pow(max(dot(n, halfway), 0.0), 400.0) * col.a;
155
+ float line = crack * (1.0 - smoothstep(0.0, CRACK_WIDTH, here.w));
156
+ col.rgb = mix(col.rgb, vec3(0.95, 0.98, 1.0) * col.a, 0.85 * line);
157
+ pane = col;
158
+ paneDepth = 1.0;
159
+ }
160
+
161
+ // the two nearest loose shards: depth along the ray, color, coverage
162
+ float t1 = 1e9, t2 = 1e9;
163
+ vec4 c1 = vec4(0.0), c2 = vec4(0.0);
164
+ float a1 = 0.0, a2 = 0.0;
165
+ float shadow = 0.0;
166
+
167
+ // the shards that broke loose, searched in the cells around and above the pixel since they fall,
168
+ // looking a bit toward the impact and the middle since they drift away and grow toward the camera
169
+ vec2 look = a - 0.06 * progress * (a - imp) / rch - (a - eye.xy) * 0.06 * progress;
170
+ vec2 g0 = floor(look / s) - 1.0;
171
+ float rows = ceil(1.0 / s);
172
+ for (int ri = 0; ri < 11; ri++) {
173
+ float j = g0.y + float(ri);
174
+ if (j > rows) break;
175
+ if (j < -1.0) continue;
176
+ for (int ci = 0; ci < 3; ci++) {
177
+ vec2 c = vec2(g0.x + float(ci), j);
178
+ vec2 ca = corner(c), cb = corner(c + vec2(1.0, 0.0)), ccc = corner(c + 1.0), cd = corner(c + vec2(0.0, 1.0));
179
+ bool up = diagonalUp(c);
180
+ for (int k = 0; k < 2; k++) {
181
+ // the corners of the triangle k of the cell, counterclockwise
182
+ vec2 p0 = (k == 1 && !up) ? cb : ca;
183
+ vec2 p1 = k == 0 ? cb : ccc;
184
+ vec2 p2 = (k == 0 && up) ? ccc : cd;
185
+ vec2 mid = (p0 + p1 + p2) / 3.0;
186
+ vec3 h1 = hash32(c + vec2(0.31, 0.57) * float(k + 1) + seedOffset());
187
+ vec2 away = mid - imp;
188
+ float dist = length(away);
189
+ float dn = clamp(dist / rch, 0.0, 1.0);
190
+ float e = progress - releaseTime(mid, dn, h1.x, g, margin);
191
+ if (e <= 0.0) continue;
192
+ vec3 h2 = hash32(c + vec2(0.73, 0.19) * float(k + 1) + seedOffset());
193
+ // pushed away from the impact and toward the camera, spinning around a random axis, falling
194
+ float near = 1.0 - dn;
195
+ vec3 vel = vec3(away / max(dist, 1e-3) * (0.03 + 0.08 * h1.y) * (0.4 + near), -(0.05 + 0.2 * near * h1.z));
196
+ vec3 pos = vec3(mid, 0.0) + vel * e - vec3(0.0, 0.5 * g * e * e, 0.0);
197
+ // already out of the frame
198
+ if (pos.y + 1.5 * s < -0.05) continue;
199
+ vec3 axis = normalize(vec3(h2.x - 0.5, h2.y - 0.5, 0.3 * (h2.z - 0.5)) + 1e-4);
200
+ float angle = (3.0 + 5.0 * h2.z) * (h2.x < 0.5 ? -1.0 : 1.0) * e;
201
+ vec3 n = rotate(vec3(0.0, 0.0, -1.0), axis, angle);
202
+ float rel = smoothstep(0.0, 0.04, e);
203
+
204
+ // the camera ray, hidden behind the pane still in place
205
+ float den = dot(ray, n);
206
+ float t = dot(pos - eye, n) / (abs(den) > 1e-4 ? den : 1e-4);
207
+ vec2 q = mid + rotate(eye + t * ray - pos, axis, -angle).xy;
208
+ float border = min(min(q.x, ratio - q.x), min(q.y, 1.0 - q.y));
209
+ float inside = triangleDist(q, p0, p1, p2);
210
+ float ed = min(inside, border);
211
+ if (t > 0.0 && t < t2 && t < paneDepth && ed > 0.0) {
212
+ vec3 nf = den > 0.0 ? -n : n;
213
+ vec4 col = getFromColor(vec2(q.x / ratio, q.y));
214
+ col.rgb *= mix(1.0, clamp(dot(nf, light) / -light.z, 0.45, 1.1), rel);
215
+ float glint = max(dot(nf, halfway), 0.0);
216
+ col.rgb += rel * 0.3 * pow(glint, 60.0) * col.a;
217
+ // the crack line it carried turns into a bright bevel
218
+ float line = 0.85 * (1.0 - smoothstep(0.0, CRACK_WIDTH, inside)) * (1.0 - rel);
219
+ float bevel = 0.8 * rel * (1.0 - smoothstep(0.0, BEVEL, ed)) * (0.3 + 0.7 * pow(glint, 6.0));
220
+ col.rgb = mix(col.rgb, vec3(0.92, 0.97, 0.97) * col.a, max(line, bevel));
221
+ float cover = mix(1.0, smoothstep(0.0, 2.0 * EDGE, ed), rel);
222
+ if (t < t1) {
223
+ t2 = t1; c2 = c1; a2 = a1;
224
+ t1 = t; c1 = col; a1 = cover;
225
+ } else {
226
+ t2 = t; c2 = col; a2 = cover;
227
+ }
46
228
  }
47
229
 
48
- if (closest) {
49
- col = getFromColor(U);
50
- break;
230
+ // the shadow on the pane and on the incoming image behind
231
+ float lden = dot(light, n);
232
+ float ts = dot(pos - vec3(a, 0.0), n) / (abs(lden) > 1e-4 ? lden : 1e-4);
233
+ vec2 qs = mid + rotate(vec3(a, 0.0) + ts * light - pos, axis, -angle).xy;
234
+ float eds = min(triangleDist(qs, p0, p1, p2), min(min(qs.x, ratio - qs.x), min(qs.y, 1.0 - qs.y)));
235
+ if (ts > 0.0 && eds > 0.0) {
236
+ shadow = max(shadow, rel * smoothstep(0.0, 0.004 + 0.08 * ts, eds) * 0.45 * (1.0 - smoothstep(0.1, 0.9, ts)));
51
237
  }
238
+ }
52
239
  }
53
- return col;
240
+ }
241
+
242
+ // the incoming image behind, then the pane still in place, then the loose shards in front
243
+ vec4 back = getToColor(uv);
244
+ back.rgb *= 1.0 - shadow;
245
+ pane.rgb *= 1.0 - shadow;
246
+ if (paneDepth == 1.0) back = pane;
247
+ vec4 color = c1 * a1 + c2 * min(a2, 1.0 - a1) + back * max(1.0 - a1 - a2, 0.0);
248
+ color.rgb += flash(a) * color.a;
249
+ return color;
54
250
  }
@@ -0,0 +1,100 @@
1
+ // SketchDissolve — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/SketchDissolve.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The outgoing image fades back to blank paper while the incoming one is drawn on it in pencil, outlines first and then hatching in the shadows, before its shading and colors fill in until the picture is complete
5
+ // Tags: pencil, drawing, sketch, edges, dissolve
6
+
7
+ // @range(0.5, 4) Thickness of the pencil outlines, in thousandths of the frame height
8
+ uniform float lineWidth; // = 1.5
9
+ // @range(0, 2) How many outlines are drawn: higher also traces the fainter edges of the picture
10
+ uniform float edges; // = 1.0
11
+ // @range(0, 1) Amount of diagonal hatching drawn in the shadows
12
+ uniform float hatching; // = 0.6
13
+ // @color Color of the paper
14
+ uniform vec4 paper; // = vec4(0.96, 0.94, 0.89, 1.0)
15
+ // @color Color of the pencil
16
+ uniform vec4 ink; // = vec4(0.16, 0.16, 0.2, 1.0)
17
+
18
+ float sdHash (vec2 p) {
19
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
20
+ p3 += dot(p3, p3.yzx + 33.33);
21
+ return fract((p3.x + p3.y) * p3.z);
22
+ }
23
+
24
+ float sdNoise (vec2 p) {
25
+ vec2 i = floor(p);
26
+ vec2 f = fract(p);
27
+ f = f * f * (3.0 - 2.0 * f);
28
+ return mix(
29
+ mix(sdHash(i), sdHash(i + vec2(1.0, 0.0)), f.x),
30
+ mix(sdHash(i + vec2(0.0, 1.0)), sdHash(i + vec2(1.0, 1.0)), f.x),
31
+ f.y
32
+ );
33
+ }
34
+
35
+ // luma and alpha of the incoming image: outlines follow both
36
+ vec2 sdTone (vec2 uv) {
37
+ vec4 c = getToColor(uv);
38
+ return vec2(dot(c.rgb, vec3(0.299, 0.587, 0.114)), c.a);
39
+ }
40
+
41
+ // one family of hatching strokes along direction d, as thick as the shadow is dark
42
+ float sdHatch (vec2 q, vec2 d, float dark) {
43
+ float s = dot(q, d) * 60.0 + 0.5 * sdNoise(q * 9.0 + d * 13.0);
44
+ float row = floor(s);
45
+ // each row is made of strokes of uneven length and pressure, with small gaps
46
+ float along = dot(q, vec2(-d.y, d.x)) * 8.0 + sdHash(vec2(row, d.y * 7.0)) * 5.0;
47
+ float cell = floor(along);
48
+ float k = sdHash(vec2(row, cell) + d * 31.0);
49
+ float gap = smoothstep(0.0, 0.12, fract(along)) * (1.0 - smoothstep(0.75 - 0.2 * k, 1.0, fract(along)));
50
+ float w = 0.5 * clamp(dark, 0.0, 1.0) * (0.7 + 0.3 * k);
51
+ return (1.0 - smoothstep(w - 0.24, w, abs(fract(s) - 0.5))) * gap * (0.6 + 0.4 * k);
52
+ }
53
+
54
+ vec4 transition (vec2 uv) {
55
+ vec2 q = vec2(uv.x * ratio, uv.y);
56
+ // a slightly wobbly hand: the outlines are traced a bit off the real edges
57
+ vec2 wob = (vec2(sdNoise(q * 6.0), sdNoise(q * 6.0 + 17.0)) - 0.5) * 0.004;
58
+ vec2 su = uv + wob * (1.0 - progress);
59
+ vec2 dx = vec2(0.001 * lineWidth / ratio, 0.0);
60
+ vec2 dy = vec2(0.0, 0.001 * lineWidth);
61
+ vec2 tl = sdTone(su - dx + dy), tm = sdTone(su + dy), tr = sdTone(su + dx + dy);
62
+ vec2 ml = sdTone(su - dx), mr = sdTone(su + dx);
63
+ vec2 bl = sdTone(su - dx - dy), bm = sdTone(su - dy), br = sdTone(su + dx - dy);
64
+ vec2 gx = (tr + 2.0 * mr + br) - (tl + 2.0 * ml + bl);
65
+ vec2 gy = (tl + 2.0 * tm + tr) - (bl + 2.0 * bm + br);
66
+ float g = max(length(vec2(gx.x, gy.x)), length(vec2(gx.y, gy.y))) * max(edges, 0.0);
67
+ float outline = smoothstep(0.12, 0.5, g);
68
+ vec4 toC = getToColor(uv);
69
+ float l = clamp((tm.x + bm.x + ml.x + mr.x) * 0.25, 0.0, 1.0);
70
+
71
+ // graphite grain, and the order in which the strokes are laid down
72
+ float grain = 0.65 + 0.35 * sdNoise(q * vec2(180.0, 60.0));
73
+ float order = sdNoise(q * 3.0 + 4.0);
74
+ float fine = sdNoise(q * 24.0);
75
+ float drawOutline = smoothstep(0.0, 0.1, progress - (0.22 * order + 0.05 * fine));
76
+ float drawHatch = smoothstep(0.0, 0.12, progress - (0.2 + 0.2 * order + 0.05 * fine));
77
+
78
+ // the shading builds up from the darkest parts to the lightest, then the colors come in
79
+ float fill = smoothstep(0.0, 0.22, progress - (0.4 + 0.25 * l + 0.1 * order));
80
+
81
+ // hatching: one direction in the shadows, crossed in the darkest parts
82
+ float dark = 1.0 - l;
83
+ float h1 = sdHatch(q, vec2(0.7071, 0.7071), smoothstep(0.35, 0.9, dark));
84
+ float h2 = sdHatch(q, vec2(0.7071, -0.7071), smoothstep(0.65, 1.0, dark));
85
+ float hatch = hatching * 0.8 * max(h1, 0.8 * h2) * toC.a;
86
+
87
+ // the hatching is absorbed by the shading as it fills in
88
+ hatch *= drawHatch * (1.0 - 0.6 * fill);
89
+ float pencil = max(outline * drawOutline, hatch) * grain;
90
+ // the pencil lines give way to the finished picture at the end
91
+ pencil *= 1.0 - smoothstep(0.7, 1.0, progress);
92
+
93
+ // the outgoing image fades back to paper
94
+ vec4 base = mix(getFromColor(uv), paper, smoothstep(0.02, 0.38, progress));
95
+ float sat = smoothstep(0.55, 1.0, progress);
96
+ vec4 tone = vec4(paper.rgb * mix(0.3, 1.0, l), paper.a * toC.a);
97
+ vec4 col = mix(tone, toC, sat);
98
+ base = mix(base, col, fill);
99
+ return mix(base, ink, pencil);
100
+ }