gl-transitions 3.2.0 → 3.3.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 (76) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/compatibility.json +210 -0
  3. package/gl-transitions.js +1 -1
  4. package/gl-transitions.json +1 -1
  5. package/glsl3/CardDeal.glsl +146 -0
  6. package/glsl3/EchoSlide.glsl +93 -0
  7. package/glsl3/GeometricCollage.glsl +241 -0
  8. package/glsl3/HingedSquares.glsl +121 -0
  9. package/glsl3/HorizontalHold.glsl +62 -0
  10. package/glsl3/LayoutGrid.glsl +147 -0
  11. package/glsl3/ProjectorThrow.glsl +75 -0
  12. package/glsl3/Reassemble.glsl +156 -0
  13. package/glsl3/Shockwave.glsl +103 -0
  14. package/glsl3/ShoreWash.glsl +150 -0
  15. package/glsl3/ShutterWipe.glsl +68 -0
  16. package/glsl3/StopMotion.glsl +118 -0
  17. package/glsl3/Vaporize.glsl +125 -0
  18. package/index.js +1 -1
  19. package/layouts.json +493 -0
  20. package/llms-full.txt +647 -434
  21. package/llms.txt +238 -225
  22. package/msl/CardDeal.metal +539 -0
  23. package/msl/EchoSlide.metal +438 -0
  24. package/msl/GeometricCollage.metal +1188 -0
  25. package/msl/HingedSquares.metal +564 -0
  26. package/msl/HorizontalHold.metal +286 -0
  27. package/msl/LayoutGrid.metal +544 -0
  28. package/msl/ProjectorThrow.metal +313 -0
  29. package/msl/Reassemble.metal +667 -0
  30. package/msl/Shockwave.metal +256 -0
  31. package/msl/ShoreWash.metal +538 -0
  32. package/msl/ShutterWipe.metal +286 -0
  33. package/msl/StopMotion.metal +551 -0
  34. package/msl/Vaporize.metal +462 -0
  35. package/package.json +1 -1
  36. package/skills/gl-transitions/references/catalog.md +70 -32
  37. package/sksl/CardDeal.sksl +156 -0
  38. package/sksl/EchoSlide.sksl +99 -0
  39. package/sksl/GeometricCollage.sksl +242 -0
  40. package/sksl/HingedSquares.sksl +124 -0
  41. package/sksl/HorizontalHold.sksl +74 -0
  42. package/sksl/LayoutGrid.sksl +156 -0
  43. package/sksl/ProjectorThrow.sksl +85 -0
  44. package/sksl/Reassemble.sksl +166 -0
  45. package/sksl/Shockwave.sksl +116 -0
  46. package/sksl/ShoreWash.sksl +159 -0
  47. package/sksl/ShutterWipe.sksl +80 -0
  48. package/sksl/StopMotion.sksl +126 -0
  49. package/sksl/Vaporize.sksl +134 -0
  50. package/sksl/index.js +1 -1
  51. package/transitions/CardDeal.glsl +145 -0
  52. package/transitions/EchoSlide.glsl +92 -0
  53. package/transitions/GeometricCollage.glsl +240 -0
  54. package/transitions/HingedSquares.glsl +120 -0
  55. package/transitions/HorizontalHold.glsl +61 -0
  56. package/transitions/LayoutGrid.glsl +146 -0
  57. package/transitions/ProjectorThrow.glsl +74 -0
  58. package/transitions/Reassemble.glsl +155 -0
  59. package/transitions/Shockwave.glsl +102 -0
  60. package/transitions/ShoreWash.glsl +149 -0
  61. package/transitions/ShutterWipe.glsl +67 -0
  62. package/transitions/StopMotion.glsl +117 -0
  63. package/transitions/Vaporize.glsl +124 -0
  64. package/wgsl/CardDeal.wgsl +496 -0
  65. package/wgsl/EchoSlide.wgsl +386 -0
  66. package/wgsl/GeometricCollage.wgsl +1075 -0
  67. package/wgsl/HingedSquares.wgsl +506 -0
  68. package/wgsl/HorizontalHold.wgsl +243 -0
  69. package/wgsl/LayoutGrid.wgsl +495 -0
  70. package/wgsl/ProjectorThrow.wgsl +274 -0
  71. package/wgsl/Reassemble.wgsl +609 -0
  72. package/wgsl/Shockwave.wgsl +226 -0
  73. package/wgsl/ShoreWash.wgsl +492 -0
  74. package/wgsl/ShutterWipe.wgsl +252 -0
  75. package/wgsl/StopMotion.wgsl +496 -0
  76. package/wgsl/Vaporize.wgsl +420 -0
@@ -0,0 +1,145 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The incoming image is dealt onto the frame like a hand of cards: tile after tile is flicked from below the frame, spinning through the air with a lifting shadow, and slides to a stop in its place until the picture is complete
4
+ // Tags: tiles, card, rotate, shadow, 3d
5
+
6
+ // @param Number of cards (columns, rows), at most 6 by 6
7
+ uniform ivec2 grid; // = ivec2(4, 3)
8
+ // @param Point the cards are dealt from, can be outside the frame
9
+ uniform vec2 deck; // = vec2(0.5, -0.4)
10
+ // @range(0, 2) Turns a card makes on its way, before it settles straight
11
+ uniform float spin; // = 0.6
12
+ // @range(0, 1) Darkness of the shadows the cards cast
13
+ uniform float shadow; // = 0.5
14
+
15
+ const float PI = 3.141592653589793;
16
+ const int MAX_CARDS = 36;
17
+ // time between two cards, relative to the time a card takes from the deck to its place
18
+ const float DEAL = 0.16;
19
+ // part of its way after which a card touches down and starts sliding
20
+ const float TOUCH = 0.55;
21
+ // speed of the throw, relative to an even pace
22
+ const float THROW = 2.2;
23
+ // length of the slide, in card heights
24
+ const float SLIDE = 0.35;
25
+ // highest point of a card's flight, and distance of the eye to the table, in frame heights
26
+ const float LIFT = 0.45;
27
+ const float EYE = 2.4;
28
+ // width of the anti-aliased edges, in frame heights
29
+ const float EDGE = 0.0015;
30
+
31
+ float hash(float n) {
32
+ vec2 p = fract(vec2(n) * vec2(0.1031, 0.1030));
33
+ p += dot(p, p.yx + 33.33);
34
+ return fract((p.x + p.y) * p.x);
35
+ }
36
+
37
+ vec2 gridSize() {
38
+ return clamp(vec2(grid), 1.0, 6.0);
39
+ }
40
+
41
+ // local time of card j: 0 on the deck, 1 once it lies still in its place
42
+ float cardTime(float j, float n) {
43
+ // the last card lands at the end
44
+ float flight = 1.0 / (1.0 + (n - 1.0) * DEAL);
45
+ return clamp((progress - j * DEAL * flight) / flight, 0.0, 1.0);
46
+ }
47
+
48
+ // center of the place of card j, dealt in reading order from the top left
49
+ vec2 cardCell(float j, vec2 g) {
50
+ float row = floor(j / g.x);
51
+ return vec2(j - row * g.x, g.y - 1.0 - row);
52
+ }
53
+
54
+ // signed distance to the edge of a card (positive inside), from its local coordinates q (0..1) and its size
55
+ float cardDist(vec2 q, vec2 size) {
56
+ vec2 e = min(q, 1.0 - q) * size;
57
+ return min(e.x, e.y);
58
+ }
59
+
60
+ vec4 transition(vec2 uv) {
61
+ if (progress <= 0.0) return getFromColor(uv);
62
+ if (progress >= 1.0) return getToColor(uv);
63
+
64
+ vec2 g = gridSize();
65
+ float n = g.x * g.y;
66
+ vec2 asp = vec2(ratio, 1.0);
67
+ vec2 size = asp / g;
68
+ vec2 p = uv * asp;
69
+ vec2 origin = deck * asp;
70
+ float darkness = clamp(shadow, 0.0, 1.0);
71
+
72
+ // the table: the cards already in their place, the outgoing image elsewhere
73
+ vec2 own = min(floor(uv * g), g - 1.0);
74
+ float ownIndex = (g.y - 1.0 - own.y) * g.x + own.x;
75
+ vec4 col = cardTime(ownIndex, n) >= 1.0 ? getToColor(uv) : getFromColor(uv);
76
+
77
+ // the cards on their way, from the first dealt to the last: later cards lie on top
78
+ for (int i = 0; i < MAX_CARDS; i++) {
79
+ float j = float(i);
80
+ if (j >= n) break;
81
+ float u = cardTime(j, n);
82
+ if (u <= 0.0) break;
83
+ if (u >= 1.0) continue;
84
+
85
+ vec2 cell = cardCell(j, g);
86
+ vec2 target = (cell + 0.5) * size;
87
+ vec2 way = target - origin;
88
+ float len = max(length(way), 1e-3);
89
+ vec2 side = vec2(-way.y, way.x);
90
+ float r1 = hash(j + 1.0);
91
+ float r2 = hash(j + 60.0);
92
+ float turn = r2 < 0.5 ? -1.0 : 1.0;
93
+ // share of its way the card slides on the table once it has touched down
94
+ float slide = min(SLIDE * size.y / len, 0.5);
95
+ // thrown fast, it flies (a), touches down and slides to a stop (s), braked by the table
96
+ float a = min(u / TOUCH, 1.0);
97
+ float s = clamp((u - TOUCH) / (1.0 - TOUCH), 0.0, 1.0);
98
+ // the flight ends at the speed the slide starts with
99
+ float v1 = 2.0 * slide * TOUCH / ((1.0 - TOUCH) * (1.0 - slide));
100
+ float f = (3.0 - 2.0 * a) * a * a + THROW * (a * a * a - 2.0 * a * a + a) + v1 * (a * a * a - a * a);
101
+ float e = u < TOUCH ? (1.0 - slide) * f : 1.0 - slide * (1.0 - s) * (1.0 - s);
102
+ // a slight curve, bending the way the card spins
103
+ vec2 c = origin + way * e + side * turn * (0.05 + 0.05 * r1) * sin(PI * e);
104
+ // height above the table, zero from the touch down on
105
+ float h = LIFT * (0.7 + 0.3 * r1) * sin(PI * a) * (1.0 - 0.35 * a);
106
+ float angle = turn * spin * (0.8 + 0.4 * r2) * 2.0 * PI * (1.0 - e);
107
+ // tilt of the card in the air, which wobbles as it spins
108
+ float tilt = 0.45 * sin(PI * a) * cos(angle * 0.5 + 6.0 * r1);
109
+ // 1 in the air, 0 once on the table
110
+ float air = 1.0 - a * a;
111
+ float fade = smoothstep(0.0, 0.05, u);
112
+
113
+ // shadow on the table, pushed away from the light and softened with height
114
+ vec2 sp = p - c - vec2(0.18, -0.3) * h - vec2(0.002, -0.003);
115
+ float ca = cos(angle), sa = sin(angle);
116
+ mat2 rot = mat2(ca, -sa, sa, ca);
117
+ vec2 sq = rot * sp / size + 0.5;
118
+ float soft = 0.006 + 0.08 * h;
119
+ float sh = smoothstep(-soft, soft, cardDist(sq, size));
120
+ // dark under a card in the air, a thin contact shadow fading as it comes to rest
121
+ float dark = mix(0.8 * (1.0 - s), 0.65 - 0.3 * h / LIFT, air);
122
+ col.rgb *= 1.0 - fade * darkness * dark * sh;
123
+
124
+ // the card, closer to the eye as it rises, seen in perspective as it tilts
125
+ vec2 d = rot * (p - c) * (EYE - h) / EYE;
126
+ float ct = cos(tilt), st = sin(tilt);
127
+ // past the horizon of the tilted card, the point is off the card
128
+ float den = EYE * ct + d.y * st;
129
+ float k = den > 1e-3 ? EYE * ct / den : 1e3;
130
+ vec2 q = vec2(k * d.x, k * d.y * ct + EYE * (1.0 - k) * st) / size + 0.5;
131
+ // its edges sharpen as it comes to rest, to meet its neighbors without a seam
132
+ float edge = EDGE * (1.0 + 2.0 * air) * min(10.0 * (1.0 - s), 1.0);
133
+ float m = fade * clamp(cardDist(q, size) / max(edge, 1e-6) + 0.5, 0.0, 1.0);
134
+ if (m > 0.0) {
135
+ vec4 face = getToColor((cell + clamp(q, 0.0, 1.0)) / g);
136
+ // light from the upper left: a tilted card catches it or turns away from it
137
+ float light = 1.0 + 0.6 * st * (0.6 - 0.4 * turn * sin(angle));
138
+ // a thin bright rim while it travels
139
+ float rim = 1.0 - smoothstep(0.0, 0.008, cardDist(q, size));
140
+ face.rgb = mix(min(face.rgb * light, vec3(face.a)), vec3(face.a), 0.45 * air * rim);
141
+ col = mix(col, face, m);
142
+ }
143
+ }
144
+ return col;
145
+ }
@@ -0,0 +1,92 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image slides away leaving a trail of discrete fading copies of itself, a stroboscopic echo, and the incoming image's echoes converge into place
4
+ // Tags: slide, echo, strobe, directional
5
+
6
+ // @param Direction in which the images slide
7
+ uniform vec2 direction; // = vec2(1.0, 0.0)
8
+ // @range(1, 7, 1) Number of echoes between the two images
9
+ uniform int echoes; // = 4
10
+ // @range(0.05, 0.6) How long the echoes trail behind each image, as a part of the transition
11
+ uniform float trail; // = 0.25
12
+ // @range(0, 1) How fast the echoes of the outgoing image fade out into those of the incoming one
13
+ uniform float decay; // = 0.5
14
+
15
+ // width of the anti-aliased edges, along the slide
16
+ const float EDGE = 0.002;
17
+ // the most echoes, the bound of the loop
18
+ const int MAX_ECHOES = 7;
19
+
20
+ float easeInOut(float t) {
21
+ return t * t * (3.0 - 2.0 * t);
22
+ }
23
+
24
+ // mirror the coordinates back into the frame
25
+ vec2 mirror(vec2 v) {
26
+ return 1.0 - abs(1.0 - mod(v, 2.0));
27
+ }
28
+
29
+ // coverage of the part of the frame past an edge at x, anti-aliased only inside the frame
30
+ float past(float s, float x) {
31
+ return x <= 0.0 ? 1.0 : x >= 1.0 ? 0.0 : clamp((s - x) / EDGE + 0.5, 0.0, 1.0);
32
+ }
33
+
34
+ // the edge between the copies at the time t of the slide
35
+ float edgeAt(float t) {
36
+ return easeInOut(clamp(t, 0.0, 1.0));
37
+ }
38
+
39
+ // step j between the two images, from the edge e0 to the edge e1: the echo of the outgoing image
40
+ // whose trailing edge is e0, fading out toward the incoming image, over the echo of the incoming
41
+ // image whose leading edge is e1
42
+ vec4 echoStep(vec2 uv, float s, vec2 shift, float j, float t0, float lag, float n) {
43
+ float e0 = edgeAt(t0 + j * lag);
44
+ float e1 = edgeAt(t0 + (j + 1.0) * lag);
45
+ vec4 a = getFromColor(mirror(uv - shift * e0));
46
+ vec4 b = getToColor(mirror(uv - shift * (e1 - 1.0)));
47
+ vec4 c = mix(b, a, pow((j + 0.5) / n, 0.5 + 2.0 * clamp(decay, 0.0, 1.0)));
48
+ // each copy casts a soft shadow behind it onto the older ones
49
+ c.rgb *= 1.0 - 0.25 * exp(-max(e1 - s, 0.0) / 0.02) * min((e1 - e0) / 0.02, 1.0);
50
+ return c;
51
+ }
52
+
53
+ vec4 transition(vec2 uv) {
54
+ float dl = length(direction);
55
+ vec2 d = dl > 1e-6 ? direction / dl : vec2(1.0, 0.0);
56
+ // s: position along the slide, from 0 (trailing side) to 1 (leading side)
57
+ float ext = abs(d.x) + abs(d.y);
58
+ vec2 shift = d * ext;
59
+ float s = 0.5 + dot(uv - 0.5, d) / ext;
60
+
61
+ float n = clamp(float(echoes), 1.0, float(MAX_ECHOES));
62
+ float tr = clamp(trail, 0.05, 0.6);
63
+ float lag = tr / n;
64
+ // the incoming image follows the outgoing one tr behind; the copies of both images sit at
65
+ // the times between them, the stroboscopic echoes of the outgoing image trailing behind it
66
+ // and those of the incoming image ahead of it
67
+ float t0 = progress >= 1.0 ? 1.0 : progress * (1.0 + tr) - tr;
68
+ float eIn = edgeAt(t0);
69
+ float eOut = edgeAt(t0 + tr);
70
+
71
+ float wIn = 1.0 - past(s, eIn);
72
+ float wOut = past(s, eOut);
73
+ float wGap = max(1.0 - wIn - wOut, 0.0);
74
+ vec4 c = vec4(0.0);
75
+ if (wGap > 0.0) {
76
+ // the step of this point, and how far it is past the next edge, to anti-alias it
77
+ float jf = 0.0;
78
+ for (int k = 1; k < MAX_ECHOES; k++) {
79
+ float m = float(k);
80
+ if (m >= n) break;
81
+ jf += past(s, edgeAt(t0 + m * lag));
82
+ }
83
+ float j = floor(jf);
84
+ c = echoStep(uv, s, shift, j, t0, lag, n);
85
+ if (jf > j) c = mix(c, echoStep(uv, s, shift, j + 1.0, t0, lag, n), jf - j);
86
+ c *= wGap;
87
+ }
88
+ // the two images on both sides of their echoes
89
+ if (wIn > 0.0) c += wIn * getToColor(mirror(uv - shift * (eIn - 1.0)));
90
+ if (wOut > 0.0) c += wOut * getFromColor(mirror(uv - shift * eOut));
91
+ return c;
92
+ }
@@ -0,0 +1,240 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The incoming image arrives cut into a geometric poster of quarter discs, half discs, triangles and their complements: piece after piece swings in around a corner of its cell, a flat plate of color just ahead of it, and lands flat with a soft paper shadow
4
+ // Tags: geometric, shapes, collage, rotate, color
5
+
6
+ // @range(1, 5, 1) Number of cells along the short side of the frame, the long side gets as many as keep them about square
7
+ uniform int cells; // = 2
8
+ // @range(0, 1) How spread out in time the pieces arrive: 0 swings them all in together, 1 lands them one after another
9
+ uniform float stagger; // = 1.0
10
+ // @param Show a flat plate of color swinging in just ahead of each piece
11
+ uniform bool plates; // = true
12
+ // @color First plate color
13
+ uniform vec4 color1; // = vec4(0.89, 0.22, 0.17, 1.0)
14
+ // @color Second plate color
15
+ uniform vec4 color2; // = vec4(0.97, 0.77, 0.15, 1.0)
16
+ // @color Third plate color
17
+ uniform vec4 color3; // = vec4(0.14, 0.32, 0.66, 1.0)
18
+ // @range(0, 1) Darkness of the shadows the pieces cast while they swing in
19
+ uniform float shadow; // = 0.6
20
+
21
+ const float PI = 3.141592653589793;
22
+ // shortest duration of the swing of one layer, delay of a cell's second piece, lead of a plate over its piece
23
+ const float DUR = 0.24;
24
+ const float GAP = 0.07;
25
+ const float LEAD = 0.06;
26
+ // part of a swing after which a layer has turned into place, and only comes down flat onto the paper
27
+ const float SETTLE = 0.8;
28
+ // width of the anti-aliased edges, in frame heights
29
+ const float EDGE = 0.002;
30
+
31
+ float hash12(vec2 v) {
32
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
33
+ v3 += dot(v3, v3.yzx + 33.33);
34
+ return fract((v3.x + v3.y) * v3.z);
35
+ }
36
+
37
+ // the cell's layout seen from its first piece: the local point turned by k quarter turns around the cell center
38
+ vec2 orient(vec2 l, float k) {
39
+ vec2 c = l - 0.5;
40
+ if (k < 0.5) return l;
41
+ if (k < 1.5) return vec2(-c.y, c.x) + 0.5;
42
+ if (k < 2.5) return 0.5 - c;
43
+ return vec2(c.y, -c.x) + 0.5;
44
+ }
45
+
46
+ // the cell corner that orient(., k) maps to the corner (0, 0): the first piece's pivot
47
+ vec2 pivotCorner(float k) {
48
+ if (k < 0.5) return vec2(0.0, 0.0);
49
+ if (k < 1.5) return vec2(0.0, 1.0);
50
+ if (k < 2.5) return vec2(1.0, 1.0);
51
+ return vec2(1.0, 0.0);
52
+ }
53
+
54
+ // signed distance (in cell units) to the cell's first piece, negative inside; the second piece is its complement
55
+ float shapeDist(vec2 o, float type) {
56
+ if (type < 0.5) return length(o) - 1.0; // quarter disc around the pivot
57
+ if (type < 1.5) return length(o - vec2(0.5, 0.0)) - 0.5; // half disc on an edge
58
+ return (o.x + o.y - 1.0) * 0.70710678; // triangle
59
+ }
60
+
61
+ // signed distance (in cell units) to a piece of a cell at the local point l, negative inside
62
+ float pieceDist(vec2 l, vec2 cell, float piece) {
63
+ float k = floor(hash12(cell + 1.7) * 4.0);
64
+ // cells side by side never share a shape
65
+ float sd = shapeDist(orient(l, k), mod(cell.x + 2.0 * cell.y + 1.0, 3.0));
66
+ return piece > 0.5 ? -sd : sd;
67
+ }
68
+
69
+ float boxDist(vec2 l) {
70
+ return min(min(l.x, l.y), min(1.0 - l.x, 1.0 - l.y));
71
+ }
72
+
73
+ float easeOutCubic(float t) {
74
+ float u = 1.0 - clamp(t, 0.0, 1.0);
75
+ return 1.0 - u * u * u;
76
+ }
77
+
78
+ // how high a layer floats above the paper along its swing, 0 once landed
79
+ float lift(float t) {
80
+ return 1.0 - smoothstep(0.3, 1.0, t);
81
+ }
82
+
83
+ // the time over which the cells start one after another, and the duration of a swing, which gets
84
+ // longer when the cells start closer together, so that the last piece always lands just before the end
85
+ float spread() {
86
+ return (1.0 - DUR - GAP - LEAD - 0.02) * clamp(stagger, 0.0, 1.0);
87
+ }
88
+ float swing() {
89
+ return 1.0 - GAP - LEAD - 0.02 - spread();
90
+ }
91
+
92
+ // when the first piece of a cell starts to swing in; the second one starts GAP later, and a plate LEAD before its piece
93
+ float startTime(vec2 cell, vec2 n) {
94
+ float order = (cell.x + (n.y - 1.0 - cell.y)) / max(n.x + n.y - 2.0, 1.0);
95
+ order = clamp(order * 0.75 + 0.25 * hash12(cell + 4.4), 0.0, 1.0);
96
+ return LEAD + spread() * order;
97
+ }
98
+
99
+ // the local point in the cell of a swinging layer at its local time t (0 < t < 1), seen at the frame point p,
100
+ // and its scale
101
+ vec3 swingPoint(vec2 p, vec2 cell, vec2 cs, float piece, float t) {
102
+ vec2 pc = pivotCorner(floor(hash12(cell + 1.7) * 4.0));
103
+ // the first piece turns around its pivot corner, its complement around the opposite one
104
+ vec2 piv = (cell + (piece < 0.5 ? pc : 1.0 - pc)) * cs;
105
+ float sgn = hash12(cell + vec2(piece * 3.3, 5.2)) < 0.5 ? -1.0 : 1.0;
106
+ // grows out of the corner while it swings a quarter turn into place, a bit bigger while it floats
107
+ float s = smoothstep(0.0, 0.45, t) * (1.0 + 0.1 * lift(t));
108
+ // the swing settles first, then the layer comes down flat onto the paper
109
+ float a = sgn * 0.5 * PI * (1.0 - easeOutCubic(t / SETTLE));
110
+ float ca = cos(a), sa = sin(a);
111
+ vec2 d = p - piv;
112
+ d = vec2(ca * d.x + sa * d.y, -sa * d.x + ca * d.y) / max(s, 0.001);
113
+ return vec3((piv + d) / cs - cell, s);
114
+ }
115
+
116
+ // the coverage of a swinging layer and its local point in the cell
117
+ vec3 layerCover(vec2 p, vec2 cell, vec2 cs, float piece, float t) {
118
+ vec3 q = swingPoint(p, cell, cs, piece, t);
119
+ if (q.z < 0.01) return vec3(0.0);
120
+ float e = EDGE / (min(cs.x, cs.y) * q.z);
121
+ float m = clamp(boxDist(q.xy) / e + 0.5, 0.0, 1.0) * clamp(-pieceDist(q.xy, cell, piece) / e + 0.5, 0.0, 1.0);
122
+ return vec3(m, clamp(q.xy, 0.0, 1.0));
123
+ }
124
+
125
+ // the coverage of the soft shadow of a swinging layer: it falls down and to the right, further away the higher it floats
126
+ float layerShadow(vec2 p, vec2 cell, vec2 cs, float piece, float t) {
127
+ float h = lift(t);
128
+ vec3 q = swingPoint(p - vec2(0.07, -0.1) * h * cs.y, cell, cs, piece, t);
129
+ if (q.z < 0.01) return 0.0;
130
+ float soft = 0.02 + 0.05 * h;
131
+ return h * (1.0 - smoothstep(-soft, soft, pieceDist(q.xy, cell, piece))) * smoothstep(-soft, soft, boxDist(q.xy));
132
+ }
133
+
134
+ vec4 plateColor(vec2 cell, float piece) {
135
+ float c = mod(floor(hash12(cell * 1.3 + 0.7) * 3.0) + piece, 3.0);
136
+ return c < 0.5 ? color1 : c < 1.5 ? color2 : color3;
137
+ }
138
+
139
+ vec4 premultiplied(vec4 c) {
140
+ return vec4(c.rgb * c.a, c.a);
141
+ }
142
+
143
+ vec4 transition(vec2 uv) {
144
+ float kc = float(cells < 1 ? 1 : cells);
145
+ vec2 n = ratio >= 1.0 ? vec2(max(1.0, floor(ratio * kc + 0.5)), kc) : vec2(kc, max(1.0, floor(kc / ratio + 0.5)));
146
+ vec2 cs = vec2(ratio, 1.0) / n;
147
+ vec2 p = uv * vec2(ratio, 1.0);
148
+ vec2 cell0 = floor(p / cs);
149
+ float sw = swing();
150
+
151
+ // the paper: the outgoing image, where the pieces that have landed show the incoming one. They lie flat side by side
152
+ // and tile the frame exactly, with hard cell edges and anti-aliased edges between the two pieces of a cell
153
+ vec2 l0 = p / cs - cell0;
154
+ float t00 = startTime(cell0, n);
155
+ float sd0 = pieceDist(l0, cell0, 0.0);
156
+ float e0 = EDGE / min(cs.x, cs.y);
157
+ float landed = (progress >= t00 + sw ? clamp(-sd0 / e0 + 0.5, 0.0, 1.0) : 0.0)
158
+ + (progress >= t00 + GAP + sw ? clamp(sd0 / e0 + 0.5, 0.0, 1.0) : 0.0);
159
+ // the layers still in the air, and the plates not yet covered by their pieces: the top one at p and the one
160
+ // under it by start time, as (start, coverage, plate, piece) and (cell, local point)
161
+ vec4 top = vec4(-1.0, 0.0, 0.0, 0.0);
162
+ vec4 topPos = vec4(0.0);
163
+ vec4 und = vec4(-1.0, 0.0, 0.0, 0.0);
164
+ vec4 undPos = vec4(0.0);
165
+ for (int dy = -1; dy <= 1; dy++) {
166
+ for (int dx = -1; dx <= 1; dx++) {
167
+ vec2 cell = cell0 + vec2(float(dx), float(dy));
168
+ if (cell.x < 0.0 || cell.y < 0.0 || cell.x >= n.x || cell.y >= n.y) continue;
169
+ float tc = startTime(cell, n);
170
+ for (int pc = 0; pc < 2; pc++) {
171
+ float piece = float(pc);
172
+ float t0 = tc + GAP * piece;
173
+ // how far the piece is in its swing
174
+ float tp = (progress - t0) / sw;
175
+ for (int ly = 0; ly < 2; ly++) {
176
+ float isPlate = ly == 0 ? 1.0 : 0.0;
177
+ if (isPlate > 0.5 && !plates) continue;
178
+ float ts = t0 - LEAD * isPlate;
179
+ float t = (progress - ts) / sw;
180
+ // a landed piece is part of the paper, and its plate fades out under it once it has turned into place
181
+ if (t <= 0.0 || tp >= 1.0 || (isPlate > 0.5 && tp >= SETTLE)) continue;
182
+ vec3 L = layerCover(p, cell, cs, piece, min(t, 1.0));
183
+ if (isPlate > 0.5) L.x *= 1.0 - smoothstep(SETTLE - 0.1, SETTLE, tp);
184
+ if (L.x <= 0.0) continue;
185
+ vec4 cur = vec4(ts, L.x, isPlate, piece);
186
+ vec4 curPos = vec4(cell, L.yz);
187
+ if (ts > top.x) {
188
+ und = top;
189
+ undPos = topPos;
190
+ top = cur;
191
+ topPos = curPos;
192
+ } else if (ts > und.x) {
193
+ und = cur;
194
+ undPos = curPos;
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ // a piece coming down next to its landed complement does not overlap it along their common edge: their coverages add up
201
+ if (top.z < 0.5 && und.x < 0.0 && topPos.x == cell0.x && topPos.y == cell0.y) {
202
+ landed = top.y < 1.0 ? landed / (1.0 - top.y) : 1.0;
203
+ }
204
+ vec4 c = mix(premultiplied(getFromColor(uv)), premultiplied(getToColor(uv)), clamp(landed, 0.0, 1.0));
205
+ if (und.x >= 0.0) {
206
+ vec4 uc = und.z > 0.5 ? plateColor(undPos.xy, und.w) : getToColor((undPos.xy + undPos.zw) * cs / vec2(ratio, 1.0));
207
+ c = mix(c, premultiplied(uc), und.y);
208
+ }
209
+ if (top.x >= 0.0) {
210
+ vec4 tc = top.z > 0.5 ? plateColor(topPos.xy, top.w) : getToColor((topPos.xy + topPos.zw) * cs / vec2(ratio, 1.0));
211
+ c = mix(c, premultiplied(tc), top.y);
212
+ }
213
+
214
+ // the soft shadows of the layers floating above the top one
215
+ float sh = 0.0;
216
+ if (shadow > 0.0) {
217
+ for (int dy = -1; dy <= 1; dy++) {
218
+ for (int dx = -1; dx <= 1; dx++) {
219
+ vec2 cell = cell0 + vec2(float(dx), float(dy));
220
+ if (cell.x < 0.0 || cell.y < 0.0 || cell.x >= n.x || cell.y >= n.y) continue;
221
+ float tc = startTime(cell, n);
222
+ for (int pc = 0; pc < 2; pc++) {
223
+ float piece = float(pc);
224
+ float t0 = tc + GAP * piece;
225
+ float tp = (progress - t0) / sw;
226
+ for (int ly = 0; ly < 2; ly++) {
227
+ float isPlate = ly == 0 ? 1.0 : 0.0;
228
+ if (isPlate > 0.5 && (!plates || tp >= SETTLE)) continue;
229
+ float ts = t0 - LEAD * isPlate;
230
+ float t = (progress - ts) / sw;
231
+ if (ts <= top.x || t <= 0.0 || t >= 1.0) continue;
232
+ sh = max(sh, layerShadow(p, cell, cs, piece, t));
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+ c.rgb *= 1.0 - 0.7 * clamp(shadow, 0.0, 1.0) * sh;
239
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
240
+ }
@@ -0,0 +1,120 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The image is cut into squares that turn in alternate directions while staying hinged at their corners, so the sheet opens into a checkerboard of diamonds showing the incoming image; those diamonds then turn back into place and close the sheet
4
+ // Tags: grid, tiles, geometric, rotate
5
+
6
+ // @range(1, 20, 1) Number of squares across the height of the frame
7
+ uniform int cells; // = 5
8
+ // @range(0, 1) Strength of the bevel on the turning squares and of the soft shadow they cast into the gaps
9
+ uniform float shading; // = 0.6
10
+ // @range(0, 1) How much the view zooms out to keep the opening sheet in frame (0: the sheet grows past the frame edges)
11
+ uniform float zoom; // = 0.5
12
+
13
+ const float PI = 3.141592653589793;
14
+ // half width of the anti-aliased edges, as a part of the frame's height
15
+ const float EDGE = 0.0012;
16
+
17
+ // turns v clockwise by the angle whose cosine and sine are cs
18
+ vec2 rot(vec2 v, vec2 cs) {
19
+ return vec2(cs.x * v.x + cs.y * v.y, -cs.y * v.x + cs.x * v.y);
20
+ }
21
+
22
+ // one of the 4 lattice nodes around a point
23
+ vec2 node(float i) {
24
+ return vec2(mod(i, 2.0), floor(i * 0.5));
25
+ }
26
+
27
+ // alternate squares turn in opposite directions
28
+ float parity(vec2 n) {
29
+ return mod(n.x + n.y, 2.0) < 0.5 ? 1.0 : -1.0;
30
+ }
31
+
32
+ // The square nearest to w among the 4 around the cell g of a hinged lattice of unit squares
33
+ // centered at (n + off) * spacing, each turned by +-the angle of cs:
34
+ // returns its local coordinates, the signed distance to it and its node index.
35
+ vec4 nearest(vec2 w, vec2 g, float spacing, vec2 off, vec2 cs) {
36
+ vec4 best = vec4(0.0, 0.0, 1e5, 0.0);
37
+ for (int i = 0; i < 4; i++) {
38
+ vec2 n = g + node(float(i));
39
+ vec2 l = rot(w - (n + off) * spacing, vec2(cs.x, parity(n) * cs.y));
40
+ vec2 q = abs(l) - 0.5;
41
+ float d = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0);
42
+ if (d < best.z) best = vec4(l, d, float(i));
43
+ }
44
+ return best;
45
+ }
46
+
47
+ // The gap of that lattice around w: a rhombus of unit sides centered at a node of the other
48
+ // lattice, with half diagonals cs.x and cs.y. Returns the local coordinates of the piece of the
49
+ // other image it shows, held at 45 degrees, and its node index.
50
+ vec3 gap(vec2 w, vec2 g, float spacing, vec2 off, vec2 cs) {
51
+ vec3 best = vec3(0.0, 0.0, 0.0);
52
+ float r = 1e5;
53
+ for (int i = 0; i < 4; i++) {
54
+ vec2 n = g + node(float(i));
55
+ vec2 v = w - (n + off) * spacing;
56
+ vec2 h = parity(n) > 0.0 ? cs.yx : cs;
57
+ // inside the rhombus when |v.x| / h.x + |v.y| / h.y < 1, scaled by h.x * h.y to avoid dividing by 0
58
+ float ri = abs(v.x) * h.y + abs(v.y) * h.x;
59
+ if (ri < r) {
60
+ r = ri;
61
+ best = vec3(rot(v, vec2(0.7071068, parity(n) * 0.7071068)), float(i));
62
+ }
63
+ }
64
+ return best;
65
+ }
66
+
67
+ // lattice coordinates (in squares, centered) to a mirrored texture uv that stays in the frame
68
+ vec2 toUV(vec2 c, float n) {
69
+ vec2 uv = c / (n * vec2(ratio, 1.0)) + 0.5;
70
+ return abs(mod(uv + 1.0, 2.0) - 1.0);
71
+ }
72
+
73
+ vec4 transition(vec2 uv) {
74
+ if (progress <= 0.0) return getFromColor(uv);
75
+ if (progress >= 1.0) return getToColor(uv);
76
+ float n = max(float(cells), 1.0);
77
+ float e = progress * progress * (3.0 - 2.0 * progress);
78
+ float a = 0.5 * PI * e;
79
+ // turn of the squares in front: 0 to 45 degrees for the outgoing ones, then 45 to 0 for the incoming ones
80
+ float th = min(a, 0.5 * PI - a);
81
+ // the hinged lattice spreads while it opens
82
+ vec2 cs = vec2(cos(th), sin(th));
83
+ float spacing = cs.x + cs.y;
84
+ float scale = n * mix(1.0, spacing, clamp(zoom, 0.0, 1.0));
85
+ vec2 w = (uv - 0.5) * vec2(ratio, 1.0) * scale;
86
+ bool first = a < 0.25 * PI;
87
+ vec2 offF = first ? vec2(0.0) : vec2(0.5);
88
+ vec2 offB = vec2(0.5) - offF;
89
+ vec2 gF = floor(w / spacing - offF);
90
+ vec2 gB = floor(w / spacing - offB);
91
+ // front: the turning squares; back: the pieces of the other image held at 45 degrees in the gaps
92
+ vec4 f = nearest(w, gF, spacing, offF, cs);
93
+ vec3 b = gap(w, gB, spacing, offB, cs);
94
+ vec2 nf = gF + node(f.w);
95
+ vec2 nb = gB + node(b.z);
96
+ vec2 uvF = toUV(nf + offF + f.xy, n);
97
+ vec2 uvB = toUV(nb + offB + b.xy, n);
98
+ vec4 colF = first ? getFromColor(uvF) : getToColor(uvF);
99
+ vec4 colB = first ? getToColor(uvB) : getFromColor(uvB);
100
+
101
+ // relief: none when the sheet is closed or fully open, strongest in between
102
+ float depth = clamp(shading, 0.0, 1.0) * sin(4.0 * th);
103
+ // soft shadow cast by the front squares toward the lower right
104
+ if (depth > 0.0) {
105
+ vec2 ws = w - vec2(0.12, -0.12) * depth;
106
+ vec4 sh = nearest(ws, floor(ws / spacing - offF), spacing, offF, cs);
107
+ colB.rgb *= 1.0 - 0.75 * depth * (1.0 - smoothstep(-0.12, 0.25, sh.z));
108
+ }
109
+ // bevel lit from the upper left, along each square's nearest side
110
+ vec2 side = abs(f.x) > abs(f.y) ? vec2(sign(f.x), 0.0) : vec2(0.0, sign(f.y));
111
+ float facing = dot(rot(side, vec2(cs.x, -parity(nf) * cs.y)), vec2(-0.7071, 0.7071));
112
+ float rim = smoothstep(-0.07, -0.01, f.z);
113
+ colF.rgb *= 1.0 + 0.35 * depth * rim * facing;
114
+
115
+ // anti-aliased edges; the squares overlap a little to hide the gaps until they are a few pixels wide
116
+ float aa = EDGE * scale;
117
+ float seal = aa * (1.0 - smoothstep(0.0, 3.0 * aa, cs.y));
118
+ float cover = 1.0 - smoothstep(-aa, aa, f.z - seal);
119
+ return mix(colB, colF, cover);
120
+ }
@@ -0,0 +1,61 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The picture loses its horizontal hold like an old TV: it shears into diagonal bands that slide sideways and wrap around, separated by a slanted blanking bar that carries the incoming image in, then the shear straightens, wobbles and locks
4
+ // Tags: retro, horizontal, shear, scanlines
5
+
6
+ // @range(2, 6, 1) Number of times the picture slips sideways before it locks
7
+ uniform int slips; // = 3
8
+ // @range(0, 4) How far the lines lag from top to bottom at the worst of the tearing, in picture widths
9
+ uniform float shear; // = 1.25
10
+ // @range(0, 0.5) Width of the blanking bar between the copies of the picture
11
+ uniform float barWidth; // = 0.14
12
+ // @color Color of the blanking bar
13
+ uniform vec4 barColor; // = vec4(0.02, 0.02, 0.03, 1.0)
14
+
15
+ float slipCount() {
16
+ return max(float(slips), 1.0);
17
+ }
18
+
19
+ // The picture stream at x: outgoing copies, then incoming ones, with a bar between them
20
+ vec4 stream(float x, float y, float unsync) {
21
+ float period = 1.0 + barWidth;
22
+ float n = floor(x / period);
23
+ float xm = x - n * period;
24
+ vec2 q = vec2(min(xm, 1.0), y);
25
+ vec4 c = n >= floor(0.5 * slipCount() + 0.5) ? getToColor(q) : getFromColor(q);
26
+ // distance to the nearest bar, negative inside it
27
+ float d = min(xm, 1.0 - xm);
28
+ // the picture overshoots to white next to the bar
29
+ float g = max(1.0 - d / 0.05, 0.0);
30
+ c.rgb += 0.3 * unsync * g * g * c.a;
31
+ float soft = min(0.012 * unsync, 0.5 * barWidth) + 1e-5;
32
+ return mix(barColor, c, clamp(d / soft, 0.0, 1.0));
33
+ }
34
+
35
+ vec4 transition(vec2 uv) {
36
+ float period = 1.0 + barWidth;
37
+ // the sync error grows then fades; the slip is its integral, a whole number of periods
38
+ float t = min(progress / 0.88, 1.0);
39
+ float err = 16.0 * t * t * (1.0 - t) * (1.0 - t);
40
+ float slip = t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
41
+ // the hold overshoots and wobbles before it locks
42
+ float u = clamp((progress - 0.74) / 0.26, 0.0, 1.0);
43
+ float lock = u * (1.0 - u) * (1.0 - u);
44
+ float tilt = -0.5 * max(shear, 0.5) * lock * sin(9.42478 * u);
45
+ float unsync = min(err + 3.0 * lock, 1.0);
46
+ // lines lower in the frame lag behind, and ripple a little
47
+ float ripple = 0.012 * sin(uv.y * 9.0 + progress * 40.0) + 0.005 * sin(uv.y * 31.0 - progress * 70.0);
48
+ float x = uv.x + period * (slipCount() * slip + shear * err * (1.0 - uv.y) + tilt * (1.0 - uv.y)) + err * ripple;
49
+ // the slip smears the picture sideways
50
+ float blur = 0.002 * err * slipCount();
51
+ vec4 c = stream(x, uv.y, unsync);
52
+ if (blur > 0.0) {
53
+ for (int i = 0; i < 4; i++) {
54
+ c += stream(x + blur * (float(i) - 1.5), uv.y, unsync);
55
+ }
56
+ c /= 5.0;
57
+ }
58
+ // the unsynced picture dims and shows its scanlines
59
+ c.rgb *= 1.0 - unsync * (0.1 + 0.08 * sin(uv.y * 480.0));
60
+ return c;
61
+ }