gl-transitions 2.5.0 → 3.0.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 (107) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +16 -1
  3. package/compatibility.json +56 -170
  4. package/gl-transitions.js +1 -1
  5. package/gl-transitions.json +1 -1
  6. package/glsl3/BandWipe.glsl +67 -0
  7. package/glsl3/BowTie.glsl +1 -1
  8. package/glsl3/DirectionalWipe.glsl +1 -1
  9. package/glsl3/GlintDissolve.glsl +125 -0
  10. package/glsl3/InsetWipe.glsl +58 -0
  11. package/glsl3/LightningFlash.glsl +200 -0
  12. package/glsl3/WarpSpeed.glsl +120 -0
  13. package/index.js +1 -1
  14. package/layouts.json +191 -198
  15. package/llms-full.txt +452 -515
  16. package/llms.txt +197 -204
  17. package/msl/BandWipe.metal +353 -0
  18. package/msl/BowTie.metal +1 -1
  19. package/msl/DirectionalWipe.metal +1 -1
  20. package/msl/GlintDissolve.metal +558 -0
  21. package/msl/InsetWipe.metal +232 -0
  22. package/msl/LightningFlash.metal +1038 -0
  23. package/msl/WarpSpeed.metal +549 -0
  24. package/package.json +1 -1
  25. package/skills/gl-transitions/references/catalog.md +36 -37
  26. package/sksl/BandWipe.sksl +77 -0
  27. package/sksl/BowTie.sksl +1 -1
  28. package/sksl/DirectionalWipe.sksl +1 -1
  29. package/sksl/GlintDissolve.sksl +136 -0
  30. package/sksl/InsetWipe.sksl +70 -0
  31. package/sksl/LightningFlash.sksl +202 -0
  32. package/sksl/WarpSpeed.sksl +131 -0
  33. package/sksl/index.js +1 -1
  34. package/transitions/BandWipe.glsl +66 -0
  35. package/transitions/BowTie.glsl +1 -1
  36. package/transitions/DirectionalWipe.glsl +1 -1
  37. package/transitions/GlintDissolve.glsl +124 -0
  38. package/transitions/InsetWipe.glsl +57 -0
  39. package/transitions/LightningFlash.glsl +199 -0
  40. package/transitions/WarpSpeed.glsl +119 -0
  41. package/wgsl/BandWipe.wgsl +319 -0
  42. package/wgsl/BowTie.wgsl +1 -1
  43. package/wgsl/DirectionalWipe.wgsl +1 -1
  44. package/wgsl/GlintDissolve.wgsl +519 -0
  45. package/wgsl/InsetWipe.wgsl +200 -0
  46. package/wgsl/LightningFlash.wgsl +964 -0
  47. package/wgsl/WarpSpeed.wgsl +497 -0
  48. package/glsl3/BlockDissolve.glsl +0 -16
  49. package/glsl3/BowTieVertical.glsl +0 -117
  50. package/glsl3/Box.glsl +0 -33
  51. package/glsl3/LinearBlur.glsl +0 -30
  52. package/glsl3/MosaicBlend.glsl +0 -21
  53. package/glsl3/MosaicFade.glsl +0 -20
  54. package/glsl3/RotateFade.glsl +0 -22
  55. package/glsl3/ScaleIn.glsl +0 -18
  56. package/glsl3/WipeDown.glsl +0 -12
  57. package/glsl3/WipeLeft.glsl +0 -12
  58. package/glsl3/WipeRight.glsl +0 -12
  59. package/glsl3/WipeUp.glsl +0 -12
  60. package/msl/BlockDissolve.metal +0 -108
  61. package/msl/BowTieVertical.metal +0 -375
  62. package/msl/Box.metal +0 -204
  63. package/msl/LinearBlur.metal +0 -169
  64. package/msl/MosaicBlend.metal +0 -136
  65. package/msl/MosaicFade.metal +0 -137
  66. package/msl/RotateFade.metal +0 -116
  67. package/msl/ScaleIn.metal +0 -111
  68. package/msl/WipeDown.metal +0 -105
  69. package/msl/WipeLeft.metal +0 -105
  70. package/msl/WipeRight.metal +0 -105
  71. package/msl/WipeUp.metal +0 -105
  72. package/sksl/BlockDissolve.sksl +0 -29
  73. package/sksl/BowTieVertical.sksl +0 -130
  74. package/sksl/Box.sksl +0 -47
  75. package/sksl/LinearBlur.sksl +0 -44
  76. package/sksl/MosaicBlend.sksl +0 -34
  77. package/sksl/MosaicFade.sksl +0 -33
  78. package/sksl/RotateFade.sksl +0 -34
  79. package/sksl/ScaleIn.sksl +0 -32
  80. package/sksl/WipeDown.sksl +0 -26
  81. package/sksl/WipeLeft.sksl +0 -26
  82. package/sksl/WipeRight.sksl +0 -26
  83. package/sksl/WipeUp.sksl +0 -26
  84. package/transitions/BlockDissolve.glsl +0 -15
  85. package/transitions/BowTieVertical.glsl +0 -116
  86. package/transitions/Box.glsl +0 -32
  87. package/transitions/LinearBlur.glsl +0 -29
  88. package/transitions/MosaicBlend.glsl +0 -20
  89. package/transitions/MosaicFade.glsl +0 -19
  90. package/transitions/RotateFade.glsl +0 -21
  91. package/transitions/ScaleIn.glsl +0 -17
  92. package/transitions/WipeDown.glsl +0 -11
  93. package/transitions/WipeLeft.glsl +0 -11
  94. package/transitions/WipeRight.glsl +0 -11
  95. package/transitions/WipeUp.glsl +0 -11
  96. package/wgsl/BlockDissolve.wgsl +0 -78
  97. package/wgsl/BowTieVertical.wgsl +0 -331
  98. package/wgsl/Box.wgsl +0 -176
  99. package/wgsl/LinearBlur.wgsl +0 -131
  100. package/wgsl/MosaicBlend.wgsl +0 -108
  101. package/wgsl/MosaicFade.wgsl +0 -107
  102. package/wgsl/RotateFade.wgsl +0 -85
  103. package/wgsl/ScaleIn.wgsl +0 -79
  104. package/wgsl/WipeDown.wgsl +0 -77
  105. package/wgsl/WipeLeft.wgsl +0 -77
  106. package/wgsl/WipeRight.wgsl +0 -77
  107. package/wgsl/WipeUp.wgsl +0 -77
@@ -0,0 +1,66 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: Alternating bands wipe in from opposite sides together and interleave like fingers, while both images stay still
4
+ // Tags: wipe, stripes, interleave, horizontal
5
+
6
+ // @range(2, 40, 1) Number of bands
7
+ uniform int bands; // = 8
8
+ // @param Cut the frame into columns that wipe up and down instead of rows that wipe sideways
9
+ uniform bool vertical; // = false
10
+ // @range(0, 0.2) Softness of the bands' leading edges
11
+ uniform float smoothness; // = 0.02
12
+ // @range(0, 0.8) Delay between the first and the last band, so they cascade from the top (or the left)
13
+ uniform float stagger; // = 0.1
14
+
15
+ // half width of the antialiased edges, in frame heights
16
+ const float AA = 0.0015;
17
+
18
+ // how far band i has wiped in (0..1) at position a along the bands (0..l), alternate bands
19
+ // entering from opposite ends
20
+ float bandMask(float i, float n, float a, float l, float s) {
21
+ // each band takes the same time, starting a little after the one before it from the top
22
+ // (or the left)
23
+ float k = vertical ? i : n - 1.0 - i;
24
+ float g = clamp(stagger, 0.0, 0.95);
25
+ float t = clamp((progress - g * k / max(n - 1.0, 1.0)) / (1.0 - g), 0.0, 1.0);
26
+ t = mix(t, t * t * (3.0 - 2.0 * t), 0.5);
27
+ float x = mod(i, 2.0) > 0.5 ? l - a : a;
28
+ // the edge starts fully before the band and ends fully past it
29
+ float c = mix(-s, l + s, t);
30
+ return 1.0 - smoothstep(c - s, c + s, x);
31
+ }
32
+
33
+ vec4 transition(vec2 uv) {
34
+ if (progress <= 0.0) return getFromColor(uv);
35
+ if (progress >= 1.0) return getToColor(uv);
36
+
37
+ float n = float(bands < 1 ? 1 : bands);
38
+ // along: position along the bands, in frame heights; across: position across them (0..1)
39
+ float along = vertical ? uv.y : uv.x * ratio;
40
+ float across = vertical ? uv.x : uv.y;
41
+ float l = vertical ? 1.0 : ratio;
42
+ // the antialiasing across the bands, in units of across
43
+ float aaAcross = vertical ? AA / ratio : AA;
44
+ float s = max(smoothness, AA);
45
+
46
+ float f = across * n;
47
+ float i = clamp(floor(f), 0.0, n - 1.0);
48
+ float m = bandMask(i, n, along, l, s);
49
+
50
+ // near a cut between two bands, blend with the neighbor band over a pixel or so so the cut
51
+ // does not alias (at the frame's borders the neighbor is the band itself)
52
+ float fr = f - i;
53
+ float edge = min(fr, 1.0 - fr) / n;
54
+ if (edge < aaAcross) {
55
+ float j = clamp(fr < 0.5 ? i - 1.0 : i + 1.0, 0.0, n - 1.0);
56
+ m = mix(bandMask(j, n, along, l, s), m, 0.5 + 0.5 * smoothstep(0.0, aaAcross, edge));
57
+ }
58
+
59
+ if (m <= 0.0) return getFromColor(uv);
60
+ if (m >= 1.0) return getToColor(uv);
61
+ vec4 a = getFromColor(uv);
62
+ vec4 b = getToColor(uv);
63
+ // mixed premultiplied, so transparent images do not bleed their color
64
+ vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), m);
65
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
66
+ }
@@ -1,6 +1,6 @@
1
1
  // Author: KMojek
2
2
  // License: MIT
3
- // Description: A bow-tie wipe with an adjustable shape that can run in reverse
3
+ // Description: Two triangles grow from the top and bottom edges into a bow tie that reveals the incoming image, with an adjustable shape, and can run in reverse
4
4
  // Tags: wipe, shape
5
5
 
6
6
  uniform float adjust; // = 0.5
@@ -1,6 +1,6 @@
1
1
  // Author: gre
2
2
  // License: MIT
3
- // Description: A soft-edged diagonal wipe
3
+ // Description: A straight wipe in any direction, diagonal and soft-edged by default; a smoothness of 0 gives a hard edge
4
4
  // Tags: wipe, directional
5
5
 
6
6
  // @param Direction of the wipe
@@ -0,0 +1,124 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The bright points of the outgoing image sparkle into crisp four-point star glints that swell and twinkle up to the cut, then shrink back into the highlights of the incoming image, which stays sharp
4
+ // Tags: light, glints, sparkle, dissolve
5
+
6
+ // @range(0.02, 0.3) Length of the longest rays of the glints at the peak, in frame heights
7
+ uniform float size; // = 0.15
8
+ // @range(0, 1) Brightness above which the image sparkles
9
+ uniform float threshold; // = 0.6
10
+ // @range(0, 4) Brightness of the glints
11
+ uniform float intensity; // = 2.0
12
+ // @param Add a shorter, softer pair of diagonal rays to each glint
13
+ uniform bool diagonals; // = false
14
+ // @range(-45, 45) Angle of the cross, in degrees
15
+ uniform float rotation; // = 0.0
16
+ // @range(0, 1) Rainbow fringes along the rays
17
+ uniform float rainbow; // = 0.35
18
+ // @color Tint of the glints, added as light
19
+ uniform vec3 tint; // = vec3(1.0, 0.95, 0.85)
20
+
21
+ // the long rays reach over this many cells of the glint grid
22
+ const float REACH = 6.0;
23
+
24
+ float hash12(vec2 v) {
25
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
26
+ v3 += dot(v3, v3.yzx + 33.33);
27
+ return fract((v3.x + v3.y) * v3.z);
28
+ }
29
+
30
+ // one thin ray along x, from the glint center to its tip at x = len (in cells)
31
+ float ray(vec2 d, float len, float width) {
32
+ float a = abs(d.x) / len;
33
+ if (a >= 1.0) return 0.0;
34
+ float fall = (1.0 - a) * (1.0 - a);
35
+ float w = width * (1.0 - 0.7 * a);
36
+ return fall * exp(-d.y * d.y / (w * w));
37
+ }
38
+
39
+ vec3 spectrum(float a) {
40
+ return 0.5 + 0.5 * cos(6.2831853 * (a + vec3(0.0, 0.33, 0.67)));
41
+ }
42
+
43
+ vec4 transition(vec2 uv) {
44
+ float p = progress;
45
+ // the glints swell up to the cut, then shrink back: 0 at both ends
46
+ float t = 1.0 - abs(2.0 * p - 1.0);
47
+ float amount = t * (2.0 - t);
48
+ // a short crossfade under the glints at their brightest
49
+ float m = smoothstep(0.42, 0.58, p);
50
+ if (amount <= 0.0) return m < 0.5 ? getFromColor(uv) : getToColor(uv);
51
+
52
+ vec4 fromColor = getFromColor(uv);
53
+ vec4 toColor = getToColor(uv);
54
+ vec4 c = mix(vec4(fromColor.rgb * fromColor.a, fromColor.a), vec4(toColor.rgb * toColor.a, toColor.a), m);
55
+ if (c.a <= 0.0) return vec4(0.0);
56
+ vec3 base = c.rgb / c.a;
57
+
58
+ // a grid of glint cells, turned with the cross so that its long rays run along the rows and columns
59
+ float cell = size / REACH;
60
+ float ang = radians(rotation);
61
+ vec2 cs = vec2(cos(ang), sin(ang));
62
+ vec2 aspect = vec2(ratio, 1.0);
63
+ vec2 o = (uv - 0.5) * aspect;
64
+ vec2 q = vec2(o.x * cs.x + o.y * cs.y, o.y * cs.x - o.x * cs.y) / cell;
65
+ vec2 home = floor(q);
66
+ // thin rays, in cells, thin enough to vanish before the next row of cells
67
+ float width = min(0.0022 / cell, 0.07);
68
+
69
+ vec3 light = vec3(0.0);
70
+ // the glints of the own cell, of the cells along its row and column (whose long rays reach this
71
+ // pixel) and of its four diagonal neighbours (for their short diagonal rays and their cores)
72
+ for (int k = 0; k < 29; k++) {
73
+ float fk = float(k);
74
+ vec2 off = vec2(0.0);
75
+ if (k >= 1 && k <= 12) off = vec2(fk < 7.0 ? fk - 7.0 : fk - 6.0, 0.0);
76
+ else if (k >= 13 && k <= 24) off = vec2(0.0, fk < 19.0 ? fk - 19.0 : fk - 18.0);
77
+ else if (k >= 25) off = vec2(mod(fk, 2.0) * 2.0 - 1.0, fk < 27.0 ? -1.0 : 1.0);
78
+ // the rays are never longer than this, so farther glints cannot reach the pixel
79
+ if (max(abs(off.x), abs(off.y)) > REACH * amount + 1.0) continue;
80
+ vec2 id = home + off;
81
+ // only some of the cells hold a glint
82
+ if (hash12(id + 89.5) > 0.55) continue;
83
+ float h0 = hash12(id + 0.5);
84
+ float h1 = hash12(id + 19.5);
85
+ float h2 = hash12(id + 41.5);
86
+ float h3 = hash12(id + 67.5);
87
+ // the glint: somewhere in its cell, so that the grid never shows
88
+ vec2 center = id + 0.5 + 0.6 * (vec2(h0, h1) - 0.5);
89
+ vec2 cw = center * cell;
90
+ vec2 st = vec2(cw.x * cs.x - cw.y * cs.y, cw.x * cs.y + cw.y * cs.x) / aspect + 0.5;
91
+ if (st.x < 0.0 || st.x > 1.0 || st.y < 0.0 || st.y > 1.0) continue;
92
+ // each glint reads one image: it blinks out at its own moment of the crossfade and comes back
93
+ // on the incoming image
94
+ float turn = 0.15 + 0.7 * h3;
95
+ vec4 src = m < turn ? getFromColor(st) : getToColor(st);
96
+ float lum = dot(src.rgb, vec3(0.2126, 0.7152, 0.0722)) * src.a;
97
+ // the brighter the image, the more of its cells sparkle
98
+ float knee = threshold + 0.8 * (1.0 - threshold) * h2;
99
+ float b = smoothstep(knee, knee + 0.2 * (1.0 - threshold) + 1e-3, lum);
100
+ if (b <= 0.0) continue;
101
+ // each glint twinkles at its own pace
102
+ float twinkle = (0.6 + 0.4 * sin(6.2831853 * (h2 + (1.5 + h0) * p))) * smoothstep(0.0, 0.12, abs(m - turn));
103
+ float len = REACH * amount * (0.45 + 0.55 * b) * (0.3 + 0.7 * h1 * h1) * (0.85 + 0.15 * twinkle);
104
+ vec2 d = q - center;
105
+ float r = length(d);
106
+ float star = ray(d, len, width) + ray(d.yx, len, width);
107
+ if (diagonals) {
108
+ vec2 e = vec2(d.x + d.y, d.x - d.y) * 0.70710678;
109
+ star += 0.5 * (ray(e, 0.25 * len, width) + ray(e.yx, 0.25 * len, width));
110
+ }
111
+ // a bright core and a faint halo
112
+ float cr = r / (0.08 * len);
113
+ star += exp(-cr * cr) + 0.3 * exp(-r / 0.2);
114
+ // white light with the hue of the highlight, and rainbow fringes toward the tips
115
+ float along = r / len;
116
+ vec3 hue = mix(vec3(1.0), spectrum(1.3 * along + h0), rainbow * smoothstep(0.05, 0.4, along));
117
+ vec3 col = mix(src.rgb / max(max(src.r, max(src.g, src.b)), 1e-3), vec3(1.0), 0.6);
118
+ light += b * twinkle * star * hue * col;
119
+ }
120
+ light *= tint * intensity * amount * amount;
121
+ // compressed, so that crossing rays never flatten into white
122
+ light = 1.0 - exp(-light);
123
+ return vec4(clamp(base + light - base * light, 0.0, 1.0), c.a);
124
+ }
@@ -0,0 +1,57 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A rectangle anchored in a corner, on an edge or in the center grows until the incoming image fills the frame, revealing it in place without scaling it; in reverse, the outgoing image shrinks into the rectangle
4
+ // Tags: wipe, shape, box
5
+
6
+ // @param Where the rectangle grows from: (0, 0) bottom left, (1, 1) top right, (0.5, 0) middle of the bottom edge, (0.5, 0.5) center
7
+ uniform vec2 anchor; // = vec2(1.0, 1.0)
8
+ // @range(0, 0.2) Softness of the rectangle's edge
9
+ uniform float smoothness; // = 0.0
10
+ // @range(0, 0.1) Width of a border drawn around the rectangle, in frame heights (0: no border)
11
+ uniform float borderWidth; // = 0.0
12
+ // @color Color of the border
13
+ uniform vec4 borderColor; // = vec4(1.0, 1.0, 1.0, 1.0)
14
+ // @param The outgoing image shrinks into the rectangle instead, toward the anchor
15
+ uniform bool reverse; // = false
16
+
17
+ // half width of the antialiased edge, in frame heights
18
+ const float AA = 0.001;
19
+
20
+ vec4 premultiplied(vec4 c) {
21
+ return vec4(c.rgb * c.a, c.a);
22
+ }
23
+
24
+ vec4 transition(vec2 uv) {
25
+ vec4 a = getFromColor(uv);
26
+ vec4 b = getToColor(uv);
27
+ if (progress <= 0.0) return a;
28
+ if (progress >= 1.0) return b;
29
+
30
+ vec2 an = clamp(anchor, 0.0, 1.0);
31
+ vec2 sq = vec2(ratio, 1.0);
32
+ // the rectangle keeps the proportions that make it reach every far side of the frame
33
+ // at once; measured in square pixels so its edge and border have an even width
34
+ vec2 ext = max(an, 1.0 - an) * sq;
35
+ vec2 d = abs(uv - an) * sq;
36
+ float s = max(smoothness, AA);
37
+ float bw = max(borderWidth, 0.0);
38
+
39
+ // eased growth, from a rectangle whose border is not yet in the frame to one whose
40
+ // soft edge has left it on every side
41
+ float t = reverse ? 1.0 - progress : progress;
42
+ float p = mix(t, t * t * (3.0 - 2.0 * t), 0.3);
43
+ vec2 size = p * ext + mix(-(bw + s), s, p);
44
+ // signed distance to the rectangle's edge, square-cornered, < 0 inside
45
+ float e = max(d.x - size.x, d.y - size.y);
46
+
47
+ // the rectangle shows the incoming image, or the outgoing one in reverse
48
+ vec4 inside = reverse ? a : b;
49
+ vec4 c = premultiplied(reverse ? b : a);
50
+ if (bw > 0.0) {
51
+ // laid over the image outside the rectangle, so a translucent border tints it
52
+ float m = 1.0 - smoothstep(bw - s, bw + s, e);
53
+ c = premultiplied(borderColor) * m + c * (1.0 - borderColor.a * m);
54
+ }
55
+ c = mix(c, premultiplied(inside), 1.0 - smoothstep(-s, s, e));
56
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
57
+ }
@@ -0,0 +1,199 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: Forked lightning bolts crack down from the top of the frame, the screen flashes white in a few stuttering strobes, and the incoming image appears lit by the last flickers as they fade out
4
+ // Tags: light, flash, weather, strobe
5
+
6
+ // @range(1, 3, 1) Number of bolts: the main one strikes the ground, the others fork out higher in the sky
7
+ uniform int bolts; // = 2
8
+ // @range(0, 1) Where the main bolt strikes, from the left (0) to the right (1) of the frame
9
+ uniform float strike; // = 0.55
10
+ // @range(0, 100, 1) Changes the shape of the bolts
11
+ uniform float seed; // = 0.0
12
+ // @color Color of the light, added to the images
13
+ uniform vec3 color; // = vec3(0.75, 0.85, 1.0)
14
+ // @range(0, 1) Size and brightness of the glow around the bolts
15
+ uniform float glow; // = 0.5
16
+ // @range(1, 4, 1) Number of strobes; the images switch during the brightest one
17
+ uniform int flashes; // = 3
18
+
19
+ // the bolts crack down until this time, then the strobes start
20
+ const float LEADER = 0.3;
21
+
22
+ float hash(vec2 p) {
23
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
24
+ p3 += dot(p3, p3.yzx + 33.33);
25
+ return fract((p3.x + p3.y) * p3.z);
26
+ }
27
+
28
+ // a value noise that is linear between its cells: a jagged polyline, centered on 0
29
+ float jag(float s, float k) {
30
+ float i = floor(s);
31
+ return mix(hash(vec2(i, k)), hash(vec2(i + 1.0, k)), fract(s)) - 0.5;
32
+ }
33
+
34
+ // the zigzag of a bolt around its straight line, at height y (narrower in a portrait frame)
35
+ float zigzag(float y, float k) {
36
+ return min(ratio, 1.0) * (0.15 * jag(y * 5.0, k) + 0.06 * jag(y * 13.0, k + 1.0) + 0.03 * jag(y * 31.0, k + 2.0) + 0.012 * jag(y * 67.0, k + 3.0));
37
+ }
38
+
39
+ // the x of a bolt at height y: from x0 at the top (y = 1) to x1 at its end (y = y1),
40
+ // given z0 and z1, its zigzag at both ends
41
+ float boltX(float y, float x0, float x1, float y1, float z0, float z1, float k) {
42
+ float t = (1.0 - y) / (1.0 - y1);
43
+ return mix(x0 - z0, x1 - z1, t) + zigzag(y, k);
44
+ }
45
+
46
+ // the x of a branch at height y: it leaves its bolt at (xb, yb), where its own zigzag is zb,
47
+ // and drifts sideways by dir per unit of height
48
+ float branchX(float y, float xb, float yb, float zb, float dir, float k) {
49
+ return xb + dir * (yb - y) + 0.6 * (zigzag(y, k) - zb);
50
+ }
51
+
52
+ // distance to a curve x = f(y), knowing its x and its slope at the pixel's height,
53
+ // and how far above or below its ends the pixel is; the slope only corrects the distance
54
+ // close to the curve, so the glow farther away does not streak along the zigzags
55
+ float curveDist(vec2 q, float x, float slope, float outside) {
56
+ float dx = abs(q.x - x);
57
+ float d = dx * mix(inversesqrt(1.0 + slope * slope), 1.0, smoothstep(0.0, 0.08, dx));
58
+ return length(vec2(d, max(outside, 0.0)));
59
+ }
60
+
61
+ // a strobe at time t0: a quick rise, a plateau of length hold, then a decay
62
+ float pulse(float p, float t0, float hold, float decay) {
63
+ float x = p - t0;
64
+ if (x < 0.0) return smoothstep(-0.012, 0.0, x);
65
+ return exp(-max(x - hold, 0.0) / decay);
66
+ }
67
+
68
+ vec4 transition(vec2 uv) {
69
+ float p = progress;
70
+ vec2 q = vec2(uv.x * ratio, uv.y);
71
+ // (seeds far apart, so that neighboring seeds share no hash keys)
72
+ float k0 = floor(seed) * 61.0;
73
+ int nb = bolts < 1 ? 1 : (bolts > 3 ? 3 : bolts);
74
+ int nf = flashes < 1 ? 1 : (flashes > 4 ? 4 : flashes);
75
+ // the images switch during the brightest strobe, the second one (or the only one)
76
+ int cut = nf > 1 ? 1 : 0;
77
+
78
+ // the strobes, a bit irregular; the bolts are lit by all of them, the screen mostly by the brightest
79
+ float flash = 0.0;
80
+ float lit = 0.0;
81
+ float tCut = LEADER;
82
+ float tLast = LEADER;
83
+ float t = LEADER;
84
+ for (int i = 0; i < 4; i++) {
85
+ if (i < nf) {
86
+ bool isCut = i == cut;
87
+ float amp = isCut ? 1.0 : (i < cut ? 0.55 : 0.7 * pow(0.75, float(i - cut - 1)));
88
+ float s = amp * pulse(p, t, isCut ? 0.025 : 0.004, isCut ? 0.03 : 0.022);
89
+ flash = max(flash, s);
90
+ lit = max(lit, pulse(p, t, 0.01, 0.045));
91
+ if (isCut) tCut = t;
92
+ tLast = t;
93
+ t += (isCut ? 0.12 : 0.08) + 0.04 * hash(vec2(float(i), k0 + 5.0));
94
+ }
95
+ }
96
+ // the stutter: the light jumps from one level to another a few times per strobe
97
+ float stutter = mix(0.7, 1.0, hash(vec2(floor(p * 70.0), k0 + 9.0)));
98
+ flash *= stutter;
99
+ // the brightest strobe whites the screen out while the images switch
100
+ float whiteout = pulse(p, tCut, 0.025, 0.02);
101
+ // then a few last flickers, fading out
102
+ float tail = p > tLast ? exp(-(p - tLast) / 0.1) * smoothstep(0.03, 0.06, p - tLast) : 0.0;
103
+ flash = max(flash, 0.35 * tail * step(0.45, hash(vec2(floor(p * 40.0), k0 + 13.0))));
104
+
105
+ // the bolts crack down in a few jumps while faintly lit, then light up with the strobes and go out
106
+ float grow = clamp(p / LEADER, 0.0, 1.0);
107
+ grow = (floor(grow * 7.0) + smoothstep(0.0, 1.0, fract(grow * 7.0))) / 7.0;
108
+ float faint = 0.5 * mix(0.6, 1.0, hash(vec2(floor(p * 50.0), k0 + 11.0)));
109
+ float boltLight = p < LEADER ? faint * smoothstep(0.0, 0.06, p) : max(lit * stutter, faint * exp(-(p - LEADER) / 0.12));
110
+ boltLight = max(boltLight, 0.6 * flash * tail);
111
+ boltLight *= 1.0 - smoothstep(tLast + 0.1, tLast + 0.3, p);
112
+
113
+ // the bolts: the main one strikes the ground at strike, the others stop in the sky
114
+ float core = 0.0;
115
+ float halo = 0.0;
116
+ float near = 10.0;
117
+ bool lightsOn = boltLight > 0.0 || flash > 0.0;
118
+ for (int b = 0; b < 3; b++) {
119
+ if (b < nb && lightsOn) {
120
+ float fb = float(b);
121
+ float kb = k0 + fb * 17.0;
122
+ float x1 = strike * ratio;
123
+ float y1 = -0.05;
124
+ float bright = 1.0;
125
+ if (b > 0) {
126
+ // the second bolt goes to the roomier side, the third to the other side if there is room there
127
+ float roomy = strike < 0.5 ? 1.0 : -1.0;
128
+ bool cramped = min(strike, 1.0 - strike) < 0.25;
129
+ float side = b == 1 || cramped ? roomy : -roomy;
130
+ float dist = b == 2 && cramped ? 0.5 : 0.22;
131
+ x1 = clamp(x1 + side * ratio * (dist + 0.12 * hash(vec2(fb, kb))), 0.08 * ratio, 0.92 * ratio);
132
+ y1 = 0.25 + 0.25 * hash(vec2(fb, kb + 1.0));
133
+ bright = 0.7;
134
+ }
135
+ float x0 = clamp(x1 + (hash(vec2(fb, kb + 2.0)) - 0.5) * 0.5 * min(ratio, 1.0), 0.1 * ratio, 0.9 * ratio);
136
+ // the tip of the bolt while it cracks down
137
+ float tip = mix(1.02, y1, grow);
138
+ // (the slope is measured over a few pixels, so it changes smoothly at the corners)
139
+ float e = 0.01;
140
+ float z0 = zigzag(1.0, kb);
141
+ float z1 = zigzag(y1, kb);
142
+ float x = boltX(q.y, x0, x1, y1, z0, z1, kb);
143
+ float slope = (boltX(q.y + e, x0, x1, y1, z0, z1, kb) - boltX(q.y - e, x0, x1, y1, z0, z1, kb)) / (2.0 * e);
144
+ float d = curveDist(q, x, slope, max(max(y1, tip) - q.y, q.y - 1.05));
145
+ near = min(near, d);
146
+ float w = 0.003 * mix(1.0, 0.7, fb / 2.0);
147
+ core += bright * exp(-d * d / (w * w));
148
+ halo += bright * (0.7 * exp(-d * 24.0) + 0.25 * exp(-d * 6.0));
149
+ // three branches, leaving the bolt on either side and fading toward their ends
150
+ for (int j = 0; j < 3; j++) {
151
+ float fj = float(j);
152
+ float kj = kb + 3.0 + fj * 5.0;
153
+ float tb = 0.12 + 0.2 * fj + 0.15 * hash(vec2(fj, kj));
154
+ float yb = mix(1.0, y1, tb);
155
+ float len = (0.3 + 0.25 * hash(vec2(fj, kj + 1.0))) * (1.0 - tb) * (1.0 - y1);
156
+ float dir = (j == 1 ? -1.0 : 1.0) * (0.2 + 0.45 * hash(vec2(fj, kj + 2.0))) * min(ratio, 1.0);
157
+ float xb = boltX(yb, x0, x1, y1, z0, z1, kb);
158
+ float zb = zigzag(yb, kj);
159
+ float bx = branchX(q.y, xb, yb, zb, dir, kj);
160
+ float bs = (branchX(q.y + e, xb, yb, zb, dir, kj) - branchX(q.y - e, xb, yb, zb, dir, kj)) / (2.0 * e);
161
+ float bd = curveDist(q, bx, bs, max(max(yb - len, tip) - q.y, q.y - yb));
162
+ near = min(near, bd);
163
+ float along = clamp((yb - q.y) / len, 0.0, 1.0);
164
+ float fade = bright * (1.0 - 0.8 * along);
165
+ float bw = w * mix(0.8, 0.4, along);
166
+ core += fade * exp(-bd * bd / (bw * bw));
167
+ halo += fade * 0.6 * (0.7 * exp(-bd * 24.0) + 0.25 * exp(-bd * 6.0));
168
+ }
169
+ }
170
+ }
171
+
172
+ // the outgoing image gives way to the incoming one at the brightest strobe, hidden by it
173
+ float m = smoothstep(tCut, tCut + 0.025, p);
174
+ vec4 c = vec4(0.0);
175
+ if (m < 1.0) {
176
+ vec4 a = getFromColor(uv);
177
+ c += (1.0 - m) * vec4(a.rgb * a.a, a.a);
178
+ }
179
+ if (m > 0.0) {
180
+ vec4 a = getToColor(uv);
181
+ c += m * vec4(a.rgb * a.a, a.a);
182
+ }
183
+ if (c.a <= 0.0) return vec4(0.0);
184
+ vec3 col = c.rgb / c.a;
185
+
186
+ // the effect fades in at the start and is gone at the end
187
+ float live = smoothstep(0.0, 0.03, p) * (1.0 - smoothstep(0.85, 1.0, p));
188
+ // the sky darkens a little as the storm builds, then the strobes overexpose the image,
189
+ // more around the bolts, and the bolts glow over it
190
+ float dim = 0.4 * smoothstep(0.0, LEADER, p) * (1.0 - smoothstep(tCut, tLast + 0.15, p));
191
+ float f = flash * mix(0.6 + 0.4 * exp(-near * 4.0), 1.0, smoothstep(0.6, 1.0, flash));
192
+ col *= 1.0 - dim * live;
193
+ col = col * (1.0 + 2.5 * f * live) + color * (1.1 * f * live);
194
+ float g = 0.4 + 1.2 * glow;
195
+ vec3 light = mix(color, vec3(1.0), 0.75) * min(core, 1.5) * 1.6 + color * g * halo;
196
+ col += light * boltLight * live;
197
+ col = mix(col, vec3(1.0), 0.92 * whiteout * live);
198
+ return vec4(clamp(col, 0.0, 1.0), c.a);
199
+ }
@@ -0,0 +1,119 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The camera jumps to light speed: star streaks shoot out from the center and stretch longer and longer while the outgoing image is pulled into a radial smear, then after a flash the incoming image emerges from the center as the streaks shrink back
4
+ // Tags: zoom, radial, light, motion-blur, space
5
+
6
+ // @param Point the camera flies toward, from (0, 0) at the bottom left to (1, 1) at the top right
7
+ uniform vec2 center; // = vec2(0.5, 0.5)
8
+ // @range(20, 400) Number of star streaks around the center
9
+ uniform float streaks; // = 160.0
10
+ // @color Color of the streaks and of the flash, added as light
11
+ uniform vec4 streakColor; // = vec4(0.78, 0.88, 1.0, 1.0)
12
+ // @range(0, 1) Length of the streaks and of the radial smear
13
+ uniform float strength; // = 0.6
14
+ // @range(0, 1) Brightness of the flash at the peak of the jump
15
+ uniform float flash; // = 0.5
16
+
17
+ const float PI = 3.141592653589793;
18
+ const int TAPS = 12;
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
+ // one layer of stars: one per angular cell, flying outward and stretched along its ray
27
+ float stars(float a, float r, float n, float layer, float travel, float speed, float reach) {
28
+ float cell = floor(a * n);
29
+ float h1 = hash(vec2(cell, layer));
30
+ float h2 = hash(vec2(cell, layer + 17.0));
31
+ float h3 = hash(vec2(cell, layer + 31.0));
32
+ // where the star is in its flight, from near the center to past the corners,
33
+ // speeding up as it comes closer
34
+ float life = fract(h1 + travel * (0.6 + 0.8 * h2));
35
+ float head = reach * (0.05 + 1.05 * pow(life, 1.4));
36
+ // the streak is the path of the star during the exposure: longer when the camera is faster
37
+ float tail = head * (1.0 - min(0.9, speed * (0.15 + 0.5 * h3)));
38
+ float along = clamp((r - tail) / max(head - tail, 1e-4), 0.0, 1.0);
39
+ float inside = step(tail, r) * (1.0 - smoothstep(head - 0.006, head, r));
40
+ // brightest at the head, fading toward the tail
41
+ float profile = inside * along * along;
42
+ // thin across the ray, a bit wider away from the center, with a faint halo,
43
+ // faded out before the edges of the cell so that no seam shows between cells
44
+ float f = fract(a * n);
45
+ float cellWidth = 2.0 * PI * r / n;
46
+ float offset = 0.3 + 0.4 * h3;
47
+ float across = (f - offset) * cellWidth;
48
+ float width = min(0.0014 + 0.002 * r / reach, 0.15 * cellWidth);
49
+ float x = across * across / (width * width);
50
+ float line = (exp(-x) + 0.25 * exp(-x / 9.0)) * smoothstep(0.0, 0.2, min(f, 1.0 - f));
51
+ // fade in from far away, out past the frame, and only some cells hold a star
52
+ float fade = smoothstep(0.0, 0.2, life) * (1.0 - smoothstep(0.9, 1.0, life));
53
+ return profile * line * fade * (0.4 + 0.6 * h2) * step(0.25, hash(vec2(cell, layer + 43.0)));
54
+ }
55
+
56
+ // an image pulled into a radial smear toward the center: scaled by k, blurred over a fraction b
57
+ vec4 smear(vec2 uv, float k, float b, float jitter, bool incoming) {
58
+ if (b <= 0.0 && k >= 1.0) {
59
+ vec4 c = incoming ? getToColor(uv) : getFromColor(uv);
60
+ return vec4(c.rgb * c.a, c.a);
61
+ }
62
+ vec4 sum = vec4(0.0);
63
+ for (int i = 0; i < TAPS; i++) {
64
+ float s = k * (1.0 - b * (float(i) + jitter) / float(TAPS));
65
+ vec2 q = center + (uv - center) * s;
66
+ vec4 c = incoming ? getToColor(q) : getFromColor(q);
67
+ sum += vec4(c.rgb * c.a, c.a);
68
+ }
69
+ return sum / float(TAPS);
70
+ }
71
+
72
+ vec4 transition(vec2 uv) {
73
+ float p = progress;
74
+ vec2 aspect = vec2(ratio, 1.0);
75
+ vec2 d = (uv - center) * aspect;
76
+ float r = length(d);
77
+ // (nudged off zero, where atan is undefined)
78
+ float a = atan(d.y, d.x + 1e-6) / (2.0 * PI) + 0.5;
79
+ // distance from the center to the farthest corner
80
+ vec2 far = max(center, 1.0 - center) * aspect;
81
+ float reach = length(far);
82
+
83
+ // the camera speeds up to the jump, at the middle, then slows down
84
+ float speed = sin(PI * p);
85
+ speed *= speed;
86
+ float travel = 3.0 * (p - sin(2.0 * PI * p) / (2.0 * PI));
87
+ float jitter = hash(floor(uv * aspect * 997.0));
88
+
89
+ // the outgoing image is pulled forward into the smear; the incoming one arrives
90
+ // magnified and smeared, and settles
91
+ float goOut = smoothstep(0.0, 0.55, p);
92
+ float goIn = 1.0 - smoothstep(0.45, 1.0, p);
93
+ // the incoming image emerges from the center and spreads out to the corners
94
+ float soft = 0.35 * reach;
95
+ float edge = mix(-soft, reach + soft, smoothstep(0.42, 0.78, p));
96
+ float m = 1.0 - smoothstep(edge - soft, edge, r);
97
+ vec4 before = vec4(0.0);
98
+ vec4 after = vec4(0.0);
99
+ if (m < 1.0) before = smear(uv, 1.0 - 0.3 * strength * goOut * goOut, 0.6 * strength * goOut, jitter, false);
100
+ if (m > 0.0) after = smear(uv, 1.0 - 0.3 * strength * goIn * goIn, 0.6 * strength * goIn, jitter, true);
101
+ vec4 c = mix(before, after, m);
102
+ // darker while in the jump, so that the streaks stand out, and brighter soon after it
103
+ // so the incoming image comes out clear
104
+ float dark = p < 0.5 ? speed : speed * speed * speed;
105
+ c.rgb *= 1.0 - 0.65 * (0.5 + 0.5 * strength) * dark;
106
+
107
+ // the streaks: two layers of stars, their length growing with the speed
108
+ float n = max(floor(streaks), 1.0);
109
+ float len = speed * (0.5 + 1.5 * strength);
110
+ float s = stars(a, r, n, 1.0, travel, len, reach);
111
+ s += stars(fract(a + 0.37), r, max(floor(n * 0.71), 1.0), 2.0, travel * 1.3, len, reach);
112
+ // the flash, brightest at the center, where the incoming image emerges
113
+ float core = r / (0.35 * reach);
114
+ float peak = (p - 0.5) * 9.0;
115
+ float glow = flash * exp(-peak * peak) * speed * (0.35 + 0.9 * exp(-core * core));
116
+ vec3 light = streakColor.rgb * streakColor.a * (2.2 * s * speed + glow);
117
+ // light is added to the image, but adds no opacity
118
+ return c.a > 0.0 ? vec4(clamp(c.rgb / c.a + light, 0.0, 1.0), c.a) : vec4(0.0);
119
+ }