gl-transitions 2.0.0 → 2.1.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 (101) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/compatibility.json +290 -0
  3. package/gl-transitions.js +1 -1
  4. package/gl-transitions.json +1 -1
  5. package/glsl3/ApertureWipe.glsl +45 -0
  6. package/glsl3/Comb.glsl +26 -0
  7. package/glsl3/Curtains.glsl +47 -0
  8. package/glsl3/DiamondWipe.glsl +21 -0
  9. package/glsl3/DitherDissolve.glsl +27 -0
  10. package/glsl3/FallOver.glsl +36 -0
  11. package/glsl3/Fisheye.glsl +23 -0
  12. package/glsl3/Halftone.glsl +49 -0
  13. package/glsl3/Honeycomb.glsl +55 -0
  14. package/glsl3/PaperTear.glsl +76 -0
  15. package/glsl3/Prisms.glsl +81 -0
  16. package/glsl3/Puzzle.glsl +124 -0
  17. package/glsl3/Shred.glsl +67 -0
  18. package/glsl3/SpiralWipe.glsl +41 -0
  19. package/glsl3/Tunnel.glsl +42 -0
  20. package/glsl3/TvRoll.glsl +43 -0
  21. package/glsl3/TvTurnOff.glsl +47 -0
  22. package/glsl3/WhipPan.glsl +50 -0
  23. package/index.js +1 -1
  24. package/layouts.json +528 -0
  25. package/llms-full.txt +520 -256
  26. package/llms.txt +154 -136
  27. package/msl/ApertureWipe.metal +193 -0
  28. package/msl/Comb.metal +167 -0
  29. package/msl/Curtains.metal +207 -0
  30. package/msl/DiamondWipe.metal +123 -0
  31. package/msl/DitherDissolve.metal +157 -0
  32. package/msl/FallOver.metal +192 -0
  33. package/msl/Fisheye.metal +121 -0
  34. package/msl/Halftone.metal +230 -0
  35. package/msl/Honeycomb.metal +263 -0
  36. package/msl/PaperTear.metal +373 -0
  37. package/msl/Prisms.metal +424 -0
  38. package/msl/Puzzle.metal +632 -0
  39. package/msl/Shred.metal +294 -0
  40. package/msl/SpiralWipe.metal +196 -0
  41. package/msl/Tunnel.metal +207 -0
  42. package/msl/TvRoll.metal +205 -0
  43. package/msl/TvTurnOff.metal +238 -0
  44. package/msl/WhipPan.metal +218 -0
  45. package/package.json +1 -1
  46. package/skills/gl-transitions/references/catalog.md +52 -34
  47. package/sksl/ApertureWipe.sksl +56 -0
  48. package/sksl/Comb.sksl +39 -0
  49. package/sksl/Curtains.sksl +60 -0
  50. package/sksl/DiamondWipe.sksl +34 -0
  51. package/sksl/DitherDissolve.sksl +39 -0
  52. package/sksl/FallOver.sksl +49 -0
  53. package/sksl/Fisheye.sksl +36 -0
  54. package/sksl/Halftone.sksl +61 -0
  55. package/sksl/Honeycomb.sksl +64 -0
  56. package/sksl/PaperTear.sksl +82 -0
  57. package/sksl/Prisms.sksl +94 -0
  58. package/sksl/Puzzle.sksl +134 -0
  59. package/sksl/Shred.sksl +79 -0
  60. package/sksl/SpiralWipe.sksl +51 -0
  61. package/sksl/Tunnel.sksl +55 -0
  62. package/sksl/TvRoll.sksl +55 -0
  63. package/sksl/TvTurnOff.sksl +59 -0
  64. package/sksl/WhipPan.sksl +62 -0
  65. package/sksl/index.js +1 -1
  66. package/transitions/ApertureWipe.glsl +44 -0
  67. package/transitions/Comb.glsl +25 -0
  68. package/transitions/Curtains.glsl +46 -0
  69. package/transitions/DiamondWipe.glsl +20 -0
  70. package/transitions/DitherDissolve.glsl +26 -0
  71. package/transitions/FallOver.glsl +35 -0
  72. package/transitions/Fisheye.glsl +22 -0
  73. package/transitions/Halftone.glsl +48 -0
  74. package/transitions/Honeycomb.glsl +54 -0
  75. package/transitions/PaperTear.glsl +75 -0
  76. package/transitions/Prisms.glsl +80 -0
  77. package/transitions/Puzzle.glsl +123 -0
  78. package/transitions/Shred.glsl +66 -0
  79. package/transitions/SpiralWipe.glsl +40 -0
  80. package/transitions/Tunnel.glsl +41 -0
  81. package/transitions/TvRoll.glsl +42 -0
  82. package/transitions/TvTurnOff.glsl +46 -0
  83. package/transitions/WhipPan.glsl +49 -0
  84. package/wgsl/ApertureWipe.wgsl +160 -0
  85. package/wgsl/Comb.wgsl +139 -0
  86. package/wgsl/Curtains.wgsl +179 -0
  87. package/wgsl/DiamondWipe.wgsl +94 -0
  88. package/wgsl/DitherDissolve.wgsl +123 -0
  89. package/wgsl/FallOver.wgsl +164 -0
  90. package/wgsl/Fisheye.wgsl +93 -0
  91. package/wgsl/Halftone.wgsl +196 -0
  92. package/wgsl/Honeycomb.wgsl +222 -0
  93. package/wgsl/PaperTear.wgsl +324 -0
  94. package/wgsl/Prisms.wgsl +385 -0
  95. package/wgsl/Puzzle.wgsl +587 -0
  96. package/wgsl/Shred.wgsl +259 -0
  97. package/wgsl/SpiralWipe.wgsl +165 -0
  98. package/wgsl/Tunnel.wgsl +177 -0
  99. package/wgsl/TvRoll.wgsl +165 -0
  100. package/wgsl/TvTurnOff.wgsl +196 -0
  101. package/wgsl/WhipPan.wgsl +177 -0
@@ -0,0 +1,44 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A camera aperture opens its turning blades to reveal the incoming image
4
+ // Tags: shape, wipe, iris, rotate
5
+
6
+ #define PI 3.141592653589793
7
+
8
+ // @range(3, 12) Number of blades
9
+ uniform int blades; // = 6
10
+ // @range(-180, 180) How much the blades turn while opening, in degrees
11
+ uniform float rotation; // = 60.0
12
+ // @range(0, 1) How dark the blades are shaded along their edges
13
+ uniform float shadow; // = 0.5
14
+
15
+ const float AA = 0.006;
16
+
17
+ vec4 transition (vec2 uv) {
18
+ // Square pixels, normalized so the frame's corners are at distance 1
19
+ vec2 q = (uv - 0.5) * vec2(ratio, 1.0) / (0.5 * length(vec2(ratio, 1.0)));
20
+ float n = clamp(float(blades), 3.0, 12.0);
21
+ float sector = 2.0 * PI / n;
22
+ float turn = radians(rotation) * progress;
23
+ // Each blade's straight edge is at distance r from the center: the opening is the polygon they enclose
24
+ float r = mix(-AA, 1.0 + AA, progress);
25
+ float dist = -1e3;
26
+ float seam = 0.0;
27
+ for (int i = 0; i < 12; i++) {
28
+ if (float(i) < n) {
29
+ float angle = turn + float(i) * sector;
30
+ float d = dot(q, vec2(cos(angle), sin(angle))) - r;
31
+ float next = dot(q, vec2(cos(angle + sector), sin(angle + sector))) - r;
32
+ dist = max(dist, d);
33
+ // Past its corner, the edge of a blade lies over the next blade and casts a shadow on it
34
+ float s = 1.0 - smoothstep(0.0, 0.12, -d);
35
+ seam = max(seam, (1.0 - smoothstep(0.0, AA, d)) * s * s * smoothstep(0.0, AA, next));
36
+ }
37
+ }
38
+ // The blades are also shaded along the opening; the shading fades in as the aperture starts to open
39
+ float rim = 1.0 - smoothstep(0.0, 0.08, dist);
40
+ float shade = shadow * max(rim * rim, seam) * smoothstep(0.0, 0.1, progress);
41
+ vec4 from = getFromColor(uv);
42
+ from.rgb *= 1.0 - shade;
43
+ return mix(from, getToColor(uv), 1.0 - smoothstep(0.0, AA, dist));
44
+ }
@@ -0,0 +1,25 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The frame is cut into interleaved strips that slide in opposite directions, each pushing the outgoing image out and the incoming one in
4
+ // Tags: slide, stripes, push, horizontal
5
+
6
+ // @range(2, 40, 1) Number of strips
7
+ uniform int strips; // = 10
8
+ // @param Cut the frame into columns that slide up and down instead
9
+ uniform bool vertical; // = false
10
+
11
+ vec4 transition (vec2 uv) {
12
+ // a: the axis along which the strips slide, b: the axis across them
13
+ float a = vertical ? uv.y : uv.x;
14
+ float b = vertical ? uv.x : uv.y;
15
+ // alternate strips slide in opposite directions
16
+ float dir = mod(floor(b * float(strips)), 2.0) < 0.5 ? 1.0 : -1.0;
17
+ // ease in and out, but keep moving from the first frame
18
+ float t = mix(progress, progress * progress * (3.0 - 2.0 * progress), 0.6);
19
+ float fa = a - dir * t;
20
+ if (fa >= 0.0 && fa <= 1.0) {
21
+ return getFromColor(vertical ? vec2(b, fa) : vec2(fa, b));
22
+ }
23
+ float ta = fa + dir;
24
+ return getToColor(vertical ? vec2(b, ta) : vec2(ta, b));
25
+ }
@@ -0,0 +1,46 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image parts in the middle like stage curtains, gathering into shaded folds as it is pulled to the sides
4
+ // Tags: split, horizontal, fold, 3d
5
+
6
+ // @range(1, 16, 1) Number of folds in each curtain (fewer in a portrait image)
7
+ uniform float folds; // = 7.0
8
+ // @range(0, 1) Depth of the shading on the folds
9
+ uniform float shading; // = 0.7
10
+ // @range(0, 0.4) Width of each curtain once gathered, relative to the image width
11
+ uniform float bunch; // = 0.12
12
+ // @range(0, 1) How much the bottom of the curtains lags behind the top
13
+ uniform float sway; // = 0.4
14
+
15
+ const float PI = 3.141592653589793;
16
+
17
+ vec4 transition (vec2 uv) {
18
+ // the bottom of the fabric follows the top with a little delay
19
+ float lag = sway * (1.0 - uv.y);
20
+ float p = progress * (1.0 - lag * (1.0 - progress));
21
+ float open = mix(p, p * p * (3.0 - 2.0 * p), 0.75);
22
+ // each curtain hangs from its outer edge, gathers to the bunch width, then leaves the frame
23
+ float edge = -bunch * open * open;
24
+ float w = mix(0.5, bunch, open);
25
+ float x = min(uv.x, 1.0 - uv.x) - edge; // distance to the outer edge of the curtain
26
+ if (x >= w) {
27
+ // soft shadow of the curtain on the stage, fading as the curtain leaves the frame
28
+ vec4 to = getToColor(uv);
29
+ float shadow = 0.4 * exp((w - x) * 25.0) * clamp((edge + w) * 20.0, 0.0, 1.0);
30
+ return vec4(to.rgb * (1.0 - shadow * open), to.a);
31
+ }
32
+ float t = x / w;
33
+ // pleats: the fabric bunches up where cos(a) > 0 and is stretched elsewhere
34
+ float n = max(1.0, floor(folds * min(ratio, 1.0) + 0.5)); // folds keep their size in portrait
35
+ float a = 2.0 * PI * n * t;
36
+ float f = 1.0 - (1.0 - open) * (1.0 - open) * (1.0 - open); // the folds form early
37
+ float gather = 0.92 * f;
38
+ float s = 0.5 * (t + gather * sin(a) / (2.0 * PI * n)); // position in the fabric
39
+ vec4 c = getFromColor(vec2(uv.x < 0.5 ? s : 1.0 - s, uv.y));
40
+ // light comes from the front, a bit from the middle of the stage
41
+ float slope = 3.0 * gather * cos(a) * (uv.x < 0.5 ? 1.0 : -1.0);
42
+ float diffuse = (1.0 + 0.5 * slope) / sqrt(1.25 * (1.0 + slope * slope));
43
+ float crease = 0.5 + 0.5 * sin(a); // the back of each pleat is in the dark
44
+ float light = mix(1.0, diffuse * (1.0 - 0.6 * crease * crease), shading * f);
45
+ return vec4(c.rgb * light, c.a);
46
+ }
@@ -0,0 +1,20 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A soft-edged diamond grows from the center to reveal the incoming image
4
+ // Tags: shape, wipe, iris
5
+
6
+ // @param Center of the diamond
7
+ uniform vec2 center; // = vec2(0.5)
8
+ // @range(0, 0.5) Softness of the diamond's edge
9
+ uniform float smoothness; // = 0.03
10
+
11
+ vec4 transition (vec2 uv) {
12
+ // Measured in square pixels, so the diamond is not stretched
13
+ vec2 d = abs(uv - center) * vec2(ratio, 1.0);
14
+ // The diamond covers the frame once it reaches the farthest corner
15
+ vec2 far = max(center, 1.0 - center) * vec2(ratio, 1.0);
16
+ float dist = (d.x + d.y) / (far.x + far.y);
17
+ float s = max(smoothness, 0.001);
18
+ float m = smoothstep(0.0, s, progress * (1.0 + s) - dist);
19
+ return mix(getFromColor(uv), getToColor(uv), m);
20
+ }
@@ -0,0 +1,26 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The incoming image appears through a regular 8x8 ordered dither pattern, like a retro computer screen
4
+ // Tags: dissolve, pattern, retro, pixelate
5
+
6
+ // @range(0.002, 0.05) Size of a dither dot, relative to the height
7
+ uniform float dotSize; // = 0.02
8
+
9
+ // Threshold of the 8x8 Bayer matrix at integer cell c, in (0, 1)
10
+ float bayer(vec2 c) {
11
+ float v = 0.0;
12
+ float scale = 16.0;
13
+ for (int i = 0; i < 3; i++) {
14
+ vec2 bit = mod(floor(c), 2.0);
15
+ // a 2x2 step: 0 2 / 3 1, i.e. 2 * (x xor y) + y
16
+ v += scale * (2.0 * abs(bit.x - bit.y) + bit.y);
17
+ c *= 0.5;
18
+ scale *= 0.25;
19
+ }
20
+ return (v + 0.5) / 64.0;
21
+ }
22
+
23
+ vec4 transition(vec2 uv) {
24
+ vec2 cell = floor(uv * vec2(ratio, 1.0) / dotSize);
25
+ return progress < bayer(cell) ? getFromColor(uv) : getToColor(uv);
26
+ }
@@ -0,0 +1,35 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image falls over backward, hinged on its bottom edge, revealing the incoming one behind it
4
+ // Tags: rotate, vertical, 3d
5
+
6
+ // @range(0, 1) Strength of the perspective
7
+ uniform float perspective; // = 0.8
8
+ // @range(0, 1) How much the image darkens as it falls
9
+ uniform float shading; // = 0.7
10
+
11
+ const float PI = 3.141592653589793;
12
+
13
+ vec4 transition (vec2 uv) {
14
+ // it starts slowly, then gravity takes over
15
+ float fall = progress * (0.25 + 0.75 * progress);
16
+ float angle = 0.5 * PI * fall;
17
+ float c = cos(angle), s = sin(angle);
18
+ // a camera in front of the middle of the image goes down to the level of the hinge,
19
+ // so that the image ends edge-on
20
+ float dist = 1.0 / max(perspective, 0.01);
21
+ vec3 eye = vec3(0.5 * ratio, 0.5 * c, -dist);
22
+ vec3 dir = vec3(uv.x * ratio, uv.y, 0.0) - eye;
23
+ // cast a ray onto the plane of the image turned back by angle around its bottom edge
24
+ float den = dir.z * c - dir.y * s;
25
+ if (den > 0.0) {
26
+ float t = (eye.y * s - eye.z * c) / den;
27
+ vec3 hit = eye + t * dir;
28
+ vec2 puv = vec2(hit.x / ratio, hit.y * c + hit.z * s);
29
+ if (t > 0.0 && puv.y > 0.0 && puv.y <= 1.0 && puv.x >= 0.0 && puv.x <= 1.0) {
30
+ vec4 col = getFromColor(puv);
31
+ return vec4(col.rgb * (1.0 - shading * s), col.a);
32
+ }
33
+ }
34
+ return getToColor(uv);
35
+ }
@@ -0,0 +1,22 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image bulges toward the viewer through a strong fisheye lens, then the incoming one flattens back into place
4
+ // Tags: lens, distort, zoom, blend
5
+
6
+ // @range(0, 1) Strength of the lens at its peak
7
+ uniform float strength; // = 0.8
8
+
9
+ vec4 transition(vec2 uv) {
10
+ // lens amount: grows, peaks in the middle, then relaxes, eased so that
11
+ // the magnification of the center (1 / (1 - k)) changes at an even pace
12
+ float h = smoothstep(0.0, 1.0, 1.0 - abs(2.0 * progress - 1.0));
13
+ float k = 1.0 - pow(max(1.0 - strength, 0.01), h);
14
+ // round lens: aspect-corrected coordinates, 1.0 at the corners
15
+ vec2 aspect = vec2(ratio, 1.0);
16
+ vec2 c = (uv - 0.5) * aspect;
17
+ float r = length(c) / length(0.5 * aspect);
18
+ // barrel mapping that keeps the corners in place: the center is magnified,
19
+ // the edges squeezed, and every sample stays inside the image
20
+ vec2 q = 0.5 + (uv - 0.5) * (1.0 - k + k * r * r);
21
+ return mix(getFromColor(q), getToColor(q), smoothstep(0.38, 0.62, progress));
22
+ }
@@ -0,0 +1,48 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The image breaks into printed halftone dots whose size follows its shades, the dots reshape into the incoming image, then merge back into it
4
+ // Tags: dots, pattern, retro
5
+
6
+ // @range(4, 80) Number of dots across the shorter side
7
+ uniform float dots; // = 28.0
8
+ // @range(0, 90) Angle of the dot grid, in degrees
9
+ uniform float angle; // = 45.0
10
+ // @color Color of the paper between the dots
11
+ uniform vec4 paper; // = vec4(1.0, 1.0, 1.0, 1.0)
12
+
13
+ // Dot radius, in cells, of a halftone printing this color (darker is bigger)
14
+ float dotRadius(vec4 c) {
15
+ float shade = 1.0 - dot(c.rgb, vec3(0.299, 0.587, 0.114));
16
+ return mix(0.1, 0.74, sqrt(clamp(shade, 0.0, 1.0))) * c.a;
17
+ }
18
+
19
+ vec4 transition(vec2 uv) {
20
+ // the image turns into dots until 0.3, the dots reshape from left to right, then merge back from 0.7
21
+ float h = smoothstep(0.0, 0.3, progress) * (1.0 - smoothstep(0.7, 1.0, progress));
22
+ float t = (progress - 0.3) / 0.4;
23
+ // rotated square grid, in cells
24
+ float a = radians(angle);
25
+ mat2 rot = mat2(cos(a), sin(a), -sin(a), cos(a));
26
+ vec2 scale = vec2(ratio, 1.0) * dots / min(ratio, 1.0);
27
+ vec2 g = rot * ((uv - 0.5) * scale);
28
+ vec2 base = floor(g - 0.5) + 0.5;
29
+ vec4 pixel = progress < 0.5 ? getFromColor(uv) : getToColor(uv);
30
+ // the dots of the 4 nearest cells may overlap this point: keep the one it is deepest in
31
+ float best = 1e3;
32
+ vec4 ink = pixel;
33
+ for (int i = 0; i < 4; i++) {
34
+ vec2 center = base + vec2(mod(float(i), 2.0), floor(float(i) / 2.0));
35
+ vec2 cuv = (center * rot) / scale + 0.5; // inverse rotation
36
+ vec4 cf = getFromColor(cuv);
37
+ vec4 ct = getToColor(cuv);
38
+ float m = smoothstep(0.0, 1.0, clamp(2.5 * t - 1.5 * cuv.x, 0.0, 1.0));
39
+ // at h = 0, the dots cover their whole cell with the image itself
40
+ float r = mix(0.78, mix(dotRadius(cf), dotRadius(ct), m), h);
41
+ float sd = length(g - center) - r;
42
+ if (sd < best) {
43
+ best = sd;
44
+ ink = mix(pixel, mix(cf, ct, m), h);
45
+ }
46
+ }
47
+ return mix(paper, ink, 1.0 - smoothstep(-0.06, 0.06, best));
48
+ }
@@ -0,0 +1,54 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The image splits into hexagons that spin and shrink away in a wave from the center, uncovering the incoming image
4
+ // Tags: hexagon, tiles, rotate, radial
5
+
6
+ // @range(2, 30) Number of hexagons across the shorter side
7
+ uniform float size; // = 6.0
8
+
9
+ // Distance to the center of a pointy-top hexagon, 0.5 on the edges of a cell
10
+ float hexDist(vec2 p) {
11
+ p = abs(p);
12
+ return max(p.x, dot(p, vec2(0.5, 0.8660254)));
13
+ }
14
+
15
+ mat2 rotation(float a) {
16
+ return mat2(cos(a), sin(a), -sin(a), cos(a));
17
+ }
18
+
19
+ // Coverage of a hexagon turned by a and scaled by s inside its cell, with soft edges of width e
20
+ // (unturned at s = 1, it covers its whole cell)
21
+ float hexMask(vec2 local, float s, float a, float e) {
22
+ float r = (0.52 + e) * s;
23
+ return 1.0 - smoothstep(r - e, r, hexDist(rotation(-a) * local));
24
+ }
25
+
26
+ // Where the image is sampled, for a point of a hexagon turned by a and scaled by s
27
+ vec2 hexUv(vec2 uv, vec2 local, vec2 cellToUv, float s, float a) {
28
+ return uv + cellToUv * (rotation(-a) * local / max(s, 0.001) - local);
29
+ }
30
+
31
+ vec4 transition(vec2 uv) {
32
+ // nearest hexagon center, on two interleaved rectangular grids (centers 1 apart)
33
+ vec2 toCells = vec2(ratio, 1.0) * size / min(ratio, 1.0);
34
+ vec2 p = (uv - 0.5) * toCells;
35
+ const vec2 grid = vec2(1.0, 1.7320508);
36
+ vec2 a = (floor(p / grid) + 0.5) * grid;
37
+ vec2 b = (floor((p - 0.5 * grid) / grid) + 1.0) * grid;
38
+ vec2 center = dot(p - a, p - a) < dot(p - b, p - b) ? a : b;
39
+ vec2 local = p - center;
40
+
41
+ // each hexagon starts later the further it is from the center
42
+ float d = min(length(center / toCells * vec2(ratio, 1.0)) / (0.5 * length(vec2(ratio, 1.0))), 1.0);
43
+ float t = clamp((progress - 0.6 * d) / 0.4, 0.0, 1.0);
44
+
45
+ // the outgoing hexagon spins (opening gaps at the corners of its cell), shrinks away and darkens,
46
+ // casting a soft shadow on the incoming image
47
+ float s = 1.0 - smoothstep(0.1, 1.0, t);
48
+ float turn = 1.8 * t * (2.0 - t);
49
+ vec4 fromTile = getFromColor(hexUv(uv, local, 1.0 / toCells, s, turn));
50
+ fromTile.rgb *= 1.0 - 0.3 * t;
51
+ vec4 below = getToColor(uv);
52
+ below.rgb *= 1.0 - 0.5 * hexMask(local - vec2(0.06, -0.08) * s, s, turn, 0.2);
53
+ return mix(below, fromTile, hexMask(local, s, turn, 0.03));
54
+ }
@@ -0,0 +1,75 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image tears in two along a ragged line, and the halves are pulled apart to reveal the incoming one
4
+ // Tags: split, horizontal, shadow
5
+
6
+ // @range(0, 0.3) How far the tear wanders from the middle, relative to the image height
7
+ uniform float roughness; // = 0.12
8
+ // @range(0, 0.5) How much the top of each half leans away first, so that the tear opens from the top
9
+ uniform float tilt; // = 0.1
10
+ // @range(0, 0.05) Width of the white torn edge, relative to the image height
11
+ uniform float rim; // = 0.012
12
+ // @color Color of the paper fibers on the torn edges
13
+ uniform vec4 paper; // = vec4(1.0, 0.98, 0.94, 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.35)
16
+
17
+ float tri (float x) {
18
+ return abs(fract(x) - 0.5) - 0.25;
19
+ }
20
+
21
+ // horizontal position of the tear at height y: smooth meanders...
22
+ float meander (float y) {
23
+ return 0.5 * ratio + roughness * (0.5 * sin(y * 4.7 + 1.3) + 0.25 * sin(y * 11.3 + 4.1));
24
+ }
25
+
26
+ // ...and sharp jags
27
+ float tear (float y) {
28
+ return meander(y) + roughness * (0.1 * sin(y * 29.0 + 0.7) + 0.35 * tri(y * 19.0 + sin(y * 7.0)) + 0.12 * tri(y * 47.0 + 0.6 * sin(y * 13.0)));
29
+ }
30
+
31
+ // width of the torn edge along it, so that the fibers look uneven
32
+ float fibers (float y, float seed) {
33
+ return rim * (0.7 + 0.3 * sin(y * 37.0 + seed) + 0.4 * tri(y * 83.0 + seed));
34
+ }
35
+
36
+ // the left half (or the mirrored right half) slides out, its top leaning away first:
37
+ // from a point on screen to the point of the paper (the frame edges stay covered)
38
+ vec2 unfold (vec2 q, float away, float lean) {
39
+ return vec2(q.x + away + lean * q.y, q.y);
40
+ }
41
+
42
+ // a torn half over the background, with its fibers and an anti-aliased edge
43
+ // e: distance past the torn edge, limit: how far the fibers reach, aa: edge softness
44
+ vec4 torn (vec4 bg, vec4 col, float e, float limit, float aa) {
45
+ vec4 c = vec4(mix(col.rgb, paper.rgb, clamp(0.5 + e / aa, 0.0, 1.0) * paper.a), col.a);
46
+ return mix(bg, c, clamp(0.5 - (e - limit) / aa, 0.0, 1.0));
47
+ }
48
+
49
+ vec4 transition (vec2 uv) {
50
+ float p = progress;
51
+ float away = p * p * (0.5 * ratio + 0.1 + roughness + 2.0 * rim); // far enough to leave the frame
52
+ float lean = tilt * p * (2.0 - p);
53
+ float fiber = smoothstep(0.0, 0.15, p); // no torn edge on the intact image
54
+ float aa = 0.002 * fiber + 1e-6;
55
+ vec2 q = vec2(uv.x * ratio, uv.y);
56
+ vec2 l = unfold(q, away, lean);
57
+ vec2 r = unfold(vec2(ratio - q.x, q.y), away, lean);
58
+ float el = l.x - tear(l.y); // > 0 right of the left half's torn edge
59
+ float er = r.x - (ratio - tear(r.y)); // > 0 left of the right half's torn edge
60
+ // soft shadow of the two halves on the incoming image, cast toward the right
61
+ vec2 sq = q - vec2(0.01, 0.0);
62
+ float dl = unfold(sq, away, lean).x - meander(sq.y);
63
+ float dr = unfold(vec2(ratio - sq.x, sq.y), away, lean).x - (ratio - meander(sq.y));
64
+ vec4 to = getToColor(uv);
65
+ float sh = shadow.a * (1.0 - smoothstep(-0.02, 0.08, min(dl, dr)));
66
+ vec4 c = vec4(mix(to.rgb, shadow.rgb, sh), to.a);
67
+ // the image stops at the tear; the bare paper fibers stick out a little beyond it
68
+ if (r.x >= 0.0) {
69
+ c = torn(c, getFromColor(vec2(1.0 - r.x / ratio, r.y)), er, fibers(r.y, 2.0) * 1.5 * fiber, aa);
70
+ }
71
+ if (l.x >= 0.0) {
72
+ c = torn(c, getFromColor(vec2(l.x / ratio, l.y)), el, fibers(l.y, 0.0) * fiber, aa);
73
+ }
74
+ return c;
75
+ }
@@ -0,0 +1,80 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The frame is cut into 3D prisms that turn in a cascade, like a rotating billboard, from the outgoing image on one face to the incoming one on the next
4
+ // Tags: 3d, rotate, stripes
5
+
6
+ // @range(2, 40, 1) Number of prisms
7
+ uniform int slats; // = 8
8
+ // @range(0, 0.9) Delay of the last prism's turn, as a part of the transition
9
+ uniform float stagger; // = 0.45
10
+ // @range(0, 4) Amount of perspective
11
+ uniform float perspective; // = 1.0
12
+ // @range(0, 1) How much the faces darken as they turn away
13
+ uniform float shading; // = 0.6
14
+ // @param Cut the frame into horizontal prisms instead
15
+ uniform bool horizontal; // = false
16
+ // @color Color seen where the turning prisms leave the frame uncovered
17
+ uniform vec4 backColor; // = vec4(0.0, 0.0, 0.0, 1.0)
18
+
19
+ const float PI = 3.141592653589793;
20
+ // width of the anti-aliased edges, in frame heights
21
+ const float EDGE = 0.002;
22
+
23
+ vec4 transition (vec2 uv) {
24
+ float n = float(slats);
25
+ // a: the axis across the prisms, b: the axis they turn around
26
+ float a = horizontal ? uv.y : uv.x;
27
+ float b = horizontal ? uv.x : uv.y;
28
+ // the prisms' half width in frame heights, and the perspective from their depth
29
+ float hw = 0.5 / n * (horizontal ? 1.0 : ratio);
30
+ float k = min(perspective * hw, 0.5);
31
+ float bScale = horizontal ? ratio : 1.0;
32
+ // a turning prism is wider than its strip: keep the two nearest faces
33
+ vec4 near1 = vec4(0.0), near2 = vec4(0.0);
34
+ float cover1 = 0.0, cover2 = 0.0;
35
+ float z1 = -2.0, z2 = -2.0;
36
+ for (int d = -1; d <= 1; d++) {
37
+ float i = floor(a * n) + float(d);
38
+ if (i < 0.0 || i > n - 1.0) continue;
39
+ // each prism turns after a delay that grows across the frame, left to right or top to bottom
40
+ float order = (horizontal ? n - 1.0 - i : i) / (n - 1.0);
41
+ float t = clamp((progress - stagger * order) / (1.0 - stagger), 0.0, 1.0);
42
+ t = mix(t, t * t * (3.0 - 2.0 * t), 0.7);
43
+ float c = cos(0.5 * PI * t);
44
+ float s = sin(0.5 * PI * t);
45
+ // soft edges while turning (sharp at rest, to keep the first and last frames exact)
46
+ float edge = EDGE * min(1.0, 20.0 * s * c) + 1e-6;
47
+ // x: position across the strip, -1 to 1; the prism's square section has its faces at distance 1
48
+ float x = 2.0 * (a * n - i) - 1.0;
49
+ for (int f = 0; f < 2; f++) {
50
+ // f = 0: the outgoing face turning away, f = 1: the incoming face turning in
51
+ float cf = f == 0 ? c : s;
52
+ if (cf < 1e-4) continue;
53
+ // u: position on the face, z: depth (1 for a face at rest)
54
+ float u = f == 0 ? (x + s) / c : (x - c) / s;
55
+ float z = f == 0 ? u * s + c : s - u * c;
56
+ if (abs(u) > 1.0 || z <= z2) continue;
57
+ // nearer parts look bigger
58
+ float scale = 1.0 - k * (z - 1.0);
59
+ float y = (b - 0.5) * scale + 0.5;
60
+ if (y < 0.0 || y > 1.0) continue;
61
+ // soften the outer edges only: the faces meet at the prism's corner
62
+ float outer = f == 0 ? 1.0 + u : 1.0 - u;
63
+ float cover = clamp(outer * hw * cf / edge, 0.0, 1.0)
64
+ * clamp(min(y, 1.0 - y) * bScale / scale / edge, 0.0, 1.0);
65
+ float sa = (i + 0.5 + 0.5 * u) / n;
66
+ vec2 p = horizontal ? vec2(y, sa) : vec2(sa, y);
67
+ vec4 img = f == 0 ? getFromColor(p) : getToColor(p);
68
+ // lit from the front and the incoming side: the outgoing face darkens as it turns away
69
+ float lambert = clamp(f == 0 ? c - 0.6 * s : s + 0.6 * c, 0.0, 1.0);
70
+ vec4 color = vec4(img.rgb * mix(1.0 - shading, 1.0, lambert), img.a);
71
+ if (z > z1) {
72
+ near2 = near1; cover2 = cover1; z2 = z1;
73
+ near1 = color; cover1 = cover; z1 = z;
74
+ } else {
75
+ near2 = color; cover2 = cover; z2 = z;
76
+ }
77
+ }
78
+ }
79
+ return mix(mix(backColor, near2, cover2), near1, cover1);
80
+ }
@@ -0,0 +1,123 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The image is cut into jigsaw puzzle pieces that lift one after another and fall away, revealing the incoming image
4
+ // Tags: tiles, shadow, rotate, fragments
5
+
6
+ // @range(2, 12) Number of pieces across the shorter side
7
+ uniform float pieces; // = 5.0
8
+ // @range(0, 1) Darkness of the shadows of the lifted pieces
9
+ uniform float shadow; // = 0.6
10
+
11
+ // Hash of a cell, without sin, in [0, 1)
12
+ float hash(vec2 c) {
13
+ vec2 p = fract(c * vec2(0.1031, 0.1030));
14
+ p += dot(p, p.yx + 33.33);
15
+ return fract((p.x + p.y) * p.x);
16
+ }
17
+
18
+ float boxDist(vec2 p, vec2 halfSize) {
19
+ vec2 q = abs(p) - halfSize;
20
+ return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0);
21
+ }
22
+
23
+ // Signed distance of a point, relative to the center of piece c, to that piece (cell units).
24
+ // Each edge has a knob (a round head on a neck): a tab for one piece, a blank for its neighbor; border edges are flat.
25
+ float pieceDist(vec2 p, vec2 c, vec2 grid, float aspect) {
26
+ vec2 halfSize = vec2(0.5 * aspect, 0.5);
27
+ float d = boxDist(p, halfSize);
28
+ float tabs = 1e3;
29
+ for (int e = 0; e < 4; e++) {
30
+ // right, left, top, bottom: the edge key is the cell on its left or below
31
+ vec2 dir = e == 0 ? vec2(1.0, 0.0) : e == 1 ? vec2(-1.0, 0.0) : e == 2 ? vec2(0.0, 1.0) : vec2(0.0, -1.0);
32
+ vec2 key = c + min(dir, 0.0);
33
+ vec2 next = c + dir;
34
+ if (next.x >= 0.0 && next.y >= 0.0 && next.x < grid.x && next.y < grid.y) {
35
+ float h = hash(key + (e < 2 ? vec2(0.0) : vec2(71.0, 37.0)));
36
+ // the knob points right or up from the key cell when h < 0.5
37
+ bool tab = (h < 0.5) == (dir.x + dir.y > 0.0);
38
+ vec2 out1 = dir * (tab ? 1.0 : -1.0);
39
+ vec2 along = vec2(abs(dir.y), abs(dir.x));
40
+ vec2 edge = dir * halfSize + along * (fract(h * 2.0) - 0.5) * 0.16;
41
+ float k = min(
42
+ length(p - edge - out1 * 0.15) - 0.125,
43
+ boxDist(p - edge - out1 * 0.06, abs(dir) * 0.08 + along * 0.085));
44
+ if (tab) tabs = min(tabs, k);
45
+ else d = max(d, -k);
46
+ }
47
+ }
48
+ return min(d, tabs);
49
+ }
50
+
51
+ vec4 transition(vec2 uv) {
52
+ // a grid of nearly square cells that fits the frame exactly
53
+ float rows = ratio < 1.0 ? floor(pieces / ratio + 0.5) : pieces;
54
+ float cols = ratio < 1.0 ? pieces : floor(pieces * ratio + 0.5);
55
+ vec2 grid = vec2(cols, rows);
56
+ float aspect = ratio * rows / cols;
57
+ vec2 g = uv * grid;
58
+ vec2 cell = floor(g);
59
+
60
+ const float aa = 0.01; // soft edges, in cells
61
+ float boardSum = 0.0;
62
+ float allSum = 0.0;
63
+ // the two top moving pieces under this point
64
+ float prio1 = -1.0, prio2 = -1.0, cov1 = 0.0, cov2 = 0.0, shade1 = 1.0, shade2 = 1.0;
65
+ vec2 uv1 = uv, uv2 = uv;
66
+ float shadowAll = 0.0;
67
+ float seam = 1.0;
68
+ for (int i = 0; i < 9; i++) {
69
+ vec2 c = cell + vec2(mod(float(i), 3.0), floor(float(i) / 3.0)) - 1.0;
70
+ if (c.x < 0.0 || c.y < 0.0 || c.x >= cols || c.y >= rows) continue;
71
+ vec2 center = c + 0.5;
72
+ vec2 local = (g - center) * vec2(aspect, 1.0);
73
+ float h = hash(c + vec2(13.0, 7.0));
74
+ // diagonal order from the top left, a little shuffled
75
+ float diag = (c.x / max(cols - 1.0, 1.0) + (rows - 1.0 - c.y) / max(rows - 1.0, 1.0)) * 0.5;
76
+ float delay = (diag + 1.2 * (h - 0.5) * diag * (1.0 - diag)) * 0.6;
77
+ float t = clamp((progress - delay) / 0.4, 0.0, 1.0);
78
+
79
+ // where the piece was: the board keeps the outgoing image where pieces are still in place
80
+ float d0 = pieceDist(local, c, grid, aspect);
81
+ float w = 1.0 - smoothstep(-aa, aa, d0);
82
+ allSum += w;
83
+ if (t <= 0.0) {
84
+ boardSum += w;
85
+ seam = min(seam, abs(d0));
86
+ continue;
87
+ }
88
+ // lift, then fall away: shrink, spin, drift down and darken
89
+ float lift = smoothstep(0.0, 0.25, t);
90
+ float fall = clamp((t - 0.2) / 0.8, 0.0, 1.0);
91
+ fall *= fall;
92
+ float s = max(1.0 - fall, 0.001);
93
+ float a = (h - 0.5) * 3.0 * fall;
94
+ vec2 off = vec2(0.0, -1.2 * fall);
95
+ mat2 rot = mat2(cos(a), -sin(a), sin(a), cos(a));
96
+ vec2 pl = rot * (local - off) / s;
97
+ float dp = pieceDist(pl, c, grid, aspect);
98
+ float cov = (1.0 - smoothstep(-aa, aa, dp * s)) * min(s * 20.0, 1.0); // fades when tiny
99
+ // darker when falling, and on its edges when lifted
100
+ float shade = (1.0 - 0.5 * fall) * (1.0 - 0.3 * lift * (1.0 - smoothstep(0.0, 0.035, -dp)));
101
+ vec2 puv = (center + pl / vec2(aspect, 1.0)) / grid;
102
+ // soft shadow, offset to the bottom right while lifted
103
+ vec2 sl = rot * (local - off - vec2(0.08, -0.1) * lift) / s;
104
+ float sh = (1.0 - smoothstep(-0.05, 0.12, pieceDist(sl, c, grid, aspect) * s)) * lift * (1.0 - fall) * shadow;
105
+ // the hole it leaves is in its shadow too
106
+ shadowAll = max(shadowAll, max(sh, w * lift * (1.0 - smoothstep(0.2, 0.5, t)) * shadow));
107
+ float prio = delay;
108
+ if (cov > 0.0 && prio > prio1) {
109
+ prio2 = prio1; cov2 = cov1; uv2 = uv1; shade2 = shade1;
110
+ prio1 = prio; cov1 = cov; uv1 = puv; shade1 = shade;
111
+ } else if (cov > 0.0 && prio > prio2) {
112
+ prio2 = prio; cov2 = cov; uv2 = puv; shade2 = shade;
113
+ }
114
+ }
115
+ vec4 base = mix(getToColor(uv), getFromColor(uv), boardSum / max(allSum, 0.001));
116
+ // the cuts show on the board as the transition starts
117
+ base.rgb *= (1.0 - shadowAll) * (1.0 - 0.4 * smoothstep(0.0, 0.1, progress) * (1.0 - smoothstep(0.0, 0.015, seam)));
118
+ vec4 p2 = getFromColor(uv2);
119
+ p2.rgb *= shade2;
120
+ vec4 p1 = getFromColor(uv1);
121
+ p1.rgb *= shade1;
122
+ return mix(mix(base, p2, cov2), p1, cov1);
123
+ }