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