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,76 +1,171 @@
1
1
  // License: MIT
2
2
  // Author: TimDonselaar
3
- // Description: The image splits into a grid of tiles that flip one by one to the incoming image
4
- // Tags: grid, tiles, flip
3
+ // Description: The image splits into a grid of cards that lift apart and turn over in perspective one after another, each one showing its part of the incoming image on its back
4
+ // Tags: grid, tiles, flip, 3d
5
5
  // ported by gre from https://gist.github.com/TimDonselaar/9bcd1c4b5934ba60087bdb55c2ea92e5
6
6
 
7
7
  // @param Number of tiles (columns, rows)
8
8
  uniform ivec2 size; // = ivec2(4)
9
+ // @range(0, 0.4) Part of the transition at the start and at the end during which the gaps between the tiles open and close
9
10
  uniform float pause; // = 0.1
11
+ // @range(0, 0.4) Width of the gaps between the tiles, as a part of a tile's shorter side
10
12
  uniform float dividerWidth; // = 0.05
11
13
  // @color Color behind the tiles
12
14
  uniform vec4 bgcolor; // = vec4(0.0, 0.0, 0.0, 1.0)
15
+ // @range(0, 1) How much the order of the flips is shuffled, from a diagonal wave across the grid to random
13
16
  uniform float randomness; // = 0.1
14
-
15
- float rand (vec2 co) {
16
- return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
17
+
18
+ const float PI = 3.141592653589793;
19
+ // width of the anti-aliased edges, as a part of the frame's height
20
+ const float EDGE = 0.0012;
21
+ // distance of the eye from each tile, in tile sizes
22
+ const float EYE = 2.2;
23
+ // part of the flips during which the last tile waits for its turn
24
+ const float STAGGER = 0.55;
25
+ // light direction (x, y over z): from the upper left, in front of the frame
26
+ const vec2 LIGHT = vec2(-0.45, 0.3);
27
+
28
+ float hash12(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);
17
32
  }
18
33
 
19
- float getDelta(vec2 p) {
20
- vec2 rectanglePos = floor(vec2(size) * p);
21
- vec2 rectangleSize = vec2(1.0 / vec2(size).x, 1.0 / vec2(size).y);
22
- float top = rectangleSize.y * (rectanglePos.y + 1.0);
23
- float bottom = rectangleSize.y * rectanglePos.y;
24
- float left = rectangleSize.x * rectanglePos.x;
25
- float right = rectangleSize.x * (rectanglePos.x + 1.0);
26
- float minX = min(abs(p.x - left), abs(p.x - right));
27
- float minY = min(abs(p.y - top), abs(p.y - bottom));
28
- return min(minX, minY);
34
+ // eased turn: smooth start and landing, without lingering at either end
35
+ float easeInOut(float t) {
36
+ return mix(t, t * t * (3.0 - 2.0 * t), 0.7);
29
37
  }
30
38
 
31
- float getDividerSize() {
32
- vec2 rectangleSize = vec2(1.0 / vec2(size).x, 1.0 / vec2(size).y);
33
- return min(rectangleSize.x, rectangleSize.y) * dividerWidth;
39
+ // time the gaps take to open and to close
40
+ float pausePart() {
41
+ return clamp(pause, 0.05, 0.4);
34
42
  }
35
43
 
36
- vec4 transition(vec2 p) {
37
- if(progress < pause) {
38
- float currentProg = progress / pause;
39
- float a = 1.0;
40
- if(getDelta(p) < getDividerSize()) {
41
- a = 1.0 - currentProg;
42
- }
43
- return mix(bgcolor, getFromColor(p), a);
44
- }
45
- else if(progress < 1.0 - pause){
46
- if(getDelta(p) < getDividerSize()) {
47
- return bgcolor;
48
- } else {
49
- float currentProg = (progress - pause) / (1.0 - pause * 2.0);
50
- vec2 q = p;
51
- vec2 rectanglePos = floor(vec2(size) * q);
52
-
53
- float r = rand(rectanglePos) - randomness;
54
- float cp = smoothstep(0.0, 1.0 - r, currentProg);
55
-
56
- float rectangleSize = 1.0 / vec2(size).x;
57
- float delta = rectanglePos.x * rectangleSize;
58
- float offset = rectangleSize / 2.0 + delta;
59
-
60
- p.x = (p.x - offset)/abs(cp - 0.5)*0.5 + offset;
61
- vec4 a = getFromColor(p);
62
- vec4 b = getToColor(p);
63
-
64
- float s = step(abs(vec2(size).x * (q.x - delta) - 0.5), abs(cp - 0.5));
65
- return mix(bgcolor, mix(b, a, step(cp, 0.5)), s);
66
- }
67
- }
68
- else {
69
- float currentProg = (progress - 1.0 + pause) / pause;
70
- float a = 1.0;
71
- if(getDelta(p) < getDividerSize()) {
72
- a = currentProg;
44
+ // the turn of a tile, 0 showing the outgoing image to 1 showing the incoming one,
45
+ // at q the progress of the flips and with stagger the delay of the last tile
46
+ float flipTime(vec2 cell, vec2 grid, float q, float stagger) {
47
+ // a diagonal wave from the top left corner, shuffled by randomness
48
+ float wave = (cell.x + (grid.y - 1.0 - cell.y)) / max(grid.x + grid.y - 2.0, 1.0);
49
+ float order = mix(wave, hash12(cell + 7.31), clamp(randomness, 0.0, 1.0));
50
+ return easeInOut(clamp((q - order * stagger) / (1.0 - stagger), 0.0, 1.0));
51
+ }
52
+
53
+ // how open the gaps are: they open at the start and close at the end
54
+ float gapAmount() {
55
+ float pp = pausePart();
56
+ return smoothstep(0.0, pp, progress) * (1.0 - smoothstep(1.0 - pp, 1.0, progress));
57
+ }
58
+
59
+ // coverage of a signed distance (positive inside) with an edge of width e
60
+ float aa(float d, float e) {
61
+ return clamp(d / max(2.0 * e, 1e-6) + 0.5, 0.0, 1.0);
62
+ }
63
+
64
+ float boxShadow(vec2 p, vec2 halfSize, float blur) {
65
+ vec2 d = abs(p) - halfSize;
66
+ float dist = length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
67
+ return 1.0 - smoothstep(-blur, blur, dist);
68
+ }
69
+
70
+ vec4 transition(vec2 uv) {
71
+ vec2 grid = max(vec2(size), 1.0);
72
+ vec2 frame = vec2(ratio, 1.0);
73
+ vec2 tileSize = frame / grid;
74
+ vec2 cell = clamp(floor(uv * grid), vec2(0.0), grid - 1.0);
75
+ vec2 pos = uv * frame;
76
+ float gapOpen = gapAmount();
77
+ float minSide = min(tileSize.x, tileSize.y);
78
+ float gap = clamp(dividerWidth, 0.0, 0.4) * minSide * gapOpen;
79
+ vec2 halfTile = 0.5 * tileSize - gap;
80
+ float eye = EYE * max(tileSize.x, tileSize.y);
81
+ // the flips start while the gaps finish opening, and end while they start closing
82
+ float pp = 0.6 * pausePart();
83
+ float q = clamp((progress - pp) / (1.0 - 2.0 * pp), 0.0, 1.0);
84
+ // a single tile takes all the time to turn
85
+ float stagger = grid.x * grid.y > 1.5 ? STAGGER : 0.0;
86
+
87
+ // the two nearest layers of the tiles that cover this point
88
+ vec4 c1 = vec4(0.0);
89
+ vec4 c2 = vec4(0.0);
90
+ float m1 = 0.0;
91
+ float m2 = 0.0;
92
+ float z1 = 1e9;
93
+ float z2 = 1e9;
94
+ bool rest1 = true;
95
+ bool rest2 = true;
96
+ float shadowBg = 0.0;
97
+ float shadowFlip = 0.0;
98
+
99
+ for (int j = -1; j <= 1; j++) {
100
+ for (int i = -1; i <= 1; i++) {
101
+ vec2 nc = cell + vec2(float(i), float(j));
102
+ if (nc.x < 0.0 || nc.y < 0.0 || nc.x > grid.x - 1.0 || nc.y > grid.y - 1.0) continue;
103
+ float t = flipTime(nc, grid, q, stagger);
104
+ float a = PI * t;
105
+ float ca = cos(a);
106
+ float sa = sin(a);
107
+ bool rest = t <= 0.0 || t >= 1.0;
108
+ if (rest) {
109
+ ca = t <= 0.0 ? 1.0 : -1.0;
110
+ sa = 0.0;
111
+ }
112
+ vec2 center = (nc + 0.5) * tileSize;
113
+ vec2 q = pos - center;
114
+
115
+ // shadows on the background: the tiles float a little above it, and higher while they turn
116
+ float lift = 0.05 * gapOpen * minSide + 0.35 * halfTile.x * sa;
117
+ vec2 shOffset = -LIGHT * lift;
118
+ vec2 shHalf = vec2(halfTile.x * abs(ca) + 0.5 * lift, halfTile.y);
119
+ float sh = boxShadow(q - shOffset, shHalf, 0.01 * minSide + 0.5 * lift);
120
+ shadowBg = 1.0 - (1.0 - shadowBg) * (1.0 - 0.45 * gapOpen * sh);
121
+ shadowFlip = max(shadowFlip, 0.45 * sa * sa * sh);
122
+
123
+ // ray from the eye in front of the tile's center, through this point, to the turned tile
124
+ // the tile turns around its vertical axis: its local x axis is (ca, 0, -sa), its normal (sa, 0, ca)
125
+ float den = eye * ca - q.x * sa;
126
+ if (abs(den) < 1e-6) continue;
127
+ float s = eye * ca / den;
128
+ if (s <= 0.0) continue;
129
+ vec3 hit = vec3(s * q.x, s * q.y, eye * (1.0 - s));
130
+ float u = hit.x * ca - hit.z * sa;
131
+ // the edges seen on screen, to anti-alias them
132
+ float xa = halfTile.x * ca * eye / (eye + halfTile.x * sa);
133
+ float xb = -halfTile.x * ca * eye / (eye - halfTile.x * sa);
134
+ float dx = min(q.x - min(xa, xb), max(xa, xb) - q.x);
135
+ float dy = (halfTile.y - abs(hit.y)) / s;
136
+ // soft edges, except where the tiles touch each other
137
+ float e = max(min(EDGE, gap), EDGE * min(8.0 * sa, 1.0));
138
+ float m = aa(min(dx, dy), e);
139
+ if (m <= 0.0) continue;
140
+
141
+ // the front shows the outgoing image, the back the incoming one, seen from behind
142
+ bool front = ca > 0.0;
143
+ vec2 src = (center + vec2(front ? u : -u, hit.y)) / frame;
144
+ vec4 col = front ? getFromColor(src) : getToColor(src);
145
+ if (!rest) {
146
+ // lit from the upper left: the turning side facing the light brightens a little, the other darkens
147
+ float nx = front ? sa : -sa;
148
+ float lit = abs(ca) + nx * LIGHT.x;
149
+ col.rgb *= mix(0.35, 1.0, clamp(lit, 0.0, 1.0)) + 0.25 * max(lit - 1.0, 0.0);
150
+ // a thin bright rim on the edges of the turning card
151
+ col.rgb += 0.12 * sa * (1.0 - smoothstep(0.0, 3.0 * EDGE, min(dx, dy)));
152
+ }
153
+
154
+ if (s < z1) {
155
+ c2 = c1; m2 = m1; z2 = z1; rest2 = rest1;
156
+ c1 = col; m1 = m; z1 = s; rest1 = rest;
157
+ } else if (s < z2) {
158
+ c2 = col; m2 = m; z2 = s; rest2 = rest;
159
+ }
73
160
  }
74
- return mix(bgcolor, getToColor(p), a);
75
161
  }
162
+
163
+ // the flipping tiles cast their shadows on the background and on the tiles lying still
164
+ vec4 color = bgcolor;
165
+ color.rgb *= 1.0 - clamp(max(shadowBg, shadowFlip), 0.0, 1.0);
166
+ if (rest2) c2.rgb *= 1.0 - shadowFlip;
167
+ if (rest1) c1.rgb *= 1.0 - shadowFlip;
168
+ color = mix(color, c2, m2);
169
+ color = mix(color, c1, m1);
170
+ return color;
76
171
  }
@@ -1,18 +1,78 @@
1
1
  // Author: gre
2
2
  // License: MIT
3
- // Description: A heart shape grows from the center to reveal the incoming image
3
+ // Description: A heart grows from the center with a little heartbeat to reveal the incoming image
4
4
  // Tags: shape, wipe, heart
5
5
 
6
- float inHeart (vec2 p, vec2 center, float size) {
7
- if (size==0.0) return 0.0;
8
- vec2 o = (p-center)/(1.6*size);
9
- float a = o.x*o.x+o.y*o.y-0.3;
10
- return step(a*a*a, o.x*o.x*o.y*o.y*o.y);
6
+ // @param Center of the heart
7
+ uniform vec2 center; // = vec2(0.5, 0.5)
8
+ // @range(0, 0.1) Softness of the heart's edge
9
+ uniform float smoothness; // = 0.006
10
+ // @range(0, 1) Strength of the heartbeat throb as the heart grows
11
+ uniform float pulse; // = 0.5
12
+ // @color Color of the soft light glowing along the heart's edge
13
+ uniform vec3 glowColor; // = vec3(1.0, 0.85, 0.9)
14
+ // @range(0, 1) Strength of the glow (0 for a clean edge)
15
+ uniform float glow; // = 0.3
16
+
17
+ // The heart shape: tip at (0, 0), notch at (0, 1), lobes are circles of radius sqrt(2)/4
18
+ // centered at (+-0.25, 0.75), tangent to the lines y = |x|. HEART_O is its center.
19
+ #define HEART_O vec2(0.0, 0.55)
20
+ #define LOBE vec2(0.25, 0.75)
21
+ #define LOBE_R 0.35355339
22
+
23
+ float dot2(vec2 v) { return dot(v, v); }
24
+
25
+ // Exact signed distance to the heart
26
+ float sdHeart(vec2 p) {
27
+ p.x = abs(p.x);
28
+ if (p.x + p.y > 1.0) return sqrt(dot2(p - LOBE)) - LOBE_R;
29
+ return sqrt(min(dot2(p - vec2(0.0, 1.0)), dot2(p - 0.5 * max(p.x + p.y, 0.0)))) * sign(p.x - p.y);
30
+ }
31
+
32
+ // Scale of the smallest heart (centered on HEART_O) that contains p: the heart is the union of a
33
+ // lobe disk and the triangle |x| <= y, |x| + y <= 1, both convex around HEART_O, so the boundary
34
+ // along a ray is the farthest of their exits.
35
+ float heartScale(vec2 p) {
36
+ float l = length(p);
37
+ if (l < 1e-6) return 0.0;
38
+ vec2 d = vec2(abs(p.x), p.y) / l;
39
+ vec2 m = HEART_O - LOBE;
40
+ float b = dot(m, d);
41
+ float tDisk = -b + sqrt(b * b - dot2(m) + LOBE_R * LOBE_R);
42
+ float tSide = d.x > d.y ? HEART_O.y / (d.x - d.y) : 1e6;
43
+ float tTop = d.x + d.y > 0.0 ? (1.0 - HEART_O.y) / (d.x + d.y) : 1e6;
44
+ return l / max(tDisk, min(tSide, tTop));
11
45
  }
46
+
12
47
  vec4 transition (vec2 uv) {
13
- return mix(
14
- getFromColor(uv),
15
- getToColor(uv),
16
- inHeart(uv, vec2(0.5, 0.4), progress)
17
- );
48
+ vec4 a = getFromColor(uv);
49
+ vec4 b = getToColor(uv);
50
+ vec2 asp = vec2(ratio, 1.0);
51
+ vec2 c = center * asp;
52
+ // Scale at which the heart covers the whole frame: the corners, plus the point of the top edge
53
+ // in line with the notch (the only concave part of the heart)
54
+ float cx = clamp(center.x, 0.0, 1.0) * ratio;
55
+ float full = max(
56
+ max(max(heartScale(vec2(0.0, 0.0) - c), heartScale(vec2(ratio, 0.0) - c)),
57
+ max(heartScale(vec2(0.0, 1.0) - c), heartScale(vec2(ratio, 1.0) - c))),
58
+ heartScale(vec2(cx, 1.0) - c));
59
+ float sm = max(smoothness, 0.001);
60
+ // Margin so the soft edge is past the frame at progress = 1
61
+ full += 4.0 * sm;
62
+
63
+ // Eased growth with two heartbeats riding on it: the heart surges, then almost stops
64
+ float p = progress;
65
+ float e = p * p * (2.0 - p);
66
+ float env = max(sin(3.14159265 * p), 0.0);
67
+ float beat = sin(6.28318531 * 2.0 * p) * env * env;
68
+ float s = full * clamp(e + 0.09 * pulse * beat, 0.0, 1.0);
69
+ if (s <= 0.0) return a;
70
+
71
+ vec2 q = uv * asp - c;
72
+ float d = s * sdHeart(q / s + HEART_O);
73
+ float m = smoothstep(0.0, sm, -d);
74
+ vec4 col = mix(a, b, m);
75
+ // Soft light just outside the edge, faded in and out with the transition (adds no alpha)
76
+ float light = exp(-max(d, 0.0) / (0.008 + sm)) * (1.0 - m) * glow * min(1.0, 4.0 * env);
77
+ return col + vec4(glowColor * light, 0.0);
18
78
  }
@@ -0,0 +1,113 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The camera stands inside a cube: the outgoing image covers the wall in front of it and the view turns toward the next inner wall, so the outgoing image swings away in perspective as the incoming one turns into view, the walls darkening into the shaded inner corner between them
4
+ // Tags: 3d, cube, rotate, perspective, directional
5
+
6
+ // @param Direction the view turns toward, snapped to its main axis (left, right, up or down): the incoming image is on the wall on that side
7
+ uniform vec2 direction; // = vec2(1.0, 0.0)
8
+ // @range(60, 120) Field of view along the turn, in degrees: at 90 the camera stays at the center of the cube, a wider view makes the walls recede more
9
+ uniform float fov; // = 90.0
10
+ // @range(0, 1) How much the walls darken as they turn away, and the shadow in the inner corners of the cube
11
+ uniform float shading; // = 0.6
12
+ // @color Color of the other faces of the cube, seen where the two walls leave the frame uncovered during the turn
13
+ uniform vec4 background; // = vec4(0.09, 0.09, 0.1, 1.0)
14
+
15
+ const float PI = 3.141592653589793;
16
+ // width of the anti-aliased edges, in frame heights
17
+ const float EDGE = 0.002;
18
+
19
+ vec4 premultiply(vec4 c) {
20
+ return vec4(c.rgb * c.a, c.a);
21
+ }
22
+
23
+ // shadow of a concave edge of the cube, at a distance dist from it
24
+ float cornerShadow(float dist, float size) {
25
+ float k = 1.0 - smoothstep(0.0, size, dist);
26
+ return k * k;
27
+ }
28
+
29
+ // the image on a wall at the point l of the wall, in frame heights from its center (l.x along
30
+ // the turn, l.y across), premultiplied; s and vertical undo the mirroring and the swap of axes
31
+ // that transition() applies to the frame coordinates
32
+ vec4 wallColor(vec2 l, bool incoming, bool vertical, float s) {
33
+ vec2 h = vec2(l.x * s, l.y);
34
+ vec2 p = vertical ? h.yx : h;
35
+ vec2 st = clamp(p / vec2(ratio, 1.0) + 0.5, 0.0, 1.0);
36
+ return premultiply(incoming ? getToColor(st) : getFromColor(st));
37
+ }
38
+
39
+ vec4 transition(vec2 uv) {
40
+ bool vertical = abs(direction.y) > abs(direction.x);
41
+ float s = (vertical ? direction.y : direction.x) < 0.0 ? -1.0 : 1.0;
42
+ // q.x: along the turn, toward the incoming wall; q.y: across; in frame heights
43
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
44
+ vec2 q = vertical ? p.yx : p;
45
+ q.x *= s;
46
+ // half sizes of a wall along and across the turn
47
+ float A = vertical ? 0.5 : 0.5 * ratio;
48
+ float B = vertical ? 0.5 * ratio : 0.5;
49
+ // focal length: a wall exactly fills the frame when seen square from that distance
50
+ // (below about 53 degrees the camera would stand outside the cube)
51
+ float F = A / tan(radians(clamp(fov, 55.0, 170.0)) * 0.5);
52
+
53
+ float e = smoothstep(0.0, 1.0, progress);
54
+ float th = 0.5 * PI * e;
55
+ float c = cos(th);
56
+ float sn = sin(th);
57
+ float amount = max(sin(PI * e), 0.0); // 0 at both ends, so the images are untouched there
58
+ float aa = EDGE * min(1.0, 40.0 * amount) + 1e-6;
59
+ float shadow = shading * min(1.0, 4.0 * amount);
60
+
61
+ // in the plane of the turn (a: along, z: depth), the outgoing wall is z = F, a in [-A, A],
62
+ // the incoming wall is a = A, z in [F - 2A, F]; the camera starts in front of the center of
63
+ // the first one and ends in front of the center of the second one
64
+ vec2 cam = (A - F) * e * vec2(1.0, -1.0);
65
+ vec2 d = vec2(q.x * c + F * sn, F * c - q.x * sn);
66
+
67
+ // the inner corner between the two walls projects to a line across the frame
68
+ vec2 P = vec2(A, F) - cam;
69
+ float sc = F * (P.x * c - P.y * sn) / max(P.x * sn + P.y * c, 1e-6);
70
+
71
+ // outgoing wall
72
+ float tf = d.y > 1e-6 ? (F - cam.y) / d.y : 1e6;
73
+ float af = cam.x + tf * d.x;
74
+ vec2 lf = vec2(af, q.y * tf);
75
+ // incoming wall
76
+ float ti = d.x > 1e-6 ? (A - cam.x) / d.x : 1e6;
77
+ float ai = (F - A) - (cam.y + ti * d.y);
78
+ vec2 li = vec2(ai, q.y * ti);
79
+
80
+ // each wall darkens as it turns away from the view, and toward the concave edges
81
+ float size = 0.8 * min(A, B);
82
+ float edgeF = cornerShadow(A - af, size) + 0.5 * cornerShadow(B - abs(lf.y), size);
83
+ float edgeI = cornerShadow(ai + A, size) + 0.5 * cornerShadow(B - abs(li.y), size);
84
+ float shadeF = (1.0 - shading * 0.8 * (1.0 - c)) * (1.0 - 0.7 * shadow * min(edgeF, 1.0));
85
+ float shadeI = (1.0 - shading * 0.8 * (1.0 - sn)) * (1.0 - 0.7 * shadow * min(edgeI, 1.0));
86
+
87
+ // how much of the pixel each wall covers, from distances on screen in frame heights: split at
88
+ // the corner line, cut across by the edges of the walls (lb = q.y * t), and at their far
89
+ // edges (along the wall, a moves F * t / d.depth times faster than q.x)
90
+ float wF = clamp(0.5 + (sc - q.x) / aa, 0.0, 1.0);
91
+ float covF = wF * clamp(0.5 + (B / tf - abs(q.y)) / aa, 0.0, 1.0)
92
+ * clamp(0.5 + (af + A) * d.y / (tf * F * aa), 0.0, 1.0);
93
+ float covI = (1.0 - wF) * clamp(0.5 + (B / ti - abs(q.y)) / aa, 0.0, 1.0)
94
+ * clamp(0.5 + (A - ai) * d.x / (ti * F * aa), 0.0, 1.0);
95
+ // only sample the walls that show in this pixel
96
+ vec4 colF = covF > 0.0 ? wallColor(lf, false, vertical, s) : vec4(0.0);
97
+ vec4 colI = covI > 0.0 ? wallColor(li, true, vertical, s) : vec4(0.0);
98
+ colF.rgb *= shadeF;
99
+ colI.rgb *= shadeI;
100
+
101
+ // the other faces of the cube, with the same shadow along their edges with the two walls
102
+ vec4 bg = premultiply(background);
103
+ float cov = covF + covI;
104
+ if (cov < 1.0) {
105
+ // where the ray meets the floor or the ceiling, never beyond the walls
106
+ float tb = min(B / max(abs(q.y), 1e-6), min(tf, ti));
107
+ vec2 fl = cam + tb * d;
108
+ float edgeB = cornerShadow(F - fl.y, size) + cornerShadow(A - fl.x, size);
109
+ bg.rgb *= 1.0 - 0.5 * shadow * min(edgeB, 1.0);
110
+ }
111
+ vec4 col = colF * covF + colI * covI + bg * (1.0 - cov);
112
+ return col.a > 0.0 ? vec4(col.rgb / col.a, col.a) : vec4(0.0);
113
+ }
@@ -0,0 +1,103 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A keyhole grows steadily from the center until the incoming image fills the frame, its bevelled rim and inner shadow making it read as a hole cut in a plate
4
+ // Tags: shape, wipe, keyhole, iris, reveal
5
+
6
+ // @param Center of the keyhole
7
+ uniform vec2 center; // = vec2(0.5, 0.5)
8
+ // @range(0, 1) Strength of the bevelled rim around the keyhole and the shadow inside it (0 for a clean cut)
9
+ uniform float rim; // = 0.6
10
+ // @range(0, 0.05) Softness of the keyhole's edge
11
+ uniform float smoothness; // = 0.002
12
+
13
+ // The keyhole, in its own units (0.85 tall, from y = -0.4 to 0.45): a round head on top of a slot
14
+ // that widens downward.
15
+ #define HEAD vec2(0.0, 0.2)
16
+ #define HEAD_R 0.25
17
+ #define SLOT_Y -0.17
18
+ const float SLOT_HE = 0.23;
19
+ const float SLOT_TOP = 0.085;
20
+ const float SLOT_BOTTOM = 0.165;
21
+ const float SLOT_ROUND = 0.025;
22
+ // height of the point the keyhole grows around, in its head
23
+ const float GROW_Y = 0.1;
24
+ // widths of the bevel and of the rim's shadows, in keyhole units
25
+ const float BEVEL = 0.028;
26
+ const float SHADE = 0.05;
27
+
28
+ float dot2(vec2 v) { return dot(v, v); }
29
+
30
+ // Signed distance to the slot, a trapezoid with rounded corners
31
+ float sdSlot(vec2 p) {
32
+ p.y -= SLOT_Y;
33
+ float r1 = SLOT_BOTTOM - SLOT_ROUND;
34
+ float r2 = SLOT_TOP - SLOT_ROUND;
35
+ float he = SLOT_HE - SLOT_ROUND;
36
+ vec2 k1 = vec2(r2, he);
37
+ vec2 k2 = vec2(r2 - r1, 2.0 * he);
38
+ p.x = abs(p.x);
39
+ vec2 ca = vec2(p.x - min(p.x, p.y < 0.0 ? r1 : r2), abs(p.y) - he);
40
+ vec2 cb = p - k1 + k2 * clamp(dot(k1 - p, k2) / dot2(k2), 0.0, 1.0);
41
+ float s = (cb.x < 0.0 && ca.y < 0.0) ? -1.0 : 1.0;
42
+ return s * sqrt(min(dot2(ca), dot2(cb))) - SLOT_ROUND;
43
+ }
44
+
45
+ float sdKeyhole(vec2 p) {
46
+ return min(length(p - HEAD) - HEAD_R, sdSlot(p));
47
+ }
48
+
49
+ // Scale at which the keyhole's head, a disk, reaches the point p (seen from the growth point):
50
+ // the root of |p - s h| = s HEAD_R, h being the head's center
51
+ float reach(vec2 p) {
52
+ vec2 h = HEAD - vec2(0.0, GROW_Y);
53
+ float k = HEAD_R * HEAD_R - dot2(h);
54
+ float b = dot(p, h);
55
+ return (sqrt(b * b + k * dot2(p)) - b) / k;
56
+ }
57
+
58
+ vec4 transition (vec2 uv) {
59
+ vec4 a = getFromColor(uv);
60
+ vec4 b = getToColor(uv);
61
+ vec2 asp = vec2(ratio, 1.0);
62
+ vec2 c = center * asp;
63
+ float sm = max(smoothness, 0.0005);
64
+
65
+ // The keyhole grows around a point of its head, at the center. It covers the frame (grown by a
66
+ // margin, so the soft edge is past it) once its head, a disk, reaches the frame's corners.
67
+ vec2 o = c;
68
+ vec2 lo = -o - 2.5 * sm;
69
+ vec2 hi = asp - o + 2.5 * sm;
70
+ float full = max(max(reach(lo), reach(hi)), max(reach(vec2(lo.x, hi.y)), reach(vec2(hi.x, lo.y))));
71
+
72
+ // The keyhole grows linearly until it fills the frame
73
+ float p = progress;
74
+ float s = full * p;
75
+ if (s <= 0.0) return a;
76
+
77
+ vec2 q = (uv * asp - o) / s + vec2(0.0, GROW_Y);
78
+ float d = sdKeyhole(q);
79
+ // the soft edge is just inside the outline, so a tiny keyhole shows nothing
80
+ float hole = 1.0 - smoothstep(-sm, sm, d * s + sm);
81
+
82
+ float fade = smoothstep(0.0, 0.08, p) * (1.0 - smoothstep(0.7, 1.0, p));
83
+ float rimA = rim * fade;
84
+ if (rimA > 0.0) {
85
+ // Plate around the hole: a bevel lit from above going down into the hole, and a soft shadow
86
+ // on its rim
87
+ vec2 e = vec2(0.002, 0.0);
88
+ vec2 n = vec2(sdKeyhole(q + e) - sdKeyhole(q - e), sdKeyhole(q + e.yx) - sdKeyhole(q - e.yx));
89
+ float lit = -dot(n / max(length(n), 1e-6), vec2(-0.35, 0.94));
90
+ float bevel = 1.0 - smoothstep(0.0, BEVEL, d);
91
+ float shade = exp(-max(d, 0.0) / SHADE);
92
+ a.rgb *= 1.0 - rimA * (0.35 * shade + bevel * 0.4 * max(-lit, 0.0));
93
+ a.rgb += rimA * bevel * bevel * 0.3 * max(lit, 0.0) * a.a;
94
+
95
+ // Inside the hole: the plate's thickness shades the incoming image under the top of the rim,
96
+ // with a softer vignette all around the edge
97
+ float wall = smoothstep(-0.03, 0.03, sdKeyhole(q + vec2(0.0, 0.05)));
98
+ float vign = exp(min(d, 0.0) / SHADE);
99
+ b.rgb *= 1.0 - rimA * (0.5 * wall + 0.3 * vign);
100
+ }
101
+
102
+ return mix(a, b, hole);
103
+ }
@@ -0,0 +1,126 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The picture zooms into a giant LED screen of round glowing diodes on a dark panel; a refresh wave sweeps across it, each diode flicking with a bright pop as it switches to the incoming image, then the diodes melt back into the plain picture
4
+ // Tags: dots, glow, grid, wave
5
+
6
+ // @range(6, 80) Number of diodes across the shorter side
7
+ uniform float cells; // = 24.0
8
+ // @range(0, 1) Strength of the glow bleeding from the diodes into the dark panel
9
+ uniform float glow; // = 0.6
10
+ // @range(0, 1) Brightness of the flash of each diode as it switches
11
+ uniform float flash; // = 0.7
12
+ // @range(0, 0.5) How much the picture zooms in while it is a screen
13
+ uniform float zoom; // = 0.15
14
+ // @param Each diode is made of red, green and blue sub-diodes
15
+ uniform bool triads; // = false
16
+ // @param Direction in which the refresh wave sweeps across the screen
17
+ uniform vec2 direction; // = vec2(1.0, 0.0)
18
+ // @color Color of the panel between the diodes
19
+ uniform vec4 panel; // = vec4(0.02, 0.02, 0.025, 1.0)
20
+
21
+ // radius of a lit diode, in cells
22
+ const float RADIUS = 0.36;
23
+ // width of the soft edge of the diodes, in cells
24
+ const float EDGE = 0.05;
25
+
26
+ float hash12(vec2 p) {
27
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
28
+ p3 += dot(p3, p3.yzx + 33.33);
29
+ return fract((p3.x + p3.y) * p3.z);
30
+ }
31
+
32
+ // folds uv back into 0..1, so the frame stays filled
33
+ vec2 mirrored(vec2 v) {
34
+ vec2 m = mod(v, 2.0);
35
+ return mix(m, 2.0 - m, step(1.0, m));
36
+ }
37
+
38
+ // 1 inside a disc of radius r, with a soft edge
39
+ float disc(float d, float r) {
40
+ return 1.0 - smoothstep(r - EDGE, r + EDGE, d);
41
+ }
42
+
43
+ vec4 transition(vec2 uv) {
44
+ // how much the picture is a screen: it resolves into diodes until 0.3, and back from 0.7
45
+ float led = smoothstep(0.0, 0.3, progress) * (1.0 - smoothstep(0.7, 1.0, progress));
46
+ float z = 1.0 + max(zoom, 0.0) * smoothstep(0.0, 0.45, progress) * (1.0 - smoothstep(0.55, 1.0, progress));
47
+ vec2 p = 0.5 + (uv - 0.5) / z;
48
+
49
+ // the grid of diodes, in cells, with a diode at the center of the frame
50
+ vec2 aspect = vec2(ratio, 1.0);
51
+ vec2 toCells = aspect * max(cells, 1.0) / min(ratio, 1.0);
52
+ vec2 q = (p - 0.5) * toCells;
53
+ vec2 id = floor(q + 0.5);
54
+ vec2 local = q - id;
55
+ vec2 side = vec2(local.x < 0.0 ? -1.0 : 1.0, local.y < 0.0 ? -1.0 : 1.0);
56
+
57
+ // the refresh wave runs along dir, from 0 to 1 across the frame
58
+ vec2 dir = length(direction) > 1e-4 ? normalize(direction) : vec2(1.0, 0.0);
59
+ float extent = abs(dir.x) * ratio + abs(dir.y);
60
+
61
+ vec4 own = vec4(0.0);
62
+ float ownSwitch = 0.0;
63
+ vec4 halo = vec4(0.0);
64
+ float haloWeight = 0.0;
65
+ // this diode and the three nearest ones, whose glow reaches this point
66
+ for (int i = 0; i < 4; i++) {
67
+ // without glow, only this diode matters
68
+ if (i > 0 && glow * led <= 0.0) break;
69
+ vec2 o = vec2(mod(float(i), 2.0), floor(float(i) / 2.0)) * side;
70
+ vec2 c = id + o;
71
+ vec2 cuv = c / toCells + 0.5;
72
+ // where the diode is seen in the frame, so that the wave crosses the visible screen
73
+ float s = clamp(dot((cuv - 0.5) * z * aspect, dir) / extent + 0.5, 0.0, 1.0);
74
+ float when = 0.2 + 0.52 * s + 0.05 * (hash12(c + 71.0) - 0.5);
75
+ float sw = smoothstep(when - 0.012, when + 0.012, progress);
76
+ // the diode blinks off just before it switches, then pops bright
77
+ float x = (progress - when) / 0.018;
78
+ float pop = exp(-x * x) - 0.5 * exp(-(x + 1.6) * (x + 1.6));
79
+ vec2 suv = mirrored(cuv);
80
+ vec4 col = mix(getFromColor(suv), getToColor(suv), sw);
81
+ col.rgb = col.rgb * (1.0 + 1.4 * flash * pop) + 0.2 * flash * max(pop, 0.0);
82
+ if (i == 0) {
83
+ own = col;
84
+ ownSwitch = sw;
85
+ }
86
+ float d = length(local - o);
87
+ float w = 0.9 * glow * exp(-6.0 * max(d - RADIUS, 0.0)) * (1.0 + 0.8 * flash * max(pop, 0.0));
88
+ // the neighbors fade out where the next ones in the other direction take over, so the glow has no seam
89
+ if (o.x != 0.0) w *= smoothstep(0.0, 0.2, abs(local.x));
90
+ if (o.y != 0.0) w *= smoothstep(0.0, 0.2, abs(local.y));
91
+ halo += w * col;
92
+ haloWeight += w;
93
+ }
94
+
95
+ // the plain picture, switched along with its diode
96
+ vec4 plain = mix(getFromColor(p), getToColor(p), ownSwitch);
97
+ float d = length(local);
98
+ // the diodes cover their whole cell with the plain picture when led = 0: the dark panel
99
+ // shows up first between them, then they light up with the color of their center
100
+ float r = mix(0.8, RADIUS, smoothstep(0.0, 0.6, led));
101
+ vec4 gap = vec4(panel.rgb, panel.a * own.a);
102
+ if (haloWeight > 0.0) {
103
+ gap = mix(gap, halo / haloWeight, clamp(haloWeight * led, 0.0, 1.0));
104
+ }
105
+ vec4 body = own;
106
+ if (triads) {
107
+ // three sub-diodes on the panel, red at the top, green and blue below
108
+ vec3 sub = vec3(
109
+ disc(length(local - vec2(0.0, 0.15)), 0.2),
110
+ disc(length(local - vec2(-0.13, -0.075)), 0.2),
111
+ disc(length(local - vec2(0.13, -0.075)), 0.2));
112
+ float m = max(sub.r, max(sub.g, sub.b));
113
+ body = vec4(gap.rgb * (1.0 - m) + own.rgb * 1.5 * sub, mix(gap.a, own.a, m));
114
+ // the sub-diodes reach out to 0.4 cells
115
+ r = max(r, 0.45);
116
+ } else {
117
+ // brighter at the core of the diode
118
+ float k = clamp(d / RADIUS, 0.0, 1.0);
119
+ body.rgb *= 0.8 + 0.45 * (1.0 - k * k);
120
+ }
121
+ // the color of the center spreads from it over the diode
122
+ float lit = smoothstep(0.0, 0.8, led);
123
+ body = mix(plain, body, lit * mix(1.0, lit, smoothstep(0.0, 0.7, d)));
124
+ vec4 color = mix(gap, body, disc(d, r));
125
+ return clamp(color, 0.0, 1.0);
126
+ }