gl-transitions 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/compatibility.json +96 -0
  3. package/gl-transitions.js +1 -1
  4. package/gl-transitions.json +1 -1
  5. package/glsl3/CylinderRoll.glsl +102 -0
  6. package/glsl3/LightStreaks.glsl +117 -0
  7. package/glsl3/PixelStretch.glsl +73 -0
  8. package/glsl3/Refraction.glsl +95 -0
  9. package/glsl3/WhipSpin.glsl +69 -0
  10. package/glsl3/WhipTilt.glsl +79 -0
  11. package/index.js +1 -1
  12. package/layouts.json +236 -0
  13. package/llms-full.txt +392 -292
  14. package/llms.txt +160 -154
  15. package/msl/CylinderRoll.metal +374 -0
  16. package/msl/LightStreaks.metal +518 -0
  17. package/msl/PixelStretch.metal +337 -0
  18. package/msl/Refraction.metal +333 -0
  19. package/msl/WhipSpin.metal +278 -0
  20. package/msl/WhipTilt.metal +327 -0
  21. package/package.json +1 -1
  22. package/skills/gl-transitions/references/catalog.md +24 -12
  23. package/sksl/CylinderRoll.sksl +112 -0
  24. package/sksl/LightStreaks.sksl +126 -0
  25. package/sksl/PixelStretch.sksl +84 -0
  26. package/sksl/Refraction.sksl +103 -0
  27. package/sksl/WhipSpin.sksl +79 -0
  28. package/sksl/WhipTilt.sksl +90 -0
  29. package/sksl/index.js +1 -1
  30. package/transitions/CylinderRoll.glsl +101 -0
  31. package/transitions/LightStreaks.glsl +116 -0
  32. package/transitions/PixelStretch.glsl +72 -0
  33. package/transitions/Refraction.glsl +94 -0
  34. package/transitions/WhipSpin.glsl +68 -0
  35. package/transitions/WhipTilt.glsl +78 -0
  36. package/wgsl/CylinderRoll.wgsl +330 -0
  37. package/wgsl/LightStreaks.wgsl +460 -0
  38. package/wgsl/PixelStretch.wgsl +298 -0
  39. package/wgsl/Refraction.wgsl +294 -0
  40. package/wgsl/WhipSpin.wgsl +241 -0
  41. package/wgsl/WhipTilt.wgsl +291 -0
@@ -0,0 +1,102 @@
1
+ // CylinderRoll — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/CylinderRoll.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The frame wraps around a drum that rolls up, the outgoing image turning away over its top in a motion blur and the incoming one coming around from below and unrolling flat
5
+ // Tags: 3d, roll, motion-blur, vertical, chromatic
6
+
7
+ // @range(0, 1) How much the frame wraps around the drum
8
+ uniform float curvature; // = 0.8
9
+ // @range(0, 1) Length of the motion blur at full speed
10
+ uniform float blur; // = 0.5
11
+ // @range(0, 1) How much the drum darkens as it turns away
12
+ uniform float shading; // = 0.6
13
+ // @range(0, 1) Amount of RGB split along the roll, growing with speed
14
+ uniform float chroma; // = 0.5
15
+ // @param Roll downward instead, the incoming image coming around from above
16
+ uniform bool downward; // = false
17
+
18
+ const int SAMPLES = 24;
19
+ // the half angle of the drum seen in the frame height, at full curvature
20
+ const float MAX_ANGLE = 1.1;
21
+ // distance from the camera to the drum's axis, in drum radii
22
+ const float DIST = 2.6;
23
+ // how much the horizontal lines arc away from the middle, per frame height squared
24
+ const float ARC = 0.12;
25
+
26
+ float hash(vec2 c) {
27
+ vec2 q = fract(c * vec2(0.1031, 0.1030));
28
+ q += dot(q, q.yx + 33.33);
29
+ return fract((q.x + q.y) * q.x);
30
+ }
31
+
32
+ // mirrored coordinate, folded back into 0..1
33
+ float fold(float v) {
34
+ return 1.0 - abs(1.0 - mod(v, 2.0));
35
+ }
36
+
37
+ // the strip around the drum: the outgoing image, with the incoming one below it (or above)
38
+ vec4 strip(float x, float v) {
39
+ if (downward ? v > 1.0 : v < 0.0) {
40
+ return getToColor(vec2(x, fold(downward ? v - 1.0 : v + 1.0)));
41
+ }
42
+ return getFromColor(vec2(x, fold(v)));
43
+ }
44
+
45
+ // angle on the drum seen at the projected height c (the drum has a radius of 1)
46
+ float angleAt(float c) {
47
+ c = clamp(c, -0.98 / sqrt(DIST * DIST - 1.0), 0.98 / sqrt(DIST * DIST - 1.0));
48
+ return asin(c * DIST / sqrt(1.0 + c * c)) - atan(c);
49
+ }
50
+
51
+ vec4 transition(vec2 uv) {
52
+ float p = progress;
53
+ // ease in, roll fast in the middle, ease out
54
+ float h = 1.0 - abs(2.0 * p - 1.0); // 0 at both ends, 1 in the middle
55
+ float e = 0.5 * h * (0.1 + 0.9 * h * h);
56
+ float roll = p < 0.5 ? e : 1.0 - e;
57
+ // the blur and the RGB split stay low until the peak of the roll
58
+ float h3 = h * h * h;
59
+ float peak = h3 * h3;
60
+
61
+ // the frame wraps around the drum early, and unwraps to flat sooner as the incoming image settles
62
+ float bend = curvature * (p < 0.5 ? h * (2.0 - h) : h * h * (3.0 - 2.0 * h));
63
+ float phi = MAX_ANGLE * bend + 1e-4;
64
+ float arcK = ARC * bend;
65
+ // the height of the frame's edge, projected with perspective
66
+ float edgeY = sin(phi) / (DIST - cos(phi));
67
+
68
+ vec2 n = 2.0 * uv - 1.0;
69
+ // the horizontal lines arc away from the middle, toward the left and right edges
70
+ float xr = n.x * ratio;
71
+ float yn = n.y * (1.0 + arcK * xr * xr);
72
+ float theta = angleAt(yn * edgeY);
73
+ // nearer parts of the drum look wider: the drum is made wide enough to fill the frame's corners
74
+ float thetaCorner = angleAt((1.0 + arcK * ratio * ratio) * edgeY);
75
+ float width = (DIST - 1.0) / (DIST - cos(theta));
76
+ float zoom = (DIST - cos(thetaCorner)) / (DIST - 1.0);
77
+ float x = 0.5 + 0.5 * n.x / (zoom * width);
78
+ // lit from the camera: darker as the surface turns away
79
+ float facing = (DIST * cos(theta) - 1.0)
80
+ / sqrt(1.0 + DIST * DIST - 2.0 * DIST * cos(theta)) ;
81
+ float light = mix(1.0, clamp(facing, 0.0, 1.0), shading);
82
+
83
+ // position on the strip (the frame height when flat), rolling the outgoing image away
84
+ float v = 0.5 * (theta / phi + 1.0) + (downward ? roll : -roll);
85
+ float len = 0.5 * blur * peak;
86
+ float split = chroma * peak;
87
+ float jitter = hash(uv * 1000.0);
88
+ vec3 color = vec3(0.0);
89
+ vec3 weight = vec3(0.0);
90
+ float alpha = 0.0;
91
+ for (int i = 0; i < SAMPLES; i++) {
92
+ float t = (float(i) + jitter) / float(SAMPLES) - 0.5;
93
+ vec4 img = strip(x, v + t * len);
94
+ // the channels weigh the samples differently along the roll: an RGB split
95
+ vec3 w = vec3(max(1.0 - 4.0 * split * t, 0.0), 1.0, max(1.0 + 4.0 * split * t, 0.0));
96
+ color += img.rgb * img.a * w;
97
+ weight += img.a * w;
98
+ alpha += img.a;
99
+ }
100
+ color = color / max(weight, vec3(1e-5));
101
+ return vec4(color * light, alpha / float(SAMPLES));
102
+ }
@@ -0,0 +1,117 @@
1
+ // LightStreaks — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/LightStreaks.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The highlights of the outgoing image flare into long horizontal (or vertical) lens streaks while it smears with motion blur; at the peak the incoming image takes over and its streaks shrink back into its highlights as it sharpens
5
+ // Tags: light, flare, motion-blur, glow
6
+
7
+ // @range(0, 2) Length of the streaks at the peak, in frame widths
8
+ uniform float reach; // = 0.6
9
+ // @range(0, 1) Brightness above which the image flares
10
+ uniform float threshold; // = 0.7
11
+ // @range(0, 4) Brightness of the streaks
12
+ uniform float intensity; // = 1.5
13
+ // @color Tint of the streaks, toward their ends
14
+ uniform vec3 tint; // = vec3(0.45, 0.7, 1.0)
15
+ // @range(0, 0.5) Length of the motion blur at the peak
16
+ uniform float blur; // = 0.1
17
+ // @param Streak and smear vertically instead
18
+ uniform bool vertical; // = false
19
+
20
+ const int BLUR_TAPS = 6;
21
+ // taps on each side of a streak, spaced further and further apart along its falloff
22
+ const int STREAK_TAPS = 11;
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
+ // mirror the coordinates back into the frame
31
+ vec2 mirror(vec2 v) {
32
+ return 1.0 - abs(1.0 - mod(v, 2.0));
33
+ }
34
+
35
+ // the image on screen: the outgoing one, then the incoming one after a short switch
36
+ vec4 frame(vec2 st, float m) {
37
+ if (m <= 0.0) return getFromColor(st);
38
+ if (m >= 1.0) return getToColor(st);
39
+ return mix(getFromColor(st), getToColor(st), m);
40
+ }
41
+
42
+ // the light of a pixel: its color above the threshold
43
+ vec3 glow(vec4 c, float knee) {
44
+ float lum = dot(c.rgb, vec3(0.2126, 0.7152, 0.0722));
45
+ return c.rgb * c.a * smoothstep(knee, knee + 0.2, lum);
46
+ }
47
+
48
+ // one image only, for the blur and streak taps: during the switch, every other tap reads each image
49
+ vec4 light(vec2 st, float m, bool incoming) {
50
+ if (m <= 0.0) return getFromColor(st);
51
+ if (m >= 1.0) return getToColor(st);
52
+ return incoming ? getToColor(st) : getFromColor(st);
53
+ }
54
+
55
+ float lightWeight(float m, bool incoming) {
56
+ if (m <= 0.0 || m >= 1.0) return 1.0;
57
+ return incoming ? 2.0 * m : 2.0 * (1.0 - m);
58
+ }
59
+
60
+ vec4 transition(vec2 uv) {
61
+ float p = progress;
62
+ // eased in on the outgoing side, and quickly out after the switch so the incoming image lands sharp
63
+ float amount = p < 0.5 ? smoothstep(0.0, 0.5, p) : pow(2.0 - 2.0 * p, 3.0);
64
+ float peak = amount * amount * amount;
65
+ float m = smoothstep(0.44, 0.56, p);
66
+ vec2 axis = vertical ? vec2(0.0, 1.0) : vec2(1.0, 0.0);
67
+ // a small shift of the taps, under their spacing, blends their copies into a smooth smear;
68
+ // hashed by integer cell so that every GPU computes the same shift
69
+ float jitter = hash12(floor(uv * vec2(ratio, 1.0) * 997.0)) - 0.5;
70
+
71
+ // the image smears along the streaks (a tent filter)
72
+ float smear = blur * amount;
73
+ vec3 base = vec3(0.0);
74
+ float alpha = 0.0;
75
+ float total = 0.0;
76
+ for (int i = 0; i < BLUR_TAPS; i++) {
77
+ float t = (float(i) + 0.5 + jitter) / float(BLUR_TAPS) - 0.5;
78
+ float w = 1.0 - abs(t);
79
+ total += w;
80
+ bool incoming = mod(float(i), 2.0) > 0.5;
81
+ w *= lightWeight(m, incoming);
82
+ vec4 c = light(mirror(uv + axis * t * smear), m, incoming);
83
+ base += w * c.rgb * c.a;
84
+ alpha += w * c.a;
85
+ }
86
+ base /= total;
87
+ alpha /= total;
88
+
89
+ // the streaks: the light above the threshold, spread along the axis with an exponential falloff
90
+ float falloff = 0.25 * reach * amount;
91
+ float knee = mix(threshold, 0.8 * threshold, peak);
92
+ vec3 streak = glow(frame(uv, m), knee);
93
+ float weights = 1.0;
94
+ for (int k = 1; k <= STREAK_TAPS; k++) {
95
+ // the distance in units of the falloff, and the stretch of the streak this tap stands for
96
+ float d = exp(0.14 * (float(k) + 0.8 * jitter)) - 1.0;
97
+ float span = 0.14 * (d + 1.0);
98
+ // white at the source, tinted along the streak, red fading first so the tails turn blue and violet
99
+ vec3 hue = mix(vec3(1.0), tint, smoothstep(0.0, 0.8, d));
100
+ hue *= exp(-d * vec3(0.6, 0.2, -0.15));
101
+ float w = exp(-d) * span * 4.0;
102
+ bool incoming = mod(float(k), 2.0) > 0.5;
103
+ vec4 ahead = light(mirror(uv + axis * d * falloff), m, incoming);
104
+ vec4 behind = light(mirror(uv - axis * d * falloff), m, !incoming);
105
+ streak += w * hue * (glow(ahead, knee) * lightWeight(m, incoming) + glow(behind, knee) * lightWeight(m, !incoming));
106
+ weights += 2.0 * w;
107
+ }
108
+ streak *= intensity * amount * (0.6 + 2.4 * peak) * 2.0 / weights;
109
+ // compressed, so that bright skies never flatten into white
110
+ streak = 0.85 * (1.0 - exp(-streak));
111
+
112
+ // a lift of the exposure at the peak, then the streaks screened on top (premultiplied colors)
113
+ base = min(base * (1.0 + 0.2 * peak), vec3(alpha));
114
+ vec3 color = base + streak - base * streak;
115
+ float a = alpha + max(streak.r, max(streak.g, streak.b)) * (1.0 - alpha);
116
+ return vec4(clamp(color / max(a, 1e-5), 0.0, 1.0), a);
117
+ }
@@ -0,0 +1,73 @@
1
+ // PixelStretch — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/PixelStretch.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: A line sweeps across the frame and drags the outgoing image's pixels behind it as long streaks, which shorten as it goes and reveal the incoming image
5
+ // Tags: smear, streaks, directional, chromatic
6
+
7
+ // @param Direction in which the line sweeps
8
+ uniform vec2 direction; // = vec2(1.0, 0.0)
9
+ // @range(0, 1) Length of the streaks at the middle of the sweep, as a part of the frame
10
+ uniform float stretch; // = 0.45
11
+ // @range(0, 1) Amount of RGB split along the streaks
12
+ uniform float chroma; // = 0.5
13
+ // @range(0, 0.2) Softness of the line and of the streaks' ends, as a part of the frame
14
+ uniform float softness; // = 0.03
15
+ // @range(0, 1) How much the streaks jitter, each row at its own length
16
+ uniform float jitter; // = 0.5
17
+
18
+ float hash(float n) {
19
+ n = fract(n * 0.1031);
20
+ n *= n + 33.33;
21
+ n *= n + n;
22
+ return fract(n);
23
+ }
24
+
25
+ // smooth max with a compact support: exactly max(x, y) when they are k apart
26
+ float smax(float x, float y, float k) {
27
+ float h = max(k - abs(x - y), 0.0) / k;
28
+ return max(x, y) + h * h * k * 0.25;
29
+ }
30
+
31
+ // position s along the sweep (0 to 1 across the frame) to a frame coordinate
32
+ vec2 at(vec2 uv, float s0, float s, vec2 d, float ext) {
33
+ return clamp(uv + d * (s - s0) * ext, 0.0, 1.0);
34
+ }
35
+
36
+ vec4 transition(vec2 uv) {
37
+ vec2 d = normalize(direction + vec2(1e-6, 0.0));
38
+ // ext: length of the frame along the sweep, in uv units
39
+ float ext = abs(d.x) + abs(d.y);
40
+ float s = 0.5 + dot(uv - 0.5, d) / ext;
41
+ // rows across the streaks (about one per pixel line), in frame heights
42
+ vec2 n = vec2(-d.y, d.x);
43
+ float t = dot((uv - 0.5) * vec2(ratio, 1.0), n);
44
+ float row = floor(t * 540.0);
45
+ float clump = floor(t * 60.0);
46
+ float rnd = 0.6 * hash(row + 17.0) + 0.4 * hash(clump + 311.0);
47
+
48
+ float p = progress;
49
+ float k = softness + 1e-4;
50
+ // the line starts and ends at rest just beyond the frame, past its soft edge, so both ends are exact;
51
+ // it enters at once and slows down a little toward the end
52
+ float margin = k + 0.002;
53
+ float a = mix(-margin, 1.0 + margin, mix(p, p * p * (3.0 - 2.0 * p), 0.5));
54
+
55
+ // the streaks are longest when the line crosses the middle and vanish as it reaches the edges,
56
+ // so they never repeat the frame's own border (often dark, or letterboxing)
57
+ float h = clamp(4.0 * a * (1.0 - a), 0.0, 1.0);
58
+ float len = stretch * h * (1.0 - 0.6 * jitter * rnd);
59
+ float split = 0.02 * chroma * h;
60
+
61
+ // ahead of the line the outgoing image is intact; behind it, each pixel repeats the pixel at the line
62
+ vec4 fr = getFromColor(at(uv, s, smax(s, a + split, k), d, ext));
63
+ vec4 fg = getFromColor(at(uv, s, smax(s, a, k), d, ext));
64
+ vec4 fb = getFromColor(at(uv, s, smax(s, a - split, k), d, ext));
65
+ vec4 streak = vec4(fr.r, fg.g, fb.b, fg.a);
66
+ // a faint flicker along the streaks
67
+ float behind = step(s, a);
68
+ streak.rgb *= 1.0 + 0.06 * jitter * h * (hash(row * 3.0 + 5.0) - 0.5) * behind;
69
+
70
+ // past the end of its streak, each row shows the incoming image as it is
71
+ float w = smoothstep(len - k, len + k, a - s);
72
+ return mix(streak, getToColor(uv), w);
73
+ }
@@ -0,0 +1,95 @@
1
+ // Refraction — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/Refraction.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The frame is seen through flowing liquid glass that bends the outgoing image more and more, with rainbow fringes, flares up as the incoming image takes over, then calms down and clears
5
+ // Tags: distortion, refraction, chromatic-aberration, glow
6
+
7
+ // @range(0, 0.3) How far the glass bends the image at the peak
8
+ uniform float strength; // = 0.15
9
+ // @range(0.5, 8) Size of the flowing waves: higher makes smaller waves
10
+ uniform float scale; // = 2.5
11
+ // @range(0, 1) Spread of the rainbow fringes
12
+ uniform float dispersion; // = 0.5
13
+ // @range(0, 3) Brightness of the flare at the peak
14
+ uniform float brightness; // = 1.0
15
+
16
+ // the wavelengths sampled from red to violet
17
+ const int TAPS = 7;
18
+
19
+ // the glass surface: smooth waves of a few sizes, warped into each other and flowing over time
20
+ float surface(vec2 q, float t) {
21
+ q += 0.45 * vec2(sin(1.3 * q.y + 0.9 * t), sin(1.1 * q.x - 1.2 * t));
22
+ float h = sin(q.x + 0.6 * t) * sin(1.2 * q.y - 0.8 * t);
23
+ h += 0.5 * sin(dot(q, vec2(1.6, -1.2)) + 1.4 * t);
24
+ h += 0.3 * sin(dot(q, vec2(-1.1, 2.9)) - 1.9 * t + 1.7 * sin(0.9 * q.x));
25
+ h += 0.15 * sin(dot(q, vec2(4.3, 3.1)) + 2.6 * t);
26
+ return h;
27
+ }
28
+
29
+ // a hash without sin, to jitter the wavelengths from pixel to pixel
30
+ float hash12(vec2 v) {
31
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
32
+ v3 += dot(v3, v3.yzx + 33.33);
33
+ return fract((v3.x + v3.y) * v3.z);
34
+ }
35
+
36
+ // mirror the coordinates back into the frame
37
+ vec2 mirror(vec2 v) {
38
+ return 1.0 - abs(1.0 - mod(v, 2.0));
39
+ }
40
+
41
+ // rough spectral response of a wavelength w (0 = red, 1 = violet), in RGB
42
+ vec3 spectrum(float w) {
43
+ vec3 c = vec3(
44
+ 1.0 - smoothstep(0.0, 0.55, w) + 0.35 * smoothstep(0.75, 1.0, w),
45
+ 1.0 - abs(2.0 * w - 1.0) * 1.2,
46
+ smoothstep(0.45, 1.0, w)
47
+ );
48
+ return clamp(c, 0.0, 1.0);
49
+ }
50
+
51
+ vec4 transition(vec2 uv) {
52
+ float p = progress;
53
+ // 0 at both ends, 1 in the middle: the glass builds up slowly, then calms down
54
+ float h = 1.0 - abs(2.0 * p - 1.0);
55
+ float amount = h * h * (2.0 - h);
56
+
57
+ // the glass refracts along the slope of its surface
58
+ vec2 q = (uv - 0.5) * vec2(ratio, 1.0) * scale;
59
+ float t = 3.0 * p;
60
+ float e = 0.01;
61
+ vec2 slope = vec2(
62
+ surface(q + vec2(e, 0.0), t) - surface(q - vec2(e, 0.0), t),
63
+ surface(q + vec2(0.0, e), t) - surface(q - vec2(0.0, e), t)
64
+ ) / (2.0 * e);
65
+ vec2 offset = slope * strength * amount / scale;
66
+ // the switch to the incoming image, around the peak: it appears through the glass's waves,
67
+ // the crests first, then the troughs
68
+ float wave = clamp(0.5 * surface(q, t), -1.0, 1.0);
69
+ float m = smoothstep(-0.015, 0.015, p - 0.5 + 0.1 * wave);
70
+
71
+ // each wavelength bends a little differently: red the least, violet the most
72
+ vec3 color = vec3(0.0);
73
+ vec3 weights = vec3(0.0);
74
+ float alpha = 0.0;
75
+ // jittered wavelengths blend the fringes into a continuous rainbow
76
+ float jitter = hash12(uv * vec2(ratio, 1.0) * 1000.0) - 0.5;
77
+ for (int i = 0; i < TAPS; i++) {
78
+ float w = float(i) / float(TAPS - 1);
79
+ float wj = (float(i) + jitter) / float(TAPS - 1);
80
+ vec2 st = mirror(uv + offset * (1.0 + dispersion * (wj - 0.5) * 1.6));
81
+ vec4 c = mix(getFromColor(st), getToColor(st), m);
82
+ vec3 s = spectrum(w);
83
+ color += s * c.rgb * c.a;
84
+ weights += s;
85
+ alpha += c.a;
86
+ }
87
+ alpha /= float(TAPS);
88
+ color = color / weights / max(alpha, 1e-5);
89
+
90
+ // a flare at the peak: the image is pushed toward an overexposed white
91
+ float flare = 2.0 * brightness * pow(h, 8.0);
92
+ color = color * (1.0 + flare) / (1.0 + flare * color);
93
+ color += 0.1 * flare * dot(color, vec3(0.3333));
94
+ return vec4(clamp(color, 0.0, 1.0), alpha);
95
+ }
@@ -0,0 +1,69 @@
1
+ // WhipSpin — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/WhipSpin.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The camera rolls faster and faster around the center of the frame, streaking the outgoing image in a spin blur, then the incoming one takes over mid-spin and slows to a stop
5
+ // Tags: rotate, motion-blur, spin
6
+
7
+ // @range(-3, 3) Total rotation, in turns, split between the two images (negative turns clockwise)
8
+ uniform float turns; // = 1.0
9
+ // @range(0, 1) Length of the motion blur along the spin
10
+ uniform float blur; // = 0.5
11
+ // @range(0, 1) How much the color channels split apart as the spin speeds up
12
+ uniform float chroma; // = 0.6
13
+ // @range(0, 1) How much the camera zooms in at the fastest point
14
+ uniform float zoom; // = 0.25
15
+
16
+ const float PI = 3.141592653589793;
17
+ const int SAMPLES = 24;
18
+
19
+ float hash(vec2 p) {
20
+ vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
21
+ p3 += dot(p3, p3.yzx + 33.33);
22
+ return fract((p3.x + p3.y) * p3.z);
23
+ }
24
+
25
+ // fold the coordinates back into the image so that the rotated frame stays filled
26
+ vec2 mirror(vec2 v) {
27
+ vec2 m = mod(v, 2.0);
28
+ return mix(m, 2.0 - m, step(1.0, m));
29
+ }
30
+
31
+ // the camera's roll angle at time t: the outgoing image speeds up until the middle,
32
+ // then the incoming one, already turning, slows down to rest
33
+ float rollAngle(float t) {
34
+ float halfTurn = PI * turns;
35
+ if (t < 0.5) {
36
+ float x = 2.0 * t;
37
+ return halfTurn * x * x * x;
38
+ }
39
+ float x = 2.0 - 2.0 * t;
40
+ return -halfTurn * x * x * x;
41
+ }
42
+
43
+ vec4 transition(vec2 uv) {
44
+ float p = progress;
45
+ float h = 1.0 - abs(2.0 * p - 1.0); // 0 at both ends, 1 at the cut
46
+ // the shutter is open longer as the spin speeds up, and closed at both ends
47
+ float shutter = blur * 0.1 * h;
48
+ float scale = 1.0 + zoom * h * h * h;
49
+ vec2 q = (uv - 0.5) * vec2(ratio, 1.0);
50
+ float jitter = hash(uv * vec2(ratio, 1.0) * 731.0);
51
+ vec3 color = vec3(0.0);
52
+ vec3 weight = vec3(0.0);
53
+ float alpha = 0.0;
54
+ for (int i = 0; i < SAMPLES; i++) {
55
+ float s = (float(i) + jitter) / float(SAMPLES) - 0.5;
56
+ float t = clamp(p + s * shutter, 0.0, 1.0);
57
+ float a = rollAngle(t);
58
+ float c = cos(a), sn = sin(a);
59
+ vec2 r = vec2(c * q.x + sn * q.y, -sn * q.x + c * q.y) / scale;
60
+ vec2 suv = mirror(r / vec2(ratio, 1.0) + 0.5);
61
+ vec4 col = t < 0.5 ? getFromColor(suv) : getToColor(suv);
62
+ // red trails behind and blue leads along the arc: the channels split with the speed
63
+ vec3 w = max(vec3(1.0 - 4.0 * chroma * s, 1.0, 1.0 + 4.0 * chroma * s), 0.0);
64
+ color += col.rgb * col.a * w;
65
+ weight += col.a * w;
66
+ alpha += col.a;
67
+ }
68
+ return vec4(color / max(weight, vec3(1e-5)), alpha / float(SAMPLES));
69
+ }
@@ -0,0 +1,79 @@
1
+ // WhipTilt — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/WhipTilt.glsl
2
+ // Author: gre
3
+ // License: MIT
4
+ // Description: The camera tilts fast from the outgoing image to the incoming one, set edge to edge at an angle above it, streaking both in perspective with a vertical motion blur
5
+ // Tags: 3d, rotate, motion-blur, vertical
6
+
7
+ // @param Tilt the camera down to an incoming image below instead of above
8
+ uniform bool down; // = false
9
+ // @range(0, 1) Length of the motion blur along the tilt
10
+ uniform float blur; // = 0.5
11
+ // @range(0, 1) How much the color channels split apart as the tilt speeds up
12
+ uniform float chroma; // = 0.5
13
+ // @range(0, 1) Strength of the perspective (field of view of the camera)
14
+ uniform float perspective; // = 0.7
15
+
16
+ const float PI = 3.141592653589793;
17
+ const int SAMPLES = 24;
18
+
19
+ float hash(vec2 p) {
20
+ vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
21
+ p3 += dot(p3, p3.yzx + 33.33);
22
+ return fract((p3.x + p3.y) * p3.z);
23
+ }
24
+
25
+ // fold the coordinates back into the image, only a safety at the far edges
26
+ vec2 mirror(vec2 v) {
27
+ vec2 m = mod(v, 2.0);
28
+ return mix(m, 2.0 - m, step(1.0, m));
29
+ }
30
+
31
+ // how far the camera has tilted at time t, from 0 to 1: slow start, whip in the middle, slow landing
32
+ float tilt(float t) {
33
+ float h = 1.0 - abs(2.0 * t - 1.0);
34
+ float e = 0.5 * h * h * h * h;
35
+ return t < 0.5 ? e : 1.0 - e;
36
+ }
37
+
38
+ vec4 transition(vec2 uv) {
39
+ float p = progress;
40
+ float h = 1.0 - abs(2.0 * p - 1.0); // 0 at both ends, 1 in the middle
41
+ // the shutter is open longer as the tilt speeds up, and closed at both ends
42
+ float shutter = blur * 0.25 * h * h;
43
+ // the images are two faces of a drum around the camera, each filling the frame from the
44
+ // middle: they meet edge to edge at the angle of the field of view, which the camera turns by
45
+ float halfFov = mix(15.0, 45.0, perspective) * PI / 180.0;
46
+ float dist = 0.5 / tan(halfFov);
47
+ vec2 q = (uv - 0.5) * vec2(ratio, 1.0);
48
+ if (down) q.y = -q.y;
49
+ float jitter = hash(uv * vec2(ratio, 1.0) * 731.0);
50
+ vec3 color = vec3(0.0);
51
+ vec3 weight = vec3(0.0);
52
+ float alpha = 0.0;
53
+ for (int i = 0; i < SAMPLES; i++) {
54
+ float s = (float(i) + jitter) / float(SAMPLES) - 0.5;
55
+ float t = clamp(p + s * shutter, 0.0, 1.0);
56
+ float a = 2.0 * halfFov * tilt(t);
57
+ // zoom in just enough that the faces always cover the frame, wherever their edge is
58
+ vec2 r = q * cos(halfFov) / cos(halfFov - a);
59
+ // the ray in the frame of the outgoing face, then of the incoming one
60
+ float c0 = cos(a), s0 = sin(a);
61
+ vec2 d0 = vec2(r.y * c0 + dist * s0, dist * c0 - r.y * s0);
62
+ float b = a - 2.0 * halfFov;
63
+ float c1 = cos(b), s1 = sin(b);
64
+ vec2 d1 = vec2(r.y * c1 + dist * s1, dist * c1 - r.y * s1);
65
+ // the ray leaves the drum through the nearest face
66
+ bool incoming = d1.y > d0.y;
67
+ vec2 d = incoming ? d1 : d0;
68
+ vec2 hit = dist / d.y * vec2(r.x, d.x);
69
+ if (down) hit.y = -hit.y;
70
+ vec2 suv = mirror(hit / vec2(ratio, 1.0) + 0.5);
71
+ vec4 col = incoming ? getToColor(suv) : getFromColor(suv);
72
+ // red trails behind and blue leads along the motion: the channels split with the speed
73
+ vec3 w = max(vec3(1.0 - 4.0 * chroma * s, 1.0, 1.0 + 4.0 * chroma * s), 0.0);
74
+ color += col.rgb * col.a * w;
75
+ weight += col.a * w;
76
+ alpha += col.a;
77
+ }
78
+ return vec4(color / max(weight, vec3(1e-5)), alpha / float(SAMPLES));
79
+ }