gl-transitions 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/compatibility.json +359 -11
  3. package/gl-transitions.js +1 -1
  4. package/gl-transitions.json +1 -1
  5. package/glsl3/BookFlip.glsl +124 -21
  6. package/glsl3/Clothesline.glsl +217 -0
  7. package/glsl3/ComicPanels.glsl +174 -0
  8. package/glsl3/Cube.glsl +105 -52
  9. package/glsl3/DominoFall.glsl +114 -0
  10. package/glsl3/Doorway.glsl +74 -38
  11. package/glsl3/Drape.glsl +186 -0
  12. package/glsl3/DuotoneFade.glsl +58 -0
  13. package/glsl3/FacetedGlass.glsl +137 -0
  14. package/glsl3/FrostWipe.glsl +176 -0
  15. package/glsl3/Funnel.glsl +71 -0
  16. package/glsl3/GlitterDissolve.glsl +171 -0
  17. package/glsl3/GridFlip.glsl +151 -56
  18. package/glsl3/HeartWipe.glsl +71 -11
  19. package/glsl3/InsideCube.glsl +114 -0
  20. package/glsl3/KeyholeWipe.glsl +104 -0
  21. package/glsl3/LedWall.glsl +127 -0
  22. package/glsl3/MoireWipe.glsl +75 -0
  23. package/glsl3/PaperFold.glsl +168 -0
  24. package/glsl3/PuzzleCube.glsl +205 -0
  25. package/glsl3/RibbonTwist.glsl +53 -0
  26. package/glsl3/Shatter.glsl +231 -35
  27. package/glsl3/SketchDissolve.glsl +100 -0
  28. package/glsl3/SlotReels.glsl +118 -0
  29. package/glsl3/SplitFlap.glsl +124 -0
  30. package/glsl3/Swirl.glsl +52 -21
  31. package/glsl3/TruchetWipe.glsl +80 -0
  32. package/glsl3/Tumble.glsl +113 -0
  33. package/glsl3/WaterDrop.glsl +69 -13
  34. package/glsl3/WaveWipe.glsl +154 -0
  35. package/index.js +1 -1
  36. package/layouts.json +991 -19
  37. package/llms-full.txt +791 -403
  38. package/llms.txt +219 -197
  39. package/msl/BookFlip.metal +575 -114
  40. package/msl/Clothesline.metal +828 -0
  41. package/msl/ComicPanels.metal +959 -0
  42. package/msl/Cube.metal +466 -170
  43. package/msl/DominoFall.metal +510 -0
  44. package/msl/Doorway.metal +350 -124
  45. package/msl/Drape.metal +767 -0
  46. package/msl/DuotoneFade.metal +218 -0
  47. package/msl/FacetedGlass.metal +529 -0
  48. package/msl/FrostWipe.metal +677 -0
  49. package/msl/Funnel.metal +276 -0
  50. package/msl/GlitterDissolve.metal +637 -0
  51. package/msl/GridFlip.metal +548 -191
  52. package/msl/HeartWipe.metal +230 -58
  53. package/msl/InsideCube.metal +537 -0
  54. package/msl/KeyholeWipe.metal +370 -0
  55. package/msl/LedWall.metal +437 -0
  56. package/msl/MoireWipe.metal +252 -0
  57. package/msl/PaperFold.metal +762 -0
  58. package/msl/PuzzleCube.metal +1179 -0
  59. package/msl/RibbonTwist.metal +235 -0
  60. package/msl/Shatter.metal +1136 -160
  61. package/msl/SketchDissolve.metal +446 -0
  62. package/msl/SlotReels.metal +436 -0
  63. package/msl/SplitFlap.metal +589 -0
  64. package/msl/Swirl.metal +144 -77
  65. package/msl/TruchetWipe.metal +285 -0
  66. package/msl/Tumble.metal +466 -0
  67. package/msl/WaterDrop.metal +258 -49
  68. package/msl/WaveWipe.metal +618 -0
  69. package/package.json +1 -1
  70. package/skills/gl-transitions/references/catalog.md +97 -51
  71. package/sksl/BookFlip.sksl +117 -20
  72. package/sksl/Clothesline.sksl +217 -0
  73. package/sksl/ComicPanels.sksl +176 -0
  74. package/sksl/Cube.sksl +99 -46
  75. package/sksl/DominoFall.sksl +122 -0
  76. package/sksl/Doorway.sksl +65 -35
  77. package/sksl/Drape.sksl +192 -0
  78. package/sksl/DuotoneFade.sksl +71 -0
  79. package/sksl/FacetedGlass.sksl +148 -0
  80. package/sksl/FrostWipe.sksl +183 -0
  81. package/sksl/Funnel.sksl +83 -0
  82. package/sksl/GlitterDissolve.sksl +175 -0
  83. package/sksl/GridFlip.sksl +141 -52
  84. package/sksl/HeartWipe.sksl +60 -11
  85. package/sksl/InsideCube.sksl +123 -0
  86. package/sksl/KeyholeWipe.sksl +109 -0
  87. package/sksl/LedWall.sksl +137 -0
  88. package/sksl/MoireWipe.sksl +85 -0
  89. package/sksl/PaperFold.sksl +170 -0
  90. package/sksl/PuzzleCube.sksl +203 -0
  91. package/sksl/RibbonTwist.sksl +66 -0
  92. package/sksl/Shatter.sksl +218 -33
  93. package/sksl/SketchDissolve.sksl +111 -0
  94. package/sksl/SlotReels.sksl +127 -0
  95. package/sksl/SplitFlap.sksl +131 -0
  96. package/sksl/Swirl.sksl +49 -20
  97. package/sksl/TruchetWipe.sksl +92 -0
  98. package/sksl/Tumble.sksl +122 -0
  99. package/sksl/WaterDrop.sksl +64 -10
  100. package/sksl/WaveWipe.sksl +165 -0
  101. package/sksl/index.js +1 -1
  102. package/transitions/BookFlip.glsl +124 -21
  103. package/transitions/Clothesline.glsl +216 -0
  104. package/transitions/ComicPanels.glsl +173 -0
  105. package/transitions/Cube.glsl +105 -52
  106. package/transitions/DominoFall.glsl +113 -0
  107. package/transitions/Doorway.glsl +74 -38
  108. package/transitions/Drape.glsl +185 -0
  109. package/transitions/DuotoneFade.glsl +57 -0
  110. package/transitions/FacetedGlass.glsl +136 -0
  111. package/transitions/FrostWipe.glsl +175 -0
  112. package/transitions/Funnel.glsl +70 -0
  113. package/transitions/GlitterDissolve.glsl +170 -0
  114. package/transitions/GridFlip.glsl +151 -56
  115. package/transitions/HeartWipe.glsl +71 -11
  116. package/transitions/InsideCube.glsl +113 -0
  117. package/transitions/KeyholeWipe.glsl +103 -0
  118. package/transitions/LedWall.glsl +126 -0
  119. package/transitions/MoireWipe.glsl +74 -0
  120. package/transitions/PaperFold.glsl +167 -0
  121. package/transitions/PuzzleCube.glsl +204 -0
  122. package/transitions/RibbonTwist.glsl +52 -0
  123. package/transitions/Shatter.glsl +231 -35
  124. package/transitions/SketchDissolve.glsl +99 -0
  125. package/transitions/SlotReels.glsl +117 -0
  126. package/transitions/SplitFlap.glsl +123 -0
  127. package/transitions/Swirl.glsl +52 -21
  128. package/transitions/TruchetWipe.glsl +79 -0
  129. package/transitions/Tumble.glsl +112 -0
  130. package/transitions/WaterDrop.glsl +69 -13
  131. package/transitions/WaveWipe.glsl +153 -0
  132. package/wgsl/BookFlip.wgsl +552 -105
  133. package/wgsl/Clothesline.wgsl +756 -0
  134. package/wgsl/ComicPanels.wgsl +886 -0
  135. package/wgsl/Cube.wgsl +461 -156
  136. package/wgsl/DominoFall.wgsl +461 -0
  137. package/wgsl/Doorway.wgsl +333 -117
  138. package/wgsl/Drape.wgsl +715 -0
  139. package/wgsl/DuotoneFade.wgsl +185 -0
  140. package/wgsl/FacetedGlass.wgsl +476 -0
  141. package/wgsl/FrostWipe.wgsl +617 -0
  142. package/wgsl/Funnel.wgsl +248 -0
  143. package/wgsl/GlitterDissolve.wgsl +582 -0
  144. package/wgsl/GridFlip.wgsl +523 -188
  145. package/wgsl/HeartWipe.wgsl +225 -55
  146. package/wgsl/InsideCube.wgsl +496 -0
  147. package/wgsl/KeyholeWipe.wgsl +337 -0
  148. package/wgsl/LedWall.wgsl +397 -0
  149. package/wgsl/MoireWipe.wgsl +222 -0
  150. package/wgsl/PaperFold.wgsl +700 -0
  151. package/wgsl/PuzzleCube.wgsl +1087 -0
  152. package/wgsl/RibbonTwist.wgsl +206 -0
  153. package/wgsl/Shatter.wgsl +1091 -148
  154. package/wgsl/SketchDissolve.wgsl +409 -0
  155. package/wgsl/SlotReels.wgsl +391 -0
  156. package/wgsl/SplitFlap.wgsl +533 -0
  157. package/wgsl/Swirl.wgsl +138 -77
  158. package/wgsl/TruchetWipe.wgsl +255 -0
  159. package/wgsl/Tumble.wgsl +424 -0
  160. package/wgsl/WaterDrop.wgsl +251 -49
  161. package/wgsl/WaveWipe.wgsl +581 -0
@@ -1,33 +1,64 @@
1
1
  // License: MIT
2
2
  // Author: Sergey Kosarevsky
3
- // Description: Both images swirl around the center while crossfading
3
+ // Description: The image twists into a round swirl around the center that peaks mid-way, where the outgoing image dissolves into the incoming one, then untwists
4
4
  // Tags: swirl, rotate, blend
5
5
  // ( http://www.linderdaum.com )
6
6
  // ported by gre from https://gist.github.com/corporateshark/cacfedb8cca0f5ce3f7c
7
7
 
8
- vec4 transition(vec2 UV)
9
- {
10
- float Radius = 1.0;
8
+ // @range(-3, 3) Turns of the swirl at its center at the peak (negative turns clockwise)
9
+ uniform float strength; // = 1.0
10
+ // @range(0.1, 2) Radius of the swirl, in frame heights
11
+ uniform float radius; // = 0.9
12
+ // Center of the swirl
13
+ uniform vec2 center; // = vec2(0.5, 0.5)
11
14
 
12
- float T = progress;
15
+ const float PI = 3.141592653589793;
16
+ const float TAU = 6.283185307179586;
17
+ // how much the swirl pulls the image toward its center at the peak
18
+ const float ZOOM = 0.12;
19
+ // spread of the motion blur, as a fraction of the swirl's speed
20
+ const float BLUR = 0.05;
21
+ const int TAPS = 12;
13
22
 
14
- UV -= vec2( 0.5, 0.5 );
15
-
16
- float Dist = length(UV);
23
+ // fold the coordinates back into the frame, so the image stays filled without smearing its border
24
+ vec2 mirrored(vec2 v) {
25
+ vec2 m = mod(v, 2.0);
26
+ return mix(m, 2.0 - m, step(1.0, m));
27
+ }
17
28
 
18
- if ( Dist < Radius )
19
- {
20
- float Percent = (Radius - Dist) / Radius;
21
- float A = ( T <= 0.5 ) ? mix( 0.0, 1.0, T/0.5 ) : mix( 1.0, 0.0, (T-0.5)/0.5 );
22
- float Theta = Percent * Percent * A * 8.0 * 3.14159;
23
- float S = sin( Theta );
24
- float C = cos( Theta );
25
- UV = vec2( dot(UV, vec2(C, -S)), dot(UV, vec2(S, C)) );
26
- }
27
- UV += vec2( 0.5, 0.5 );
29
+ vec4 transition(vec2 uv) {
30
+ // the swirl eases in and out, and is exactly 0 at both ends
31
+ float s = sin(PI * progress);
32
+ float amount = s * s;
33
+ // its speed, used for the motion blur, also 0 at both ends
34
+ float speed = PI * sin(TAU * progress);
35
+ // the switch from the outgoing to the incoming image happens around the peak
36
+ float reveal = smoothstep(0.3, 0.7, progress);
28
37
 
29
- vec4 C0 = getFromColor(UV);
30
- vec4 C1 = getToColor(UV);
38
+ // measured in frame heights, so the swirl is round
39
+ vec2 aspect = vec2(ratio, 1.0);
40
+ vec2 d = (uv - center) * aspect;
41
+ float x = clamp(length(d) / max(radius, 1e-3), 0.0, 1.0);
42
+ // the twist fades out smoothly toward the edge of the swirl
43
+ float falloff = (1.0 - x) * (1.0 - x);
44
+ float twist = strength * TAU * falloff;
45
+ float angle = twist * amount;
46
+ // capped so the blur taps never spread apart into visible streaks
47
+ float spread = clamp(twist * speed * BLUR, -1.2, 1.2);
48
+ // the swirl also slightly pulls the image toward its center
49
+ d *= 1.0 - ZOOM * amount * falloff;
31
50
 
32
- return mix( C0, C1, T );
51
+ vec4 col = vec4(0.0);
52
+ float total = 0.0;
53
+ for (int i = 0; i < TAPS; i++) {
54
+ float k = float(i) / float(TAPS - 1) - 0.5;
55
+ float w = 1.0 - abs(k);
56
+ float a = angle + spread * k;
57
+ float c = cos(a);
58
+ float sn = sin(a);
59
+ vec2 q = mirrored(center + vec2(c * d.x - sn * d.y, sn * d.x + c * d.y) / aspect);
60
+ col += mix(getFromColor(q), getToColor(q), reveal) * w;
61
+ total += w;
62
+ }
63
+ return col / total;
33
64
  }
@@ -0,0 +1,79 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A grid of square tiles, each holding two quarter-circle arcs, links into long winding paths; starting from the middle and spreading outward, the paths are drawn as thin lines of the incoming image, then thicken into bands with a dark outline and a soft shadow until they merge over the whole frame
4
+ // Tags: truchet, pattern, tiles, paths, graphic, reveal
5
+
6
+ // @range(3, 20, 1) Number of tiles across the frame's height
7
+ uniform float cells; // = 8.0
8
+ // @range(0, 1) Strength of the dark outline and of the shadow along the bands
9
+ uniform float outline; // = 0.6
10
+ // @range(0, 1) How much the paths are staggered from the middle outward: 0 draws them all at once
11
+ uniform float spread; // = 0.75
12
+
13
+ // half width of the antialiased edges, in frame heights
14
+ const float AA = 0.0012;
15
+ // width of the outline, in frame heights
16
+ const float LINE = 0.003;
17
+ // how far the shadow reaches outside a band, in frame heights
18
+ const float SHADOW = 0.025;
19
+ // half width of the thin line a path is first drawn as, in tiles
20
+ const float STROKE = 0.08;
21
+
22
+ float hash12(vec2 v) {
23
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
24
+ v3 += dot(v3, v3.yzx + 33.33);
25
+ return fract((v3.x + v3.y) * v3.z);
26
+ }
27
+
28
+ float vnoise(vec2 v) {
29
+ vec2 i = floor(v);
30
+ vec2 f = fract(v);
31
+ f = f * f * (3.0 - 2.0 * f);
32
+ return mix(
33
+ mix(hash12(i), hash12(i + vec2(1.0, 0.0)), f.x),
34
+ mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), f.x),
35
+ f.y
36
+ );
37
+ }
38
+
39
+ vec4 transition(vec2 uv) {
40
+ if (progress <= 0.0) return getFromColor(uv);
41
+ if (progress >= 1.0) return getToColor(uv);
42
+
43
+ float n = max(floor(cells + 0.5), 1.0);
44
+ // aspect-correct square tiles, centered on the frame
45
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
46
+ vec2 g = p * n + 0.5;
47
+ vec2 cell = floor(g);
48
+ vec2 q = fract(g);
49
+ // each tile is mirrored at random, so its two arcs (centered on opposite corners) link up with its neighbors' in two ways
50
+ if (hash12(cell + 17.0) > 0.5) q.x = 1.0 - q.x;
51
+ // distance to the nearest arc, in tiles: continuous across the tiles' edges, at most 0.5 (at the corners)
52
+ float d = min(abs(length(q) - 0.5), abs(length(q - 1.0) - 0.5));
53
+
54
+ // when the paths reach this point: from the middle outward, made irregular by a noise
55
+ float T = clamp(length(p) / (0.5 * length(vec2(ratio, 1.0))) + 0.4 * (vnoise(p * 3.0 + 4.0) - 0.5), 0.0, 1.0);
56
+ float lag = 0.8 * clamp(spread, 0.0, 1.0);
57
+ // every point is fully covered at progress 0.95
58
+ float s = clamp((progress - lag * T) / (0.95 - lag), 0.0, 1.0);
59
+ // in tiles: the paths are first drawn as thin lines, then the bands widen past the tiles' corners
60
+ float aa = AA * n;
61
+ float k = clamp((s - 0.25) / 0.75, 0.0, 1.0);
62
+ float w = STROKE * smoothstep(0.0, 0.3, s) + (0.5 + LINE * n + 3.0 * aa - STROKE) * k * k;
63
+ // signed distance to the edge of the bands (negative inside), in tiles
64
+ float e = d - w;
65
+
66
+ float band = 1.0 - smoothstep(-2.0 * aa, 0.0, e);
67
+ // outside the bands: a thin outline on their edge and a soft shadow, fading in with the line
68
+ float gap = max(e + aa, 0.0);
69
+ float fall = 1.0 - smoothstep(0.0, SHADOW * n, gap);
70
+ float edge = max(0.8 * (1.0 - smoothstep(LINE * n, LINE * n + 2.0 * aa, gap)), 0.4 * fall * fall);
71
+ float shade = clamp(outline, 0.0, 1.0) * smoothstep(0.0, STROKE, w) * edge;
72
+
73
+ vec4 a = getFromColor(uv);
74
+ a.rgb *= 1.0 - shade;
75
+ vec4 b = getToColor(uv);
76
+ // mixed premultiplied, so transparent images do not bleed their color
77
+ vec4 o = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), band);
78
+ return o.a > 0.0 ? vec4(o.rgb / o.a, o.a) : vec4(0.0);
79
+ }
@@ -0,0 +1,112 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image is thrown away like a rigid card, tumbling end over end with a slight spin as it flies off into the distance in perspective, its darker back showing on every flip and its soft shadow shrinking on the incoming image behind it
4
+ // Tags: 3d, rotate, flip, card, perspective
5
+
6
+ // @range(-4, 4) Number of turns end over end, negative to tumble the other way
7
+ uniform float flips; // = 2.0
8
+ // @range(-1, 1) Turns of the secondary spin around the line of sight
9
+ uniform float spin; // = 0.15
10
+ // @param Where the card flies toward on screen, in frame heights from the center
11
+ uniform vec2 direction; // = vec2(0.0, 0.3)
12
+ // @range(0.1, 1) Strength of the perspective
13
+ uniform float perspective; // = 0.6
14
+ // @range(0, 1) Shading of the card as it turns, darkness of its back and of its shadow
15
+ uniform float shading; // = 0.7
16
+
17
+ const float PI = 3.141592653589793;
18
+ // width of the anti-aliased card edges, in frame heights
19
+ const float EDGE = 0.0015;
20
+ // direction toward the light: above, to the right, in front
21
+ const vec3 LIGHT = vec3(0.348, 0.696, -0.628);
22
+
23
+ // rotates v around the line of sight
24
+ vec3 roll(vec3 v, float c, float s) {
25
+ return vec3(c * v.x - s * v.y, s * v.x + c * v.y, v.z);
26
+ }
27
+
28
+ // signed distance to the card's rectangle, in its plane
29
+ float cardDistance(vec2 q) {
30
+ vec2 e = abs(q) - vec2(0.5 * ratio, 0.5);
31
+ return max(e.x, e.y);
32
+ }
33
+
34
+ // casts the ray d from the eye onto the card's plane, rel being the card's center from the eye:
35
+ // (the point hit in the card's axes, the distance along d), or a negative distance when it misses
36
+ vec3 castOnCard(vec3 d, vec3 rel, vec3 U, vec3 V, vec3 N) {
37
+ float dn = dot(d, N);
38
+ if (abs(dn) < 1e-6) return vec3(0.0, 0.0, -1.0);
39
+ float k = dot(rel, N) / dn;
40
+ vec3 h = k * d - rel;
41
+ return vec3(dot(h, U), dot(h, V), k);
42
+ }
43
+
44
+ vec2 cardUv(vec2 q) {
45
+ return clamp(vec2(q.x / ratio, q.y) + 0.5, 0.0, 1.0);
46
+ }
47
+
48
+ vec4 transition(vec2 uv) {
49
+ // the card is gone a little before the end
50
+ float t = clamp(progress / 0.95, 0.0, 1.0);
51
+ // its size on screen shrinks faster and faster, down to a few percent
52
+ float size = exp(-2.8 * t * t * (0.4 + 0.6 * t));
53
+ float away = 1.0 - size;
54
+ // it spins at its own pace, starting smoothly
55
+ float turn = t * t * (3.0 - 2.0 * t);
56
+ float a = 2.0 * PI * flips * turn;
57
+ float r = 2.0 * PI * spin * turn;
58
+ float cr = cos(r), sr = sin(r);
59
+ // end over end around its horizontal axis, then around the line of sight
60
+ vec3 U = roll(vec3(1.0, 0.0, 0.0), cr, sr);
61
+ vec3 V = roll(vec3(0.0, cos(a), sin(a)), cr, sr);
62
+ vec3 N = roll(vec3(0.0, -sin(a), cos(a)), cr, sr);
63
+
64
+ // the camera, at dist in front of the plane z = 0, sees the frame at rest on it
65
+ float dist = 1.0 / clamp(perspective, 0.1, 1.0);
66
+ // the card's center, seen at direction * away on screen while it goes away, with a slight rise
67
+ vec2 seen = direction * away + vec2(0.0, 0.12 * t * (1.0 - t));
68
+ vec3 rel = vec3(seen / size, dist / size);
69
+ float fade = 1.0 - smoothstep(0.8, 1.0, t);
70
+ float shadowAmount = 0.6 * shading * sqrt(size) * fade;
71
+
72
+ vec2 p = vec2((uv.x - 0.5) * ratio, uv.y - 0.5);
73
+ vec4 color = getToColor(uv);
74
+
75
+ // the soft shadow on the incoming image, cast down and to the left, shrinking with the card
76
+ if (shadowAmount > 0.0) {
77
+ vec3 ds = vec3(p - vec2(-0.05, -0.08) * min(4.0 * t, 1.0) * size, dist);
78
+ vec3 hs = castOnCard(ds, rel, U, V, N);
79
+ if (hs.z > 0.0) {
80
+ float blur = 0.005 + 0.06 * min(3.0 * t, 1.0) * size;
81
+ float sd = cardDistance(hs.xy) * max(abs(dot(ds, N)) / length(ds), 0.05) / hs.z;
82
+ float sh = (1.0 - smoothstep(-blur, blur, sd)) * getFromColor(cardUv(hs.xy)).a;
83
+ color.rgb *= 1.0 - shadowAmount * sh;
84
+ }
85
+ }
86
+
87
+ // cast the ray onto the card
88
+ vec3 d = vec3(p, dist);
89
+ vec3 hit = castOnCard(d, rel, U, V, N);
90
+ if (hit.z <= 0.0) return color;
91
+ float dn = dot(d, N);
92
+ // anti-aliased edges: a screen pixel covers more of the card when it is far or seen at a grazing angle
93
+ float grazing = max(abs(dn) / length(d), 0.05);
94
+ float e = EDGE * min(20.0 * t, 1.0) * hit.z / grazing;
95
+ float m = clamp(0.5 - cardDistance(hit.xy) / max(e, 1e-6), 0.0, 1.0) * fade;
96
+ if (m <= 0.0) return color;
97
+
98
+ vec4 card = getFromColor(cardUv(hit.xy));
99
+ // the side facing the camera: the front, or the back which shows the image through, darker and duller
100
+ bool front = dn > 0.0;
101
+ vec3 facing = front ? -N : N;
102
+ float lit = min((0.35 + 0.65 * max(dot(facing, LIGHT), 0.0)) / (0.35 + 0.65 * -LIGHT.z), 1.0);
103
+ float shade = mix(1.0, lit * (front ? 1.0 : 0.55), shading);
104
+ if (!front) card.rgb = mix(card.rgb, vec3(dot(card.rgb, vec3(0.299, 0.587, 0.114))), 0.4 * shading);
105
+ // a glint as the card turns through the light, a light added to the image
106
+ float glint = pow(max(dot(facing, normalize(LIGHT - normalize(d))), 0.0), 60.0);
107
+ card.rgb = card.rgb * shade + 0.35 * shading * glint * smoothstep(0.0, 0.2, t);
108
+ if (m >= 1.0) return card;
109
+ // blend premultiplied, so that a transparent layer gives no color to the other one
110
+ vec4 mixed = mix(vec4(color.rgb * color.a, color.a), vec4(card.rgb * card.a, card.a), m);
111
+ return mixed.a > 0.0 ? vec4(mixed.rgb / mixed.a, mixed.a) : vec4(0.0);
112
+ }
@@ -1,20 +1,76 @@
1
1
  // Author: Paweł Płóciennik
2
2
  // License: MIT
3
- // Description: Ripples spread from the center like a drop falling into water, crossfading to the incoming image
4
- // Tags: ripple, water, blend
5
- // @param Frequency of the ripples
3
+ // Description: A drop falls into the image like into still water: round ripples spread out from where it hits, bending the image with glints on their slopes, the incoming image shows up inside the leading ripple, and the water calms down
4
+ // Tags: ripple, water, refraction, circle
5
+ // @range(10, 80) Frequency of the ripples: higher makes them closer together
6
6
  uniform float amplitude; // = 30
7
- // @param Speed of the ripples
7
+ // @range(0, 80) Speed of the ripples as they run outward through the spreading rings
8
8
  uniform float speed; // = 30
9
+ // @param Where the drop falls, in texture coordinates
10
+ uniform vec2 center; // = vec2(0.5, 0.5)
11
+ // @range(0, 0.08) How far the ripples bend the image, in frame heights
12
+ uniform float refraction; // = 0.015
13
+ // @range(0, 1) Brightness of the glints on the ripples
14
+ uniform float highlight; // = 0.5
9
15
 
10
- vec4 transition(vec2 p) {
11
- vec2 dir = p - vec2(.5);
12
- float dist = length(dir);
16
+ // mirror the coordinates back into the frame
17
+ vec2 mirror(vec2 v) {
18
+ return 1.0 - abs(1.0 - mod(v, 2.0));
19
+ }
20
+
21
+ // height of the water, from -1 to 1, at a distance s inside the front
22
+ float wave(float s, float k, float lambda, float t) {
23
+ // it rises just ahead of the front and dies out a few ripples behind it
24
+ float env = smoothstep(-0.3 * lambda, 0.6 * lambda, s) * exp(-s / (3.5 * lambda));
25
+ // the ripples run out through the train, faster than the train itself spreads
26
+ return env * sin(k * s + speed * t);
27
+ }
28
+
29
+ vec4 transition(vec2 uv) {
30
+ if (progress <= 0.0) return getFromColor(uv);
31
+ if (progress >= 1.0) return getToColor(uv);
32
+
33
+ float k = 2.0 * max(amplitude, 1.0);
34
+ float lambda = 6.2831853 / k;
35
+ // measured in square pixels, so the ripples are round
36
+ vec2 q = (uv - center) * vec2(ratio, 1.0);
37
+ float r = length(q);
38
+ vec2 dir = r > 0.0 ? q / r : vec2(0.0);
39
+ // the farthest corner of the frame
40
+ vec2 far = max(center, 1.0 - center) * vec2(ratio, 1.0);
41
+ float R = length(far);
42
+
43
+ // the incoming image shows from a little behind the front, with a soft edge
44
+ float edge = 0.35 * lambda;
45
+ float soft = 0.1 * lambda;
46
+ // the front spreads out, slowing down a little, from just before the drop hits until
47
+ // its revealed area is past the farthest corner
48
+ float t = progress;
49
+ float e = mix(t, 1.0 - (1.0 - t) * (1.0 - t), 0.4);
50
+ float front = mix(-0.3 * lambda, R + edge + soft + 0.01, e);
51
+ float s = front - r;
52
+
53
+ // the water calms down at the end
54
+ float calm = 1.0 - smoothstep(0.55, 1.0, t);
55
+ calm *= calm;
56
+ // slope of the water along the radius, normalized to at most about 1
57
+ // (one-sided at the very center)
58
+ float d = 0.02 * lambda;
59
+ float r0 = max(r - d, 0.0);
60
+ float slope = calm * (wave(front - r - d, k, lambda, t) - wave(front - r0, k, lambda, t)) / ((r + d - r0) * k);
61
+ vec2 offset = dir * slope * refraction / vec2(ratio, 1.0);
62
+
63
+ vec4 ca = getFromColor(mirror(uv - offset));
64
+ vec4 cb = getToColor(mirror(uv - offset));
65
+ float m = smoothstep(edge - soft, edge + soft, s);
66
+ // mixed premultiplied, so transparent images do not bleed their color
67
+ vec4 c = mix(vec4(ca.rgb * ca.a, ca.a), vec4(cb.rgb * cb.a, cb.a), m);
13
68
 
14
- if (dist > progress) {
15
- return mix(getFromColor( p), getToColor( p), progress);
16
- } else {
17
- vec2 offset = dir * sin(dist * amplitude - progress * speed);
18
- return mix(getFromColor( p + offset), getToColor( p), progress);
19
- }
69
+ // the slopes facing the light glint, the ones facing away darken a little,
70
+ // and the crests are a little brighter than the troughs
71
+ float h = calm * wave(s, k, lambda, t);
72
+ float lit = -dot(dir, normalize(vec2(-0.6, 0.8))) * slope;
73
+ float glint = highlight * (0.2 * h + 0.6 * smoothstep(0.2, 0.9, lit) - 0.3 * smoothstep(0.2, 0.9, -lit));
74
+ c.rgb = clamp(c.rgb + glint * c.a, 0.0, c.a);
75
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
20
76
  }
@@ -0,0 +1,153 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A breaking wave crashes across the frame, its lip curling over in front of its face and throwing foam and spray ahead, its shadow darkening the outgoing image; the incoming image is left behind it, tinted and bent by the water, clearing as the wave passes
4
+ // Tags: water, wave, ocean, foam, directional, reveal
5
+
6
+ // @param Direction the wave travels toward
7
+ uniform vec2 direction; // = vec2(1.0, 0.0)
8
+ // @range(0.1, 0.45) Size of the curling lip, in wave heights: how far it overhangs ahead of the face
9
+ uniform float curl; // = 0.3
10
+ // @range(0, 1) Amount of foam on the crest and spray thrown ahead of it
11
+ uniform float foam; // = 0.6
12
+ // @range(0, 0.1) How much the water bends the incoming image behind the wave
13
+ uniform float refraction; // = 0.04
14
+ // @color Color of the water tinting the incoming image behind the wave (its alpha is its strength)
15
+ uniform vec4 water; // = vec4(0.05, 0.36, 0.46, 0.75)
16
+ // @color Color of the foam and spray (its alpha is its strength)
17
+ uniform vec4 foamColor; // = vec4(1.0, 1.0, 1.0, 1.0)
18
+
19
+ const float PI = 3.141592653589793;
20
+ // half width of the antialiased edges, in wave heights
21
+ const float AA = 0.002;
22
+ // how far the base of the face trails behind its top, in wave heights
23
+ const float TRAIL = 0.35;
24
+ // how far behind the face the water still tints the incoming image, in wave heights
25
+ const float BAND = 0.4;
26
+ // how far ahead of the lip the spray reaches, in wave heights
27
+ const float REACH = 0.25;
28
+
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
+ float vnoise(vec2 v) {
36
+ vec2 i = floor(v);
37
+ vec2 f = fract(v);
38
+ f = f * f * (3.0 - 2.0 * f);
39
+ return mix(
40
+ mix(hash12(i), hash12(i + vec2(1.0, 0.0)), f.x),
41
+ mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), f.x),
42
+ f.y
43
+ );
44
+ }
45
+
46
+ // folds coordinates back into the frame, so a displaced image never shows its clamped edges
47
+ vec2 mirror(vec2 v) {
48
+ return 1.0 - abs(1.0 - mod(v, 2.0));
49
+ }
50
+
51
+ // droplets scattered in cells, one per cell at most, kept inside their cell
52
+ float droplets(vec2 q, float cell, float density, float seed) {
53
+ vec2 g = q / cell;
54
+ vec2 id = floor(g);
55
+ if (hash12(id + seed) >= density) return 0.0;
56
+ float r = 0.1 + 0.2 * hash12(id + seed + 4.7);
57
+ vec2 c = id + 0.5 + (0.45 - r) * (vec2(hash12(id + seed + 1.3), hash12(id + seed + 8.1)) * 2.0 - 1.0);
58
+ float px = AA / cell;
59
+ return 1.0 - smoothstep(r - px, r + px, length(g - c));
60
+ }
61
+
62
+ vec4 transition(vec2 uv) {
63
+ if (progress <= 0.0) return getFromColor(uv);
64
+ if (progress >= 1.0) return getToColor(uv);
65
+ float t = progress;
66
+
67
+ vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
68
+ // the crest points up the frame, or to the left when the wave travels straight up or down
69
+ vec2 up = vec2(-dir.y, dir.x);
70
+ if (up.y < 0.0 || (up.y == 0.0 && up.x > 0.0)) up = -up;
71
+ // half extents of the frame along the travel and across it, in frame heights
72
+ float e = 0.5 * (abs(dir.x) * ratio + abs(dir.y));
73
+ float w = 0.5 * (abs(up.x) * ratio + abs(up.y));
74
+ // in wave heights: u along the travel, v from the trough (0) to the crest (1)
75
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0) / (2.0 * w);
76
+ vec2 q = vec2(dot(p, dir), dot(p, up) + 0.5);
77
+ float E = e / (2.0 * w);
78
+
79
+ float R = max(curl, 0.01);
80
+ // radius of the hollow at the back of the curl, where it meets the face
81
+ float Rb = 0.5 * R;
82
+ // the lip pitches forward, then curls further down as the wave travels
83
+ float tipAngle = PI * (0.08 - 0.5 * smoothstep(0.0, 0.85, t));
84
+ // the wave sweeps from fully ahead of the frame, spray included, to fully past it, tinted water included
85
+ float travel = mix(t, t * t * (3.0 - 2.0 * t), 0.25);
86
+ vec2 C = vec2(mix(-E - R - REACH, E + Rb + TRAIL + BAND, travel), 1.02 - R);
87
+
88
+ // polar coordinates around the center of the curl
89
+ vec2 d = q - C;
90
+ // atan is undefined at the very center
91
+ if (d.x == 0.0) d.x = 1e-6;
92
+ float r = length(d);
93
+ float ang = atan(d.y, d.x);
94
+ // the inner surface of the curl spirals in from the tip of the lip (zero thickness) to the back of the hollow
95
+ float k = clamp((ang - tipAngle) / (PI - tipAngle), 0.0, 1.0);
96
+ float rIn = R - (R - Rb) * (1.0 - (1.0 - k) * (1.0 - k));
97
+ bool curled = ang >= tipAngle;
98
+ // the face below the curl: vertical where it meets the hollow, its base trailing behind
99
+ float s = 1.0 - clamp(q.y / C.y, 0.0, 1.0);
100
+ float face = C.x - Rb - TRAIL * s * s;
101
+ float behind = face - q.x; // > 0 behind the face
102
+
103
+ float wet;
104
+ if (curled) {
105
+ wet = smoothstep(-AA, AA, r - rIn) * (ang > 0.5 * PI ? 1.0 : 1.0 - smoothstep(-AA, AA, r - R));
106
+ } else {
107
+ wet = smoothstep(-AA, AA, behind);
108
+ }
109
+ // the lip: the curl in front of the top of the wave
110
+ float lip = curled ? 1.0 - smoothstep(0.5 * PI - 0.3, 0.5 * PI + 0.5, ang) : 0.0;
111
+
112
+ float n = vnoise(q * vec2(14.0, 10.0) + vec2(-9.0 * t, 3.0 * t));
113
+
114
+ // outgoing image, darkened in the hollow and in the shadow of the overhang just ahead of it
115
+ vec4 a = getFromColor(uv);
116
+ float gap = max(min(r - R, -behind), 0.0);
117
+ float shade = 0.55 * exp(-gap / 0.1) * (1.0 - smoothstep(0.0, REACH, gap)) * smoothstep(0.0, 0.6, q.y) * (1.0 - smoothstep(C.y + 0.2 * R, C.y + 1.1 * R, q.y));
118
+ shade += 0.25 * (1.0 - smoothstep(0.0, R, r));
119
+ a.rgb *= 1.0 - shade;
120
+ // spray thrown ahead of the crest, drifting forward and falling, and a mist along it
121
+ float fwd = max(r - R, 0.0);
122
+ float zone = smoothstep(tipAngle - 0.4, tipAngle + 0.2, ang) * (1.0 - smoothstep(0.0, REACH, fwd)) * step(0.0, r - R);
123
+ // stretched along the throw, so the droplets streak forward
124
+ vec2 sq = (d - t * vec2(0.5, -0.25)) * vec2(0.55, 1.0);
125
+ float thin = exp(-fwd / 0.12);
126
+ float spray = droplets(sq, 0.02, foam * thin, 1.0) + 0.6 * droplets(sq * 1.6 + 3.1, 0.02, foam * thin, 7.0);
127
+ // the mist hugs the outside of the lip only
128
+ float mist = foam * n * n * exp(-fwd / 0.06) * (1.0 - smoothstep(0.0, REACH, fwd)) * smoothstep(-AA, AA, r - R) * smoothstep(tipAngle, tipAngle + 0.3, ang);
129
+ a.rgb = mix(a.rgb, foamColor.rgb, foamColor.a * clamp(spray * zone + mist, 0.0, 1.0));
130
+
131
+ // incoming image behind the face, bent and tinted by the water, clearing further behind
132
+ float band = max(1.0 - smoothstep(0.05, BAND, behind), lip);
133
+ float bend = refraction * band * band;
134
+ vec2 off = bend * (dir * sin(17.0 * q.y + 2.0 * sin(9.0 * q.x) - 6.0 * t) + up * cos(13.0 * q.x - 5.0 * t));
135
+ vec4 b = getToColor(mirror(uv + off * 2.0 * w / vec2(ratio, 1.0)));
136
+ float luma = dot(b.rgb, vec3(0.299, 0.587, 0.114));
137
+ // lit near the top of the face and through the thin lip, darker on the underside of the lip
138
+ vec3 tinted = water.rgb * (0.4 + 0.9 * luma) * (1.0 + 0.6 * q.y);
139
+ tinted += 0.18 * lip * (1.0 - k) * vec3(0.5, 1.0, 0.9);
140
+ tinted *= 1.0 - 0.35 * lip * (1.0 - smoothstep(0.0, 0.06, r - rIn));
141
+ // a bright line along the surface of the face, fading up into the hollow
142
+ tinted += 0.35 * (curled ? k * (1.0 - smoothstep(0.0, 0.015, r - rIn)) : 1.0 - smoothstep(0.0, 0.015, behind)) * vec3(0.7, 0.95, 1.0);
143
+ b.rgb = mix(b.rgb, tinted, water.a * band);
144
+
145
+ // foam: whitewater along the outer edge of the lip, and churning at the base of the face
146
+ float crest = curled ? (1.0 - smoothstep(0.01, 0.02 + 0.12 * n, abs(R - r))) * smoothstep(tipAngle, tipAngle + 0.4, ang) * (1.0 - smoothstep(0.5 * PI + 0.2, 0.5 * PI + 0.8, ang)) : 0.0;
147
+ float churn = (1.0 - smoothstep(0.0, 0.15 + 0.1 * n, q.y)) * (1.0 - smoothstep(0.0, 0.3, abs(behind))) * smoothstep(0.3, 0.7, n);
148
+ b.rgb = mix(b.rgb, foamColor.rgb, foamColor.a * clamp(foam * 1.5 * (crest + churn), 0.0, 1.0));
149
+
150
+ // mixed premultiplied, so transparent images do not bleed their color
151
+ vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), wet);
152
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
153
+ }