gl-transitions 2.2.0 → 2.3.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 (136) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/compatibility.json +400 -0
  3. package/gl-transitions.js +1 -1
  4. package/gl-transitions.json +1 -1
  5. package/glsl3/Accordion.glsl +85 -0
  6. package/glsl3/Ascii.glsl +124 -0
  7. package/glsl3/BlockCover.glsl +87 -0
  8. package/glsl3/BloomDissolve.glsl +110 -0
  9. package/glsl3/BokehDissolve.glsl +123 -0
  10. package/glsl3/BrushWipe.glsl +100 -0
  11. package/glsl3/CameraShake.glsl +98 -0
  12. package/glsl3/CardSwipe.glsl +81 -0
  13. package/glsl3/CurvedWipe.glsl +52 -0
  14. package/glsl3/Disintegrate.glsl +112 -0
  15. package/glsl3/FilmDissolve.glsl +49 -0
  16. package/glsl3/FilmStrip.glsl +105 -0
  17. package/glsl3/FlameWipe.glsl +154 -0
  18. package/glsl3/GooeyWipe.glsl +97 -0
  19. package/glsl3/InkBleed.glsl +96 -0
  20. package/glsl3/LensFlare.glsl +125 -0
  21. package/glsl3/LightRays.glsl +106 -0
  22. package/glsl3/LightWipe.glsl +89 -0
  23. package/glsl3/PhotoDevelop.glsl +59 -0
  24. package/glsl3/PlusWipe.glsl +38 -0
  25. package/glsl3/PopIn.glsl +57 -0
  26. package/glsl3/SmokeDissolve.glsl +102 -0
  27. package/glsl3/SplatterWipe.glsl +154 -0
  28. package/glsl3/StretchSlide.glsl +62 -0
  29. package/glsl3/WedgeWipe.glsl +35 -0
  30. package/index.js +1 -1
  31. package/layouts.json +945 -40
  32. package/llms-full.txt +705 -304
  33. package/llms.txt +185 -160
  34. package/msl/Accordion.metal +421 -0
  35. package/msl/Ascii.metal +567 -0
  36. package/msl/BlockCover.metal +403 -0
  37. package/msl/BloomDissolve.metal +416 -0
  38. package/msl/BokehDissolve.metal +447 -0
  39. package/msl/BrushWipe.metal +488 -0
  40. package/msl/CameraShake.metal +393 -0
  41. package/msl/CardSwipe.metal +342 -0
  42. package/msl/CurvedWipe.metal +229 -0
  43. package/msl/Disintegrate.metal +468 -0
  44. package/msl/FilmDissolve.metal +199 -0
  45. package/msl/FilmStrip.metal +429 -0
  46. package/msl/FlameWipe.metal +575 -0
  47. package/msl/GooeyWipe.metal +398 -0
  48. package/msl/InkBleed.metal +409 -0
  49. package/msl/LensFlare.metal +455 -0
  50. package/msl/LightRays.metal +427 -0
  51. package/msl/LightWipe.metal +321 -0
  52. package/msl/PhotoDevelop.metal +245 -0
  53. package/msl/PlusWipe.metal +199 -0
  54. package/msl/PopIn.metal +245 -0
  55. package/msl/SmokeDissolve.metal +400 -0
  56. package/msl/SplatterWipe.metal +677 -0
  57. package/msl/StretchSlide.metal +243 -0
  58. package/msl/WedgeWipe.metal +154 -0
  59. package/package.json +1 -1
  60. package/skills/gl-transitions/references/catalog.md +100 -36
  61. package/sksl/Accordion.sksl +94 -0
  62. package/sksl/Ascii.sksl +131 -0
  63. package/sksl/BlockCover.sksl +96 -0
  64. package/sksl/BloomDissolve.sksl +119 -0
  65. package/sksl/BokehDissolve.sksl +132 -0
  66. package/sksl/BrushWipe.sksl +109 -0
  67. package/sksl/CameraShake.sksl +108 -0
  68. package/sksl/CardSwipe.sksl +93 -0
  69. package/sksl/CurvedWipe.sksl +64 -0
  70. package/sksl/Disintegrate.sksl +117 -0
  71. package/sksl/FilmDissolve.sksl +60 -0
  72. package/sksl/FilmStrip.sksl +114 -0
  73. package/sksl/FlameWipe.sksl +162 -0
  74. package/sksl/GooeyWipe.sksl +109 -0
  75. package/sksl/InkBleed.sksl +109 -0
  76. package/sksl/LensFlare.sksl +135 -0
  77. package/sksl/LightRays.sksl +115 -0
  78. package/sksl/LightWipe.sksl +97 -0
  79. package/sksl/PhotoDevelop.sksl +72 -0
  80. package/sksl/PlusWipe.sksl +50 -0
  81. package/sksl/PopIn.sksl +69 -0
  82. package/sksl/SmokeDissolve.sksl +115 -0
  83. package/sksl/SplatterWipe.sksl +161 -0
  84. package/sksl/StretchSlide.sksl +74 -0
  85. package/sksl/WedgeWipe.sksl +46 -0
  86. package/sksl/index.js +1 -1
  87. package/transitions/Accordion.glsl +84 -0
  88. package/transitions/Ascii.glsl +123 -0
  89. package/transitions/BlockCover.glsl +86 -0
  90. package/transitions/BloomDissolve.glsl +109 -0
  91. package/transitions/BokehDissolve.glsl +122 -0
  92. package/transitions/BrushWipe.glsl +99 -0
  93. package/transitions/CameraShake.glsl +97 -0
  94. package/transitions/CardSwipe.glsl +80 -0
  95. package/transitions/CurvedWipe.glsl +51 -0
  96. package/transitions/Disintegrate.glsl +111 -0
  97. package/transitions/FilmDissolve.glsl +48 -0
  98. package/transitions/FilmStrip.glsl +104 -0
  99. package/transitions/FlameWipe.glsl +153 -0
  100. package/transitions/GooeyWipe.glsl +96 -0
  101. package/transitions/InkBleed.glsl +95 -0
  102. package/transitions/LensFlare.glsl +124 -0
  103. package/transitions/LightRays.glsl +105 -0
  104. package/transitions/LightWipe.glsl +88 -0
  105. package/transitions/PhotoDevelop.glsl +58 -0
  106. package/transitions/PlusWipe.glsl +37 -0
  107. package/transitions/PopIn.glsl +56 -0
  108. package/transitions/SmokeDissolve.glsl +101 -0
  109. package/transitions/SplatterWipe.glsl +153 -0
  110. package/transitions/StretchSlide.glsl +61 -0
  111. package/transitions/WedgeWipe.glsl +34 -0
  112. package/wgsl/Accordion.wgsl +376 -0
  113. package/wgsl/Ascii.wgsl +519 -0
  114. package/wgsl/BlockCover.wgsl +352 -0
  115. package/wgsl/BloomDissolve.wgsl +372 -0
  116. package/wgsl/BokehDissolve.wgsl +409 -0
  117. package/wgsl/BrushWipe.wgsl +443 -0
  118. package/wgsl/CameraShake.wgsl +348 -0
  119. package/wgsl/CardSwipe.wgsl +308 -0
  120. package/wgsl/CurvedWipe.wgsl +198 -0
  121. package/wgsl/Disintegrate.wgsl +426 -0
  122. package/wgsl/FilmDissolve.wgsl +169 -0
  123. package/wgsl/FilmStrip.wgsl +381 -0
  124. package/wgsl/FlameWipe.wgsl +531 -0
  125. package/wgsl/GooeyWipe.wgsl +353 -0
  126. package/wgsl/InkBleed.wgsl +366 -0
  127. package/wgsl/LensFlare.wgsl +406 -0
  128. package/wgsl/LightRays.wgsl +380 -0
  129. package/wgsl/LightWipe.wgsl +277 -0
  130. package/wgsl/PhotoDevelop.wgsl +213 -0
  131. package/wgsl/PlusWipe.wgsl +165 -0
  132. package/wgsl/PopIn.wgsl +213 -0
  133. package/wgsl/SmokeDissolve.wgsl +363 -0
  134. package/wgsl/SplatterWipe.wgsl +613 -0
  135. package/wgsl/StretchSlide.wgsl +213 -0
  136. package/wgsl/WedgeWipe.wgsl +126 -0
@@ -0,0 +1,97 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The camera jolts violently in random directions, with motion blur and color fringes along each jolt; the cut happens at the peak of the shake, which then settles on the incoming image
4
+ // Tags: shake, camera, motion-blur, chromatic, impact
5
+
6
+ // @range(0, 1) How far the camera jolts (and rolls) at the peak of the shake
7
+ uniform float strength; // = 0.5
8
+ // @range(4, 32) Number of jolts over the transition
9
+ uniform float jolts; // = 12.0
10
+ // @range(0, 1) Length of the motion blur along each jolt
11
+ uniform float blur; // = 0.5
12
+ // @range(0, 1) How far the color channels split apart along each jolt
13
+ uniform float split; // = 0.5
14
+
15
+ const int TAPS = 10;
16
+
17
+ float hash12(vec2 v) {
18
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
19
+ v3 += dot(v3, v3.yzx + 33.33);
20
+ return fract((v3.x + v3.y) * v3.z);
21
+ }
22
+
23
+ vec2 mirror(vec2 v) {
24
+ return 1.0 - abs(1.0 - mod(v, 2.0));
25
+ }
26
+
27
+ // the camera position at jolt key k: offset (x, y) and roll, each in -1..1
28
+ vec3 jolt(float k) {
29
+ // successive jolts go in nearly opposite directions
30
+ float a = 2.4 * k + 1.2 * hash12(vec2(k, 11.0));
31
+ float m = 0.55 + 0.45 * hash12(vec2(k, 23.0));
32
+ return vec3(m * cos(a), m * sin(a), 2.0 * hash12(vec2(k, 37.0)) - 1.0);
33
+ }
34
+
35
+ // how strong the shake is at time t: it builds up quickly, peaks around the cut, then settles
36
+ float envelope(float t) {
37
+ float h = clamp(1.6 * (1.0 - abs(2.0 * t - 1.0)), 0.0, 1.0);
38
+ return h * h * (3.0 - 2.0 * h);
39
+ }
40
+
41
+ // the image seen by the camera at time t (in progress units), premultiplied
42
+ vec4 shot(vec2 uv, float t, bool incoming) {
43
+ float env = envelope(t);
44
+ // a key every 1/jolts, one of them exactly at the cut
45
+ float s = (t - 0.5) * jolts;
46
+ float k = floor(s);
47
+ float g = 1.0 - (s - k);
48
+ float e = 1.0 - g * g * g; // snaps to the next key, then holds
49
+ vec3 j = mix(jolt(k), jolt(k + 1.0), e) * env;
50
+ float omax = 0.14 * strength * env;
51
+ float rmax = 0.07 * strength * env;
52
+ vec2 off = j.xy * omax;
53
+ float roll = j.z * rmax;
54
+ // zoom in just enough that the frame edges never show, for any offset and roll up to these
55
+ float zoom = (cos(rmax) + sin(rmax) * max(ratio, 1.0 / ratio)) / (1.0 - 2.0 * omax);
56
+ vec2 q = (uv - 0.5) * vec2(ratio, 1.0);
57
+ q = mat2(cos(roll), sin(roll), -sin(roll), cos(roll)) * q / zoom;
58
+ vec2 p = mirror(q / vec2(ratio, 1.0) + 0.5 + off);
59
+ vec4 c = incoming ? getToColor(p) : getFromColor(p);
60
+ return vec4(c.rgb * c.a, c.a);
61
+ }
62
+
63
+ vec4 transition(vec2 uv) {
64
+ // the exposure follows the shake: no blur at the very ends
65
+ float open = envelope(progress);
66
+ float shutter = 0.8 * blur / jolts * open;
67
+ float lag = 0.2 * split / jolts * open;
68
+ // each channel, premultiplied, and its alpha
69
+ vec2 sumR = vec2(0.0);
70
+ vec2 sumG = vec2(0.0);
71
+ vec2 sumB = vec2(0.0);
72
+ float wsum = 0.0;
73
+ for (int i = 0; i < TAPS; i++) {
74
+ float u = (float(i) + 0.5) / float(TAPS) - 0.5;
75
+ float t = progress + u * shutter;
76
+ // the trails fade out at both ends of the exposure
77
+ float w = 1.0 - 1.4 * abs(u);
78
+ // the cut happens during the exposure: the channels of a tap show the same image
79
+ bool incoming = t >= 0.5;
80
+ // red leads and blue trails the motion, so they split by the speed of the jolt
81
+ vec4 r = shot(uv, t + lag, incoming);
82
+ vec4 c = shot(uv, t, incoming);
83
+ vec4 b = shot(uv, t - lag, incoming);
84
+ sumR += w * r.ra;
85
+ sumG += w * c.ga;
86
+ sumB += w * b.ba;
87
+ wsum += w;
88
+ }
89
+ float alpha = (sumR.y + sumG.y + sumB.y) / (3.0 * wsum);
90
+ if (alpha <= 0.0) return vec4(0.0);
91
+ vec3 color = vec3(
92
+ sumR.x / max(sumR.y, 1e-5),
93
+ sumG.x / max(sumG.y, 1e-5),
94
+ sumB.x / max(sumB.y, 1e-5)
95
+ );
96
+ return vec4(color, alpha);
97
+ }
@@ -0,0 +1,80 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image is flicked off like the top card of a stack, swinging around a point below it as it flies out, while the incoming card behind it grows to fill the frame
4
+ // Tags: card, swipe, stack, rotate, slide, directional
5
+
6
+ // @param Direction in which the outgoing card is flicked
7
+ uniform vec2 direction; // = vec2(1.0, 0.25)
8
+ // @range(0, 1) How much the outgoing card swings as it flies out
9
+ uniform float rotation; // = 0.5
10
+ // @range(0, 0.5) How much smaller the incoming card starts
11
+ uniform float depth; // = 0.15
12
+ // @color Color seen around the incoming card while it is smaller than the frame
13
+ uniform vec4 backColor; // = vec4(0.06, 0.06, 0.07, 1.0)
14
+
15
+ const float RADIUS = 0.045; // corner radius of the cards, in frame heights
16
+ const float AA = 0.002; // width of the antialiased card edges
17
+
18
+ // signed distance to a rounded box of half size b and corner radius r
19
+ float roundedBox(vec2 q, vec2 b, float r) {
20
+ vec2 d = abs(q) - b + r;
21
+ return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r;
22
+ }
23
+
24
+ vec4 premultiply(vec4 c) {
25
+ return vec4(c.rgb * c.a, c.a);
26
+ }
27
+
28
+ vec4 transition(vec2 uv) {
29
+ float dl = length(direction);
30
+ vec2 d = dl > 1e-6 ? direction / dl : vec2(0.970143, 0.242536);
31
+ vec2 q = (uv - 0.5) * vec2(ratio, 1.0);
32
+ vec2 b = vec2(0.5 * ratio, 0.5);
33
+ float p = progress;
34
+
35
+ // the incoming card, behind: grows from a smaller card to the full frame,
36
+ // and its corners straighten as it fills it
37
+ float h = clamp((p - 0.2) / 0.8, 0.0, 1.0);
38
+ float g = h * h * (3.0 - 2.0 * h);
39
+ float k = 1.0 - g;
40
+ float sc = 1.0 - depth * k;
41
+ float rb = RADIUS * min(1.0, 12.0 * k);
42
+ float db = roundedBox(q, b * sc, rb);
43
+ float cb = clamp(0.5 - db / max(AA * min(1.0, 40.0 * k), 1e-6), 0.0, 1.0);
44
+ vec4 tc = getToColor(clamp(0.5 + (uv - 0.5) / sc, 0.0, 1.0));
45
+ // still in the shade of the top card at first
46
+ tc.rgb *= 1.0 - 0.35 * k * k;
47
+ // the cards are opaque: each one replaces what is behind it, keeping its image's alpha
48
+ vec4 col = mix(premultiply(backColor), premultiply(tc), cb);
49
+
50
+ // the outgoing card, on top: swings around a point below it as it is flicked away
51
+ float t = clamp(p / 0.75, 0.0, 1.0);
52
+ float lift = smoothstep(0.0, 0.15, p);
53
+ float u = min(t / 0.7, 1.0);
54
+ float swing = u * u * (3.0 - 2.0 * u);
55
+ // it tilts toward the side it is flicked to
56
+ float a = (d.x < 0.0 ? 1.3 : -1.3) * rotation * swing;
57
+ vec2 pivot = vec2(0.0, -1.1);
58
+ // where the swing alone takes the center of the card, to throw it far enough
59
+ float ca = cos(a), sa = sin(a);
60
+ vec2 swung = pivot + mat2(ca, sa, -sa, ca) * -pivot;
61
+ float far = 2.0 * length(b) + length(swung) + 0.3;
62
+ vec2 shift = d * far * t * t * (0.4 + 0.6 * t);
63
+ mat2 unrotate = mat2(ca, -sa, sa, ca);
64
+ vec2 r = unrotate * (q - shift - pivot) + pivot;
65
+ float rf = RADIUS * lift;
66
+
67
+ // its soft shadow on the card behind, cast down and away as it lifts
68
+ float sh = 0.6 * lift * (1.0 - t);
69
+ if (sh > 0.0) {
70
+ vec2 rs = unrotate * (q - (0.03 * d + vec2(0.0, -0.03)) * lift - shift - pivot) + pivot;
71
+ float ds = roundedBox(rs, b, rf);
72
+ col.rgb *= 1.0 - sh * (1.0 - smoothstep(-0.05, 0.08, ds));
73
+ }
74
+
75
+ float df = roundedBox(r, b, rf);
76
+ float cf = clamp(0.5 - df / max(AA * min(1.0, 40.0 * lift), 1e-6), 0.0, 1.0);
77
+ vec4 fc = getFromColor(clamp(r / vec2(ratio, 1.0) + 0.5, 0.0, 1.0));
78
+ col = mix(col, premultiply(fc), cf);
79
+ return col.a > 0.0 ? vec4(col.rgb / col.a, col.a) : vec4(0.0);
80
+ }
@@ -0,0 +1,51 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image is pulled away by its middle: the wipe edge bulges into a smooth curve that leads the way, then flattens as it reaches the far side
4
+ // Tags: wipe, curve, directional, shadow
5
+
6
+ // @param Direction the edge moves toward
7
+ uniform vec2 direction; // = vec2(0.0, 1.0)
8
+ // @range(0, 1) How far the middle of the edge leads its sides
9
+ uniform float curvature; // = 0.6
10
+ // @range(0, 0.2) Softness of the edge
11
+ uniform float smoothness; // = 0.02
12
+ // @color Color of the soft shadow the lifted edge casts on the incoming image (its alpha is its strength; 0 for none)
13
+ uniform vec4 shadow; // = vec4(0.0, 0.0, 0.0, 0.4)
14
+
15
+ const float PI = 3.141592653589793;
16
+
17
+ // a gentle ease in and out, which does not linger at the ends
18
+ float ease (float t) {
19
+ return 0.5 * (t + t * t * (3.0 - 2.0 * t));
20
+ }
21
+
22
+ vec4 transition (vec2 uv) {
23
+ vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(0.0, 1.0);
24
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
25
+ // half extents of the frame along the direction and across it
26
+ float e = 0.5 * (abs(dir.x) * ratio + abs(dir.y));
27
+ float w = 0.5 * (abs(dir.y) * ratio + abs(dir.x));
28
+ vec2 across = vec2(-dir.y, dir.x);
29
+ float d = dot(p, dir);
30
+ // where the pixel is across the frame, from -1 to 1 (on a diagonal, these are the corners); it is the same
31
+ // all along the direction, so the edge is a single curve, centered on the middle of the frame
32
+ float x = clamp(dot(p, across) / w, -1.0, 1.0);
33
+ float s = max(smoothness, 0.001);
34
+ // each point of the edge runs on its own clock: the middle runs ahead and slows down at the far side,
35
+ // where the sides catch up with it; the lead keeps the curve's shape alike on wide and narrow frames
36
+ float k = clamp(curvature, 0.0, 1.0) * min(1.0, w / e) * (1.0 - x * x);
37
+ float t = progress + k * progress * (1.0 - progress);
38
+ float travel = 2.0 * (e + s);
39
+ float edge = -e - s + travel * ease(t);
40
+ float side = -e - s + travel * ease(progress);
41
+ float m = 1.0 - smoothstep(-s, s, d - edge);
42
+ // the more the edge is lifted, the wider and softer the shadow it casts on the incoming image
43
+ float lift = edge - side;
44
+ float spread = 0.012 + 0.25 * lift;
45
+ // it falls behind the edge only, on the incoming image, cast by the outgoing image at the edge
46
+ vec4 to = getToColor(uv);
47
+ vec2 caster = clamp((p + (edge - d) * dir) / vec2(ratio, 1.0) + 0.5, 0.0, 1.0);
48
+ float sh = shadow.a * sin(PI * progress) * exp(-max(edge - d, 0.0) / spread) * m * getFromColor(caster).a * to.a;
49
+ to.rgb = mix(to.rgb, shadow.rgb, sh);
50
+ return mix(getFromColor(uv), to, m);
51
+ }
@@ -0,0 +1,111 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image crumbles into fine dust from one side, its grains blown away by the wind and fading out, revealing the incoming image underneath
4
+ // Tags: particles, dust, wind, directional
5
+
6
+ // @range(0.0075, 0.03) Size of the dust grains, in frame heights
7
+ uniform float particleSize; // = 0.008
8
+ // @param Direction in which the wind blows the dust
9
+ uniform vec2 direction; // = vec2(1.0, -0.15)
10
+ // @range(0, 1) How far the dust flies and scatters before it fades out
11
+ uniform float spread; // = 0.75
12
+
13
+ // the grains a pixel looks back to, along the wind: every grain up to 16 cells away,
14
+ // one in 2 up to 32 cells, one in 4 up to 64 cells (only those stay visible that far,
15
+ // so the dust thins out as it flies): 35 candidates, without unrolling a long loop
16
+ const int NEAR = 17;
17
+ const int CANDIDATES = 35;
18
+ // part of the transition during which a grain flies, from its release to its fade-out
19
+ const float LIFE = 0.45;
20
+
21
+ float hash12(vec2 p) {
22
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
23
+ p3 += dot(p3, p3.yzx + 33.33);
24
+ return fract((p3.x + p3.y) * p3.z);
25
+ }
26
+
27
+ // smooth value noise, between -1 and 1
28
+ float noise(vec2 p) {
29
+ vec2 i = floor(p);
30
+ vec2 f = fract(p);
31
+ f = f * f * (3.0 - 2.0 * f);
32
+ float a = hash12(i);
33
+ float b = hash12(i + vec2(1.0, 0.0));
34
+ float c = hash12(i + vec2(0.0, 1.0));
35
+ float d = hash12(i + vec2(1.0, 1.0));
36
+ return 2.0 * mix(mix(a, b, f.x), mix(c, d, f.x), f.y) - 1.0;
37
+ }
38
+
39
+ // the grains' sideways drift, in gusts along the wind, between -1 and 1: it depends only
40
+ // on where a grain comes from along the wind, so that a pixel knows which row to look in
41
+ float gust(float x) {
42
+ float i = floor(x);
43
+ float f = fract(x);
44
+ f = f * f * (3.0 - 2.0 * f);
45
+ return 2.0 * mix(hash12(vec2(i, 7.0)), hash12(vec2(i + 1.0, 7.0)), f) - 1.0;
46
+ }
47
+
48
+ // when the grain at this center (in cells) is released, from the downwind side first,
49
+ // along a ragged front
50
+ float release(vec2 center, float h, float halfLength, float s) {
51
+ float front = 1.0 - (center.x + halfLength) / (2.0 * halfLength) + 0.14 * noise(center * s * 6.0) + 0.08 * (h - 0.5);
52
+ return clamp((front + 0.12) / 1.24, 0.0, 1.0) * (1.0 - LIFE);
53
+ }
54
+
55
+ vec4 transition(vec2 uv) {
56
+ vec2 d = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
57
+ vec2 n = vec2(-d.y, d.x);
58
+ // grid of grains aligned with the wind: x along it, y across it, in cells
59
+ vec2 fp = (uv - 0.5) * vec2(ratio, 1.0);
60
+ float s = particleSize;
61
+ vec2 g = vec2(dot(fp, d), dot(fp, n)) / s;
62
+ float halfLength = 0.5 * (ratio * abs(d.x) + abs(d.y)) / s;
63
+ // the longest flight, in cells (at most 60, within the 64 cells looked back to)
64
+ float reach = min(spread * 0.45 / s, 60.0);
65
+ float px = floor(g.x);
66
+
67
+ // this pixel's own grain: once it has left, the incoming image shows through
68
+ vec2 own = floor(g);
69
+ vec4 under = progress > release(own + 0.5, hash12(own), halfLength, s) ? getToColor(uv) : getFromColor(uv);
70
+ vec2 grainUV = vec2(0.5);
71
+ float cover = 0.0;
72
+ for (int i = 0; i < CANDIDATES; i++) {
73
+ // the column of the candidate grain
74
+ float fi = float(i);
75
+ float cx = px - fi;
76
+ if (i >= NEAR + 9) {
77
+ cx = floor(px / 4.0) * 4.0 - 4.0 * (fi - float(NEAR + 9) + 8.0);
78
+ } else if (i >= NEAR) {
79
+ cx = floor(px / 2.0) * 2.0 - 2.0 * (fi - float(NEAR) + 8.0);
80
+ }
81
+ // how far the grain stays visible (in cells): further when its column is a multiple
82
+ // of 2, and of 4, as far as the pixels look back to
83
+ float visible = mod(cx, 4.0) < 0.5 ? 63.0 : mod(cx, 2.0) < 0.5 ? 31.0 : 15.0;
84
+ float drift = 0.3 * gust(cx * s * 4.0);
85
+ // the row the grain comes from: its sideways drift is known from its column and how
86
+ // far it has flown to get here
87
+ vec2 cell = vec2(cx, floor(g.y - drift * (g.x - cx - 0.5)));
88
+ vec2 center = cell + 0.5;
89
+ vec2 cuv = (center.x * d + center.y * n) * s / vec2(ratio, 1.0) + 0.5;
90
+ if (cuv.x < 0.0 || cuv.x > 1.0 || cuv.y < 0.0 || cuv.y > 1.0) continue;
91
+ float h = hash12(cell);
92
+ float t = (progress - release(center, h, halfLength, s)) / LIFE;
93
+ if (t <= 0.0 || t >= 1.0) continue;
94
+ float r2 = fract(h * 13.7);
95
+ // the grain speeds up, drifts sideways, shrinks and fades out
96
+ float travel = reach * (0.4 + 0.6 * r2) * t * (0.2 + 0.8 * t);
97
+ // it first fills its cell, then crumbles to a smaller speck
98
+ float crumble = smoothstep(0.0, 0.25, t);
99
+ vec2 pos = center + vec2(travel + (fract(h * 71.1) - 0.5) * 0.3 * crumble, drift * travel);
100
+ vec2 local = abs(g - pos);
101
+ float size = mix(0.5, 0.3 * (1.0 - 0.5 * t) * (0.6 + 0.4 * h), crumble);
102
+ float feather = 0.001 + 0.12 * crumble;
103
+ float a = (1.0 - smoothstep(size - feather, size, max(local.x, local.y))) * (1.0 - smoothstep(0.15, 1.0, t))
104
+ * (1.0 - smoothstep(0.6 * visible, visible, travel));
105
+ if (a > cover) {
106
+ cover = a;
107
+ grainUV = cuv;
108
+ }
109
+ }
110
+ return mix(under, getFromColor(grainUV), cover);
111
+ }
@@ -0,0 +1,48 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A cross-dissolve blended in linear light, as light adds up on film: the frame keeps its brightness all the way through and the highlights of each image shine through the other
4
+ // Tags: dissolve, fade, blend, light
5
+
6
+ // @range(0, 1) Extra light where the two images overlap at mid-dissolve, softly rolled off so it never clips
7
+ uniform float overlap; // = 0.25
8
+ // @range(0, 1) Easing of the dissolve: 0 is linear, 1 eases in and out
9
+ uniform float smoothness; // = 0.5
10
+
11
+ // sRGB to linear light (the exact piecewise curve)
12
+ vec3 toLinear(vec3 c) {
13
+ vec3 lo = c / 12.92;
14
+ vec3 hi = pow((c + 0.055) / 1.055, vec3(2.4));
15
+ return mix(lo, hi, vec3(greaterThan(c, vec3(0.04045))));
16
+ }
17
+
18
+ // linear light back to sRGB
19
+ vec3 toSrgb(vec3 c) {
20
+ vec3 lo = c * 12.92;
21
+ vec3 hi = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055;
22
+ return mix(lo, hi, vec3(greaterThan(c, vec3(0.0031308))));
23
+ }
24
+
25
+ vec4 transition(vec2 uv) {
26
+ vec4 a = getFromColor(uv);
27
+ vec4 b = getToColor(uv);
28
+ if (progress <= 0.0) return a;
29
+ if (progress >= 1.0) return b;
30
+
31
+ float t = mix(progress, smoothstep(0.0, 1.0, progress), smoothness);
32
+
33
+ // premultiplied linear light
34
+ vec3 la = toLinear(clamp(a.rgb, 0.0, 1.0)) * a.a;
35
+ vec3 lb = toLinear(clamp(b.rgb, 0.0, 1.0)) * b.a;
36
+ vec3 base = mix(la, lb, t);
37
+ float alpha = mix(a.a, b.a, t);
38
+
39
+ // the overlap: each image stays brighter for longer, as in an additive dissolve,
40
+ // rolled off toward full exposure so that bright areas glow instead of clipping
41
+ float extra = overlap * min(t, 1.0 - t);
42
+ vec3 excess = extra * (la + lb);
43
+ vec3 room = max(vec3(alpha) - base, vec3(1e-5));
44
+ vec3 color = base + room * (1.0 - exp(-excess / room));
45
+
46
+ if (alpha <= 0.0) return vec4(0.0);
47
+ return vec4(toSrgb(clamp(color / alpha, 0.0, 1.0)), alpha);
48
+ }
@@ -0,0 +1,104 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The picture slips like film in a projector gate: it shrinks to show the sprocket holes, the strip runs down with motion blur and a slight weave, then the incoming frame lands in place
4
+ // Tags: retro, vertical, motion-blur, film
5
+
6
+ // @range(1, 6, 1) Number of frames that slip by
7
+ uniform int frames; // = 2
8
+ // @range(0, 0.4) How much the picture shrinks during the slip, showing the film's edges
9
+ uniform float shrink; // = 0.2
10
+ // @range(0, 1) Length of the motion blur at full speed
11
+ uniform float blur; // = 0.5
12
+ // @range(0, 1) Amount of horizontal weave and vertical jitter
13
+ uniform float weave; // = 0.5
14
+ // @color Color of the film around the pictures and of the line between frames
15
+ uniform vec4 filmColor; // = vec4(0.06, 0.05, 0.05, 1.0)
16
+ // @color Color of the light through the sprocket holes
17
+ uniform vec4 holeColor; // = vec4(0.96, 0.93, 0.85, 1.0)
18
+
19
+ // height of the line between two frames, in frame heights
20
+ const float FRAME_LINE = 0.08;
21
+ // sprocket holes per frame
22
+ const float HOLES = 4.0;
23
+ const int SAMPLES = 16;
24
+
25
+ // a fine, evenly spread dither pattern over small cells of the frame
26
+ float dither(vec2 cell) {
27
+ return fract(52.9829189 * fract(dot(cell, vec2(0.06711056, 0.00583715))));
28
+ }
29
+
30
+ // the film at (x, y): x across it (0 to 1 over the picture), y along it from the start of frame
31
+ // number base, in frame heights; holes fades the sprocket holes in
32
+ vec4 film(float x, float y, float base, float n, float aa, float holeX, vec2 holeSize, float holes) {
33
+ float pitch = 1.0 + FRAME_LINE;
34
+ float jy = floor(y / pitch);
35
+ float j = base + jy;
36
+ float fy = y - jy * pitch;
37
+ vec4 c = filmColor;
38
+ if (x >= 0.0 && x <= 1.0 && fy <= 1.0) {
39
+ vec2 q = vec2(x, fy);
40
+ c = j < n ? getFromColor(q) : getToColor(q);
41
+ }
42
+ // soft edges for the picture during the slip (none at rest, where it fills the frame)
43
+ float inside = min(min(x, 1.0 - x) * ratio, min(fy, 1.0 - fy));
44
+ c = mix(filmColor, c, clamp(inside / aa + 0.5, 0.0, 1.0));
45
+ // the sprocket holes, in the margins on both sides, in frame heights
46
+ float hy = mod(y, pitch / HOLES) - 0.5 * pitch / HOLES;
47
+ float hx = (abs(x - 0.5) - holeX) * ratio;
48
+ vec2 dd = abs(vec2(hx, hy)) - holeSize + 0.3 * holeSize.x;
49
+ float sd = length(max(dd, 0.0)) + min(max(dd.x, dd.y), 0.0) - 0.3 * holeSize.x;
50
+ return mix(c, holeColor, clamp(0.5 - sd / aa, 0.0, 1.0) * holes);
51
+ }
52
+
53
+ vec4 transition(vec2 uv) {
54
+ if (progress <= 0.0) return getFromColor(uv);
55
+ if (progress >= 1.0) return getToColor(uv);
56
+ float n = max(float(frames), 1.0);
57
+ float pitch = 1.0 + FRAME_LINE;
58
+ float p = progress;
59
+ // the picture shrinks first, slips, then grows back
60
+ float env = smoothstep(0.0, 0.3, p) * (1.0 - smoothstep(0.7, 1.0, p));
61
+ float k = 1.0 - shrink * env;
62
+ // the slip, in frames: smooth start and landing
63
+ float x0 = clamp((p - 0.15) / 0.7, 0.0, 1.0);
64
+ float slip = x0 * x0 * x0 * (x0 * (x0 * 6.0 - 15.0) + 10.0);
65
+ float speed = 30.0 * x0 * x0 * (1.0 - x0) * (1.0 - x0) / 0.7; // d(slip)/d(progress), up to ~2.7
66
+ // weave and jitter, only while the film moves
67
+ float wob = weave * env;
68
+ // (the weave stays within the film's margin)
69
+ float dx = wob * smoothstep(0.0, 0.1, shrink) * (0.006 * sin(p * 47.0) + 0.004 * sin(p * 113.0 + 1.3));
70
+ float dy = wob * 0.012 * sin(p * 71.0 + 0.4) * (1.0 - speed / 2.7);
71
+
72
+ // the frames slipped by so far: whole frames, and the position within the current one
73
+ float frameSlip = slip * n;
74
+ float base = floor(frameSlip);
75
+ float x = (uv.x - 0.5) / k + 0.5 + dx;
76
+ float y = (uv.y - 0.5) / k + 0.5 + dy + (frameSlip - base) * pitch;
77
+ // anti-aliasing width, in frame heights: none at rest or without margin
78
+ float aa = 0.002 * min(1.0, 10.0 * env) * min(1.0, 20.0 * shrink) + 1e-4;
79
+ // the holes sit in the middle of the margin the shrinking picture shows
80
+ float margin = 0.5 * shrink / max(1.0 - shrink, 0.01);
81
+ float holeX = 0.5 + 0.5 * margin;
82
+ vec2 holeSize = vec2(0.28 * margin * ratio, 0.11 * pitch / HOLES);
83
+ float holes = smoothstep(0.0, 0.02, margin);
84
+
85
+ // motion blur along the strip, dithered to hide the steps
86
+ float len = blur * 0.06 * speed * n;
87
+ vec4 color = vec4(0.0);
88
+ if (len < 1e-5) {
89
+ color = film(x, y, base, n, aa, holeX, holeSize, holes);
90
+ } else {
91
+ // averaged with premultiplied colors, so transparent parts don't darken the others
92
+ float jitter = dither(floor(uv * vec2(ratio, 1.0) * 540.0));
93
+ for (int i = 0; i < SAMPLES; i++) {
94
+ float t = (float(i) + jitter) / float(SAMPLES) - 0.5;
95
+ vec4 c = film(x, y + t * len, base, n, aa, holeX, holeSize, holes);
96
+ color += vec4(c.rgb * c.a, c.a);
97
+ }
98
+ color /= float(SAMPLES);
99
+ color.rgb = color.a > 0.0 ? color.rgb / color.a : vec3(0.0);
100
+ }
101
+ // the projector's light flickers a little while the film runs
102
+ color.rgb *= 1.0 - 0.08 * wob * (0.5 + 0.5 * sin(p * 157.0));
103
+ return color;
104
+ }
@@ -0,0 +1,153 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A wall of flames sweeps across the frame, scorching the outgoing image ahead of it and leaving the incoming image under a fading warm glow
4
+ // Tags: fire, flame, burn, wipe, directional
5
+
6
+ // @param Direction in which the flames sweep across the frame
7
+ uniform vec2 direction; // = vec2(0.0, 1.0)
8
+ // @range(0, 1) Height of the flames, as a fraction of the frame height
9
+ uniform float height; // = 0.4
10
+ // @range(0, 1) How much the outgoing image browns and chars ahead of the flames
11
+ uniform float scorch; // = 0.7
12
+ // @range(0, 1) Strength of the warm glow left on the incoming image
13
+ uniform float glow; // = 0.6
14
+ // @color Tint of the body of the flames
15
+ uniform vec3 color; // = vec3(1.0, 0.4, 0.08)
16
+
17
+ // width of the scorched band ahead of the flames, and of the glow behind them
18
+ const float BAND = 0.45;
19
+ // how far off the frame the front starts and ends
20
+ const float PAD = 0.3;
21
+ // how far the front of the fire wanders around its straight line
22
+ const float RAGGED = 0.05;
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
+ float noise(vec2 v) {
31
+ vec2 i = floor(v);
32
+ vec2 f = v - i;
33
+ f = f * f * (3.0 - 2.0 * f);
34
+ return mix(mix(hash12(i), hash12(i + vec2(1.0, 0.0)), f.x),
35
+ mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), f.x), f.y);
36
+ }
37
+
38
+ float fbm(vec2 v) {
39
+ float sum = 0.0;
40
+ float amp = 0.5;
41
+ for (int i = 0; i < 4; i++) {
42
+ sum += amp * noise(v);
43
+ v = v * 2.03 + vec2(17.3, 9.1);
44
+ amp *= 0.5;
45
+ }
46
+ return sum / 0.9375;
47
+ }
48
+
49
+ // mirror the coordinates back into the frame
50
+ vec2 mirror(vec2 v) {
51
+ return 1.0 - abs(1.0 - mod(v, 2.0));
52
+ }
53
+
54
+ // color of the fire by its heat: dark red tips, a tinted body, a white-yellow core
55
+ vec3 fire(float h) {
56
+ vec3 c = mix(vec3(0.22, 0.01, 0.0), color * color * vec3(1.0, 0.6, 0.4), smoothstep(0.0, 0.3, h));
57
+ c = mix(c, color, smoothstep(0.25, 0.55, h));
58
+ c = mix(c, vec3(1.0, 0.8, 0.35), smoothstep(0.55, 0.8, h));
59
+ return mix(c, vec3(1.0, 0.96, 0.82), smoothstep(0.8, 1.0, h));
60
+ }
61
+
62
+ // width of a flame tongue climbing along an upright line, from its base (s = 0) to its tip
63
+ // (s = 1), with a random size
64
+ float climbing(float s, float size) {
65
+ return (0.42 + 0.56 * size) * 6.75 * s * (1.0 - s) * (1.0 - s);
66
+ }
67
+
68
+ vec4 transition(vec2 uv) {
69
+ vec2 dir = length(direction) > 1e-5 ? normalize(direction) : vec2(1.0, 0.0);
70
+ vec2 q = (uv - 0.5) * vec2(ratio, 1.0);
71
+ // the flames rise upward from the front: over this distance along the direction
72
+ float rise = height * dir.y;
73
+ // half-width of the burning line, and how far it swells
74
+ float w = 0.05 + 0.35 * height;
75
+ float reach = w * (1.75 + 0.6 * abs(dir.x));
76
+ // the front crosses the frame at the same pace whatever the height of the flames
77
+ float extent = 0.5 * (abs(dir.x) * ratio + abs(dir.y)) + PAD;
78
+ float e = mix(progress, progress * progress * (3.0 - 2.0 * progress), 0.3);
79
+ // the fire catches at the start and dies out at the end, the scorch grows in, the glow fades
80
+ float burn = smoothstep(0.0, 0.12, progress) * (1.0 - smoothstep(0.88, 1.0, progress));
81
+ float scorchAmount = scorch * smoothstep(0.0, 0.2, progress);
82
+ float glowAmount = glow * (1.0 - smoothstep(0.75, 1.0, progress));
83
+ // the flames flicker as they go
84
+ float t = progress * 5.0;
85
+
86
+ float side = dot(q, vec2(-dir.y, dir.x));
87
+ float front = mix(-extent, extent, e) + RAGGED * (2.0 * noise(vec2(side * 4.0, t * 0.4)) - 1.0);
88
+ // > 0 ahead of the fire, on the outgoing image
89
+ float k = dot(q, dir) - front;
90
+
91
+ // heat before the turbulence: the burning line, and the flames rising from it.
92
+ // Billows rising in screen space swell and thin the line; where it stands upright,
93
+ // they are tongues climbing along it, each widest at its base and pointed at its tip
94
+ float billow = noise(vec2(q.x * 3.0 + 5.0, q.y * 2.5 - t * 1.6));
95
+ float y = q.y * 3.0 - t * 1.4;
96
+ float y2 = y + 0.5;
97
+ float climb = max(climbing(fract(y), hash12(vec2(floor(y), 3.0))),
98
+ climbing(fract(y2), hash12(vec2(floor(y2), 7.0))));
99
+ billow = mix(billow, 0.4 * billow + climb, abs(dir.x));
100
+ float lineWidth = w * (0.25 + 1.5 * billow);
101
+ float line = 1.0 - smoothstep(0.0, lineWidth, abs(k));
102
+ float tongue = 0.0;
103
+ if (abs(rise) > 1e-4) {
104
+ float s = k / rise;
105
+ if (s >= 0.0) tongue = clamp(1.0 - s, 0.0, 1.0);
106
+ }
107
+ float heat = max(line, tongue) * burn;
108
+ float near = 1.0 - smoothstep(0.0, BAND, abs(k));
109
+
110
+ // the outgoing image shimmers in the heat ahead of the fire
111
+ vec2 h = q * vec2(9.0, 5.0) + vec2(0.0, -t * 3.0);
112
+ vec2 shimmer = (vec2(noise(h), noise(h + 31.7)) - 0.5) * 0.012 * min(near + heat, 1.0) * burn;
113
+ vec4 a = getFromColor(mirror(uv + shimmer));
114
+ vec4 b = getToColor(uv);
115
+
116
+ // the outgoing image browns, then chars close to the flames
117
+ float brown = k > 0.0 ? scorchAmount * near : 0.0;
118
+ float lum = dot(a.rgb, vec3(0.299, 0.587, 0.114));
119
+ a.rgb = mix(a.rgb, lum * vec3(0.9, 0.55, 0.28), brown) * (1.0 - 0.35 * brown) * (1.0 - 0.9 * brown * near * near);
120
+ // the incoming image under a warm glow fading away from the fire
121
+ float g = k < 0.0 ? glowAmount * near : 0.0;
122
+ b.rgb = b.rgb * mix(vec3(1.0), vec3(1.0, 0.6, 0.35), 0.7 * g) + color * 0.4 * g * g;
123
+
124
+ // far from the fire, only one of the images shows
125
+ if (k >= max(BAND, max(rise, reach))) return a.a > 0.0 ? a : vec4(0.0);
126
+ if (-k >= max(BAND, max(-rise, reach))) return b.a > 0.0 ? b : vec4(0.0);
127
+
128
+ // the two images meet under the burning line (mixed premultiplied)
129
+ float m = smoothstep(-0.5 * w, 0.5 * w, k);
130
+ vec4 c = mix(vec4(b.rgb * b.a, b.a), vec4(a.rgb * a.a, a.a), m);
131
+ if (c.a <= 0.0) return vec4(0.0);
132
+ vec3 col = c.rgb / c.a;
133
+
134
+ // turbulence rising in screen space, stretched upward and swaying into pointed tongues
135
+ vec2 f = vec2(q.x * mix(10.0, 6.0, abs(dir.x)), q.y * mix(1.8, 3.2, abs(dir.x)) - t * 2.4);
136
+ float sway = fbm(vec2(q.x * 2.5, q.y * 1.5 - t * 1.2));
137
+ float n = fbm(f + vec2(1.5 * sway - 0.75, 0.0));
138
+ n = clamp(1.7 * n - 0.35, 0.0, 1.0);
139
+ // a continuous hot core hugging the base of the flames
140
+ float core = (1.0 - smoothstep(0.0, 0.35 * lineWidth, abs(k + 0.4 * w * (sway - 0.5)))) * burn * (1.0 - 0.5 * abs(dir.x));
141
+ // under the flames, where they take root, the turbulence calms down into a soft glow
142
+ float root = rise > 0.0 ? clamp(-k / w, 0.0, 1.0) : rise < 0.0 ? clamp(k / w, 0.0, 1.0) : 0.0;
143
+ root *= abs(dir.y);
144
+ float flame = clamp(heat * 0.95 + 0.45 * core * (0.75 + 0.25 * n) - (1.0 - n) * 1.1 * (1.0 - 0.8 * root), 0.0, 1.0);
145
+
146
+ // the flames darken what is behind their body and add their light, with a soft halo;
147
+ // the alpha stays the image's
148
+ // crisp around the tongues, soft at their roots
149
+ float body = smoothstep(0.0, 0.08 + 0.5 * root, flame);
150
+ col = col * (1.0 - 0.7 * body) + fire(flame) * (0.45 + 0.65 * flame) * body;
151
+ col += color * 0.25 * heat * heat * (1.0 - body);
152
+ return vec4(clamp(col, 0.0, 1.0), c.a);
153
+ }