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,36 +1,139 @@
1
1
  // Author: hong
2
2
  // License: MIT
3
- // Description: The outgoing image turns like a book page from right to left, revealing the incoming one
3
+ // Description: The right half of the outgoing image is a book page that turns over from right to left on the spine at the middle of the frame, curling near its free edge, its back bringing the left half of the incoming image
4
4
  // Tags: page, flip, 3d
5
5
 
6
- // Avoids dividing by zero when the page is edge-on (progress = 0.5).
7
- float nonZero(float x) {
8
- return abs(x) < 1e-4 ? (x < 0.0 ? -1e-4 : 1e-4) : x;
6
+ // @range(0, 1) Strength of the perspective: the page grows as it lifts toward the viewer
7
+ uniform float perspective; // = 0.5
8
+ // @range(0, 1) How much the page darkens as it turns away from the light, and the shadows it casts
9
+ uniform float shading; // = 0.6
10
+ // @range(0, 1) How much the page bends near its free edge, which trails behind as it turns
11
+ uniform float curl; // = 0.5
12
+
13
+ const float PI = 3.141592653589793;
14
+ // width of the anti-aliased edges, as a part of the frame's height
15
+ const float EDGE = 0.0015;
16
+ // part of the page's width that curls
17
+ const float CURL_PART = 0.45;
18
+ // direction of the light, in (x, height toward the viewer)
19
+ const vec2 LIGHT = vec2(-0.447214, 0.894427);
20
+
21
+ float cross2(vec2 a, vec2 b) {
22
+ return a.x * b.y - a.y * b.x;
9
23
  }
10
24
 
11
- vec2 skewRight(vec2 p) {
12
- float skewX = (p.x - progress)/nonZero(0.5 - progress) * 0.5;
13
- float skewY = (p.y - 0.5)/(0.5 + progress * (p.x - 0.5) / 0.5)* 0.5 + 0.5;
14
- return vec2(skewX, skewY);
25
+ // the page's angle, 0 lying on the right to PI lying on the left: eased, but never at rest
26
+ float pageAngle() {
27
+ float p = clamp(progress, 0.0, 1.0);
28
+ return PI * p * (0.35 + p * (1.95 - 1.3 * p));
15
29
  }
16
30
 
17
- vec2 skewLeft(vec2 p) {
18
- float skewX = (p.x - 0.5)/nonZero(progress - 0.5) * 0.5 + 0.5;
19
- float skewY = (p.y - 0.5) / (0.5 + (1.0 - progress ) * (0.5 - p.x) / 0.5) * 0.5 + 0.5;
20
- return vec2(skewX, skewY);
31
+ // The page is seen in a cross-section across the spine, in (x, height toward the viewer) from the spine:
32
+ // a straight part at angle a from the spine, then, when k is not 0, an arc of curvature k centered on c up to its free edge,
33
+ // extruded along y. Returns the nearest point of the page hit by the ray from eye along dir:
34
+ // (ray length, distance along the page, angle there), with a negative ray length when it is missed.
35
+ vec3 hitPage(vec2 eye, vec2 dir, float a, float k, float straight, vec2 c, float w) {
36
+ vec3 best = vec3(-1.0, 0.0, 0.0);
37
+ vec2 d = vec2(cos(a), sin(a));
38
+ // the straight part
39
+ float den = cross2(d, dir);
40
+ if (abs(den) > 1e-7) {
41
+ float u = cross2(eye, dir) / den;
42
+ float t = cross2(eye, d) / den;
43
+ if (t > 0.0 && u >= 0.0 && u <= straight) best = vec3(t, u, a);
44
+ }
45
+ if (k != 0.0) {
46
+ float r = 1.0 / k;
47
+ vec2 oc = eye - c;
48
+ float qa = dot(dir, dir);
49
+ float qb = dot(oc, dir);
50
+ float disc = qb * qb - qa * (dot(oc, oc) - r * r);
51
+ if (disc >= 0.0) {
52
+ float sq = sqrt(disc);
53
+ for (int i = 0; i < 2; i++) {
54
+ float t = (-qb + (i == 0 ? -sq : sq)) / qa;
55
+ if (t > 0.0 && (best.x < 0.0 || t < best.x)) {
56
+ // (sin(b), -cos(b)) where b is the angle of the page at that point
57
+ vec2 v = (oc + t * dir) * k;
58
+ float db = atan(v.x, -v.y) - a;
59
+ db -= 2.0 * PI * floor((db + PI) / (2.0 * PI));
60
+ float s = db / k;
61
+ if (s >= 0.0 && s <= w - straight) best = vec3(t, straight + s, a + db);
62
+ }
63
+ }
64
+ }
65
+ }
66
+ return best;
21
67
  }
22
68
 
23
- vec4 addShade() {
24
- float shadeVal = max(0.7, abs(progress - 0.5) * 2.0);
25
- return vec4(vec3(shadeVal ), 1.0);
69
+ // the point of the curled part of the page where its angle is b
70
+ vec2 curlPoint(vec2 c, float k, float b) {
71
+ return c + vec2(sin(b), -cos(b)) / k;
26
72
  }
27
73
 
28
- vec4 transition (vec2 p) {
29
- float pr = step(1.0 - progress, p.x);
74
+ vec4 transition (vec2 uv) {
75
+ float a = pageAngle();
76
+ float lift = sin(a);
77
+ // half the frame's width: the page's width
78
+ float w = 0.5 * ratio;
79
+ float x = uv.x * ratio - w;
80
+ // the viewer is above the spine, the page lifting toward it
81
+ float dist = w * (1.0 + 1.5 / max(perspective, 0.01));
82
+ vec2 eye = vec2(0.0, dist);
83
+ vec2 dir = vec2(x, -dist);
84
+
85
+ // the shape of the page: straight, then curled with its free edge trailing behind (a negative curvature)
86
+ vec2 d = vec2(cos(a), sin(a));
87
+ float k = -clamp(curl, 0.0, 1.0) * lift / (CURL_PART * w);
88
+ if (abs(k) * CURL_PART * w <= 1e-4) k = 0.0;
89
+ float straight = k != 0.0 ? (1.0 - CURL_PART) * w : w;
90
+ vec2 c = straight * d + vec2(-d.y, d.x) / (k != 0.0 ? k : 1.0);
91
+ vec2 bend = straight * d;
92
+ vec2 middle = k != 0.0 ? curlPoint(c, k, a + 0.5 * k * (w - straight)) : bend;
93
+ vec2 edge = k != 0.0 ? curlPoint(c, k, a + k * (w - straight)) : bend;
30
94
 
31
- if (p.x < 0.5) {
32
- return mix(getFromColor(p), getToColor(skewLeft(p)) * addShade(), pr);
33
- } else {
34
- return mix(getFromColor(skewRight(p)) * addShade(), getToColor(p), pr);
95
+ // anti-aliased edges, only once the page has left the frame's plane, so that it covers it exactly at both ends
96
+ float aa = EDGE * min(20.0 * lift, 1.0);
97
+ vec4 img = vec4(0.0);
98
+ float m = 0.0;
99
+ vec3 hit = hitPage(eye, dir, a, k, straight, c, w);
100
+ if (hit.x > 0.0) {
101
+ float t = hit.x;
102
+ float u = hit.y;
103
+ float b = hit.z;
104
+ vec2 pt = eye + t * dir;
105
+ // the height on the page, magnified as it comes closer (its top and bottom edges are out of the frame)
106
+ float y = clamp(0.5 + (uv.y - 0.5) * t, 0.0, 1.0);
107
+ // near its free edge, the distance to it on the screen
108
+ float edgeX = edge.x * dist / max(dist - edge.y, 1e-4);
109
+ m = aa > 0.0 && u > (k != 0.0 ? straight : 0.5 * w) ? clamp(abs(x - edgeX) / aa, 0.0, 1.0) : 1.0;
110
+ vec2 normal = vec2(-sin(b), cos(b));
111
+ bool front = dot(normal, eye - pt) > 0.0;
112
+ img = front
113
+ ? getFromColor(vec2(clamp(w + u, w, ratio) / ratio, y))
114
+ : getToColor(vec2(clamp(w - u, 0.0, w) / ratio, y));
115
+ // lit from the upper left: brighter as it turns toward the light, darker as it turns away, with a soft crease along the spine
116
+ float diffuse = max(dot(front ? normal : -normal, LIGHT), 0.0) / LIGHT.y;
117
+ float shade = mix(1.0, 0.25 + 0.75 * diffuse, shading);
118
+ shade *= 1.0 - 0.35 * shading * lift * exp(-u / (0.04 * w));
119
+ img.rgb *= shade;
120
+ if (m >= 1.0) return img;
35
121
  }
122
+
123
+ // the pages beneath: the outgoing image on the left, the incoming one on the right
124
+ vec4 color = x < 0.0 ? getFromColor(uv) : getToColor(uv);
125
+ // the lifted page shades them, the more it hides of the sky (and so the more near the spine and its free edge)
126
+ vec2 toEdge = edge - vec2(x, 0.0);
127
+ float cosEdge = toEdge.x / max(length(toEdge), 1e-6);
128
+ float blocked = 0.5 * abs((x < 0.0 ? 1.0 : -1.0) - cosEdge);
129
+ float shadow = blocked * blocked * (3.0 - 2.0 * blocked);
130
+ // and casts a shadow, the light coming from the upper left, softer as the page is higher
131
+ float slope = -LIGHT.x / LIGHT.y;
132
+ vec3 reach = vec3(bend.x, middle.x, edge.x) + slope * vec3(bend.y, middle.y, edge.y);
133
+ float lo = min(0.0, min(reach.x, min(reach.y, reach.z)));
134
+ float hi = max(0.0, max(reach.x, max(reach.y, reach.z)));
135
+ float soft = max(0.25 * edge.y, 1e-5);
136
+ shadow = max(0.5 * shadow, 0.85 * clamp(min(x - lo, hi - x) / soft + 0.5, 0.0, 1.0) * min(4.0 * lift, 1.0));
137
+ color.rgb *= 1.0 - shading * shadow;
138
+ return mix(color, img, m);
36
139
  }
@@ -0,0 +1,216 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The camera pulls back to show the outgoing image as a print hung by two clothespins on a line in front of a wall, the line is pulled sideways and carries it away while the incoming print slides in, both prints swinging and tilting like hanging paper, then the camera moves back in on the incoming print until it fills the frame
4
+ // Tags: 3d, perspective, slide, swing, paper, directional
5
+
6
+ // @param Way the line is pulled: 1 brings the incoming print in from the right, -1 from the left
7
+ uniform float direction; // = 1.0
8
+ // @range(0, 1) How much the prints swing and tilt as the line moves
9
+ uniform float sway; // = 0.5
10
+ // @range(0.4, 0.95) Size of the prints when the camera is farthest, as a part of the frame
11
+ uniform float size; // = 0.72
12
+ // @color Color of the wall behind the line
13
+ uniform vec4 background; // = vec4(0.86, 0.84, 0.8, 1.0)
14
+ // @color Color of the line
15
+ uniform vec4 lineColor; // = vec4(0.42, 0.34, 0.26, 1.0)
16
+ // @color Color of the clothespins
17
+ uniform vec4 pinColor; // = vec4(0.84, 0.68, 0.47, 1.0)
18
+
19
+ const float FOCAL = 2.0; // distance from the camera to a print when it fills the frame
20
+ const float GAP = 0.35; // space between two prints on the line, in frame heights
21
+ const float WALL = 0.14; // distance from the line to the wall behind it
22
+ const float ROPE = 0.0055; // half thickness of the line
23
+ const vec2 PIN = vec2(0.021, 0.072); // half size of a clothespin
24
+ const float PIN_Y = -0.01; // center of a clothespin below the top edge of its print
25
+ const float AA = 0.0015; // width of the antialiased edges, in frame heights
26
+ const vec3 LIGHT = vec3(-0.28, 0.48, 0.83); // toward the light: above, a bit on the left, in front
27
+ const float PIN_X = 0.32; // clothespins from the center of their print, in print widths
28
+ const int STEPS = 32; // steps of the swing simulation over the whole transition
29
+
30
+ // the line moves between these progress values
31
+ const float SLIDE_START = 0.1;
32
+ const float SLIDE_END = 0.86;
33
+
34
+ vec4 premultiply(vec4 c) {
35
+ return vec4(c.rgb * c.a, c.a);
36
+ }
37
+
38
+ // time of the line's move at p, from 0 to 1
39
+ float slideTime(float p) {
40
+ return clamp((p - SLIDE_START) / (SLIDE_END - SLIDE_START), 0.0, 1.0);
41
+ }
42
+
43
+ // part of its travel done (smootherstep of the time)
44
+ float slideAmount(float u) {
45
+ return u * u * u * (u * (u * 6.0 - 15.0) + 10.0);
46
+ }
47
+
48
+ // acceleration of the travel at p, per progress squared
49
+ float slideAccel(float p) {
50
+ float u = slideTime(p);
51
+ float dur = SLIDE_END - SLIDE_START;
52
+ return 60.0 * u * (1.0 - u) * (1.0 - 2.0 * u) / (dur * dur);
53
+ }
54
+
55
+ // the sideways swing of the prints' bottoms, along the travel: a damped pendulum driven by the
56
+ // line's acceleration, lagging behind it at the start and overshooting at the stop
57
+ float swing(float p) {
58
+ const float OMEGA = 10.0; // about 1.6 swings over the transition
59
+ const float DAMP = 0.28;
60
+ const float STEP = 1.0 / float(STEPS);
61
+ float x = 0.0;
62
+ float v = 0.0;
63
+ // fixed steps, the last one cut at p, so that every frame follows the same curve
64
+ for (int i = 0; i < STEPS; i++) {
65
+ float t0 = float(i) * STEP;
66
+ float dt = clamp(p - t0, 0.0, STEP);
67
+ float a = slideAccel(t0 + 0.5 * dt) - OMEGA * OMEGA * x - 2.0 * DAMP * OMEGA * v;
68
+ v += a * dt;
69
+ x += v * dt;
70
+ }
71
+ // it settles as the camera moves back in
72
+ return x * (1.0 - smoothstep(0.7, 1.0, p));
73
+ }
74
+
75
+ // signed distance to a rounded box of half size b and corner radius r
76
+ float roundedBox(vec2 q, vec2 b, float r) {
77
+ vec2 d = abs(q) - b + r;
78
+ return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r;
79
+ }
80
+
81
+ // the point (u across, v down from the top edge) where the ray o + t d meets the plane of a print
82
+ // hanging from (cx, 0.5, 0) and swung back by psi around its top edge, and t
83
+ vec3 printHit(vec3 o, vec3 d, float cx, float psi) {
84
+ vec3 dn = vec3(0.0, -cos(psi), -sin(psi));
85
+ vec3 n = vec3(0.0, sin(psi), -cos(psi));
86
+ vec3 p0 = vec3(cx, 0.5, 0.0);
87
+ float t = dot(p0 - o, n) / dot(d, n);
88
+ vec3 q = o + d * t - p0;
89
+ return vec3(q.x, dot(q, dn), t);
90
+ }
91
+
92
+ // the bottom of the print bends sideways by bend frame heights
93
+ float bendShift(float v, float bend) {
94
+ float h = clamp(v, 0.0, 1.0);
95
+ return bend * h * (0.6 + 0.4 * h);
96
+ }
97
+
98
+ // signed distance to the paper (negative inside), in frame heights
99
+ float paperDist(vec2 uv, float bend) {
100
+ vec2 q = abs(vec2(uv.x - bendShift(uv.y, bend), uv.y - 0.5)) - vec2(0.5 * ratio, 0.5);
101
+ return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0);
102
+ }
103
+
104
+ // signed distance to the two clothespins of a print
105
+ float pinDist(vec2 uv) {
106
+ vec2 q = vec2(abs(uv.x) - PIN_X * ratio, uv.y - PIN_Y);
107
+ return roundedBox(q, PIN, 0.012);
108
+ }
109
+
110
+ // the print hanging at cx over col (premultiplied), then its clothespins
111
+ vec4 drawPrint(vec4 col, vec3 h, bool isFrom, float bend, float psi, float aa, float vis) {
112
+ vec2 lp = h.xy;
113
+ float d = paperDist(lp, bend);
114
+ float cov = clamp(0.5 - d / (h.z * aa), 0.0, 1.0);
115
+ if (cov > 0.0) {
116
+ vec2 st = clamp(vec2((lp.x - bendShift(lp.y, bend)) / ratio + 0.5, 1.0 - lp.y), 0.0, 1.0);
117
+ vec4 c = premultiply(isFrom ? getFromColor(st) : getToColor(st));
118
+ // the paper darkens as it swings back and bends, and under the clothespins
119
+ float shade = 1.0 - 1.2 * abs(sin(psi)) * lp.y - 0.35 * abs(bend) * lp.y;
120
+ float ps = pinDist(lp - vec2(0.006, 0.01));
121
+ shade -= 0.35 * vis * (1.0 - smoothstep(-0.004, 0.012, ps));
122
+ c.rgb *= clamp(shade, 0.0, 1.0);
123
+ col = c * cov + col * (1.0 - c.a * cov);
124
+ }
125
+ return col;
126
+ }
127
+
128
+ vec4 drawPins(vec4 col, vec3 h, float aa, float vis) {
129
+ vec2 lp = h.xy;
130
+ float d = pinDist(lp);
131
+ float cov = vis * clamp(0.5 - d / (h.z * aa), 0.0, 1.0);
132
+ if (cov > 0.0) {
133
+ // rounded wood, with the steel spring across it
134
+ float k = clamp((abs(lp.x) - PIN_X * ratio) / PIN.x, -1.0, 1.0);
135
+ vec3 c = pinColor.rgb * (0.62 + 0.45 * sqrt(1.0 - k * k));
136
+ float y = lp.y - PIN_Y;
137
+ float spring = 1.0 - smoothstep(0.004, 0.007, abs(y + 0.02));
138
+ c = mix(c, vec3(0.3, 0.31, 0.33) * (0.6 + 0.8 * sqrt(1.0 - k * k)), spring);
139
+ // the groove that grips the paper
140
+ c *= 1.0 - 0.3 * (1.0 - smoothstep(0.002, 0.005, abs(y - 0.012)));
141
+ vec4 pc = premultiply(vec4(c, pinColor.a));
142
+ col = pc * cov + col * (1.0 - pc.a * cov);
143
+ }
144
+ return col;
145
+ }
146
+
147
+ vec4 transition(vec2 uv) {
148
+ float p = progress;
149
+ float s = direction < 0.0 ? -1.0 : 1.0;
150
+ float sw = clamp(sway, 0.0, 1.0);
151
+
152
+ // the camera pulls back, then moves back in on the incoming print
153
+ float back = smoothstep(0.0, 0.3, p) * (1.0 - smoothstep(0.6, 1.0, p));
154
+ float zoom = mix(1.0, clamp(size, 0.1, 1.0), back);
155
+ float vis = smoothstep(0.0, 0.35, back);
156
+ vec3 o = vec3(0.0, 0.05 * back, FOCAL / zoom);
157
+ vec3 d = vec3((uv - 0.5) * vec2(ratio, 1.0), -FOCAL);
158
+ float aa = max(AA * min(1.0, 40.0 * back), 1e-6);
159
+
160
+ // the line carries the prints along
161
+ float u = slideTime(p);
162
+ float m = slideAmount(u);
163
+ float speed = 16.0 * u * u * (1.0 - u) * (1.0 - u);
164
+ float spacing = ratio + GAP;
165
+ float cFrom = -s * spacing * m;
166
+ float cTo = s * spacing * (1.0 - m);
167
+ // the bottoms lag behind and overshoot, and swing back in the wind of the move
168
+ float bend = s * 0.65 * sw * swing(p);
169
+ float psi = 0.45 * sw * speed;
170
+
171
+ vec3 hf = printHit(o, d, cFrom, psi);
172
+ vec3 ht = printHit(o, d, cTo, psi);
173
+
174
+ // the wall, seen around the prints (only behind their transparent parts at the ends),
175
+ // with the soft shadows of the prints, the pins and the line
176
+ vec4 col = premultiply(background);
177
+ float cover = max(
178
+ clamp(0.5 - paperDist(hf.xy, bend) / (hf.z * aa), 0.0, 1.0),
179
+ clamp(0.5 - paperDist(ht.xy, bend) / (ht.z * aa), 0.0, 1.0));
180
+ col *= mix(1.0, back, cover);
181
+ if (back > 0.0) {
182
+ vec3 w = o + d * ((o.z + WALL) / FOCAL);
183
+ vec3 sf = printHit(w, LIGHT, cFrom, psi);
184
+ vec3 st = printHit(w, LIGHT, cTo, psi);
185
+ float blur = 0.025;
186
+ float sh = 1.0 - smoothstep(-blur, blur, min(paperDist(sf.xy, bend), paperDist(st.xy, bend)));
187
+ sh = max(sh, 1.0 - smoothstep(-0.012, 0.02, min(pinDist(sf.xy), pinDist(st.xy))));
188
+ float ry = w.y + LIGHT.y * (WALL / LIGHT.z) - (0.5 - 0.012);
189
+ sh = max(sh, 0.8 * (1.0 - smoothstep(0.0, 0.012, abs(ry))));
190
+ // and a soft falloff of the light away from the top left
191
+ float fall = 0.1 * clamp(length(w.xy - vec2(-0.4 * ratio, 0.6)) / (1.2 * ratio + 0.6), 0.0, 1.0);
192
+ col.rgb *= (1.0 - 0.42 * vis * sh) * (1.0 - fall * vis);
193
+ }
194
+
195
+ col = drawPrint(col, hf, true, bend, psi, aa, vis);
196
+ col = drawPrint(col, ht, false, bend, psi, aa, vis);
197
+
198
+ // the line, in front of the top of the prints
199
+ if (vis > 0.0) {
200
+ float tl = (o.z - 0.004) / FOCAL;
201
+ float ly = o.y + d.y * tl - (0.5 - 0.012);
202
+ float lc = vis * clamp(0.5 - (abs(ly) - ROPE) / (tl * aa), 0.0, 1.0);
203
+ if (lc > 0.0) {
204
+ float k = clamp(ly / ROPE, -1.0, 1.0);
205
+ // twisted strands, carried along with the line, lit from above
206
+ float lx = o.x + d.x * tl + s * spacing * m;
207
+ float strand = 0.88 + 0.12 * sin((lx + ly * 0.6) * 360.0);
208
+ vec3 c = lineColor.rgb * (0.7 + 0.45 * sqrt(1.0 - k * k) + 0.15 * k) * strand;
209
+ vec4 lcp = premultiply(vec4(c, lineColor.a));
210
+ col = lcp * lc + col * (1.0 - lcp.a * lc);
211
+ }
212
+ col = drawPins(col, hf, aa, vis);
213
+ col = drawPins(col, ht, aa, vis);
214
+ }
215
+ return col.a > 0.0 ? vec4(col.rgb / col.a, col.a) : vec4(0.0);
216
+ }
@@ -0,0 +1,173 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The frame splits into slanted comic-book panels with gutters and ink borders; one after another in reading order, each panel lifts off the page with a zoom kick and a drop shadow and punches over to the incoming image, then the gutters close up over the full incoming image
4
+ // Tags: comic, panels, grid, zoom
5
+
6
+ // @range(0, 0.1) Width of the gutters between the panels, as a part of the frame's height
7
+ uniform float gutter; // = 0.03
8
+ // @color Color of the gutters and of the page's margin
9
+ uniform vec4 gutterColor; // = vec4(1.0, 1.0, 1.0, 1.0)
10
+ // @color Color of the ink borders around the panels
11
+ uniform vec4 borderColor; // = vec4(0.0, 0.0, 0.0, 1.0)
12
+ // @range(0, 100, 1) Changes the layout of the panels
13
+ uniform float seed; // = 0.0
14
+
15
+ const float PI = 3.141592653589793;
16
+ // width of the ink borders, as a part of the frame's height
17
+ const float INK = 0.005;
18
+ // width of the anti-aliased edges, as a part of the frame's height
19
+ const float EDGE = 0.0012;
20
+ // part of the transition taken by each panel's punch
21
+ const float PUNCH = 0.3;
22
+ // the first panel's punch starts at START, the last one ends at END
23
+ const float START = 0.05;
24
+ const float END = 0.97;
25
+ // number of spikes of the burst that brings the incoming image into a panel
26
+ const float SPIKES = 11.0;
27
+
28
+ float hash(vec2 v) {
29
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
30
+ v3 += dot(v3, v3.yzx + 33.33);
31
+ return fract((v3.x + v3.y) * v3.z);
32
+ }
33
+
34
+ // number of panels in row r (0 is the top row)
35
+ float cols(float r) {
36
+ float h = hash(vec2(r * 7.0 + 3.0, seed * 1.37 + 11.0));
37
+ float n = h < 0.15 ? 1.0 : (h < 0.6 ? 2.0 : 3.0);
38
+ // the middle row is never a single panel, a narrow frame takes at most 2 panels per row
39
+ if (r == 1.0) n = max(n, 2.0);
40
+ if (ratio < 0.8) n = min(n, 2.0);
41
+ return n;
42
+ }
43
+
44
+ // signed distance of p (x from 0 to ratio, y from 0 at the top to 1) below the gutter k between the rows
45
+ // (0 is the top of the frame, 3 its bottom)
46
+ float rowDist(float k, vec2 p) {
47
+ if (k < 0.5) return p.y;
48
+ if (k > 2.5) return p.y - 1.0;
49
+ float y = (k + (hash(vec2(k * 5.0 + 1.0, seed * 1.37)) - 0.5) * 0.35) / 3.0;
50
+ float s = (hash(vec2(k * 9.0 + 4.0, seed * 1.37 + 5.0)) - 0.5) * 0.24;
51
+ return (p.y - y - s * (p.x / ratio - 0.5)) / sqrt(1.0 + s * s / (ratio * ratio));
52
+ }
53
+
54
+ // signed distance of p right of the gutter j of row r, which has n panels (0 is the left of the frame, n its right)
55
+ float colDist(float r, float j, float n, vec2 p) {
56
+ if (j < 0.5) return p.x;
57
+ if (j > n - 0.5) return p.x - ratio;
58
+ float x = (j + (hash(vec2(r * 3.0 + j * 13.0, seed * 1.37 + 2.0)) - 0.5) * 0.45) / n;
59
+ float s = (hash(vec2(r * 11.0 + j * 5.0, seed * 1.37 + 7.0)) - 0.5) * 0.5;
60
+ return (p.x - ratio * (x + s * (p.y - 0.5))) / sqrt(1.0 + ratio * ratio * s * s);
61
+ }
62
+
63
+ // signed distance to the edges of panel c of row r, positive inside
64
+ float panelDist(float r, float c, float n, vec2 p) {
65
+ return min(min(rowDist(r, p), -rowDist(r + 1.0, p)), min(colDist(r, c, n, p), -colDist(r, c + 1.0, n, p)));
66
+ }
67
+
68
+ // a point inside panel c of row r, as far from its top as from its bottom and from its left as from its right
69
+ vec2 panelCenter(float r, float c, float n) {
70
+ // the sums of the distances to the opposite edges are linear: find where they are 0
71
+ float y0 = rowDist(r, vec2(0.5 * ratio, 0.0)) + rowDist(r + 1.0, vec2(0.5 * ratio, 0.0));
72
+ float y1 = rowDist(r, vec2(0.5 * ratio, 1.0)) + rowDist(r + 1.0, vec2(0.5 * ratio, 1.0));
73
+ float y = y0 / (y0 - y1);
74
+ float x0 = colDist(r, c, n, vec2(0.0, y)) + colDist(r, c + 1.0, n, vec2(0.0, y));
75
+ float x1 = colDist(r, c, n, vec2(1.0, y)) + colDist(r, c + 1.0, n, vec2(1.0, y));
76
+ return vec2(x0 / (x0 - x1), y);
77
+ }
78
+
79
+ // the panel's punch, 0 to 1: panel k of the n panels of the page, in reading order
80
+ float panelTime(float k, float total) {
81
+ float t0 = START + (END - START - PUNCH) * k / max(total - 1.0, 1.0);
82
+ return clamp((progress - t0) / PUNCH, 0.0, 1.0);
83
+ }
84
+
85
+ // how high the panel is lifted off the page: a quick rise, a slower settle
86
+ float lift(float t) {
87
+ float u = 1.0 - (1.0 - t) * (1.0 - t);
88
+ return sin(PI * u);
89
+ }
90
+
91
+ // the panel's image at the page point p: the outgoing one until the incoming one bursts out of the panel's center
92
+ // in a jagged star with an ink outline
93
+ vec4 panelImage(vec2 p, vec2 center, float t) {
94
+ float k = lift(t);
95
+ // the image zooms in with the kick, then settles
96
+ vec2 q = center + (p - center) / (1.0 + 0.1 * k);
97
+ vec2 uv = vec2(q.x / ratio, 1.0 - q.y);
98
+ if (t <= 0.0) return getFromColor(uv);
99
+ if (t >= 1.0) return getToColor(uv);
100
+ vec2 v = p - center;
101
+ float a = (atan(v.y, v.x + 1e-6) + PI) / (2.0 * PI) * SPIKES + center.x * 7.0;
102
+ float i = floor(a);
103
+ // the spikes, of uneven lengths
104
+ // (the spike index wraps around so that the star has no seam where the angle wraps)
105
+ float spike = (1.0 - abs(2.0 * (a - i) - 1.0)) * (0.5 + 0.5 * hash(vec2(mod(i, SPIKES), center.y * 13.0 + seed)));
106
+ // large enough to cover the widest panel, a whole row of a wide frame
107
+ float burst = 1.5 * max(1.0, ratio / 1.8) * smoothstep(0.06, 0.42, t);
108
+ float d = length(v) - burst * (0.62 + 0.38 * spike);
109
+ float w = 1.4 * INK;
110
+ vec4 c = mix(getToColor(uv), borderColor, smoothstep(-w - EDGE, -w + EDGE, d));
111
+ return mix(c, getFromColor(uv), smoothstep(-EDGE, EDGE, d));
112
+ }
113
+
114
+ // the panel drawn over color: its gutter edge at g from its edges, its ink border inside it
115
+ vec4 drawPanel(vec4 color, vec4 img, float d, float g, float ink, float fade) {
116
+ vec4 c = mix(borderColor, img, mix(1.0, smoothstep(g + ink - EDGE, g + ink + EDGE, d), fade));
117
+ return mix(color, c, mix(1.0, smoothstep(g - EDGE, g + EDGE, d), fade));
118
+ }
119
+
120
+ vec4 transition(vec2 uv) {
121
+ if (progress <= 0.0) return getFromColor(uv);
122
+ if (progress >= 1.0) return getToColor(uv);
123
+ vec2 p = vec2(uv.x * ratio, 1.0 - uv.y);
124
+
125
+ // the gutters open at the start and close over the incoming image at the end
126
+ float open = smoothstep(0.0, 0.14, progress) * (1.0 - smoothstep(0.8, 1.0, progress));
127
+ float g = 0.5 * gutter * open;
128
+ float ink = INK * open;
129
+ // the edges come in gently instead of popping in at half coverage
130
+ float fade = clamp(open * 6.0, 0.0, 1.0);
131
+
132
+ float n0 = cols(0.0);
133
+ float n1 = cols(1.0);
134
+ float n2 = cols(2.0);
135
+ float total = n0 + n1 + n2;
136
+
137
+ // the panel under the point, on the page
138
+ float r = rowDist(1.0, p) < 0.0 ? 0.0 : (rowDist(2.0, p) < 0.0 ? 1.0 : 2.0);
139
+ float n = r == 0.0 ? n0 : (r == 1.0 ? n1 : n2);
140
+ float c = colDist(r, 1.0, n, p) < 0.0 ? 0.0 : (colDist(r, 2.0, n, p) < 0.0 || n < 2.5 ? 1.0 : 2.0);
141
+ c = min(c, n - 1.0);
142
+ float first = r == 0.0 ? 0.0 : (r == 1.0 ? n0 : n0 + n1);
143
+ float t = panelTime(first + c, total);
144
+
145
+ vec4 color = gutterColor;
146
+ if (t <= 0.0 || t >= 1.0) {
147
+ color = drawPanel(color, panelImage(p, panelCenter(r, c, n), t), panelDist(r, c, n, p), g, ink, fade);
148
+ }
149
+
150
+ // the panels lifted off the page, the later ones on top: at most 4 of them punch at once
151
+ float spacing = (END - START - PUNCH) / max(total - 1.0, 1.0);
152
+ // (with a margin, so that a panel at the very end of its punch is not missed to rounding)
153
+ float kFirst = floor((progress - START - PUNCH) / spacing - 0.01) + 1.0;
154
+ for (int i = 0; i < 4; i++) {
155
+ float pk = kFirst + float(i);
156
+ if (pk < 0.0 || pk > total - 0.5) continue;
157
+ float pt = panelTime(pk, total);
158
+ if (pt <= 0.0 || pt >= 1.0) continue;
159
+ float pr = pk < n0 ? 0.0 : (pk < n0 + n1 ? 1.0 : 2.0);
160
+ float pn = pr == 0.0 ? n0 : (pr == 1.0 ? n1 : n2);
161
+ float pc = pk - (pr == 0.0 ? 0.0 : (pr == 1.0 ? n0 : n0 + n1));
162
+ float k = lift(pt);
163
+ vec2 center = panelCenter(pr, pc, pn);
164
+ float s = 1.0 + 0.08 * k;
165
+ // its soft shadow on the page, down and to the right
166
+ vec2 sq = center + (p - vec2(0.012, 0.018) * k - center) / s;
167
+ float sd = panelDist(pr, pc, pn, sq) - g;
168
+ color.rgb *= 1.0 - 0.4 * k * fade * smoothstep(-0.02, 0.01, sd);
169
+ vec2 q = center + (p - center) / s;
170
+ color = drawPanel(color, panelImage(q, center, pt), panelDist(pr, pc, pn, q), g, ink, 1.0);
171
+ }
172
+ return color;
173
+ }