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