gl-transitions 2.4.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 (86) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/compatibility.json +244 -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/Crumple.glsl +173 -0
  9. package/glsl3/HeatHaze.glsl +79 -0
  10. package/glsl3/Hologram.glsl +97 -0
  11. package/glsl3/LiquidFill.glsl +102 -0
  12. package/glsl3/PlasmaDissolve.glsl +51 -0
  13. package/glsl3/RingsWipe.glsl +106 -0
  14. package/glsl3/SawtoothWipe.glsl +73 -0
  15. package/glsl3/SnakeBlockWipe.glsl +40 -0
  16. package/glsl3/Snapshot.glsl +86 -0
  17. package/glsl3/Sphere.glsl +95 -0
  18. package/glsl3/SpiralBlockWipe.glsl +65 -0
  19. package/glsl3/Vortex.glsl +106 -0
  20. package/index.js +1 -1
  21. package/layouts.json +618 -18
  22. package/llms-full.txt +614 -362
  23. package/llms.txt +204 -189
  24. package/msl/ArrowWipe.metal +391 -0
  25. package/msl/BlockSlide.metal +418 -0
  26. package/msl/CellDissolve.metal +374 -0
  27. package/msl/Crumple.metal +766 -0
  28. package/msl/HeatHaze.metal +320 -0
  29. package/msl/Hologram.metal +380 -0
  30. package/msl/LiquidFill.metal +373 -0
  31. package/msl/PlasmaDissolve.metal +178 -0
  32. package/msl/RingsWipe.metal +437 -0
  33. package/msl/SawtoothWipe.metal +310 -0
  34. package/msl/SnakeBlockWipe.metal +216 -0
  35. package/msl/Snapshot.metal +321 -0
  36. package/msl/Sphere.metal +345 -0
  37. package/msl/SpiralBlockWipe.metal +281 -0
  38. package/msl/Vortex.metal +522 -0
  39. package/package.json +1 -1
  40. package/skills/gl-transitions/references/catalog.md +68 -34
  41. package/sksl/ArrowWipe.sksl +111 -0
  42. package/sksl/BlockSlide.sksl +99 -0
  43. package/sksl/CellDissolve.sksl +103 -0
  44. package/sksl/Crumple.sksl +179 -0
  45. package/sksl/HeatHaze.sksl +90 -0
  46. package/sksl/Hologram.sksl +108 -0
  47. package/sksl/LiquidFill.sksl +113 -0
  48. package/sksl/PlasmaDissolve.sksl +64 -0
  49. package/sksl/RingsWipe.sksl +115 -0
  50. package/sksl/SawtoothWipe.sksl +83 -0
  51. package/sksl/SnakeBlockWipe.sksl +53 -0
  52. package/sksl/Snapshot.sksl +98 -0
  53. package/sksl/Sphere.sksl +108 -0
  54. package/sksl/SpiralBlockWipe.sksl +76 -0
  55. package/sksl/Vortex.sksl +116 -0
  56. package/sksl/index.js +1 -1
  57. package/transitions/ArrowWipe.glsl +99 -0
  58. package/transitions/BlockSlide.glsl +86 -0
  59. package/transitions/CellDissolve.glsl +90 -0
  60. package/transitions/Crumple.glsl +172 -0
  61. package/transitions/HeatHaze.glsl +78 -0
  62. package/transitions/Hologram.glsl +96 -0
  63. package/transitions/LiquidFill.glsl +101 -0
  64. package/transitions/PlasmaDissolve.glsl +50 -0
  65. package/transitions/RingsWipe.glsl +105 -0
  66. package/transitions/SawtoothWipe.glsl +72 -0
  67. package/transitions/SnakeBlockWipe.glsl +39 -0
  68. package/transitions/Snapshot.glsl +85 -0
  69. package/transitions/Sphere.glsl +94 -0
  70. package/transitions/SpiralBlockWipe.glsl +64 -0
  71. package/transitions/Vortex.glsl +105 -0
  72. package/wgsl/ArrowWipe.wgsl +352 -0
  73. package/wgsl/BlockSlide.wgsl +384 -0
  74. package/wgsl/CellDissolve.wgsl +323 -0
  75. package/wgsl/Crumple.wgsl +709 -0
  76. package/wgsl/HeatHaze.wgsl +282 -0
  77. package/wgsl/Hologram.wgsl +339 -0
  78. package/wgsl/LiquidFill.wgsl +339 -0
  79. package/wgsl/PlasmaDissolve.wgsl +149 -0
  80. package/wgsl/RingsWipe.wgsl +394 -0
  81. package/wgsl/SawtoothWipe.wgsl +279 -0
  82. package/wgsl/SnakeBlockWipe.wgsl +188 -0
  83. package/wgsl/Snapshot.wgsl +287 -0
  84. package/wgsl/Sphere.wgsl +316 -0
  85. package/wgsl/SpiralBlockWipe.wgsl +250 -0
  86. 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,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,78 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: Shimmering heat waves rise through the frame, strongest at the bottom, making the outgoing image wobble like the air over hot asphalt; the incoming image shows through the haze and settles as it calms
4
+ // Tags: distort, heat, shimmer, noise, organic, blend
5
+
6
+ // @range(0, 0.1) How far the haze bends the image, in frame heights (the strongest waves bend it about 1.5 times as far)
7
+ uniform float strength; // = 0.04
8
+ // @range(1, 12) Size of the heat waves: more, smaller ones with a larger value
9
+ uniform float scale; // = 6.0
10
+ // @range(0, 6) How fast the heat waves rise
11
+ uniform float speed; // = 2.0
12
+
13
+ // reflects coordinates that leave the frame back into it, so the edges do not smear
14
+ vec2 mirror(vec2 v) {
15
+ return 1.0 - abs(1.0 - mod(v, 2.0));
16
+ }
17
+
18
+ float hash12(vec2 v) {
19
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
20
+ v3 += dot(v3, v3.yzx + 33.33);
21
+ return fract((v3.x + v3.y) * v3.z);
22
+ }
23
+
24
+ float vnoise(vec2 v) {
25
+ vec2 i = floor(v);
26
+ vec2 f = fract(v);
27
+ f = f * f * (3.0 - 2.0 * f);
28
+ return mix(
29
+ mix(hash12(i), hash12(i + vec2(1.0, 0.0)), f.x),
30
+ mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), f.x),
31
+ f.y
32
+ );
33
+ }
34
+
35
+ // centered on 0, within [-1.5, 1.5]
36
+ float fbm(vec2 v) {
37
+ float sum = 0.0;
38
+ float amp = 0.5;
39
+ for (int i = 0; i < 4; i++) {
40
+ sum += amp * vnoise(v);
41
+ v = mat2(1.6, 1.2, -1.2, 1.6) * v + 5.3;
42
+ amp *= 0.5;
43
+ }
44
+ return (sum / 0.9375 - 0.5) * 3.0;
45
+ }
46
+
47
+ vec4 transition(vec2 uv) {
48
+ if (progress <= 0.0) return getFromColor(uv);
49
+ if (progress >= 1.0) return getToColor(uv);
50
+
51
+ const float PI = 3.141592653589793;
52
+ float p = progress;
53
+ // the haze builds up then calms down
54
+ float amount = sin(PI * p);
55
+ // the waves scroll upward and slowly churn as they rise
56
+ float t = p * speed;
57
+ // in square pixels, then squashed vertically into the thin bands of rising air
58
+ vec2 q = vec2(uv.x * ratio, uv.y * 2.5) * scale;
59
+ q.y -= t * scale;
60
+ // the bands are bent by a slower, larger turbulence so they do not stay straight
61
+ vec2 w = vec2(fbm(q * 0.35 + vec2(0.0, t)), fbm(q * 0.35 + vec2(7.1, -t)));
62
+ q += 1.5 * w;
63
+ vec2 offset = vec2(fbm(q), 0.5 * fbm(q + vec2(3.7, 1.9)));
64
+ // the hot air is near the ground: strongest at the bottom, fainter at the top
65
+ float ground = mix(1.0, 0.3, uv.y);
66
+ offset *= strength * amount * ground * vec2(1.0 / ratio, 1.0);
67
+
68
+ vec2 d = mirror(uv + offset);
69
+ // the images swap in the thick of the haze
70
+ float m = smoothstep(0.3, 0.7, p);
71
+ if (m <= 0.0) return getFromColor(d);
72
+ if (m >= 1.0) return getToColor(d);
73
+ vec4 a = getFromColor(d);
74
+ vec4 b = getToColor(d);
75
+ // mixed premultiplied, so transparent images do not bleed their color
76
+ vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), m);
77
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
78
+ }
@@ -0,0 +1,96 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image turns into a flickering hologram (blue by default) with scanlines and jittering rows, breaks up, and the hologram resolves into the incoming image in full color
4
+ // Tags: hologram, sci-fi, scanlines, flicker, glitch
5
+
6
+ // @color Color of the hologram
7
+ uniform vec3 tint; // = vec3(0.2, 0.75, 1.0)
8
+ // @color Color behind the hologram, seen between its scanlines and where it breaks up
9
+ uniform vec4 background; // = vec4(0.0, 0.02, 0.05, 1.0)
10
+ // @range(20, 300) Number of scanlines over the frame height
11
+ uniform float scanlines; // = 150.0
12
+ // @range(0, 0.2) How far rows of the hologram jump sideways, relative to the frame width
13
+ uniform float jitter; // = 0.04
14
+ // @range(0, 1) Strength of the flicker and of the rows that drop out
15
+ uniform float flicker; // = 0.6
16
+
17
+ const float PI = 3.14159265;
18
+ // steps per transition of the flicker and the jitter
19
+ const float STEPS = 32.0;
20
+
21
+ float hash(vec2 p) {
22
+ p = fract(p * vec2(443.897, 441.423));
23
+ p += dot(p, p.yx + 19.19);
24
+ return fract((p.x + p.y) * p.x);
25
+ }
26
+
27
+ float luma(vec3 c) {
28
+ return dot(c, vec3(0.299, 0.587, 0.114));
29
+ }
30
+
31
+ vec4 premultiplied(vec4 c) {
32
+ return vec4(c.rgb * c.a, c.a);
33
+ }
34
+
35
+ // the image the hologram shows: rows switch from the outgoing image to the incoming one
36
+ // while the hologram breaks up
37
+ vec4 source(vec2 uv, float m) {
38
+ return m > 0.5 ? getToColor(uv) : getFromColor(uv);
39
+ }
40
+
41
+ vec4 transition(vec2 uv) {
42
+ if (progress <= 0.0) return getFromColor(uv);
43
+ if (progress >= 1.0) return getToColor(uv);
44
+
45
+ float p = progress;
46
+ // how much of the hologram shows, and how broken up it is (peaking mid-transition)
47
+ float h = smoothstep(0.0, 0.3, p) * (1.0 - smoothstep(0.7, 1.0, p));
48
+ float b = smoothstep(0.0, 1.0, 1.0 - abs(p - 0.5) / 0.22);
49
+ float f = floor(p * STEPS);
50
+
51
+ // rows of the hologram jump sideways, more while it breaks up
52
+ float band = floor(uv.y * 36.0);
53
+ float jump = step(1.0 - (0.2 + 0.6 * b) * h, hash(vec2(band, f)));
54
+ float offset = (hash(vec2(band, f + 0.37)) - 0.5) * 2.0 * jitter * jump * (0.3 + 0.7 * b);
55
+ offset += sin(uv.y * 23.0 + f * 1.7) * 0.0015 * h;
56
+ vec2 q = uv + vec2(offset, 0.0);
57
+
58
+ // when each row of the hologram switches to the incoming image
59
+ float m = step(hash(vec2(floor(uv.y * 24.0), 7.0)), (p - 0.35) / 0.3);
60
+
61
+ // the hologram: the luma of the image in the tint, with colored fringes
62
+ // (sampled inside the frame, the fringes weighted by the alpha of their texels)
63
+ vec4 c = source(clamp(q, 0.0, 1.0), m);
64
+ vec2 dx = vec2(0.003 + 0.01 * b, 0.0);
65
+ float l = luma(c.rgb);
66
+ vec4 cr = source(clamp(q + dx, 0.0, 1.0), m);
67
+ vec4 cb = source(clamp(q - dx, 0.0, 1.0), m);
68
+ float lr = luma(cr.rgb) * cr.a;
69
+ float lb = luma(cb.rgb) * cb.a;
70
+ vec3 g = smoothstep(0.05, 0.9, vec3(lr, l, lb));
71
+ // the brightest parts burn toward white
72
+ vec3 holo = tint * (0.06 + 1.25 * g) + 0.45 * g * g * g;
73
+ // brighter scan band rolling down
74
+ float roll = fract(uv.y + 2.0 * p);
75
+ holo += tint * 0.35 * smoothstep(0.85, 1.0, roll) * (1.0 - smoothstep(0.98, 1.0, roll));
76
+ holo = clamp(holo, 0.0, 1.0);
77
+ // nothing outside the image where a row jumped out of the frame
78
+ float inside = step(0.0, q.x) * step(q.x, 1.0);
79
+
80
+ // opacity of the hologram: scanlines, flicker and missing rows
81
+ float lines = 0.5 + 0.5 * sin((uv.y * scanlines - p * 6.0) * 2.0 * PI);
82
+ float vis = mix(1.0, 0.15 + 0.85 * lines, h);
83
+ vis *= 1.0 - flicker * (0.25 + 0.75 * b) * hash(vec2(f, 3.1)) * h;
84
+ float gap = step(hash(vec2(floor(uv.y * 90.0), f + 0.71)), flicker * 0.45 * b);
85
+ vis *= 1.0 - gap;
86
+ vec4 layer = vec4(holo, c.a * vis * inside);
87
+ // the hologram over its background, transparent where neither the image nor the
88
+ // hologram is
89
+ vec4 plain = premultiplied(source(uv, m));
90
+ vec4 back = premultiplied(vec4(background.rgb, background.a * max(plain.a, layer.a)));
91
+ vec4 holoColor = premultiplied(layer) + back * (1.0 - layer.a);
92
+
93
+ // the images in full color, then the hologram over them
94
+ vec4 o = mix(plain, holoColor, h);
95
+ return o.a > 0.0 ? vec4(o.rgb / o.a, o.a) : vec4(0.0);
96
+ }