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
@@ -0,0 +1,74 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // 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
4
+ // Tags: moire, rings, interference, pattern, graphic, reveal
5
+
6
+ // @range(10, 80) Number of rings per frame height in each set
7
+ uniform float density; // = 36.0
8
+ // @range(1, 8) How many moire bands the rings make at the start; they get fewer and wider as the centers come together
9
+ uniform float bands; // = 3.0
10
+ // @range(-1, 1) How far the two centers turn around each other, in turns
11
+ uniform float drift; // = 0.25
12
+ // @range(0, 1) Strength of the ring lines drawn over the image
13
+ uniform float lines; // = 0.5
14
+
15
+ const float PI = 3.141592653589793;
16
+ // half width of the antialiased edges, in frame heights
17
+ const float AA = 0.0012;
18
+ // half width of a ring line, in ring spacings
19
+ const float LINE = 0.1;
20
+ // widest antialiased edge of the bands, in bands, which also sets when they start and finish
21
+ // opening
22
+ const float EDGE = 0.05;
23
+ // angle of the line between the two centers at the start, in radians
24
+ const float START = 0.35;
25
+ // strength of the ring lines at lines = 1, so the image always shows through them
26
+ const float INK = 0.7;
27
+
28
+ // coverage of the ring lines at radius r, box-filtered over the antialiasing width, and
29
+ // faded to their mean coverage when the rings get too fine to resolve
30
+ float ringLines(float r, float f) {
31
+ float q = abs(fract(r * f + 0.5) - 0.5);
32
+ float aa = AA * f;
33
+ float c = clamp((LINE - q) / (2.0 * aa) + 0.5, 0.0, 1.0);
34
+ return mix(c, 2.0 * LINE, clamp(10.0 * aa - 0.5, 0.0, 1.0));
35
+ }
36
+
37
+ vec4 transition(vec2 uv) {
38
+ vec4 a = getFromColor(uv);
39
+ vec4 b = getToColor(uv);
40
+ if (progress <= 0.0) return a;
41
+ if (progress >= 1.0) return b;
42
+
43
+ float t = progress * progress * (3.0 - 2.0 * progress);
44
+ float f = max(density, 1.0);
45
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
46
+
47
+ // the two centers turn around the middle of the frame and come together
48
+ float ang = 2.0 * PI * drift * t + START;
49
+ float k = max(bands, 1.0) * (1.0 - 0.75 * t);
50
+ vec2 axis = vec2(cos(ang), sin(ang)) * 0.5 * k / f;
51
+ float r1 = length(p - axis);
52
+ float r2 = length(p + axis);
53
+ // the second set is slightly finer than the first, which bends the bands into curves
54
+ float f2 = f + 1.2 * k;
55
+
56
+ // the beat of the two ring sets: wide bands where their rings line up, at this distance
57
+ // from the middle of the nearest band, in bands
58
+ float beat = abs(fract(f2 * r2 - f * r1 + 0.5) - 0.5);
59
+ // the bands open from their middles and widen until they cover the frame
60
+ // with an edge antialiased from the analytic gradient of the beat
61
+ vec2 grad = f2 * (p + axis) / max(r2, AA) - f * (p - axis) / max(r1, AA);
62
+ float s = min(AA * length(grad) + 0.004, EDGE);
63
+ float w = mix(-EDGE, 0.5 + EDGE, t);
64
+ float m = 1.0 - smoothstep(w - s, w + s, beat);
65
+
66
+ vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), m);
67
+
68
+ // the thin lines of both sets, dark over the outgoing image and light over the incoming
69
+ // one, fade in and out
70
+ float o = INK * clamp(lines, 0.0, 1.0) * sin(PI * t);
71
+ float l = 1.0 - (1.0 - o * ringLines(r1, f)) * (1.0 - o * ringLines(r2, f2));
72
+ c.rgb = mix(c.rgb, vec3(c.a * m), l);
73
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
74
+ }
@@ -0,0 +1,167 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // 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
4
+ // Tags: paper, fold, 3d, shadow
5
+
6
+ // @param Direction the folded packet flies off toward
7
+ uniform vec2 direction; // = vec2(1.0, 0.5)
8
+ // @range(0, 1) How much the sheet tilts and recedes while it folds, so that the folds are seen in 3D
9
+ uniform float tilt; // = 0.6
10
+ // @range(0, 1) How much the faces darken as they turn away from the light, and the shadows they cast
11
+ uniform float shading; // = 0.6
12
+ // @color Color of the back of the paper, through which the print faintly shows
13
+ uniform vec4 paper; // = vec4(0.95, 0.94, 0.9, 1.0)
14
+
15
+ const float PI = 3.141592653589793;
16
+ // width of the anti-aliased edges, as a part of the frame's height
17
+ const float EDGE = 0.0015;
18
+ // how much the print shows through the back of the paper
19
+ const float SHOW = 0.1;
20
+ // width of the shaded crease, in frame heights
21
+ const float CREASE = 0.02;
22
+ // direction of the light, from the top left and the front
23
+ const vec3 LIGHT = vec3(-0.3995, 0.4494, 0.799);
24
+
25
+ vec4 front(vec2 st) {
26
+ return getFromColor(st / vec2(ratio, 1.0));
27
+ }
28
+
29
+ vec4 back(vec2 st) {
30
+ vec4 c = front(st);
31
+ return vec4(mix(paper.rgb, c.rgb, SHOW), c.a * paper.a);
32
+ }
33
+
34
+ // the face of the packet's top layer: the image itself during the first fold, then the back
35
+ // of the right half, laid mirrored over the left half
36
+ vec4 topFace(vec2 st, bool second) {
37
+ return second ? back(vec2(ratio - st.x, st.y)) : front(st);
38
+ }
39
+
40
+ // distance inside the rectangle [0, h] x [0, k] (negative outside)
41
+ float inside(vec2 p, float h, float k) {
42
+ return min(min(p.x, h - p.x), min(p.y, k - p.y));
43
+ }
44
+
45
+ // The sheet in its own frame: a flat part [0, h] x [0, k] lying at z = 0 and a flap of the same
46
+ // size hinged on its edge x = h, turned toward the viewer so that it lies along `along`, with the
47
+ // normal n. During the second fold, x and y are swapped so that the crease is always along y.
48
+ // Where the ray o + t * v meets the flap's plane: (t, distance from the hinge, y), t < 0 if never.
49
+ vec3 hitFlap(vec3 o, vec3 v, float h, vec3 n, vec3 along) {
50
+ float den = dot(n, v);
51
+ if (abs(den) < 1e-5) return vec3(-1.0, 0.0, 0.0);
52
+ vec3 hinge = vec3(h, 0.0, 0.0);
53
+ float t = dot(n, hinge - o) / den;
54
+ vec3 q = o + t * v;
55
+ return vec3(t, dot(q - hinge, along), q.y);
56
+ }
57
+
58
+ // how much the point q is shaded, lit by l: by the flap, and by the flat part once it lifts
59
+ // above the incoming image
60
+ float shadowAt(vec3 q, vec3 l, float h, float k, vec3 n, vec3 along) {
61
+ float sh = 0.0;
62
+ if (q.z < -1e-4) {
63
+ float soft = 0.004 - 0.4 * q.z;
64
+ sh = smoothstep(-soft, soft, inside(q.xy - q.z / l.z * l.xy, h, k));
65
+ }
66
+ vec3 hit = hitFlap(q, l, h, n, along);
67
+ if (hit.x > 0.0) {
68
+ float height = hit.x * l.z;
69
+ float soft = 0.004 + 0.3 * height;
70
+ // the flap's shadow appears as it lifts and vanishes as it lands
71
+ 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));
72
+ }
73
+ return sh;
74
+ }
75
+
76
+ // a vector of the frame into the frame of the sheet, turned by yaw (around y), pitch (around x)
77
+ // and spin (around z), each given as (cos, sin)
78
+ vec3 toSheet(vec3 v, vec2 yaw, vec2 pitch, vec2 spin) {
79
+ v = vec3(yaw.x * v.x + yaw.y * v.z, v.y, yaw.x * v.z - yaw.y * v.x);
80
+ v = vec3(v.x, pitch.x * v.y + pitch.y * v.z, pitch.x * v.z - pitch.y * v.y);
81
+ return vec3(spin.x * v.x + spin.y * v.y, spin.x * v.y - spin.y * v.x, v.z);
82
+ }
83
+
84
+ vec4 transition(vec2 uv) {
85
+ float w = ratio;
86
+ float shade = clamp(shading, 0.0, 1.0);
87
+ // the two folds, one right after the other, then the flight of the packet
88
+ float s = 2.0 * smoothstep(0.0, 0.62, progress);
89
+ bool second = s > 1.0;
90
+ float x = second ? s - 1.0 : s;
91
+ float a = PI * mix(x, x * x * (3.0 - 2.0 * x), 0.6);
92
+ float f = clamp((progress - 0.5) / 0.47, 0.0, 1.0);
93
+
94
+ // the sheet tilts and recedes while it folds, so that the folds are seen in 3D, and lies flat
95
+ // again as the packet flies off
96
+ float turn = clamp(tilt, 0.0, 1.0) * (smoothstep(0.0, 0.25, progress) - smoothstep(0.4, 0.8, progress));
97
+ vec2 yaw = vec2(cos(0.45 * turn), sin(0.45 * turn));
98
+ vec2 pitch = vec2(cos(0.55 * turn), -sin(0.55 * turn));
99
+ float dist = 2.5 * max(w, 1.0);
100
+ float recede = dist * 0.35 * turn;
101
+
102
+ vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
103
+ // the point of the sheet held in the middle of the frame slides to the middle of the packet
104
+ vec2 c = vec2(0.5 * w - 0.25 * w * min(s, 1.0), 0.5 - 0.25 * max(s - 1.0, 0.0));
105
+ // far enough for the packet and its shadow to leave the frame
106
+ float reach = 0.5 * (abs(dir.x) * w + abs(dir.y)) + length(vec2(0.25 * w, 0.25)) + 0.4;
107
+ float lift = 0.3 * smoothstep(0.0, 0.5, f);
108
+ float turned = (dir.x < 0.0 ? 0.7 : -0.7) * f * f;
109
+ vec2 spin = vec2(cos(turned), sin(turned));
110
+
111
+ // the eye, the ray toward the point of the frame and the light, in the frame of the sheet,
112
+ // where the sheet lies on the plane z = 0 and the incoming image on z = -lift
113
+ vec3 center = vec3(vec2(0.5 * w, 0.5) + dir * reach * f * f, -recede);
114
+ vec3 eye = vec3(0.5 * w, 0.5, dist);
115
+ vec3 e = toSheet(eye - center, yaw, pitch, spin) + vec3(c, 0.0);
116
+ vec3 d = toSheet(vec3(uv.x * w, uv.y, 0.0) - eye, yaw, pitch, spin);
117
+ vec3 l = toSheet(LIGHT, yaw, pitch, spin);
118
+ if (second) {
119
+ e.xy = e.yx;
120
+ d.xy = d.yx;
121
+ l.xy = l.yx;
122
+ }
123
+ float h = second ? 0.5 : 0.5 * w;
124
+ float k = second ? 0.5 * w : 1.0;
125
+ float creased = sin(a);
126
+ vec3 n = vec3(-creased, 0.0, cos(a));
127
+ vec3 along = vec3(cos(a), 0.0, creased);
128
+
129
+ vec4 col = getToColor(uv);
130
+ if (d.z < 0.0) {
131
+ vec3 g = e + d * (e.z + lift) / -d.z;
132
+ // the shadow fades as the packet flies higher
133
+ col.rgb *= 1.0 - 0.7 * shade * (1.0 - f * f) * shadowAt(g, l, h, k, n, along);
134
+ }
135
+
136
+ // the flat part
137
+ float t = d.z < 0.0 ? e.z / -d.z : -1.0;
138
+ vec3 p = e + t * d;
139
+ float m = clamp(inside(p.xy, h, k) / (EDGE * t) + 1.0, 0.0, 1.0);
140
+ if (t > 0.0 && m > 0.0) {
141
+ vec4 img = topFace(second ? p.yx : p.xy, second);
142
+ float sh = shadowAt(p, l, h, k, n, along);
143
+ img.rgb *= (1.0 - 0.7 * shade * sh) * (1.0 - 0.5 * shade * creased * exp(-abs(h - p.x) / CREASE));
144
+ col = mix(col, img, m);
145
+ }
146
+
147
+ // the flap
148
+ vec3 hit = hitFlap(e, d, h, n, along);
149
+ if (hit.x > 0.0) {
150
+ float r = hit.y;
151
+ // edges seen at a grazing angle are narrower on screen
152
+ float dr = dot(along, normalize(d));
153
+ float fore = sqrt(max(1.0 - dr * dr, 0.0025));
154
+ float mf = clamp(min(min(r, h - r) * fore, min(hit.z, k - hit.z)) / (EDGE * hit.x) + 1.0, 0.0, 1.0);
155
+ if (mf > 0.0) {
156
+ bool up = dot(n, e - vec3(h, 0.0, 0.0)) > 0.0;
157
+ vec2 st = vec2(h + r, hit.z);
158
+ if (second) st = st.yx;
159
+ vec4 img = up ? topFace(st, second) : back(st);
160
+ // lit by the light, relative to the sheet lying flat
161
+ float lit = dot(up ? n : -n, l) - l.z;
162
+ img.rgb *= max(1.0 + 0.6 * shade * lit, 0.0) * (1.0 - 0.5 * shade * creased * exp(-abs(r) / CREASE));
163
+ col = mix(col, img, mf);
164
+ }
165
+ }
166
+ return col;
167
+ }
@@ -0,0 +1,204 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // 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
4
+ // Tags: 3d, rotate, grid
5
+
6
+ // @range(2, 8, 1) Number of cubies along each side of the face
7
+ uniform int size; // = 3
8
+ // @range(0, 0.05) Width of the gaps between the cubies, as a part of the frame's height
9
+ uniform float gap; // = 0.012
10
+ // @range(0, 1) How much the turning sides darken away from the light, and the shadows inside the cube
11
+ uniform float shading; // = 0.6
12
+ // @color Color of the cubies' body, seen in the gaps, on their inner sides and around the cube
13
+ uniform vec4 background; // = vec4(0.04, 0.04, 0.05, 1.0)
14
+
15
+ const float PI = 3.141592653589793;
16
+ // delay between the turns of a group, as a part of a turn
17
+ const float STAGGER = 0.45;
18
+ // width of the anti-aliased edges, in frame heights
19
+ const float EDGE = 0.0012;
20
+
21
+ float gridSize() {
22
+ return float(size < 2 ? 2 : (size > 8 ? 8 : size));
23
+ }
24
+
25
+ // the turns run in 3 groups, one after the other: the even columns, the even rows (counted from the top),
26
+ // then the odd columns; the turns of a group overlap
27
+ float groupLength(float m) {
28
+ return m > 0.0 ? 1.0 + (m - 1.0) * STAGGER : 0.0;
29
+ }
30
+
31
+ // the time in turn units, and the length of the groups of even and odd slices
32
+ vec3 timeline(float n) {
33
+ float lenEven = groupLength(floor((n + 1.0) * 0.5));
34
+ float lenOdd = groupLength(floor(n * 0.5));
35
+ float u = clamp((progress - 0.05) / 0.85, 0.0, 1.0) * (2.0 * lenEven + lenOdd);
36
+ return vec3(u, lenEven, lenOdd);
37
+ }
38
+
39
+ // the turn of a column (isCol) or of a row, 0 at rest to 1 turned
40
+ float turnTime(vec3 tl, bool isCol, float idx, float n) {
41
+ // rows are counted from the top
42
+ float k = isCol ? idx : n - 1.0 - idx;
43
+ bool odd = mod(k, 2.0) > 0.5;
44
+ // the odd rows never turn: the columns already brought the incoming image there
45
+ if (odd && !isCol) return 0.0;
46
+ float start = (odd ? 2.0 * tl.y : (isCol ? 0.0 : tl.y)) + floor(k * 0.5) * STAGGER;
47
+ return clamp(tl.x - start, 0.0, 1.0);
48
+ }
49
+
50
+ // the turn's direction: +1 brings the side of the cube at higher coordinates to the front
51
+ float turnDir(bool isCol, float idx) {
52
+ return mod(idx + (isCol ? 0.0 : 1.0), 2.0) < 0.5 ? 1.0 : -1.0;
53
+ }
54
+
55
+ // eased angle, landing with a little speed left like a click
56
+ float turnAngle(float t) {
57
+ return 0.5 * PI * mix(t, t * t * (3.0 - 2.0 * t), 0.8);
58
+ }
59
+
60
+ // 1 on the cubies' faces, 0 in the gaps, at the point fp of the face (frame heights)
61
+ float faceMask(vec2 fp, float n, float g) {
62
+ if (g <= 0.0) return 1.0;
63
+ vec2 cell = vec2(ratio, 1.0) / n;
64
+ vec2 c = fp / cell;
65
+ vec2 r = floor(c + 0.5);
66
+ // distance to the nearest cubie edge inside the face (the face's own border has no gap)
67
+ vec2 d = abs(c - r) * cell;
68
+ d.x = (r.x < 0.5 || r.x > n - 0.5) ? 1.0 : d.x;
69
+ d.y = (r.y < 0.5 || r.y > n - 0.5) ? 1.0 : d.y;
70
+ float e = min(EDGE, 0.5 * g);
71
+ return smoothstep(0.5 * g - e, 0.5 * g + e, min(d.x, d.y));
72
+ }
73
+
74
+ // does the cubie of the face at fp show the incoming image, from the turns done so far
75
+ bool isDone(vec3 tl, vec2 fp, float n) {
76
+ vec2 cell = clamp(floor(fp / (vec2(ratio, 1.0) / n)), 0.0, n - 1.0);
77
+ return turnTime(tl, true, cell.x, n) >= 1.0 || turnTime(tl, false, cell.y, n) >= 1.0;
78
+ }
79
+
80
+ vec4 sticker(vec2 fp, bool incoming, float light, float n, float g) {
81
+ vec2 uv = clamp(fp / vec2(ratio, 1.0), 0.0, 1.0);
82
+ vec4 img = incoming ? getToColor(uv) : getFromColor(uv);
83
+ vec4 body = vec4(background.rgb * light, background.a);
84
+ return mix(body, vec4(img.rgb * light, img.a), faceMask(fp, n, g));
85
+ }
86
+
87
+ // brightness of a face of normal nrm (across the slices, along the turn, depth) in the turn's space, 1 facing the viewer
88
+ float lighting(vec3 nrm, bool isCol) {
89
+ vec3 l = normalize(vec3(-0.35, 0.55, 1.0));
90
+ if (isCol) l = l.yxz;
91
+ return 1.0 - shading * (1.0 - clamp(dot(nrm, l) / l.z, 0.0, 1.0));
92
+ }
93
+
94
+ vec2 rot(vec2 v, float a) {
95
+ float c = cos(a), s = sin(a);
96
+ return vec2(c * v.x - s * v.y, s * v.x + c * v.y);
97
+ }
98
+
99
+ // casts the ray (o, d), in the turn's space (across the slices, along the turn, depth), onto the slice
100
+ // [a0, a0 + w] turned by the angle a around the middle of the cube (a square section of side S):
101
+ // returns the ray's parameter at the hit (or -1), the face hit (0 front, 1 back, 2 and 3 the sides
102
+ // at higher and lower coordinates along the turn at rest, 4 the slice's ends), and the point hit
103
+ // (across the slices, and across the face, -1 to 1)
104
+ vec4 sliceHit(vec3 o, vec3 d, float a0, float w, float S, float a) {
105
+ vec2 lo = rot(o.yz - vec2(0.5 * S, -0.5 * S), -a);
106
+ vec2 ld = rot(d.yz, -a);
107
+ ld = vec2(abs(ld.x) < 1e-6 ? 1e-6 : ld.x, abs(ld.y) < 1e-6 ? 1e-6 : ld.y);
108
+ float dx = abs(d.x) < 1e-6 ? 1e-6 : d.x;
109
+ vec3 t1 = vec3((a0 - o.x) / dx, (-0.5 * S - lo) / ld);
110
+ vec3 t2 = vec3((a0 + w - o.x) / dx, (0.5 * S - lo) / ld);
111
+ vec3 tn = min(t1, t2);
112
+ vec3 tf = max(t1, t2);
113
+ float tNear = max(tn.x, max(tn.y, tn.z));
114
+ float tFar = min(tf.x, min(tf.y, tf.z));
115
+ if (tNear > tFar || tNear <= 0.0) return vec4(-1.0);
116
+ vec2 q = (lo + tNear * ld) / (0.5 * S);
117
+ float across = o.x + tNear * d.x;
118
+ if (tn.x >= tn.y && tn.x >= tn.z) return vec4(tNear, 4.0, across, sign(-dx));
119
+ if (tn.y > tn.z) return vec4(tNear, ld.x < 0.0 ? 2.0 : 3.0, across, q.y);
120
+ return vec4(tNear, ld.y < 0.0 ? 0.0 : 1.0, across, q.x);
121
+ }
122
+
123
+ // the color of a turning slice at its hit
124
+ vec4 sliceColor(vec4 hit, vec3 tl, bool isCol, float a, float dir, float S, float n, float g) {
125
+ float f = hit.y;
126
+ if (f > 3.5) return vec4(background.rgb * lighting(vec3(hit.w, 0.0, 0.0), isCol), background.a);
127
+ 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);
128
+ float light = lighting(vec3(0.0, rot(nl, a)), isCol);
129
+ // the front shows what the cubies showed before this turn, the side that comes to the front
130
+ // shows the incoming image where it lands
131
+ bool front = f < 0.5;
132
+ bool coming = nl.x * dir > 0.5;
133
+ if (!front && !coming) return vec4(background.rgb * light, background.a);
134
+ // on the side coming to the front, the point across lands at -dir times its depth
135
+ float r = 0.5 * S * (1.0 + (front ? hit.w : -dir * hit.w));
136
+ vec2 fp = isCol ? vec2(hit.z, r) : vec2(r, hit.z);
137
+ return sticker(fp, coming || isDone(tl, fp, n), light, n, g);
138
+ }
139
+
140
+ vec4 transition(vec2 uv) {
141
+ float n = gridSize();
142
+ vec3 tl = timeline(n);
143
+ // the gaps open at the start and close at the end, after the last turn
144
+ float g = gap * smoothstep(0.0, 0.1, progress) * (1.0 - smoothstep(0.9, 1.0, progress));
145
+ vec2 P = vec2(uv.x * ratio, uv.y);
146
+
147
+ // the turns going on are of columns or of rows, never both
148
+ bool isCol = tl.x < tl.y || tl.x >= 2.0 * tl.y;
149
+ // the turn's space: (across the slices, along the turn, depth toward the viewer);
150
+ // a column turns around the horizontal axis through the middle of the cube, a row around the vertical one
151
+ float w = (isCol ? ratio : 1.0) / n;
152
+ float S = isCol ? 1.0 : ratio;
153
+ vec2 pp = isCol ? P : P.yx;
154
+ vec3 o = vec3(isCol ? vec2(0.5 * ratio, 0.5) : vec2(0.5, 0.5 * ratio), 1.2 + 0.6 * max(ratio, 1.0));
155
+ // the ray reaches the face (z = 0) at t = 1
156
+ vec3 d = vec3(pp, 0.0) - o;
157
+
158
+ float k0 = clamp(floor(pp.x / w), 0.0, n - 1.0);
159
+ float t0 = turnTime(tl, isCol, k0, n);
160
+
161
+ float nearest = 1.0;
162
+ vec4 color;
163
+ if (t0 <= 0.0 || t0 >= 1.0) {
164
+ // the face at rest: the exact image
165
+ color = isDone(tl, P, n) ? getToColor(uv) : getFromColor(uv);
166
+ color = mix(background, color, faceMask(P, n, g));
167
+ // the shade of the turning slices next to this one, deepest mid-turn
168
+ for (int j = -1; j <= 1; j += 2) {
169
+ float k = k0 + float(j);
170
+ if (k < 0.0 || k > n - 1.0) continue;
171
+ float tk = turnTime(tl, isCol, k, n);
172
+ if (tk <= 0.0 || tk >= 1.0) continue;
173
+ float dist = abs(pp.x - (k + 0.5) * w) - 0.5 * w;
174
+ color.rgb *= 1.0 - 0.5 * shading * sin(2.0 * turnAngle(tk)) * exp(-dist / (0.2 * w));
175
+ }
176
+ } else {
177
+ // inside the hollow left by the turning slice: the sides of the slices next to it and the cube's inside, in the dark
178
+ float tw = abs(d.x) < 1e-6 ? 1e6 : (d.x < 0.0 ? k0 * w - o.x : (k0 + 1.0) * w - o.x) / d.x;
179
+ float tb = (o.z + S) / -d.z;
180
+ nearest = min(tw, tb);
181
+ float along = o.y + nearest * d.y;
182
+ float depth = (o.z + nearest * d.z) / -S;
183
+ float light = tw < tb ? lighting(vec3(-sign(d.x), 0.0, 0.0), isCol) : 1.0;
184
+ light *= 1.0 - shading * (0.5 + 0.4 * clamp(depth, 0.0, 1.0));
185
+ // beyond the cube's edges: the background
186
+ color = along < 0.0 || along > S ? background : vec4(background.rgb * light, background.a);
187
+ }
188
+
189
+ // the turning slices, which come out in front of the face as they turn
190
+ for (int j = -1; j <= 1; j++) {
191
+ float k = k0 + float(j);
192
+ if (k < 0.0 || k > n - 1.0) continue;
193
+ float tk = turnTime(tl, isCol, k, n);
194
+ if (tk <= 0.0 || tk >= 1.0) continue;
195
+ float dir = turnDir(isCol, k);
196
+ float a = dir * turnAngle(tk);
197
+ vec4 hit = sliceHit(o, d, k * w, w, S, a);
198
+ if (hit.x > 0.0 && hit.x < nearest) {
199
+ nearest = hit.x;
200
+ color = sliceColor(hit, tl, isCol, a, dir, S, n, g);
201
+ }
202
+ }
203
+ return color;
204
+ }
@@ -0,0 +1,52 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // 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
4
+ // Tags: 3d, flip, rotate
5
+
6
+ // @range(0.1, 2) Length of the twisted section, as a part of the frame's width
7
+ uniform float spread; // = 0.8
8
+ // @range(0, 0.8) Amount of perspective: the edge turning toward the viewer grows
9
+ uniform float perspective; // = 0.4
10
+ // @range(0, 1) How much the ribbon darkens as it turns away
11
+ uniform float shading; // = 0.6
12
+ // @param Twist around the vertical center line instead, travelling from top to bottom
13
+ uniform bool vertical; // = false
14
+ // @color Color seen where the twisting ribbon leaves the frame uncovered
15
+ uniform vec4 backColor; // = vec4(0.0, 0.0, 0.0, 1.0)
16
+
17
+ const float PI = 3.141592653589793;
18
+ // width of the anti-aliased edges, in frame heights
19
+ const float EDGE = 0.002;
20
+
21
+ vec4 transition (vec2 uv) {
22
+ // q.x: along the ribbon, the way the twist travels; q.y: across the ribbon
23
+ vec2 q = vertical ? vec2(1.0 - uv.y, uv.x) : uv;
24
+ // the ribbon's half width across, in frame heights
25
+ float halfSize = vertical ? 0.5 * ratio : 0.5;
26
+ // each line across the ribbon turns half a turn, a little later than the one before
27
+ float t = smoothstep(0.0, 1.0, (progress * (1.0 + spread) - q.x) / spread);
28
+ // the visible face (outgoing front, incoming back) and its angle from its rest position
29
+ bool front = t < 0.5;
30
+ float angle = PI * (front ? t : t - 1.0);
31
+ float c = cos(angle);
32
+ float s = sin(angle);
33
+ // w: screen position across the ribbon, -1 to 1 at rest; v: the matching position on the face
34
+ // a point v of the face goes to v * c across and v * s in depth, nearer points look bigger
35
+ float w = 2.0 * q.y - 1.0;
36
+ float den = c + perspective * w * s;
37
+ if (den <= 0.0) return backColor;
38
+ float v = w / den;
39
+ if (abs(v) >= 1.0) return backColor;
40
+ // soft edges while twisting (sharp at rest, to keep the first and last frames exact)
41
+ float edge = max(EDGE * min(1.0, 20.0 * abs(s)), 1e-4);
42
+ float top = c / (1.0 - perspective * s);
43
+ float bottom = -c / (1.0 + perspective * s);
44
+ float cover = clamp(min(top - w, w - bottom) * halfSize / edge, 0.0, 1.0);
45
+ vec2 p = vec2(q.x, 0.5 + 0.5 * v);
46
+ p = vertical ? vec2(p.y, 1.0 - p.x) : p;
47
+ vec4 img = front ? getFromColor(p) : getToColor(p);
48
+ // lit from the front and slightly from one side of the axis
49
+ float lambert = clamp(c - 0.25 * s, 0.0, 1.0);
50
+ vec4 color = vec4(img.rgb * mix(1.0 - shading, 1.0, lambert), img.a);
51
+ return mix(backColor, color, cover);
52
+ }