gl-transitions 3.0.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 (161) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/compatibility.json +359 -11
  3. package/gl-transitions.js +1 -1
  4. package/gl-transitions.json +1 -1
  5. package/glsl3/BookFlip.glsl +124 -21
  6. package/glsl3/Clothesline.glsl +217 -0
  7. package/glsl3/ComicPanels.glsl +174 -0
  8. package/glsl3/Cube.glsl +105 -52
  9. package/glsl3/DominoFall.glsl +114 -0
  10. package/glsl3/Doorway.glsl +74 -38
  11. package/glsl3/Drape.glsl +186 -0
  12. package/glsl3/DuotoneFade.glsl +58 -0
  13. package/glsl3/FacetedGlass.glsl +137 -0
  14. package/glsl3/FrostWipe.glsl +176 -0
  15. package/glsl3/Funnel.glsl +71 -0
  16. package/glsl3/GlitterDissolve.glsl +171 -0
  17. package/glsl3/GridFlip.glsl +151 -56
  18. package/glsl3/HeartWipe.glsl +71 -11
  19. package/glsl3/InsideCube.glsl +114 -0
  20. package/glsl3/KeyholeWipe.glsl +104 -0
  21. package/glsl3/LedWall.glsl +127 -0
  22. package/glsl3/MoireWipe.glsl +75 -0
  23. package/glsl3/PaperFold.glsl +168 -0
  24. package/glsl3/PuzzleCube.glsl +205 -0
  25. package/glsl3/RibbonTwist.glsl +53 -0
  26. package/glsl3/Shatter.glsl +231 -35
  27. package/glsl3/SketchDissolve.glsl +100 -0
  28. package/glsl3/SlotReels.glsl +118 -0
  29. package/glsl3/SplitFlap.glsl +124 -0
  30. package/glsl3/Swirl.glsl +52 -21
  31. package/glsl3/TruchetWipe.glsl +80 -0
  32. package/glsl3/Tumble.glsl +113 -0
  33. package/glsl3/WaterDrop.glsl +69 -13
  34. package/glsl3/WaveWipe.glsl +154 -0
  35. package/index.js +1 -1
  36. package/layouts.json +991 -19
  37. package/llms-full.txt +791 -403
  38. package/llms.txt +219 -197
  39. package/msl/BookFlip.metal +575 -114
  40. package/msl/Clothesline.metal +828 -0
  41. package/msl/ComicPanels.metal +959 -0
  42. package/msl/Cube.metal +466 -170
  43. package/msl/DominoFall.metal +510 -0
  44. package/msl/Doorway.metal +350 -124
  45. package/msl/Drape.metal +767 -0
  46. package/msl/DuotoneFade.metal +218 -0
  47. package/msl/FacetedGlass.metal +529 -0
  48. package/msl/FrostWipe.metal +677 -0
  49. package/msl/Funnel.metal +276 -0
  50. package/msl/GlitterDissolve.metal +637 -0
  51. package/msl/GridFlip.metal +548 -191
  52. package/msl/HeartWipe.metal +230 -58
  53. package/msl/InsideCube.metal +537 -0
  54. package/msl/KeyholeWipe.metal +370 -0
  55. package/msl/LedWall.metal +437 -0
  56. package/msl/MoireWipe.metal +252 -0
  57. package/msl/PaperFold.metal +762 -0
  58. package/msl/PuzzleCube.metal +1179 -0
  59. package/msl/RibbonTwist.metal +235 -0
  60. package/msl/Shatter.metal +1136 -160
  61. package/msl/SketchDissolve.metal +446 -0
  62. package/msl/SlotReels.metal +436 -0
  63. package/msl/SplitFlap.metal +589 -0
  64. package/msl/Swirl.metal +144 -77
  65. package/msl/TruchetWipe.metal +285 -0
  66. package/msl/Tumble.metal +466 -0
  67. package/msl/WaterDrop.metal +258 -49
  68. package/msl/WaveWipe.metal +618 -0
  69. package/package.json +1 -1
  70. package/skills/gl-transitions/references/catalog.md +97 -51
  71. package/sksl/BookFlip.sksl +117 -20
  72. package/sksl/Clothesline.sksl +217 -0
  73. package/sksl/ComicPanels.sksl +176 -0
  74. package/sksl/Cube.sksl +99 -46
  75. package/sksl/DominoFall.sksl +122 -0
  76. package/sksl/Doorway.sksl +65 -35
  77. package/sksl/Drape.sksl +192 -0
  78. package/sksl/DuotoneFade.sksl +71 -0
  79. package/sksl/FacetedGlass.sksl +148 -0
  80. package/sksl/FrostWipe.sksl +183 -0
  81. package/sksl/Funnel.sksl +83 -0
  82. package/sksl/GlitterDissolve.sksl +175 -0
  83. package/sksl/GridFlip.sksl +141 -52
  84. package/sksl/HeartWipe.sksl +60 -11
  85. package/sksl/InsideCube.sksl +123 -0
  86. package/sksl/KeyholeWipe.sksl +109 -0
  87. package/sksl/LedWall.sksl +137 -0
  88. package/sksl/MoireWipe.sksl +85 -0
  89. package/sksl/PaperFold.sksl +170 -0
  90. package/sksl/PuzzleCube.sksl +203 -0
  91. package/sksl/RibbonTwist.sksl +66 -0
  92. package/sksl/Shatter.sksl +218 -33
  93. package/sksl/SketchDissolve.sksl +111 -0
  94. package/sksl/SlotReels.sksl +127 -0
  95. package/sksl/SplitFlap.sksl +131 -0
  96. package/sksl/Swirl.sksl +49 -20
  97. package/sksl/TruchetWipe.sksl +92 -0
  98. package/sksl/Tumble.sksl +122 -0
  99. package/sksl/WaterDrop.sksl +64 -10
  100. package/sksl/WaveWipe.sksl +165 -0
  101. package/sksl/index.js +1 -1
  102. package/transitions/BookFlip.glsl +124 -21
  103. package/transitions/Clothesline.glsl +216 -0
  104. package/transitions/ComicPanels.glsl +173 -0
  105. package/transitions/Cube.glsl +105 -52
  106. package/transitions/DominoFall.glsl +113 -0
  107. package/transitions/Doorway.glsl +74 -38
  108. package/transitions/Drape.glsl +185 -0
  109. package/transitions/DuotoneFade.glsl +57 -0
  110. package/transitions/FacetedGlass.glsl +136 -0
  111. package/transitions/FrostWipe.glsl +175 -0
  112. package/transitions/Funnel.glsl +70 -0
  113. package/transitions/GlitterDissolve.glsl +170 -0
  114. package/transitions/GridFlip.glsl +151 -56
  115. package/transitions/HeartWipe.glsl +71 -11
  116. package/transitions/InsideCube.glsl +113 -0
  117. package/transitions/KeyholeWipe.glsl +103 -0
  118. package/transitions/LedWall.glsl +126 -0
  119. package/transitions/MoireWipe.glsl +74 -0
  120. package/transitions/PaperFold.glsl +167 -0
  121. package/transitions/PuzzleCube.glsl +204 -0
  122. package/transitions/RibbonTwist.glsl +52 -0
  123. package/transitions/Shatter.glsl +231 -35
  124. package/transitions/SketchDissolve.glsl +99 -0
  125. package/transitions/SlotReels.glsl +117 -0
  126. package/transitions/SplitFlap.glsl +123 -0
  127. package/transitions/Swirl.glsl +52 -21
  128. package/transitions/TruchetWipe.glsl +79 -0
  129. package/transitions/Tumble.glsl +112 -0
  130. package/transitions/WaterDrop.glsl +69 -13
  131. package/transitions/WaveWipe.glsl +153 -0
  132. package/wgsl/BookFlip.wgsl +552 -105
  133. package/wgsl/Clothesline.wgsl +756 -0
  134. package/wgsl/ComicPanels.wgsl +886 -0
  135. package/wgsl/Cube.wgsl +461 -156
  136. package/wgsl/DominoFall.wgsl +461 -0
  137. package/wgsl/Doorway.wgsl +333 -117
  138. package/wgsl/Drape.wgsl +715 -0
  139. package/wgsl/DuotoneFade.wgsl +185 -0
  140. package/wgsl/FacetedGlass.wgsl +476 -0
  141. package/wgsl/FrostWipe.wgsl +617 -0
  142. package/wgsl/Funnel.wgsl +248 -0
  143. package/wgsl/GlitterDissolve.wgsl +582 -0
  144. package/wgsl/GridFlip.wgsl +523 -188
  145. package/wgsl/HeartWipe.wgsl +225 -55
  146. package/wgsl/InsideCube.wgsl +496 -0
  147. package/wgsl/KeyholeWipe.wgsl +337 -0
  148. package/wgsl/LedWall.wgsl +397 -0
  149. package/wgsl/MoireWipe.wgsl +222 -0
  150. package/wgsl/PaperFold.wgsl +700 -0
  151. package/wgsl/PuzzleCube.wgsl +1087 -0
  152. package/wgsl/RibbonTwist.wgsl +206 -0
  153. package/wgsl/Shatter.wgsl +1091 -148
  154. package/wgsl/SketchDissolve.wgsl +409 -0
  155. package/wgsl/SlotReels.wgsl +391 -0
  156. package/wgsl/SplitFlap.wgsl +533 -0
  157. package/wgsl/Swirl.wgsl +138 -77
  158. package/wgsl/TruchetWipe.wgsl +255 -0
  159. package/wgsl/Tumble.wgsl +424 -0
  160. package/wgsl/WaterDrop.wgsl +251 -49
  161. package/wgsl/WaveWipe.wgsl +581 -0
@@ -1,53 +1,249 @@
1
1
  // Author: lbl
2
2
  // License: MIT
3
- // Description: The outgoing image shatters into fragments that fly away
4
- // Tags: shatter, fragments
3
+ // 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
4
+ // Tags: shatter, fragments, glass, 3d
5
5
 
6
- #define POINTS 10
6
+ // @param Impact point where the cracks start, from (0, 0) at the bottom left to (1, 1) at the top right
7
+ uniform vec2 center; // = vec2(0.5, 0.5)
8
+ // @range(3, 8) Approximate number of rows of shards across the height of the frame
9
+ uniform float shards; // = 6.0
10
+ // @range(0.5, 3) Strength of the gravity: the shards fall faster, and break loose over a longer time
11
+ uniform float gravity; // = 1.0
12
+ // @param Random seed: another value gives other shards, tumbling another way
13
+ uniform float seed; // = 0.0
7
14
 
8
- float random(vec2 par) {
9
- return fract(sin(dot(par.xy, vec2(12.9898, 78.233))) * 43758.5453);
15
+ // distance from the camera to the pane, as a part of the frame's height
16
+ const float EYE = 2.5;
17
+ // how far the corners of the shards are moved from a regular grid, as a part of a cell
18
+ const float JITTER = 0.32;
19
+ // width of the anti-aliased edges, the crack lines and the bevels, as a part of the frame's height
20
+ const float EDGE = 0.0012;
21
+ const float CRACK_WIDTH = 0.0025;
22
+ const float BEVEL = 0.006;
23
+
24
+ vec3 hash32(vec2 p) {
25
+ vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
26
+ p3 += dot(p3, p3.yxz + 33.33);
27
+ return fract((p3.xxy + p3.yzz) * p3.zyx);
10
28
  }
11
29
 
12
- vec2 random2(vec2 par) {
13
- float rand = random(par);
14
- return vec2(rand, random(par + rand));
30
+ float cellSize() {
31
+ return 1.0 / clamp(shards, 3.0, 8.0);
15
32
  }
16
33
 
17
- vec4 transition (vec2 uv) {
18
- if (progress <= 0.0) return getFromColor(uv);
19
- if (progress >= 1.0) return getToColor(uv);
34
+ vec2 seedOffset() {
35
+ return vec2(37.0, 17.0) * floor(seed);
36
+ }
20
37
 
21
- const float duration = 8.0;
22
- float time = progress * duration;
23
- vec2 point[POINTS];
24
- for (int i = 0; i < POINTS; i++) {
25
- point[i] = random2(vec2(float(i)));
26
- }
38
+ // a corner of the cracks: the point p of a grid, moved at random
39
+ vec2 corner(vec2 p) {
40
+ return (p + JITTER * (2.0 * hash32(p + seedOffset()).xy - 1.0)) * cellSize();
41
+ }
42
+
43
+ // signed distance from q to the line a -> b, positive on its left
44
+ float side(vec2 q, vec2 a, vec2 b) {
45
+ vec2 d = b - a;
46
+ return (d.x * (q.y - a.y) - d.y * (q.x - a.x)) / length(d);
47
+ }
48
+
49
+ // the cell c is cut into two triangular shards along one of its diagonals, picked at random
50
+ bool diagonalUp(vec2 c) {
51
+ return hash32(c + seedOffset() + 0.5).z > 0.5;
52
+ }
53
+
54
+ // distance from q to the edges of the triangle p0 p1 p2 (counterclockwise), positive inside
55
+ float triangleDist(vec2 q, vec2 p0, vec2 p1, vec2 p2) {
56
+ return min(min(side(q, p0, p1), side(q, p1, p2)), side(q, p2, p0));
57
+ }
58
+
59
+ // the shard that contains q on the unbroken pane: (its cell, its triangle, the distance from q to its nearest crack)
60
+ vec4 locate(vec2 q) {
61
+ vec2 c = floor(q / cellSize());
62
+ // the cells' sides are not straight: step to the neighbor cell when q is beyond one of them
63
+ vec2 a, b, cc, d;
64
+ for (int i = 0; i < 2; i++) {
65
+ a = corner(c);
66
+ b = corner(c + vec2(1.0, 0.0));
67
+ cc = corner(c + 1.0);
68
+ d = corner(c + vec2(0.0, 1.0));
69
+ c.x += side(q, d, a) < 0.0 ? -1.0 : (side(q, b, cc) < 0.0 ? 1.0 : 0.0);
70
+ a = corner(c);
71
+ b = corner(c + vec2(1.0, 0.0));
72
+ cc = corner(c + 1.0);
73
+ d = corner(c + vec2(0.0, 1.0));
74
+ c.y += side(q, a, b) < 0.0 ? -1.0 : (side(q, cc, d) < 0.0 ? 1.0 : 0.0);
75
+ }
76
+ a = corner(c);
77
+ b = corner(c + vec2(1.0, 0.0));
78
+ cc = corner(c + 1.0);
79
+ d = corner(c + vec2(0.0, 1.0));
80
+ bool up = diagonalUp(c);
81
+ float d0 = up ? triangleDist(q, a, b, cc) : triangleDist(q, a, b, d);
82
+ float d1 = up ? triangleDist(q, a, cc, d) : triangleDist(q, b, cc, d);
83
+ return vec4(c, d1 > d0 ? 1.0 : 0.0, abs(max(d0, d1)));
84
+ }
85
+
86
+ // Rodrigues' rotation of v around the unit axis k
87
+ vec3 rotate(vec3 v, vec3 k, float angle) {
88
+ float c = cos(angle), s = sin(angle);
89
+ return v * c + cross(k, v) * s + k * dot(k, v) * (1.0 - c);
90
+ }
27
91
 
28
- vec4 col = getToColor(uv);
92
+ vec2 impact() {
93
+ return clamp(center, 0.0, 1.0) * vec2(ratio, 1.0);
94
+ }
29
95
 
30
- for (int i = 0; i < POINTS; i++) {
31
- vec2 dir = normalize(random2(vec2(float(i), float(i) + 11.)));
32
- float v = (1.0 + random(dir) * 0.5) * 0.2;
33
- vec2 ofst = dir * clamp(time - 0.5, 0.0, duration) * v;
34
- vec2 U = uv - ofst;
96
+ // distance from the impact to the farthest corner of the frame
97
+ float reach() {
98
+ vec2 c = impact();
99
+ return length(max(c, vec2(ratio, 1.0) - c));
100
+ }
35
101
 
36
- if (U.x < 0.0 || U.x > 1.0 || U.y < 0.0 || U.y > 1.0) continue;
102
+ // how far below its center a shard must fall to leave the frame
103
+ float fallMargin() {
104
+ return 0.1 + 1.5 * cellSize();
105
+ }
37
106
 
38
- float dist_i = distance(U, point[i]);
39
- bool closest = true;
40
- for (int j = 0; j < POINTS; j++) {
41
- if (distance(U, point[j]) < dist_i) {
42
- closest = false;
43
- break;
44
- }
107
+ // the time a shard breaks loose: the nearer the impact the sooner, and late enough to fall out of the frame by the end
108
+ // (dn: its distance to the impact, as a part of the reach)
109
+ float releaseTime(vec2 mid, float dn, float h, float g, float margin) {
110
+ float latest = max(0.98 - sqrt(2.0 * (mid.y + margin) / g), 0.04);
111
+ return 0.04 + (latest - 0.04) * (0.8 * pow(dn, 0.8) + 0.2 * h);
112
+ }
113
+
114
+ // a flash at the impact, at the start
115
+ float flash(vec2 q) {
116
+ float f = sin(3.141592653589793 * clamp(progress / 0.12, 0.0, 1.0));
117
+ vec2 d = q - impact();
118
+ return 0.6 * f * exp(-dot(d, d) / (0.004 + 0.02 * progress));
119
+ }
120
+
121
+ vec4 transition(vec2 uv) {
122
+ if (progress <= 0.0) return getFromColor(uv);
123
+ if (progress >= 1.0) return getToColor(uv);
124
+ float s = cellSize();
125
+ vec2 a = vec2(uv.x * ratio, uv.y);
126
+ vec3 eye = vec3(0.5 * ratio, 0.5, -EYE);
127
+ vec3 ray = vec3(a, 0.0) - eye;
128
+ vec3 light = normalize(vec3(-0.35, 0.55, -1.0));
129
+ vec3 halfway = normalize(light - normalize(ray));
130
+ float g = 12.0 * clamp(gravity, 0.5, 3.0);
131
+ vec2 imp = impact();
132
+ float rch = reach();
133
+ float margin = fallMargin();
134
+ // the cracks run from the impact to the farthest corner, before the last shards break loose
135
+ float crackTime = clamp(0.6 * (0.94 - sqrt(2.0 * (1.0 + margin) / g)), 0.05, 0.22);
136
+
137
+ // the part of the pane still in place, behind the loose shards
138
+ vec4 pane = vec4(0.0);
139
+ float paneDepth = 1e9;
140
+ vec4 here = locate(a);
141
+ vec2 hc = here.xy;
142
+ 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));
143
+ bool hup = diagonalUp(hc);
144
+ vec2 hcenter = here.z < 0.5 ? (hup ? ha + hb + hcc : ha + hb + hd) : (hup ? ha + hcc + hd : hb + hcc + hd);
145
+ vec3 hh = hash32(hc + vec2(0.31, 0.57) * (here.z + 1.0) + seedOffset());
146
+ hcenter /= 3.0;
147
+ if (progress < releaseTime(hcenter, clamp(length(hcenter - imp) / rch, 0.0, 1.0), hh.x, g, margin)) {
148
+ vec4 col = getFromColor(uv);
149
+ float crack = clamp((progress - crackTime * length(a - imp) / rch) / 0.03, 0.0, 1.0);
150
+ // cracked shards settle at slightly different angles (no change while flat: dot(n, light) = -light.z)
151
+ 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));
152
+ col.rgb *= 1.0 + 1.2 * (dot(n, light) + light.z);
153
+ col.rgb += crack * 0.35 * pow(max(dot(n, halfway), 0.0), 400.0) * col.a;
154
+ float line = crack * (1.0 - smoothstep(0.0, CRACK_WIDTH, here.w));
155
+ col.rgb = mix(col.rgb, vec3(0.95, 0.98, 1.0) * col.a, 0.85 * line);
156
+ pane = col;
157
+ paneDepth = 1.0;
158
+ }
159
+
160
+ // the two nearest loose shards: depth along the ray, color, coverage
161
+ float t1 = 1e9, t2 = 1e9;
162
+ vec4 c1 = vec4(0.0), c2 = vec4(0.0);
163
+ float a1 = 0.0, a2 = 0.0;
164
+ float shadow = 0.0;
165
+
166
+ // the shards that broke loose, searched in the cells around and above the pixel since they fall,
167
+ // looking a bit toward the impact and the middle since they drift away and grow toward the camera
168
+ vec2 look = a - 0.06 * progress * (a - imp) / rch - (a - eye.xy) * 0.06 * progress;
169
+ vec2 g0 = floor(look / s) - 1.0;
170
+ float rows = ceil(1.0 / s);
171
+ for (int ri = 0; ri < 11; ri++) {
172
+ float j = g0.y + float(ri);
173
+ if (j > rows) break;
174
+ if (j < -1.0) continue;
175
+ for (int ci = 0; ci < 3; ci++) {
176
+ vec2 c = vec2(g0.x + float(ci), j);
177
+ 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));
178
+ bool up = diagonalUp(c);
179
+ for (int k = 0; k < 2; k++) {
180
+ // the corners of the triangle k of the cell, counterclockwise
181
+ vec2 p0 = (k == 1 && !up) ? cb : ca;
182
+ vec2 p1 = k == 0 ? cb : ccc;
183
+ vec2 p2 = (k == 0 && up) ? ccc : cd;
184
+ vec2 mid = (p0 + p1 + p2) / 3.0;
185
+ vec3 h1 = hash32(c + vec2(0.31, 0.57) * float(k + 1) + seedOffset());
186
+ vec2 away = mid - imp;
187
+ float dist = length(away);
188
+ float dn = clamp(dist / rch, 0.0, 1.0);
189
+ float e = progress - releaseTime(mid, dn, h1.x, g, margin);
190
+ if (e <= 0.0) continue;
191
+ vec3 h2 = hash32(c + vec2(0.73, 0.19) * float(k + 1) + seedOffset());
192
+ // pushed away from the impact and toward the camera, spinning around a random axis, falling
193
+ float near = 1.0 - dn;
194
+ vec3 vel = vec3(away / max(dist, 1e-3) * (0.03 + 0.08 * h1.y) * (0.4 + near), -(0.05 + 0.2 * near * h1.z));
195
+ vec3 pos = vec3(mid, 0.0) + vel * e - vec3(0.0, 0.5 * g * e * e, 0.0);
196
+ // already out of the frame
197
+ if (pos.y + 1.5 * s < -0.05) continue;
198
+ vec3 axis = normalize(vec3(h2.x - 0.5, h2.y - 0.5, 0.3 * (h2.z - 0.5)) + 1e-4);
199
+ float angle = (3.0 + 5.0 * h2.z) * (h2.x < 0.5 ? -1.0 : 1.0) * e;
200
+ vec3 n = rotate(vec3(0.0, 0.0, -1.0), axis, angle);
201
+ float rel = smoothstep(0.0, 0.04, e);
202
+
203
+ // the camera ray, hidden behind the pane still in place
204
+ float den = dot(ray, n);
205
+ float t = dot(pos - eye, n) / (abs(den) > 1e-4 ? den : 1e-4);
206
+ vec2 q = mid + rotate(eye + t * ray - pos, axis, -angle).xy;
207
+ float border = min(min(q.x, ratio - q.x), min(q.y, 1.0 - q.y));
208
+ float inside = triangleDist(q, p0, p1, p2);
209
+ float ed = min(inside, border);
210
+ if (t > 0.0 && t < t2 && t < paneDepth && ed > 0.0) {
211
+ vec3 nf = den > 0.0 ? -n : n;
212
+ vec4 col = getFromColor(vec2(q.x / ratio, q.y));
213
+ col.rgb *= mix(1.0, clamp(dot(nf, light) / -light.z, 0.45, 1.1), rel);
214
+ float glint = max(dot(nf, halfway), 0.0);
215
+ col.rgb += rel * 0.3 * pow(glint, 60.0) * col.a;
216
+ // the crack line it carried turns into a bright bevel
217
+ float line = 0.85 * (1.0 - smoothstep(0.0, CRACK_WIDTH, inside)) * (1.0 - rel);
218
+ float bevel = 0.8 * rel * (1.0 - smoothstep(0.0, BEVEL, ed)) * (0.3 + 0.7 * pow(glint, 6.0));
219
+ col.rgb = mix(col.rgb, vec3(0.92, 0.97, 0.97) * col.a, max(line, bevel));
220
+ float cover = mix(1.0, smoothstep(0.0, 2.0 * EDGE, ed), rel);
221
+ if (t < t1) {
222
+ t2 = t1; c2 = c1; a2 = a1;
223
+ t1 = t; c1 = col; a1 = cover;
224
+ } else {
225
+ t2 = t; c2 = col; a2 = cover;
226
+ }
45
227
  }
46
228
 
47
- if (closest) {
48
- col = getFromColor(U);
49
- break;
229
+ // the shadow on the pane and on the incoming image behind
230
+ float lden = dot(light, n);
231
+ float ts = dot(pos - vec3(a, 0.0), n) / (abs(lden) > 1e-4 ? lden : 1e-4);
232
+ vec2 qs = mid + rotate(vec3(a, 0.0) + ts * light - pos, axis, -angle).xy;
233
+ float eds = min(triangleDist(qs, p0, p1, p2), min(min(qs.x, ratio - qs.x), min(qs.y, 1.0 - qs.y)));
234
+ if (ts > 0.0 && eds > 0.0) {
235
+ shadow = max(shadow, rel * smoothstep(0.0, 0.004 + 0.08 * ts, eds) * 0.45 * (1.0 - smoothstep(0.1, 0.9, ts)));
50
236
  }
237
+ }
51
238
  }
52
- return col;
239
+ }
240
+
241
+ // the incoming image behind, then the pane still in place, then the loose shards in front
242
+ vec4 back = getToColor(uv);
243
+ back.rgb *= 1.0 - shadow;
244
+ pane.rgb *= 1.0 - shadow;
245
+ if (paneDepth == 1.0) back = pane;
246
+ vec4 color = c1 * a1 + c2 * min(a2, 1.0 - a1) + back * max(1.0 - a1 - a2, 0.0);
247
+ color.rgb += flash(a) * color.a;
248
+ return color;
53
249
  }
@@ -0,0 +1,99 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // 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
4
+ // Tags: pencil, drawing, sketch, edges, dissolve
5
+
6
+ // @range(0.5, 4) Thickness of the pencil outlines, in thousandths of the frame height
7
+ uniform float lineWidth; // = 1.5
8
+ // @range(0, 2) How many outlines are drawn: higher also traces the fainter edges of the picture
9
+ uniform float edges; // = 1.0
10
+ // @range(0, 1) Amount of diagonal hatching drawn in the shadows
11
+ uniform float hatching; // = 0.6
12
+ // @color Color of the paper
13
+ uniform vec4 paper; // = vec4(0.96, 0.94, 0.89, 1.0)
14
+ // @color Color of the pencil
15
+ uniform vec4 ink; // = vec4(0.16, 0.16, 0.2, 1.0)
16
+
17
+ float sdHash (vec2 p) {
18
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
19
+ p3 += dot(p3, p3.yzx + 33.33);
20
+ return fract((p3.x + p3.y) * p3.z);
21
+ }
22
+
23
+ float sdNoise (vec2 p) {
24
+ vec2 i = floor(p);
25
+ vec2 f = fract(p);
26
+ f = f * f * (3.0 - 2.0 * f);
27
+ return mix(
28
+ mix(sdHash(i), sdHash(i + vec2(1.0, 0.0)), f.x),
29
+ mix(sdHash(i + vec2(0.0, 1.0)), sdHash(i + vec2(1.0, 1.0)), f.x),
30
+ f.y
31
+ );
32
+ }
33
+
34
+ // luma and alpha of the incoming image: outlines follow both
35
+ vec2 sdTone (vec2 uv) {
36
+ vec4 c = getToColor(uv);
37
+ return vec2(dot(c.rgb, vec3(0.299, 0.587, 0.114)), c.a);
38
+ }
39
+
40
+ // one family of hatching strokes along direction d, as thick as the shadow is dark
41
+ float sdHatch (vec2 q, vec2 d, float dark) {
42
+ float s = dot(q, d) * 60.0 + 0.5 * sdNoise(q * 9.0 + d * 13.0);
43
+ float row = floor(s);
44
+ // each row is made of strokes of uneven length and pressure, with small gaps
45
+ float along = dot(q, vec2(-d.y, d.x)) * 8.0 + sdHash(vec2(row, d.y * 7.0)) * 5.0;
46
+ float cell = floor(along);
47
+ float k = sdHash(vec2(row, cell) + d * 31.0);
48
+ float gap = smoothstep(0.0, 0.12, fract(along)) * (1.0 - smoothstep(0.75 - 0.2 * k, 1.0, fract(along)));
49
+ float w = 0.5 * clamp(dark, 0.0, 1.0) * (0.7 + 0.3 * k);
50
+ return (1.0 - smoothstep(w - 0.24, w, abs(fract(s) - 0.5))) * gap * (0.6 + 0.4 * k);
51
+ }
52
+
53
+ vec4 transition (vec2 uv) {
54
+ vec2 q = vec2(uv.x * ratio, uv.y);
55
+ // a slightly wobbly hand: the outlines are traced a bit off the real edges
56
+ vec2 wob = (vec2(sdNoise(q * 6.0), sdNoise(q * 6.0 + 17.0)) - 0.5) * 0.004;
57
+ vec2 su = uv + wob * (1.0 - progress);
58
+ vec2 dx = vec2(0.001 * lineWidth / ratio, 0.0);
59
+ vec2 dy = vec2(0.0, 0.001 * lineWidth);
60
+ vec2 tl = sdTone(su - dx + dy), tm = sdTone(su + dy), tr = sdTone(su + dx + dy);
61
+ vec2 ml = sdTone(su - dx), mr = sdTone(su + dx);
62
+ vec2 bl = sdTone(su - dx - dy), bm = sdTone(su - dy), br = sdTone(su + dx - dy);
63
+ vec2 gx = (tr + 2.0 * mr + br) - (tl + 2.0 * ml + bl);
64
+ vec2 gy = (tl + 2.0 * tm + tr) - (bl + 2.0 * bm + br);
65
+ float g = max(length(vec2(gx.x, gy.x)), length(vec2(gx.y, gy.y))) * max(edges, 0.0);
66
+ float outline = smoothstep(0.12, 0.5, g);
67
+ vec4 toC = getToColor(uv);
68
+ float l = clamp((tm.x + bm.x + ml.x + mr.x) * 0.25, 0.0, 1.0);
69
+
70
+ // graphite grain, and the order in which the strokes are laid down
71
+ float grain = 0.65 + 0.35 * sdNoise(q * vec2(180.0, 60.0));
72
+ float order = sdNoise(q * 3.0 + 4.0);
73
+ float fine = sdNoise(q * 24.0);
74
+ float drawOutline = smoothstep(0.0, 0.1, progress - (0.22 * order + 0.05 * fine));
75
+ float drawHatch = smoothstep(0.0, 0.12, progress - (0.2 + 0.2 * order + 0.05 * fine));
76
+
77
+ // the shading builds up from the darkest parts to the lightest, then the colors come in
78
+ float fill = smoothstep(0.0, 0.22, progress - (0.4 + 0.25 * l + 0.1 * order));
79
+
80
+ // hatching: one direction in the shadows, crossed in the darkest parts
81
+ float dark = 1.0 - l;
82
+ float h1 = sdHatch(q, vec2(0.7071, 0.7071), smoothstep(0.35, 0.9, dark));
83
+ float h2 = sdHatch(q, vec2(0.7071, -0.7071), smoothstep(0.65, 1.0, dark));
84
+ float hatch = hatching * 0.8 * max(h1, 0.8 * h2) * toC.a;
85
+
86
+ // the hatching is absorbed by the shading as it fills in
87
+ hatch *= drawHatch * (1.0 - 0.6 * fill);
88
+ float pencil = max(outline * drawOutline, hatch) * grain;
89
+ // the pencil lines give way to the finished picture at the end
90
+ pencil *= 1.0 - smoothstep(0.7, 1.0, progress);
91
+
92
+ // the outgoing image fades back to paper
93
+ vec4 base = mix(getFromColor(uv), paper, smoothstep(0.02, 0.38, progress));
94
+ float sat = smoothstep(0.55, 1.0, progress);
95
+ vec4 tone = vec4(paper.rgb * mix(0.3, 1.0, l), paper.a * toC.a);
96
+ vec4 col = mix(tone, toC, sat);
97
+ base = mix(base, col, fill);
98
+ return mix(base, ink, pencil);
99
+ }
@@ -0,0 +1,117 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The frame is cut into vertical reels that spin downward like drums, motion-blurred with speed, carrying the outgoing image then the incoming one, and stop one after another from left to right with a small mechanical bounce
4
+ // Tags: 3d, spin, stripes, motion-blur
5
+
6
+ // @range(1, 16, 1) Number of reels
7
+ uniform int reels; // = 5
8
+ // @range(0, 1) Amount of vertical motion blur while the reels spin fast
9
+ uniform float blur; // = 0.6
10
+ // @range(0, 0.9) Delay between the first and the last reel's stop, as a part of the transition
11
+ uniform float stagger; // = 0.45
12
+ // @range(0, 1) Size of the bounce when a reel stops
13
+ uniform float bounce; // = 0.5
14
+ // @color Color of the separators between the reels
15
+ uniform vec4 separator; // = vec4(0.04, 0.04, 0.05, 1.0)
16
+
17
+ const float PI = 3.141592653589793;
18
+ // half of the arc of the drum seen in the frame, in radians
19
+ const float ARC = 1.15;
20
+ // duration of the bounce, as a part of the transition
21
+ const float SETTLE = 0.1;
22
+ // width of the separators, in frame heights
23
+ const float LINE = 0.006;
24
+ // width of the anti-aliased edges, in frame heights
25
+ const float EDGE = 0.0015;
26
+
27
+ // the time at which the reel stops, before its bounce
28
+ float stopTime(float i, float n) {
29
+ float order = n > 1.0 ? i / (n - 1.0) : 1.0;
30
+ return (1.0 - SETTLE) * (1.0 - clamp(stagger, 0.0, 0.9) * (1.0 - order));
31
+ }
32
+
33
+ // how far the reel has turned at time t, in image heights: it speeds up, slows down to its stop
34
+ // a little past the incoming image and springs back onto it
35
+ float reelOffset(float t, float stopT, float turns) {
36
+ float amp = 0.07 * bounce;
37
+ // speed at the stop, matched with the start of the bounce
38
+ float v1 = amp * PI * stopT / (turns * SETTLE);
39
+ float u = clamp(t / stopT, 0.0, 1.0);
40
+ float g = u * u * (3.0 - 2.0 * u) + v1 * (u * u * u - u * u);
41
+ float b = clamp((t - stopT) / SETTLE, 0.0, 1.0);
42
+ return turns * g + amp * sin(PI * b) * (1.0 - b) * (1.0 - b);
43
+ }
44
+
45
+ // the reel's speed at time t, the derivative of reelOffset, in image heights per transition
46
+ float reelSpeed(float t, float stopT, float turns) {
47
+ float amp = 0.07 * bounce;
48
+ float v1 = amp * PI * stopT / (turns * SETTLE);
49
+ if (t < stopT) {
50
+ float u = max(t / stopT, 0.0);
51
+ return turns * (6.0 * u * (1.0 - u) + v1 * u * (3.0 * u - 2.0)) / stopT;
52
+ }
53
+ float b = min((t - stopT) / SETTLE, 1.0);
54
+ return amp * (1.0 - b) * (PI * cos(PI * b) * (1.0 - b) - 2.0 * sin(PI * b)) / SETTLE;
55
+ }
56
+
57
+ vec4 transition (vec2 uv) {
58
+ float n = max(float(reels), 1.0);
59
+ float i = min(floor(uv.x * n), n - 1.0);
60
+ float lx = uv.x * n - i;
61
+ float stopT = stopTime(i, n);
62
+ // an odd number of turns, more for the reels that spin longer, so they land on the incoming image
63
+ float turns = 2.0 * floor(stopT * 4.0) + 1.0;
64
+
65
+ // the reel is a drum while it spins, and flattens back as it settles
66
+ float drum = smoothstep(0.0, 0.12, progress) * (1.0 - smoothstep(stopT, stopT + SETTLE, progress));
67
+ float y = 2.0 * uv.y - 1.0;
68
+ // theta: the angle around the drum's axis, 0 facing the viewer
69
+ float theta = asin(clamp(y * sin(ARC), -1.0, 1.0));
70
+ float v = mix(uv.y, 0.5 + theta / (2.0 * ARC), drum);
71
+ // the far edges of the drum look narrower
72
+ float depth = (1.0 - cos(theta)) * drum;
73
+ float px = 0.5 + (lx - 0.5) * (1.0 + 0.2 * depth);
74
+
75
+ // offset from the resting position, -turns at the start, 0 once landed
76
+ float off = reelOffset(progress, stopT, turns) - turns;
77
+ float speed = abs(reelSpeed(progress, stopT, turns));
78
+ // the blur spans the distance the reel travels in about a frame
79
+ float spread = blur * min(speed * 0.02, 0.22) * drum;
80
+
81
+ // up to 8 taps along the reel, weighted toward the middle, one when it stands still
82
+ vec4 c = vec4(0.0);
83
+ float wsum = 0.0;
84
+ for (int k = 0; k < 8; k++) {
85
+ float f = float(k) / 7.0 - 0.5;
86
+ float w = 1.0 - abs(f);
87
+ float vv = v + off + spread * f;
88
+ float seg = floor(vv);
89
+ vec2 q = vec2((i + clamp(px, 0.0, 1.0)) / n, vv - seg);
90
+ // the drum carries the incoming image on even segments, the outgoing one on odd segments
91
+ vec4 s = mod(seg, 2.0) < 0.5 ? getToColor(q) : getFromColor(q);
92
+ // a thin shadow at the seams between the images, not at the frame's top and bottom edges
93
+ s.rgb *= 1.0 - 0.6 * drum * (1.0 - y * y) * (1.0 - smoothstep(0.0, 0.02, min(q.y, 1.0 - q.y)));
94
+ c += w * s;
95
+ wsum += w;
96
+ if (spread < 1e-4) break;
97
+ }
98
+ c /= wsum;
99
+
100
+ // the drum's faces darken as they turn away, with a soft highlight above its middle
101
+ float facing = cos(theta);
102
+ c.rgb *= mix(1.0, 0.25 + 0.75 * facing * facing, drum);
103
+ c.rgb += drum * 0.07 * c.a * exp(-12.0 * (y - 0.3) * (y - 0.3));
104
+
105
+ // separators between the reels, and the background around the narrower far edges of the drums
106
+ float env = smoothstep(0.0, 0.1, progress) * (1.0 - smoothstep(0.9, 1.0, progress));
107
+ float reelW = ratio / n;
108
+ float persp = reelW / (1.0 + 0.2 * depth);
109
+ // distance to the reel's sides, and to its sides next to the other reels
110
+ float dSide = min(px, 1.0 - px) * persp;
111
+ float dInner = min(i > 0.5 ? px : 2.0, i < n - 1.5 ? 1.0 - px : 2.0) * persp;
112
+ float line = 1.0 - smoothstep(0.5 * LINE - EDGE, 0.5 * LINE + EDGE, dInner);
113
+ float outside = 1.0 - smoothstep(-EDGE, 0.0, dSide);
114
+ // a soft shadow cast by the separators on the reels
115
+ c.rgb *= 1.0 - 0.35 * env * (1.0 - smoothstep(0.0, 0.03 * reelW + LINE, dInner));
116
+ return mix(c, separator, max(line * env, outside));
117
+ }
@@ -0,0 +1,123 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The frame becomes a split-flap board: in each cell the top half of the outgoing image flips down on a hinge across the middle, cell after cell, its back bringing the bottom half of the incoming image
4
+ // Tags: 3d, flip, grid
5
+
6
+ // @param Number of cells (columns, rows)
7
+ uniform ivec2 size; // = ivec2(8, 6)
8
+ // @range(0, 0.9) Delay of the last cell's flip, as a part of the transition
9
+ uniform float stagger; // = 0.6
10
+ // @range(0, 1) How much the order of the cells is shuffled, from a wave across the board to random
11
+ uniform float randomness; // = 0.3
12
+ // @range(1, 4, 1) Number of flaps that fall in each cell, the ones before the last showing other parts of the incoming image
13
+ uniform int flaps; // = 1
14
+ // @range(0, 0.05) Width of the gaps between the cells, as a part of the frame's shorter side (the hinges get half of it)
15
+ uniform float gap; // = 0.004
16
+ // @range(0, 1) Amount of perspective: the falling flaps grow as they come toward the viewer
17
+ uniform float perspective; // = 0.35
18
+ // @range(0, 1) How much the flaps darken as they turn away from the light, and the shadows they cast
19
+ uniform float shading; // = 0.4
20
+ // @color Color seen in the gaps between the cells
21
+ uniform vec4 background; // = vec4(0.0, 0.0, 0.0, 1.0)
22
+
23
+ const float PI = 3.141592653589793;
24
+ // width of the anti-aliased edges, as a part of the frame's shorter side
25
+ const float EDGE = 0.001;
26
+
27
+ float hash12(vec2 v) {
28
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
29
+ v3 += dot(v3, v3.yzx + 33.33);
30
+ return fract((v3.x + v3.y) * v3.z);
31
+ }
32
+
33
+ // the cell's flip, 0 to 1
34
+ float cellTime(vec2 cell, vec2 grid) {
35
+ float wave = (cell.x + 0.5 * (grid.y - 1.0 - cell.y)) / max(grid.x - 1.0 + 0.5 * (grid.y - 1.0), 1.0);
36
+ float order = mix(wave, hash12(cell + 17.0), randomness);
37
+ float delay = clamp(stagger, 0.0, 0.99);
38
+ return clamp((progress - order * delay) / (1.0 - delay), 0.0, 1.0);
39
+ }
40
+
41
+ // the card on the front of the falling flap, at the cell's flip t
42
+ float flapIndex(float t, float n) {
43
+ return min(floor(t * n), n - 1.0);
44
+ }
45
+
46
+ // the falling flap's angle, 0 upright to PI down: it starts gently and lands fast
47
+ float flapAngle(float t, float n) {
48
+ float u = t * n - flapIndex(t, n);
49
+ return PI * u * (0.3 + 0.7 * u);
50
+ }
51
+
52
+ // card i of a cell at the point lc of the card: the outgoing image first, the incoming one last,
53
+ // and in between the incoming image of another cell
54
+ vec4 card(float i, float n, vec2 cell, vec2 grid, vec2 lc) {
55
+ if (i < 0.5) return getFromColor((cell + lc) / grid);
56
+ vec2 src = cell;
57
+ if (i < n - 0.5) src = floor(vec2(hash12(cell * 3.7 + i * 11.3), hash12(cell * 5.3 + i * 7.9 + 1.7)) * grid);
58
+ return getToColor((src + lc) / grid);
59
+ }
60
+
61
+ // 1 inside a half card, 0 in the gaps: x across the card and f the distance from the hinge, in cell sizes
62
+ float cardMask(float x, float f, vec2 cellSize, float g) {
63
+ if (g <= 0.0) return 1.0;
64
+ float e = EDGE * min(1.0, g / max(gap, 1e-4));
65
+ // the gap at the hinge is half as wide as the one between the cells
66
+ float d = min(min(x, 1.0 - x) * cellSize.x, min(2.0 * f, 0.5 - f) * cellSize.y);
67
+ return smoothstep(0.5 * g - e, 0.5 * g + e, d);
68
+ }
69
+
70
+ vec4 transition (vec2 uv) {
71
+ vec2 grid = max(vec2(size), 1.0);
72
+ float n = max(float(flaps), 1.0);
73
+ vec2 cellSize = vec2(ratio, 1.0) / grid / min(ratio, 1.0);
74
+ vec2 cell = floor(uv * grid);
75
+ vec2 l = uv * grid - cell;
76
+ // the gaps open at the start and close at the end
77
+ float g = gap * smoothstep(0.0, 0.12, progress) * (1.0 - smoothstep(0.88, 1.0, progress));
78
+ // w: height above the hinge, in cell heights
79
+ float w = l.y - 0.5;
80
+ bool upper = w >= 0.0;
81
+
82
+ // the board behind the falling flaps: the top half of the next card once the flap has left it,
83
+ // the bottom half of the current card until the flap has landed on it
84
+ float t = cellTime(cell, grid);
85
+ float k = flapIndex(t, n);
86
+ float a = flapAngle(t, n);
87
+ bool started = t * n > k;
88
+ bool landed = t >= 1.0;
89
+ vec4 color = card(k + (upper ? (started ? 1.0 : 0.0) : (landed ? 1.0 : 0.0)), n, cell, grid, l);
90
+ // shadows of the flap leaning over the top half, then falling onto the bottom half
91
+ if (started && !landed) color.rgb *= 1.0 - 0.45 * shading * max(upper ? cos(a) : -cos(a), 0.0);
92
+ color = mix(background, color, cardMask(l.x, abs(w), cellSize, g));
93
+
94
+ // the falling flaps of this cell and of its neighbors, which grow beyond their cells as they come closer
95
+ float nearest = -1.0;
96
+ for (int d = -1; d <= 1; d++) {
97
+ vec2 nc = cell + vec2(float(d), 0.0);
98
+ if (nc.x < 0.0 || nc.x > grid.x - 1.0) continue;
99
+ float nt = d == 0 ? t : cellTime(nc, grid);
100
+ float na = d == 0 ? a : flapAngle(nt, n);
101
+ float fc = cos(na);
102
+ float fs = sin(na);
103
+ // a point at distance f from the hinge is at height f * fc and depth f * fs, nearer points look wider
104
+ if (abs(fc) < 1e-5 || (w >= 0.0) != (fc > 0.0)) continue;
105
+ float f = w / fc;
106
+ if (f > 0.5) continue;
107
+ float z = f * fs;
108
+ if (z <= nearest) continue;
109
+ float lx = 0.5 + (l.x - float(d) - 0.5) * (1.0 - perspective * z);
110
+ if (lx < 0.0 || lx > 1.0) continue;
111
+ bool front = fc > 0.0;
112
+ vec2 lc = vec2(lx, front ? 0.5 + f : 0.5 - f);
113
+ float m = cardMask(lx, f, cellSize, g);
114
+ if (m <= 0.0) continue;
115
+ vec4 img = card(flapIndex(nt, n) + (front ? 0.0 : 1.0), n, nc, grid, lc);
116
+ // lit from above the viewer: the front darkens as it turns down, the back brightens as it lands
117
+ float lambert = (front ? 0.92 * fc - 0.4 * fs : 0.4 * fs - 0.92 * fc) / 0.92;
118
+ img.rgb *= mix(1.0 - shading, 1.0, clamp(lambert, 0.0, 1.0));
119
+ color = mix(color, img, m);
120
+ nearest = z;
121
+ }
122
+ return color;
123
+ }