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