gl-transitions 2.3.0 → 2.5.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 (106) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/compatibility.json +308 -0
  3. package/gl-transitions.js +1 -1
  4. package/gl-transitions.json +1 -1
  5. package/glsl3/ArrowWipe.glsl +100 -0
  6. package/glsl3/BlockSlide.glsl +87 -0
  7. package/glsl3/CellDissolve.glsl +91 -0
  8. package/glsl3/ColorPanelWipe.glsl +75 -0
  9. package/glsl3/Crumple.glsl +173 -0
  10. package/glsl3/EyeBlink.glsl +83 -0
  11. package/glsl3/Gallery.glsl +133 -0
  12. package/glsl3/HeatHaze.glsl +79 -0
  13. package/glsl3/Hologram.glsl +97 -0
  14. package/glsl3/LiquidFill.glsl +102 -0
  15. package/glsl3/PlasmaDissolve.glsl +51 -0
  16. package/glsl3/RingsWipe.glsl +106 -0
  17. package/glsl3/SawtoothWipe.glsl +73 -0
  18. package/glsl3/SnakeBlockWipe.glsl +40 -0
  19. package/glsl3/Snapshot.glsl +86 -0
  20. package/glsl3/Sphere.glsl +95 -0
  21. package/glsl3/SpiralBlockWipe.glsl +65 -0
  22. package/glsl3/VhsTracking.glsl +127 -0
  23. package/glsl3/Vortex.glsl +106 -0
  24. package/index.js +1 -1
  25. package/layouts.json +787 -18
  26. package/llms-full.txt +675 -354
  27. package/llms.txt +204 -185
  28. package/msl/ArrowWipe.metal +391 -0
  29. package/msl/BlockSlide.metal +418 -0
  30. package/msl/CellDissolve.metal +374 -0
  31. package/msl/ColorPanelWipe.metal +314 -0
  32. package/msl/Crumple.metal +766 -0
  33. package/msl/EyeBlink.metal +355 -0
  34. package/msl/Gallery.metal +813 -0
  35. package/msl/HeatHaze.metal +320 -0
  36. package/msl/Hologram.metal +380 -0
  37. package/msl/LiquidFill.metal +373 -0
  38. package/msl/PlasmaDissolve.metal +178 -0
  39. package/msl/RingsWipe.metal +437 -0
  40. package/msl/SawtoothWipe.metal +310 -0
  41. package/msl/SnakeBlockWipe.metal +216 -0
  42. package/msl/Snapshot.metal +321 -0
  43. package/msl/Sphere.metal +345 -0
  44. package/msl/SpiralBlockWipe.metal +281 -0
  45. package/msl/VhsTracking.metal +514 -0
  46. package/msl/Vortex.metal +522 -0
  47. package/package.json +1 -1
  48. package/skills/gl-transitions/references/catalog.md +84 -38
  49. package/sksl/ArrowWipe.sksl +111 -0
  50. package/sksl/BlockSlide.sksl +99 -0
  51. package/sksl/CellDissolve.sksl +103 -0
  52. package/sksl/ColorPanelWipe.sksl +85 -0
  53. package/sksl/Crumple.sksl +179 -0
  54. package/sksl/EyeBlink.sksl +94 -0
  55. package/sksl/Gallery.sksl +139 -0
  56. package/sksl/HeatHaze.sksl +90 -0
  57. package/sksl/Hologram.sksl +108 -0
  58. package/sksl/LiquidFill.sksl +113 -0
  59. package/sksl/PlasmaDissolve.sksl +64 -0
  60. package/sksl/RingsWipe.sksl +115 -0
  61. package/sksl/SawtoothWipe.sksl +83 -0
  62. package/sksl/SnakeBlockWipe.sksl +53 -0
  63. package/sksl/Snapshot.sksl +98 -0
  64. package/sksl/Sphere.sksl +108 -0
  65. package/sksl/SpiralBlockWipe.sksl +76 -0
  66. package/sksl/VhsTracking.sksl +138 -0
  67. package/sksl/Vortex.sksl +116 -0
  68. package/sksl/index.js +1 -1
  69. package/transitions/ArrowWipe.glsl +99 -0
  70. package/transitions/BlockSlide.glsl +86 -0
  71. package/transitions/CellDissolve.glsl +90 -0
  72. package/transitions/ColorPanelWipe.glsl +74 -0
  73. package/transitions/Crumple.glsl +172 -0
  74. package/transitions/EyeBlink.glsl +82 -0
  75. package/transitions/Gallery.glsl +132 -0
  76. package/transitions/HeatHaze.glsl +78 -0
  77. package/transitions/Hologram.glsl +96 -0
  78. package/transitions/LiquidFill.glsl +101 -0
  79. package/transitions/PlasmaDissolve.glsl +50 -0
  80. package/transitions/RingsWipe.glsl +105 -0
  81. package/transitions/SawtoothWipe.glsl +72 -0
  82. package/transitions/SnakeBlockWipe.glsl +39 -0
  83. package/transitions/Snapshot.glsl +85 -0
  84. package/transitions/Sphere.glsl +94 -0
  85. package/transitions/SpiralBlockWipe.glsl +64 -0
  86. package/transitions/VhsTracking.glsl +126 -0
  87. package/transitions/Vortex.glsl +105 -0
  88. package/wgsl/ArrowWipe.wgsl +352 -0
  89. package/wgsl/BlockSlide.wgsl +384 -0
  90. package/wgsl/CellDissolve.wgsl +323 -0
  91. package/wgsl/ColorPanelWipe.wgsl +274 -0
  92. package/wgsl/Crumple.wgsl +709 -0
  93. package/wgsl/EyeBlink.wgsl +308 -0
  94. package/wgsl/Gallery.wgsl +741 -0
  95. package/wgsl/HeatHaze.wgsl +282 -0
  96. package/wgsl/Hologram.wgsl +339 -0
  97. package/wgsl/LiquidFill.wgsl +339 -0
  98. package/wgsl/PlasmaDissolve.wgsl +149 -0
  99. package/wgsl/RingsWipe.wgsl +394 -0
  100. package/wgsl/SawtoothWipe.wgsl +279 -0
  101. package/wgsl/SnakeBlockWipe.wgsl +188 -0
  102. package/wgsl/Snapshot.wgsl +287 -0
  103. package/wgsl/Sphere.wgsl +316 -0
  104. package/wgsl/SpiralBlockWipe.wgsl +250 -0
  105. package/wgsl/VhsTracking.wgsl +462 -0
  106. package/wgsl/Vortex.wgsl +463 -0
@@ -0,0 +1,99 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A notched arrowhead window onto the incoming image flies in from the edge behind it (or appears at the center), then swells until it fills the frame
4
+ // Tags: shape, wipe, arrow, chevron, directional
5
+
6
+ // @param Direction the arrow points and flies toward
7
+ uniform vec2 direction; // = vec2(1.0, 0.0)
8
+ // @range(0, 0.9) Depth of the notch at the back of the arrowhead (0 for a plain triangle)
9
+ uniform float notch; // = 0.4
10
+ // @range(20, 160) Opening angle of the arrowhead's tip, in degrees
11
+ uniform float width; // = 80.0
12
+ // @range(1, 3, 1) Number of nested chevrons flying in a row
13
+ uniform int count; // = 1
14
+ // @param Grow the arrow from the center of the frame instead of flying it in
15
+ uniform bool origin; // = false
16
+ // @range(0, 0.1) Softness of the arrow's edges
17
+ uniform float smoothness; // = 0.004
18
+
19
+ // Signed distance (in frame heights) to an arrowhead whose tip is at x = tip and whose notch
20
+ // reaches back to x = back, in the arrow's frame (x along the direction, y = |across|)
21
+ float arrow(vec2 q, float tip, float back, vec2 tipN, vec2 notchN) {
22
+ float front = dot(vec2(q.x - tip, q.y), tipN);
23
+ float rear = dot(vec2(back - q.x, -q.y), notchN);
24
+ return max(front, rear);
25
+ }
26
+
27
+ vec4 transition(vec2 uv) {
28
+ vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
29
+ vec2 across = vec2(-dir.y, dir.x);
30
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
31
+ vec2 q = vec2(dot(p, dir), abs(dot(p, across)));
32
+
33
+ float s = max(smoothness, 0.001);
34
+ float n = clamp(notch, 0.0, 0.9);
35
+ float h = radians(0.5 * clamp(width, 20.0, 160.0));
36
+ float cot = cos(h) / sin(h);
37
+ // outward normals of the tip's edges and of the notch's edges
38
+ vec2 tipN = vec2(sin(h), cos(h));
39
+ float notchLen = length(vec2(1.0, n * cot));
40
+ vec2 notchN = vec2(1.0, n * cot) / notchLen;
41
+ // how far the tip must pass a point for the soft edge to clear it
42
+ float tipPad = s / sin(h);
43
+
44
+ // The frame's corners in the arrow's frame
45
+ vec2 c1 = vec2(0.5 * ratio, 0.5);
46
+ vec2 c2 = vec2(0.5 * ratio, -0.5);
47
+ vec2 k1 = vec2(abs(dot(c1, dir)), abs(dot(c1, across)));
48
+ vec2 k2 = vec2(abs(dot(c2, dir)), abs(dot(c2, across)));
49
+ // half extent of the frame along the direction, and where its back edge crosses the axis
50
+ float e = max(k1.x, k2.x);
51
+ float r = 0.5 / max(abs(dir.x) / ratio, abs(dir.y));
52
+ // To cover the frame, the tip must be ahead of every corner, and the notch behind every
53
+ // corner and behind the back edge's middle (with room for the soft edge)
54
+ float tipMin = max(k1.x + k1.y * cot, k2.x + k2.y * cot) + tipPad;
55
+ float notchMax = min(min(n * cot * k1.y - k1.x, n * cot * k2.y - k2.x), -r) - s * notchLen;
56
+
57
+ // The arrow (length 1 from tip to barbs) turns around the middle of its axis: its tip is
58
+ // half its body ahead of that point, its notch half its body behind
59
+ float body = 0.5 * (1.0 - n);
60
+ // The scale at which the arrow centered on the frame covers it
61
+ float cover = max(tipMin, -notchMax) / body;
62
+
63
+ float t = progress;
64
+ float o; // middle of the arrow
65
+ float l; // size of the arrow
66
+ if (origin) {
67
+ o = 0.0;
68
+ l = cover * t * (0.4 + 0.6 * t);
69
+ } else {
70
+ // while it flies, its larger side (length or span) is about the frame's smaller side
71
+ float l0 = 0.92 * min(1.0, ratio) / max(1.0, 2.0 * tan(h));
72
+ // starts just behind the frame, flies to the middle, then swells
73
+ float o0 = -e - 2.0 * tipPad - body * l0;
74
+ // it is already moving when it enters, and slows down as it starts to swell
75
+ float u = 1.0 - clamp(t / 0.65, 0.0, 1.0);
76
+ float fly = 1.0 - u * u * u;
77
+ // the swell speeds up and still moves at the end, so the last corners do not linger
78
+ float grow = clamp((t - 0.3) / 0.7, 0.0, 1.0);
79
+ o = mix(o0, 0.0, fly);
80
+ l = mix(l0, cover, grow * grow * (2.0 - grow));
81
+ }
82
+
83
+ // the nested chevrons follow the first one, each tucked behind the previous one's notch
84
+ float gap = (1.0 - n) * 1.35;
85
+ float d = arrow(q, o + body * l, o - body * l, tipN, notchN);
86
+ for (int i = 1; i < 3; i++) {
87
+ if (i < count) {
88
+ float back = o - float(i) * gap * l;
89
+ d = min(d, arrow(q, back + body * l, back - body * l, tipN, notchN));
90
+ }
91
+ }
92
+ // the soft edge slides from outside the arrow to inside it, so nothing shows at the start
93
+ float m = 1.0 - smoothstep(-s, s, d + 2.0 * s * (1.0 - t));
94
+
95
+ vec4 a = getFromColor(uv);
96
+ vec4 b = getToColor(uv);
97
+ vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), m);
98
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
99
+ }
@@ -0,0 +1,86 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The frame is cut into a grid of blocks that slide out one after another in a staggered cascade, some of them shrinking as they go, while the blocks of the incoming image slide in behind them to take their place
4
+ // Tags: slide, blocks, grid, directional, zoom
5
+
6
+ // @param Number of blocks (columns, rows), at most 40 along the direction
7
+ uniform ivec2 grid; // = ivec2(5, 4)
8
+ // @param Direction the blocks slide toward (rounded to the nearest axis)
9
+ uniform vec2 direction; // = vec2(1.0, 0.0)
10
+ // @range(0, 0.95) Share of the transition over which the blocks set off one after another (0 slides them all together)
11
+ uniform float stagger; // = 0.6
12
+ // @range(0, 0.9) How much the zooming blocks shrink on their way, as a share of their size
13
+ uniform float zoom; // = 0.35
14
+ // @color Color seen in the gaps between the blocks
15
+ uniform vec4 background; // = vec4(0.0, 0.0, 0.0, 1.0)
16
+
17
+ // blocks per strip, at most
18
+ const int MAX_BLOCKS = 40;
19
+
20
+ float hash(vec2 p) {
21
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
22
+ p3 += dot(p3, p3.yzx + 33.33);
23
+ return fract((p3.x + p3.y) * p3.z);
24
+ }
25
+
26
+ vec4 transition(vec2 uv) {
27
+ if (progress <= 0.0) return getFromColor(uv);
28
+ if (progress >= 1.0) return getToColor(uv);
29
+
30
+ bool vertical = abs(direction.y) > abs(direction.x);
31
+ bool backward = vertical ? direction.y < 0.0 : direction.x < 0.0;
32
+ vec2 g = max(vec2(grid), 1.0);
33
+ // a: position along the motion, toward which the blocks slide, b: across it
34
+ float a = vertical ? uv.y : uv.x;
35
+ float b = vertical ? uv.x : uv.y;
36
+ if (backward) a = 1.0 - a;
37
+ float n = min(vertical ? g.y : g.x, float(MAX_BLOCKS));
38
+ float strips = vertical ? g.x : g.y;
39
+ // every block of a strip slides along it, so a point can only show a block of its own strip
40
+ float r = min(floor(b * strips), strips - 1.0);
41
+ // the strips set off one after another, from the top (or the left)
42
+ float rowOrder = strips > 1.0 ? (vertical ? r : strips - 1.0 - r) / (strips - 1.0) : 0.0;
43
+ float st = clamp(stagger, 0.0, 0.95);
44
+ float z = clamp(zoom, 0.0, 0.9);
45
+ // in blocks
46
+ float an = a * n;
47
+ float bn = b * strips - r;
48
+
49
+ // the incoming blocks follow the last outgoing block to leave, the rear one: they all
50
+ // stay behind it, so no block ever overlaps another, and each one gets closer to the
51
+ // block ahead of it until they all arrive together
52
+ float rear = clamp((progress - st * mix(rowOrder, 1.0, 0.2)) / (1.0 - st), 0.0, 1.0);
53
+ rear = rear * rear * (3.0 - 2.0 * rear);
54
+
55
+ for (int k = 0; k < MAX_BLOCKS; k++) {
56
+ float i = float(k);
57
+ if (i >= n) break;
58
+ // the block at the front sets off first, so that the outgoing blocks move apart
59
+ float order = mix(rowOrder, n > 1.0 ? (n - 1.0 - i) / (n - 1.0) : 0.0, 0.2);
60
+ float p = clamp((progress - st * order) / (1.0 - st), 0.0, 1.0);
61
+ p = p * p * (3.0 - 2.0 * p);
62
+ float pin = max(0.0, 1.0 - (1.0 - rear) * (1.0 + (n - 1.0 - i) / n));
63
+ // about half of the blocks shrink as they leave, and their incoming blocks grow as they come
64
+ float zi = hash(vec2(i, r) + 3.7) < 0.5 ? z : 0.0;
65
+ // position in the block, from its corner, for the outgoing block (xy), which travels the
66
+ // frame's length to leave it, and the incoming one (zw), from one length behind; at rest,
67
+ // the blocks tile the frame exactly
68
+ float sFrom = 1.0 - zi * p * p;
69
+ float sTo = 1.0 - zi * (1.0 - pin) * (1.0 - pin);
70
+ vec4 l = vec4(
71
+ (an - i - p * n - 0.5 * (1.0 - sFrom)) / sFrom,
72
+ (bn - 0.5 * (1.0 - sFrom)) / sFrom,
73
+ (an - i - (pin - 1.0) * n - 0.5 * (1.0 - sTo)) / sTo,
74
+ (bn - 0.5 * (1.0 - sTo)) / sTo);
75
+ bool inFrom = all(greaterThanEqual(l.xy, vec2(0.0))) && all(lessThan(l.xy, vec2(1.0)));
76
+ bool inTo = all(greaterThanEqual(l.zw, vec2(0.0))) && all(lessThan(l.zw, vec2(1.0)));
77
+ if (inFrom || inTo) {
78
+ // back to the frame's coordinates
79
+ vec2 q = (vec2(i, r) + (inTo ? l.zw : l.xy)) / vec2(n, strips);
80
+ if (backward) q.x = 1.0 - q.x;
81
+ q = vertical ? q.yx : q;
82
+ return inTo ? getToColor(q) : getFromColor(q);
83
+ }
84
+ }
85
+ return background;
86
+ }
@@ -0,0 +1,90 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: Irregular cells, like cracked mud or soap foam, switch to the incoming image one by one, with an optional bright border glowing along the cracks between them
4
+ // Tags: dissolve, cells, voronoi, random
5
+
6
+ // @range(1, 40) Number of cells across the height of the frame
7
+ uniform float cells; // = 8.0
8
+ // @range(0, 1) Duration of each cell's switch, as a fraction of the transition (0: each cell switches at once)
9
+ uniform float smoothness; // = 0.1
10
+ // @range(0, 0.05) Width of the border along the cell edges, in frame heights (0: no border)
11
+ uniform float border; // = 0.006
12
+ // @color Color of the border
13
+ uniform vec4 borderColor; // = vec4(1.0, 0.95, 0.8, 1.0)
14
+ // @param Random seed: another value gives other cells, switching in another order
15
+ uniform float seed; // = 0.0
16
+
17
+ // half width of the antialiased edges, in frame heights
18
+ const float AA = 0.0015;
19
+
20
+ vec2 hash22(vec2 p) {
21
+ vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
22
+ p3 += dot(p3, p3.yzx + 33.33);
23
+ return fract((p3.xx + p3.yz) * p3.zy);
24
+ }
25
+
26
+ vec4 transition(vec2 uv) {
27
+ vec4 a = getFromColor(uv);
28
+ vec4 b = getToColor(uv);
29
+ if (progress <= 0.0) return a;
30
+ if (progress >= 1.0) return b;
31
+
32
+ float n = max(cells, 1.0);
33
+ // measured in square pixels, so the cells are not stretched
34
+ vec2 p = uv * vec2(ratio, 1.0) * n;
35
+ vec2 i = floor(p);
36
+ vec2 f = p - i;
37
+ vec2 offset = vec2(17.31, 41.97) * seed;
38
+
39
+ // nearest cell point
40
+ vec2 mg = vec2(0.0);
41
+ vec2 mr = vec2(0.0);
42
+ float md = 8.0;
43
+ for (int y = -1; y <= 1; y++) {
44
+ for (int x = -1; x <= 1; x++) {
45
+ vec2 g = vec2(float(x), float(y));
46
+ vec2 r = g + hash22(i + g + offset) - f;
47
+ float d = dot(r, r);
48
+ if (d < md) {
49
+ md = d;
50
+ mr = r;
51
+ mg = g;
52
+ }
53
+ }
54
+ }
55
+
56
+ // distance to the nearest cell edge: the bisector with the closest neighbor point,
57
+ // searched over 5x5 cells around the nearest one so that no edge is missed
58
+ float edge = 8.0;
59
+ for (int y = -2; y <= 2; y++) {
60
+ for (int x = -2; x <= 2; x++) {
61
+ vec2 g = mg + vec2(float(x), float(y));
62
+ vec2 r = g + hash22(i + g + offset) - f;
63
+ vec2 dr = r - mr;
64
+ if (dot(dr, dr) > 0.00001) {
65
+ edge = min(edge, dot(0.5 * (mr + r), normalize(dr)));
66
+ }
67
+ }
68
+ }
69
+ // in frame heights
70
+ edge /= n;
71
+
72
+ // the cell's own switch time, from its hash
73
+ float h = hash22(i + mg + offset + 97.13).x;
74
+ float w = clamp(smoothness, 0.0, 1.0);
75
+ float start = h * (1.0 - w);
76
+ float m = w > 0.0 ? smoothstep(start, start + w, progress) : step(start, progress);
77
+
78
+ // mixed premultiplied, so transparent images do not bleed their color
79
+ vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), m);
80
+
81
+ // the cracks open at the start and close at the end
82
+ float open = smoothstep(0.0, 0.2, progress) * (1.0 - smoothstep(0.8, 1.0, progress));
83
+ float bw = max(border, 0.0) * open;
84
+ if (bw > 0.0) {
85
+ float l = 1.0 - smoothstep(0.5 * bw - AA, 0.5 * bw + AA, edge);
86
+ float ba = borderColor.a * l * min(1.0, bw / (2.0 * AA));
87
+ c = vec4(borderColor.rgb * ba, ba) + c * (1.0 - ba);
88
+ }
89
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
90
+ }
@@ -0,0 +1,74 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: Solid color panels, slightly staggered, sweep across and cover the frame, then sweep off the far side and reveal the incoming image
4
+ // Tags: wipe, panels, color, slanted, motion-graphics
5
+
6
+ // @param Direction the panels sweep toward
7
+ uniform vec2 direction; // = vec2(1.0, 0.0)
8
+ // @range(1, 3, 1) Number of panels
9
+ uniform int panels; // = 3
10
+ // @color Color of the first panel
11
+ uniform vec4 color1; // = vec4(0.98, 0.76, 0.22, 1.0)
12
+ // @color Color of the second panel
13
+ uniform vec4 color2; // = vec4(0.93, 0.33, 0.36, 1.0)
14
+ // @color Color of the third panel
15
+ uniform vec4 color3; // = vec4(0.16, 0.2, 0.42, 1.0)
16
+ // @range(0, 1) Delay between the panels, relative to the sweep of one panel (at 0, they move as one and only the last shows)
17
+ uniform float stagger; // = 0.35
18
+ // @range(-1, 1) Slant of the panels' edges
19
+ uniform float skew; // = 0.25
20
+
21
+ // the frame is fully covered from cut - hold to cut + hold, where the image switches
22
+ const float cut = 0.46;
23
+ const float hold = 0.01;
24
+ // half width of the antialiased edges, in frame heights
25
+ const float aa = 0.0015;
26
+
27
+ // a short acceleration, a fast sweep, and a long settle
28
+ float ease(float t) {
29
+ float s = clamp(t, 0.0, 1.0);
30
+ float u = 1.0 - s * s * (3.0 - 2.0 * s);
31
+ return 1.0 - u * u * u;
32
+ }
33
+
34
+ // how much of x a panel between the edges back and front covers
35
+ float cover(float x, float back, float front) {
36
+ return smoothstep(back - aa, back + aa, x) * (1.0 - smoothstep(front - aa, front + aa, x));
37
+ }
38
+
39
+ vec4 transition(vec2 uv) {
40
+ vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
41
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
42
+ float k = clamp(skew, -1.0, 1.0);
43
+ // position along the sweep, slanted across it, in frame heights across the edges
44
+ vec2 a = (dir + k * vec2(-dir.y, dir.x)) / sqrt(1.0 + k * k);
45
+ float x = dot(p, a);
46
+ // half extent of the frame along x
47
+ float e = 0.5 * (abs(a.x) * ratio + abs(a.y));
48
+ float start = -e - 2.0 * aa;
49
+ float span = 2.0 * (e + 2.0 * aa);
50
+
51
+ int n = panels < 1 ? 1 : panels > 3 ? 3 : panels;
52
+ float m = float(n - 1);
53
+ float st = clamp(stagger, 0.0, 1.0);
54
+ // durations of a panel's sweep in and out
55
+ vec2 d = vec2(cut - hold, 1.0 - cut - hold) / (1.0 + m * st);
56
+
57
+ // the first panel enters first and leaves last: the outgoing image is ahead of it, the incoming one behind it
58
+ // (both are sampled, so that no texture read sits in a branch that differs between pixels)
59
+ float front0 = start + span * ease(progress / d.x);
60
+ float back0 = start + span * ease((progress - 1.0 + d.y) / d.y);
61
+ vec4 c = mix(getToColor(uv), getFromColor(uv), step(0.5 * (front0 + back0), x));
62
+ c = mix(c, color1, cover(x, back0, front0));
63
+
64
+ // each next panel covers the ones before it, enters after them and leaves before them
65
+ for (int i = 1; i < 3; i++) {
66
+ if (i < n) {
67
+ vec2 t = float(i) * st * d;
68
+ float front = start + span * ease((progress - t.x) / d.x);
69
+ float back = start + span * ease((progress - 1.0 + d.y + t.y) / d.y);
70
+ c = mix(c, i == 1 ? color2 : color3, cover(x, back, front));
71
+ }
72
+ }
73
+ return c.a > 0.0 ? c : vec4(0.0);
74
+ }
@@ -0,0 +1,172 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image crumples into a creased paper ball, shaded along its folds, which is then tossed away to reveal the incoming image
4
+ // Tags: paper, 3d, shrink, shadow
5
+
6
+ // @range(1, 32, 1) Number of folds creasing the paper
7
+ uniform int creases; // = 16
8
+ // @range(0.05, 0.4) Radius of the paper ball, relative to the image height
9
+ uniform float size; // = 0.2
10
+ // @param Direction the ball is tossed toward
11
+ uniform vec2 direction; // = vec2(1.0, 0.4)
12
+ // @color Color of the bare paper showing through the ink along the sharpest creases
13
+ uniform vec4 paper; // = vec4(0.96, 0.95, 0.91, 1.0)
14
+ // @color Color of the shadow cast on the incoming image
15
+ uniform vec4 shadow; // = vec4(0.0, 0.0, 0.0, 0.45)
16
+
17
+ const float PI = 3.14159265;
18
+
19
+ vec2 hash2(vec2 p) {
20
+ p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));
21
+ return fract(sin(p) * 43758.5453);
22
+ }
23
+
24
+ mat2 rot(float a) {
25
+ float s = sin(a);
26
+ float c = cos(a);
27
+ return mat2(c, -s, s, c);
28
+ }
29
+
30
+ // distance from the center to the edge of the frame in the direction a (unit vector)
31
+ float frame(vec2 a) {
32
+ return min(0.5 * ratio / max(abs(a.x), 1e-4), 0.5 / max(abs(a.y), 1e-4));
33
+ }
34
+
35
+ // distance from the center to the edge of the paper in the direction a (unit vector):
36
+ // the frame shrinking and buckling while it crumples (c), turning into a lumpy ball (k)
37
+ float outline(vec2 a, float c, float k, float radius) {
38
+ float rect = frame(a);
39
+ float th = atan(a.y, a.x);
40
+ float buckle = 0.03 + 0.05 * abs(sin(4.0 * th + 0.7)) + 0.03 * abs(sin(9.0 * th + 2.0)) + 0.015 * abs(sin(23.0 * th + 1.3));
41
+ // the ball is a polygon with irregular corners
42
+ float i = floor((th / (2.0 * PI) + 0.5) * 9.0);
43
+ float a0 = i * 2.0 * PI / 9.0 - PI;
44
+ float a1 = a0 + 2.0 * PI / 9.0;
45
+ vec2 v0 = vec2(cos(a0), sin(a0)) * (0.78 + 0.27 * hash2(vec2(mod(i, 9.0), 3.0)).x);
46
+ vec2 v1 = vec2(cos(a1), sin(a1)) * (0.78 + 0.27 * hash2(vec2(mod(i + 1.0, 9.0), 3.0)).x);
47
+ vec2 e = v1 - v0;
48
+ float ball = radius * (v0.x * e.y - v0.y * e.x) / (a.x * e.y - a.y * e.x);
49
+ return mix(rect * mix(1.0, 0.75, c) * (1.0 - c * buckle), ball, k);
50
+ }
51
+
52
+ // n straight creases of random position, orientation and length, in a space where the
53
+ // paper spans about [-span, span]; each one tilts the paper on its two sides (a sharp ridge
54
+ // or valley between flat facets) and swallows a strip of the image. They come one after
55
+ // another as c grows; px is the half width of a crease line, in the units of x.
56
+ void fold(vec2 x, float seed, int n, vec2 span, float len, float c, float px, float weight,
57
+ inout vec2 grad, inout vec2 shift, inout float valley, inout float ridge) {
58
+ float tilt = 2.0 / sqrt(float(n));
59
+ for (int i = 0; i < 32; i++) {
60
+ if (i >= n) break;
61
+ float fi = float(i);
62
+ vec2 h = hash2(vec2(fi, seed));
63
+ vec2 g = hash2(vec2(fi, seed + 11.8));
64
+ vec2 o = (h - 0.5) * 2.0 * span;
65
+ vec2 nrm = vec2(cos(2.0 * PI * g.x), sin(2.0 * PI * g.x));
66
+ float d = dot(x - o, nrm);
67
+ float along = dot(x - o, vec2(-nrm.y, nrm.x));
68
+ float l = len * (0.5 + g.y);
69
+ float start = 0.4 * fi / float(n);
70
+ float act = weight * smoothstep(start, start + 0.3, c) * (1.0 - smoothstep(0.5 * l, l, abs(along)));
71
+ float amp = (h.x > 0.5 ? 1.0 : -1.0) * (0.5 + 0.5 * h.y);
72
+ float side = d / (abs(d) + px);
73
+ grad += act * amp * side * nrm * tilt;
74
+ shift += act * 0.03 * side * nrm;
75
+ float line = 1.0 - smoothstep(0.0, 2.0 * px, abs(d));
76
+ if (amp < 0.0) valley += act * line;
77
+ else ridge += act * line * amp;
78
+ }
79
+ }
80
+
81
+ vec4 transition(vec2 uv) {
82
+ if (progress <= 0.0) return getFromColor(uv);
83
+ vec4 b = getToColor(uv);
84
+ if (progress >= 1.0) return b;
85
+
86
+ // crumpling (c), balling up (k), then tossing (t)
87
+ float c = smoothstep(0.0, 0.6, progress);
88
+ float k = smoothstep(0.1, 0.62, progress);
89
+ float t = smoothstep(0.58, 1.0, progress);
90
+ t *= t;
91
+
92
+ vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
93
+ float radius = max(size, 0.01) * mix(1.0, 0.6, t);
94
+ // far enough along the direction for the ball and its shadow (offset and blurred by up
95
+ // to about 0.09 each) to leave the frame
96
+ float reach = 0.5 * (abs(dir.x) * ratio + abs(dir.y)) + 1.2 * radius + 0.3;
97
+ float bend = dir.x < 0.0 ? -1.0 : 1.0;
98
+ vec2 center = dir * reach * t + vec2(-dir.y, dir.x) * 0.15 * bend * sin(PI * t);
99
+ float angle = 0.6 * c - 5.0 * bend * t;
100
+ // how high the paper is above the incoming image
101
+ float lift = 0.012 * c + 0.06 * t;
102
+
103
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
104
+
105
+ // soft shadow on the incoming image
106
+ vec2 sp = rot(angle) * (p - center - vec2(0.6, -1.0) * lift);
107
+ float sl = length(sp);
108
+ float sd = sl - outline(sl > 1e-5 ? sp / sl : vec2(1.0, 0.0), c, k, radius);
109
+ float blur = 0.005 + 1.2 * lift;
110
+ vec4 col = vec4(mix(b.rgb, shadow.rgb, shadow.a * c * (1.0 - smoothstep(-blur, blur, sd))), b.a);
111
+
112
+ vec2 q = rot(angle) * (p - center);
113
+ float l = length(q);
114
+ vec2 dq = l > 1e-5 ? q / l : vec2(1.0, 0.0);
115
+ float edge = outline(dq, c, k, radius);
116
+ // the edge (about a pixel at 300 px high) is antialiased only once the sheet has left the
117
+ // borders of the frame
118
+ float aa = 0.003 * smoothstep(0.0, 0.1, progress) + 1e-5;
119
+ float inside = 1.0 - smoothstep(-aa, aa, l - edge);
120
+ if (inside <= 0.0) return col;
121
+
122
+ // back onto the flat sheet: the outline is mapped onto the frame, the middle of the ball
123
+ // holds more of it, as if the edges were tucked under
124
+ float r = l / edge;
125
+ float rect = frame(dq);
126
+ vec2 s = dq * rect * mix(r, r * (0.6 + 0.4 * r), k);
127
+
128
+ // the creases of the sheet, then those of the ball, that crumpling adds over them
129
+ int count = creases < 1 ? 1 : creases;
130
+ vec2 grad = vec2(0.0);
131
+ vec2 shift = vec2(0.0);
132
+ float valley = 0.0;
133
+ float ridge = 0.0;
134
+ fold(s, 7.3, count, 0.45 * vec2(ratio, 1.0), 0.6, c, 0.003 * rect / edge, 1.0 - 0.8 * k, grad, shift, valley, ridge);
135
+ vec2 g2 = vec2(0.0);
136
+ vec2 s2 = vec2(0.0);
137
+ float v2 = 0.0;
138
+ float r2 = 0.0;
139
+ fold(q / radius, 2.9, count, vec2(0.7), 8.0, k, 0.003 / radius, k, g2, s2, v2, r2);
140
+ grad += g2 * 0.8;
141
+ vec2 piece = s + shift + s2 * 3.0;
142
+
143
+ // the facets over the volume of the ball, lit from the top left (the light does not turn
144
+ // with the ball)
145
+ float rr = clamp(l / (radius * 1.1), 0.0, 1.0);
146
+ vec3 sphere = vec3(q / (radius * 1.1) * k * 0.8, sqrt(1.0 - 0.64 * rr * rr * k));
147
+ vec3 n = normalize(sphere + vec3(grad, 0.0));
148
+ n.xy = rot(-angle) * n.xy;
149
+ vec3 light = normalize(vec3(-0.5, 0.6, 0.8));
150
+ float diffuse = max(dot(n, light), 0.0);
151
+ vec3 hv = normalize(light + vec3(0.0, 0.0, 1.0));
152
+ // only what facets add over the flat sheet
153
+ float spec = max(pow(max(dot(n, hv), 0.0), 20.0) - pow(hv.z, 20.0), 0.0);
154
+ float level = light.z;
155
+ float relief = min(2.0 * c, 1.0);
156
+ float shade = 1.0 + relief * ((0.12 + diffuse) / (0.12 + level) - 1.0) + 0.7 * spec * relief;
157
+ shade -= 0.2 * relief * min(valley, 1.0);
158
+ // occlusion toward the rim of the ball
159
+ shade *= 1.0 - 0.3 * k * smoothstep(0.6, 1.0, r);
160
+
161
+ // the edges of the sheet that the folds pull in are mirrored, as if folded back
162
+ vec2 f = piece / vec2(ratio, 1.0) + 0.5;
163
+ vec4 img = getFromColor(1.0 - abs(1.0 - mod(f, 2.0)));
164
+ // the ink cracks along the ridges
165
+ img.rgb = mix(img.rgb, paper.rgb, 0.6 * min(ridge, 1.0) * paper.a * c);
166
+ vec4 ball = vec4(img.rgb * shade, img.a);
167
+
168
+ // mixed premultiplied, so transparent images do not bleed their color
169
+ float m = inside * ball.a;
170
+ vec4 o = vec4(mix(col.rgb * col.a, ball.rgb, m), mix(col.a, 1.0, m));
171
+ return o.a > 0.0 ? vec4(o.rgb / o.a, o.a) : vec4(0.0);
172
+ }
@@ -0,0 +1,82 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: Curved eyelids close from the top and bottom over the outgoing image, which blurs and dims, then open on the incoming image as it comes back into focus, as if the viewer blinked
4
+ // Tags: blink, eye, blur, shape
5
+
6
+ // @range(0, 1) How much the image blurs and dims while the eyes are closed
7
+ uniform float blur; // = 0.5
8
+ // @range(0.01, 0.3) Width of the soft shadow along the rim of the eyelids
9
+ uniform float softness; // = 0.12
10
+ // @range(1, 2, 1) Number of blinks: 1, or 2 for a quick double blink (the cut happens on the first one)
11
+ uniform int blinks; // = 1
12
+ // @color Color of the eyelids
13
+ uniform vec4 color; // = vec4(0.03, 0.02, 0.02, 1.0)
14
+
15
+ const int TAPS = 16;
16
+ // how much the eyelids curve: the opening is widest at the center and the corners close first
17
+ const float CURVE = 0.25;
18
+ // where the eyelids meet, below the middle: the upper lid travels further than the lower one
19
+ const float MEET = 0.44;
20
+
21
+ vec2 mirror(vec2 v) {
22
+ return 1.0 - abs(1.0 - mod(v, 2.0));
23
+ }
24
+
25
+ // a blink fully closed at c (held for 2 * hold): the lids close over wc before it
26
+ // and open over wo after it, slower, like a real blink
27
+ float lidBlink(float t, float c, float wc, float wo, float hold) {
28
+ return 1.0 - smoothstep(hold, t < c ? wc : wo, abs(t - c));
29
+ }
30
+
31
+ vec4 image(vec2 uv, bool incoming) {
32
+ vec4 c = incoming ? getToColor(uv) : getFromColor(uv);
33
+ return vec4(c.rgb * c.a, c.a);
34
+ }
35
+
36
+ vec4 transition(vec2 uv) {
37
+ bool two = blinks > 1;
38
+ // the moment the eyes are fully closed, when the images are swapped
39
+ float cut = two ? 0.3 : 0.42;
40
+ // how closed the eyes are: 0 open, 1 closed
41
+ float closed = two
42
+ ? max(lidBlink(progress, cut, 0.26, 0.26, 0.015), lidBlink(progress, 0.7, 0.14, 0.24, 0.01))
43
+ : lidBlink(progress, cut, 0.36, 0.5, 0.02);
44
+ bool incoming = progress >= cut;
45
+
46
+ // the rim of each eyelid is an arc; fully open, even its corners clear the frame by the widest shadow
47
+ float soft = clamp(softness, 0.001, 0.3);
48
+ float x = 2.0 * uv.x - 1.0;
49
+ float rim = (1.0 - closed) * (1.31 + CURVE) - CURVE * x * x;
50
+ // distance inside the opening from the nearest lid, as a share of that lid's travel
51
+ float y = uv.y - MEET;
52
+ float d = rim - max(y / (1.0 - MEET), -y / MEET);
53
+ // the lid fills beyond its rim, with a soft shadow falling inside the opening
54
+ float s = 1.0 - smoothstep(0.0, soft, d);
55
+ float lid = s * s;
56
+ if (lid >= 1.0) return color;
57
+
58
+ // how out of focus and dim the view is: it peaks at the cut, follows the lids, and clears at both ends
59
+ float f = progress < cut ? progress / cut : (1.0 - progress) / (1.0 - cut);
60
+ f = clamp(f, 0.0, 1.0);
61
+ f = max(f * (2.0 - f), closed) * blur;
62
+
63
+ vec4 c;
64
+ if (f <= 0.0) {
65
+ c = incoming ? getToColor(uv) : getFromColor(uv);
66
+ } else {
67
+ // a disc of taps along a golden-angle spiral, premultiplied
68
+ float r = 0.025 * f;
69
+ c = vec4(0.0);
70
+ for (int i = 0; i < TAPS; i++) {
71
+ float k = float(i) + 0.5;
72
+ float a = 2.39996 * k;
73
+ vec2 o = sqrt(k / float(TAPS)) * vec2(cos(a), sin(a)) * r;
74
+ c += image(mirror(uv + o * vec2(1.0 / ratio, 1.0)), incoming);
75
+ }
76
+ c /= float(TAPS);
77
+ c = c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
78
+ // less light reaches the eye as it closes
79
+ c.rgb *= 1.0 - 0.35 * f;
80
+ }
81
+ return mix(c, color, lid);
82
+ }