gl-transitions 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/compatibility.json +455 -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/CircleBurst.glsl +77 -0
  7. package/glsl3/Clothesline.glsl +217 -0
  8. package/glsl3/CodeRain.glsl +114 -0
  9. package/glsl3/ComicPanels.glsl +174 -0
  10. package/glsl3/Cube.glsl +105 -52
  11. package/glsl3/CurtainRise.glsl +71 -0
  12. package/glsl3/DominoFall.glsl +114 -0
  13. package/glsl3/Doorway.glsl +74 -38
  14. package/glsl3/Drape.glsl +186 -0
  15. package/glsl3/DuotoneFade.glsl +58 -0
  16. package/glsl3/FacetedGlass.glsl +137 -0
  17. package/glsl3/FrostWipe.glsl +176 -0
  18. package/glsl3/Funnel.glsl +71 -0
  19. package/glsl3/GlitterDissolve.glsl +171 -0
  20. package/glsl3/GravityLens.glsl +66 -0
  21. package/glsl3/GridFlip.glsl +151 -56
  22. package/glsl3/HeartWipe.glsl +71 -11
  23. package/glsl3/InsideCube.glsl +114 -0
  24. package/glsl3/KeyholeWipe.glsl +104 -0
  25. package/glsl3/LedWall.glsl +127 -0
  26. package/glsl3/MoireWipe.glsl +75 -0
  27. package/glsl3/PaperFold.glsl +168 -0
  28. package/glsl3/PuzzleCube.glsl +205 -0
  29. package/glsl3/RibbonTwist.glsl +53 -0
  30. package/glsl3/RingSpin.glsl +112 -0
  31. package/glsl3/Shatter.glsl +231 -35
  32. package/glsl3/SketchDissolve.glsl +100 -0
  33. package/glsl3/SlotReels.glsl +118 -0
  34. package/glsl3/SplitFlap.glsl +124 -0
  35. package/glsl3/SpotlightWipe.glsl +63 -0
  36. package/glsl3/Swirl.glsl +52 -21
  37. package/glsl3/TruchetWipe.glsl +80 -0
  38. package/glsl3/Tumble.glsl +113 -0
  39. package/glsl3/WaterDrop.glsl +69 -13
  40. package/glsl3/WaveWipe.glsl +154 -0
  41. package/index.js +1 -1
  42. package/layouts.json +1232 -29
  43. package/llms-full.txt +890 -403
  44. package/llms.txt +225 -197
  45. package/msl/BookFlip.metal +575 -114
  46. package/msl/CircleBurst.metal +351 -0
  47. package/msl/Clothesline.metal +828 -0
  48. package/msl/CodeRain.metal +451 -0
  49. package/msl/ComicPanels.metal +959 -0
  50. package/msl/Cube.metal +466 -170
  51. package/msl/CurtainRise.metal +263 -0
  52. package/msl/DominoFall.metal +510 -0
  53. package/msl/Doorway.metal +350 -124
  54. package/msl/Drape.metal +767 -0
  55. package/msl/DuotoneFade.metal +218 -0
  56. package/msl/FacetedGlass.metal +529 -0
  57. package/msl/FrostWipe.metal +677 -0
  58. package/msl/Funnel.metal +276 -0
  59. package/msl/GlitterDissolve.metal +637 -0
  60. package/msl/GravityLens.metal +236 -0
  61. package/msl/GridFlip.metal +548 -191
  62. package/msl/HeartWipe.metal +230 -58
  63. package/msl/InsideCube.metal +537 -0
  64. package/msl/KeyholeWipe.metal +370 -0
  65. package/msl/LedWall.metal +437 -0
  66. package/msl/MoireWipe.metal +252 -0
  67. package/msl/PaperFold.metal +762 -0
  68. package/msl/PuzzleCube.metal +1179 -0
  69. package/msl/RibbonTwist.metal +235 -0
  70. package/msl/RingSpin.metal +474 -0
  71. package/msl/Shatter.metal +1136 -160
  72. package/msl/SketchDissolve.metal +446 -0
  73. package/msl/SlotReels.metal +436 -0
  74. package/msl/SplitFlap.metal +589 -0
  75. package/msl/SpotlightWipe.metal +217 -0
  76. package/msl/Swirl.metal +144 -77
  77. package/msl/TruchetWipe.metal +285 -0
  78. package/msl/Tumble.metal +466 -0
  79. package/msl/WaterDrop.metal +258 -49
  80. package/msl/WaveWipe.metal +618 -0
  81. package/package.json +1 -1
  82. package/skills/gl-transitions/references/catalog.md +115 -57
  83. package/sksl/BookFlip.sksl +117 -20
  84. package/sksl/CircleBurst.sksl +84 -0
  85. package/sksl/Clothesline.sksl +217 -0
  86. package/sksl/CodeRain.sksl +124 -0
  87. package/sksl/ComicPanels.sksl +176 -0
  88. package/sksl/Cube.sksl +99 -46
  89. package/sksl/CurtainRise.sksl +84 -0
  90. package/sksl/DominoFall.sksl +122 -0
  91. package/sksl/Doorway.sksl +65 -35
  92. package/sksl/Drape.sksl +192 -0
  93. package/sksl/DuotoneFade.sksl +71 -0
  94. package/sksl/FacetedGlass.sksl +148 -0
  95. package/sksl/FrostWipe.sksl +183 -0
  96. package/sksl/Funnel.sksl +83 -0
  97. package/sksl/GlitterDissolve.sksl +175 -0
  98. package/sksl/GravityLens.sksl +77 -0
  99. package/sksl/GridFlip.sksl +141 -52
  100. package/sksl/HeartWipe.sksl +60 -11
  101. package/sksl/InsideCube.sksl +123 -0
  102. package/sksl/KeyholeWipe.sksl +109 -0
  103. package/sksl/LedWall.sksl +137 -0
  104. package/sksl/MoireWipe.sksl +85 -0
  105. package/sksl/PaperFold.sksl +170 -0
  106. package/sksl/PuzzleCube.sksl +203 -0
  107. package/sksl/RibbonTwist.sksl +66 -0
  108. package/sksl/RingSpin.sksl +121 -0
  109. package/sksl/Shatter.sksl +218 -33
  110. package/sksl/SketchDissolve.sksl +111 -0
  111. package/sksl/SlotReels.sksl +127 -0
  112. package/sksl/SplitFlap.sksl +131 -0
  113. package/sksl/SpotlightWipe.sksl +74 -0
  114. package/sksl/Swirl.sksl +49 -20
  115. package/sksl/TruchetWipe.sksl +92 -0
  116. package/sksl/Tumble.sksl +122 -0
  117. package/sksl/WaterDrop.sksl +64 -10
  118. package/sksl/WaveWipe.sksl +165 -0
  119. package/sksl/index.js +1 -1
  120. package/transitions/BookFlip.glsl +124 -21
  121. package/transitions/CircleBurst.glsl +76 -0
  122. package/transitions/Clothesline.glsl +216 -0
  123. package/transitions/CodeRain.glsl +113 -0
  124. package/transitions/ComicPanels.glsl +173 -0
  125. package/transitions/Cube.glsl +105 -52
  126. package/transitions/CurtainRise.glsl +70 -0
  127. package/transitions/DominoFall.glsl +113 -0
  128. package/transitions/Doorway.glsl +74 -38
  129. package/transitions/Drape.glsl +185 -0
  130. package/transitions/DuotoneFade.glsl +57 -0
  131. package/transitions/FacetedGlass.glsl +136 -0
  132. package/transitions/FrostWipe.glsl +175 -0
  133. package/transitions/Funnel.glsl +70 -0
  134. package/transitions/GlitterDissolve.glsl +170 -0
  135. package/transitions/GravityLens.glsl +65 -0
  136. package/transitions/GridFlip.glsl +151 -56
  137. package/transitions/HeartWipe.glsl +71 -11
  138. package/transitions/InsideCube.glsl +113 -0
  139. package/transitions/KeyholeWipe.glsl +103 -0
  140. package/transitions/LedWall.glsl +126 -0
  141. package/transitions/MoireWipe.glsl +74 -0
  142. package/transitions/PaperFold.glsl +167 -0
  143. package/transitions/PuzzleCube.glsl +204 -0
  144. package/transitions/RibbonTwist.glsl +52 -0
  145. package/transitions/RingSpin.glsl +111 -0
  146. package/transitions/Shatter.glsl +231 -35
  147. package/transitions/SketchDissolve.glsl +99 -0
  148. package/transitions/SlotReels.glsl +117 -0
  149. package/transitions/SplitFlap.glsl +123 -0
  150. package/transitions/SpotlightWipe.glsl +62 -0
  151. package/transitions/Swirl.glsl +52 -21
  152. package/transitions/TruchetWipe.glsl +79 -0
  153. package/transitions/Tumble.glsl +112 -0
  154. package/transitions/WaterDrop.glsl +69 -13
  155. package/transitions/WaveWipe.glsl +153 -0
  156. package/wgsl/BookFlip.wgsl +552 -105
  157. package/wgsl/CircleBurst.wgsl +310 -0
  158. package/wgsl/Clothesline.wgsl +756 -0
  159. package/wgsl/CodeRain.wgsl +415 -0
  160. package/wgsl/ComicPanels.wgsl +886 -0
  161. package/wgsl/Cube.wgsl +461 -156
  162. package/wgsl/CurtainRise.wgsl +235 -0
  163. package/wgsl/DominoFall.wgsl +461 -0
  164. package/wgsl/Doorway.wgsl +333 -117
  165. package/wgsl/Drape.wgsl +715 -0
  166. package/wgsl/DuotoneFade.wgsl +185 -0
  167. package/wgsl/FacetedGlass.wgsl +476 -0
  168. package/wgsl/FrostWipe.wgsl +617 -0
  169. package/wgsl/Funnel.wgsl +248 -0
  170. package/wgsl/GlitterDissolve.wgsl +582 -0
  171. package/wgsl/GravityLens.wgsl +206 -0
  172. package/wgsl/GridFlip.wgsl +523 -188
  173. package/wgsl/HeartWipe.wgsl +225 -55
  174. package/wgsl/InsideCube.wgsl +496 -0
  175. package/wgsl/KeyholeWipe.wgsl +337 -0
  176. package/wgsl/LedWall.wgsl +397 -0
  177. package/wgsl/MoireWipe.wgsl +222 -0
  178. package/wgsl/PaperFold.wgsl +700 -0
  179. package/wgsl/PuzzleCube.wgsl +1087 -0
  180. package/wgsl/RibbonTwist.wgsl +206 -0
  181. package/wgsl/RingSpin.wgsl +426 -0
  182. package/wgsl/Shatter.wgsl +1091 -148
  183. package/wgsl/SketchDissolve.wgsl +409 -0
  184. package/wgsl/SlotReels.wgsl +391 -0
  185. package/wgsl/SplitFlap.wgsl +533 -0
  186. package/wgsl/SpotlightWipe.wgsl +186 -0
  187. package/wgsl/Swirl.wgsl +138 -77
  188. package/wgsl/TruchetWipe.wgsl +255 -0
  189. package/wgsl/Tumble.wgsl +424 -0
  190. package/wgsl/WaterDrop.wgsl +251 -49
  191. package/wgsl/WaveWipe.wgsl +581 -0
@@ -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
+ }
@@ -1,70 +1,123 @@
1
1
  // Author: gre
2
2
  // License: MIT
3
- // Description: The two images are faces of a rotating 3D cube, with a floor reflection
3
+ // Description: The two images are faces of a box that turns a quarter turn in perspective, the outgoing face darkening as it turns away, above a reflective floor
4
4
  // Tags: 3d, cube, rotate, reflection
5
5
  // @range(0, 1) Amount of perspective
6
6
  uniform float persp; // = 0.7
7
+ // @range(0, 1) How far the camera pulls back mid-turn, as a part of the frame
7
8
  uniform float unzoom; // = 0.3
8
9
  // @range(0, 1) Strength of the reflection
9
10
  uniform float reflection; // = 0.4
11
+ // @range(0, 20) Gap between the box and its reflection, as a percentage of the frame height
10
12
  uniform float floating; // = 3.0
13
+ // @range(0, 1) How much the faces darken as they turn away, and the shadow on the floor
14
+ uniform float shading; // = 0.5
11
15
 
12
- vec2 project (vec2 p) {
13
- return p * vec2(1.0, -1.2) + vec2(0.0, -floating/100.);
14
- }
15
-
16
- bool inBounds (vec2 p) {
17
- return all(lessThan(vec2(0.0), p)) && all(lessThan(p, vec2(1.0)));
18
- }
16
+ const float PI = 3.141592653589793;
17
+ // width of the anti-aliased edges, as a part of the frame's height at the box's front
18
+ const float EDGE = 0.002;
19
19
 
20
- vec4 bgColor (vec2 p, vec2 pfr, vec2 pto) {
21
- vec4 c = vec4(0.0); // where no image is drawn: transparent
22
- pfr = project(pfr);
23
- // FIXME avoid branching might help perf!
24
- if (inBounds(pfr)) {
25
- c += mix(vec4(0.0), getFromColor(pfr), reflection * mix(1.0, 0.0, pfr.y));
20
+ // the ray (eye, dir) in the box's frame, the box turned by (c, s) around its vertical axis:
21
+ // returns (distance along the ray, horizontal position on the face, height, face) with face 0 for
22
+ // the outgoing image's face, 1 for the incoming one's, and a negative distance where it misses
23
+ vec4 hitBox(vec3 eye, vec3 dir, float w, float c, float s) {
24
+ vec2 pivot = vec2(0.5 * w);
25
+ vec2 e = eye.xz - pivot;
26
+ vec2 o = vec2(e.x * c + e.y * s, -e.x * s + e.y * c) + pivot;
27
+ vec2 d = vec2(dir.x * c + dir.z * s, -dir.x * s + dir.z * c);
28
+ // the side faces seen from outside: the box spans [0, w] on x and z
29
+ vec2 inv = 1.0 / vec2(d.x < 0.0 ? min(d.x, -1e-6) : max(d.x, 1e-6), d.y < 0.0 ? min(d.y, -1e-6) : max(d.y, 1e-6));
30
+ vec2 t0 = (vec2(0.0) - o) * inv;
31
+ vec2 t1 = (vec2(w) - o) * inv;
32
+ vec2 tn = min(t0, t1);
33
+ vec2 tf = max(t0, t1);
34
+ float tin = max(tn.x, tn.y);
35
+ if (tin <= 0.0 || tin > min(tf.x, tf.y)) return vec4(-1.0);
36
+ vec2 hit = o + tin * d;
37
+ float y = eye.y + tin * dir.y;
38
+ if (y < 0.0 || y > 1.0) return vec4(-1.0);
39
+ // the face first entered: z = 0 is the outgoing face, x = 0 the incoming one, the others are hidden
40
+ if (tn.y >= tn.x) {
41
+ if (d.y <= 0.0) return vec4(-1.0);
42
+ return vec4(tin, hit.x / w, y, 0.0);
26
43
  }
27
- pto = project(pto);
28
- if (inBounds(pto)) {
29
- c += mix(vec4(0.0), getToColor(pto), reflection * mix(1.0, 0.0, pto.y));
30
- }
31
- return c;
44
+ if (d.x <= 0.0) return vec4(-1.0);
45
+ return vec4(tin, 1.0 - hit.y / w, y, 1.0);
32
46
  }
33
47
 
34
- // p : the position
35
- // persp : the perspective in [ 0, 1 ]
36
- // center : the xcenter in [0, 1] \ 0.5 excluded
37
- vec2 xskew (vec2 p, float persp, float center) {
38
- float x = mix(p.x, 1.0-p.x, center);
39
- return (
40
- (
41
- vec2( x, (p.y - 0.5*(1.0-persp) * x) / (1.0+(persp-1.0)*x) )
42
- - vec2(0.5-distance(center, 0.5), 0.0)
43
- )
44
- * vec2(0.5 / distance(center, 0.5) * (center<0.5 ? 1.0 : -1.0), 1.0)
45
- + vec2(center<0.5 ? 0.0 : 1.0, 0.0)
46
- );
47
- }
48
+ vec4 transition(vec2 uv) {
49
+ float w = ratio;
50
+ // the turn starts and ends softly
51
+ float turn = progress * progress * (3.0 - 2.0 * progress);
52
+ float a = 0.5 * PI * turn;
53
+ float c = cos(a), s = sin(a);
54
+ if (progress >= 1.0) { c = 0.0; s = 1.0; }
55
+ // 0 at both ends, for exact images and hard edges there
56
+ float motion = sin(PI * clamp(progress, 0.0, 1.0));
57
+ float zoom = 1.0 + max(unzoom, 0.0) * motion;
48
58
 
49
- vec4 transition(vec2 op) {
50
- float uz = unzoom * 2.0*(0.5-distance(0.5, progress));
51
- vec2 p = -uz*0.5+(1.0+uz) * op;
52
- vec2 fromP = xskew(
53
- (p - vec2(progress, 0.0)) / vec2(1.0-progress, 1.0),
54
- 1.0-mix(progress, 0.0, persp),
55
- 0.0
56
- );
57
- vec2 toP = xskew(
58
- p / vec2(progress, 1.0),
59
- mix(pow(progress, 2.0), 1.0, persp),
60
- 1.0
61
- );
62
- // FIXME avoid branching might help perf!
63
- if (inBounds(fromP)) {
64
- return getFromColor(fromP);
59
+ // the front of the box is the screen: the camera keeps it framed, pulling back mid-turn
60
+ float dist = 0.8 * max(w, 1.0) / clamp(persp, 0.01, 1.0);
61
+ vec3 eye = vec3(0.5 * w, 0.5, -dist);
62
+ vec2 sp = (uv - 0.5) * zoom + 0.5;
63
+ vec3 dir = vec3(sp.x * w, sp.y, 0.0) - eye;
64
+
65
+ // pixel footprint on the screen plane, for the anti-aliased edges
66
+ float px = EDGE * zoom * min(10.0 * motion, 1.0);
67
+ float shade0 = 1.0 - shading * (1.0 - c);
68
+ float shade1 = 1.0 - shading * (1.0 - s);
69
+
70
+ // the box in front, premultiplied
71
+ vec4 front = vec4(0.0);
72
+ vec4 b = hitBox(eye, dir, w, c, s);
73
+ if (b.x > 0.0) {
74
+ vec4 img = b.w < 0.5 ? getFromColor(vec2(b.y, b.z)) : getToColor(vec2(b.y, b.z));
75
+ float m = 1.0;
76
+ if (px > 0.0) {
77
+ // the silhouette: top, bottom and the outer vertical edge of the face, seen foreshortened
78
+ float e = px * b.x;
79
+ vec3 n = b.w < 0.5 ? vec3(s, 0.0, -c) : vec3(-c, 0.0, -s);
80
+ float fore = max(abs(dot(n, normalize(dir))), 0.05);
81
+ float edge = b.w < 0.5 ? 1.0 - b.y : b.y;
82
+ m = clamp(min(b.z, 1.0 - b.z) / e, 0.0, 1.0)
83
+ * clamp(edge * w * fore / e, 0.0, 1.0);
84
+ }
85
+ // where the box covers the pixel, nothing behind it shows: the exact image at both ends
86
+ if (m >= 1.0 && img.a >= 1.0) {
87
+ return vec4(img.rgb * (b.w < 0.5 ? shade0 : shade1), img.a);
88
+ }
89
+ front = vec4(img.rgb * (b.w < 0.5 ? shade0 : shade1) * img.a, img.a) * m;
65
90
  }
66
- else if (inBounds(toP)) {
67
- return getToColor(toP);
91
+
92
+ // the floor, h below the box, premultiplied; it fades in and out with the motion
93
+ vec4 ground = vec4(0.0);
94
+ float h = 0.005 * max(floating, 0.0);
95
+ if (dir.y < 0.0 && motion > 0.0) {
96
+ float tf = -(eye.y + h) / dir.y;
97
+ vec3 f = eye + tf * dir;
98
+ // the reflection: the same ray mirrored by the floor, fading with the height on the box
99
+ vec3 meye = vec3(eye.x, -2.0 * h - eye.y, eye.z);
100
+ vec3 mdir = vec3(dir.x, -dir.y, dir.z);
101
+ vec4 r = hitBox(meye, mdir, w, c, s);
102
+ if (r.x > 0.0) {
103
+ vec4 img = r.w < 0.5 ? getFromColor(vec2(r.y, r.z)) : getToColor(vec2(r.y, r.z));
104
+ float k = clamp(reflection, 0.0, 1.0) * (1.0 - r.z) * (1.0 - r.z);
105
+ ground = vec4(img.rgb * (r.w < 0.5 ? shade0 : shade1) * img.a, img.a) * k;
106
+ }
107
+ // the contact shadow around the box, softer as it floats higher
108
+ vec2 q = f.xz - vec2(0.5 * w);
109
+ vec2 l = vec2(q.x * c + q.y * s, -q.x * s + q.y * c);
110
+ float soft = 0.03 + 1.5 * h;
111
+ float sh = shading * 0.7 * exp(-length(max(abs(l) - vec2(0.5 * w), 0.0)) / soft);
112
+ // only as opaque as the bottom of the nearest face
113
+ vec2 bl = l + vec2(0.5 * w);
114
+ sh *= l.y < l.x
115
+ ? getFromColor(vec2(clamp(bl.x / w, 0.0, 1.0), 0.0)).a
116
+ : getToColor(vec2(clamp(1.0 - bl.y / w, 0.0, 1.0), 0.0)).a;
117
+ ground = ground * (1.0 - sh) + vec4(0.0, 0.0, 0.0, sh);
118
+ ground *= min(6.0 * motion, 1.0);
68
119
  }
69
- return bgColor(op, fromP, toP);
120
+
121
+ vec4 color = front + ground * (1.0 - front.a);
122
+ return color.a > 0.0 ? vec4(color.rgb / color.a, color.a) : vec4(0.0);
70
123
  }
@@ -0,0 +1,70 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image rises like a theater festoon curtain: cords lift its hem into scalloped swags while the fabric gathers into shaded ruffles, and it is drawn up out of the frame over the incoming image
4
+ // Tags: 3d, fold, vertical
5
+
6
+ // @range(1, 8, 1) Number of swags across a 16:9 frame (fewer in a portrait image)
7
+ uniform float swags; // = 3.0
8
+ // @range(0, 0.3) How low each swag droops between two cords, as a part of the frame's height
9
+ uniform float sag; // = 0.14
10
+ // @range(4, 30, 1) Number of gathered ruffles in the fabric
11
+ uniform float ruffles; // = 14.0
12
+ // @range(0, 1) Depth of the shading on the ruffles and swags, and of the shadow under the hem
13
+ uniform float shading; // = 0.7
14
+
15
+ const float PI = 3.141592653589793;
16
+
17
+ vec4 transition (vec2 uv) {
18
+ float p = progress;
19
+ // the fabric gathers early, then the cords pull it up
20
+ float f = 1.0 - (1.0 - p) * (1.0 - p) * (1.0 - p);
21
+ // the cords start pulling at once and are fastest midway
22
+ float e = mix(p, p * p * (3.0 - 2.0 * p), 0.4);
23
+ float s = sag * f;
24
+ float lift = mix(-0.01, 1.0 + sag + 0.08, e);
25
+ // across a swag, -1 and 1 at the cords
26
+ float n = max(1.0, floor(swags * sqrt(ratio / 1.78) + 0.5)); // fewer swags in portrait
27
+ float u = fract(uv.x * n) * 2.0 - 1.0;
28
+ float bump = 1.0 - u * u;
29
+ float hem = lift - s * bump;
30
+ float aa = 0.002 + 0.004 * f;
31
+ float inside = smoothstep(hem - aa, hem + aa, uv.y);
32
+
33
+ vec4 c = vec4(0.0);
34
+ if (inside > 0.0) {
35
+ // q goes from 0 at the top rod to 1 at the hem; the whole height of fabric is gathered into it
36
+ float h = max(1.0 - max(hem, 0.0), 1e-4);
37
+ float q = clamp((1.0 - uv.y) / h, 0.0, 1.0);
38
+ // ruffles: the fabric bunches where cos(a) > 0, rows parallel to the scalloped hem
39
+ // as the curtain shortens, its ruffles merge so none gets thinner than 2% of the frame
40
+ float m = min(max(1.0, floor(ruffles + 0.5)), h / 0.02);
41
+ float a = 2.0 * PI * m * q;
42
+ // the ruffles puff out most in the middle of each swag
43
+ float g = 0.85 * f * min(1.0, 0.3 + 5.0 * (1.0 - h)) * (0.6 + 0.4 * bump);
44
+ float v = clamp(q + g * sin(a) / (2.0 * PI * m), 0.0, 1.0);
45
+ // the fabric is also pulled in toward the cords near the hem
46
+ float pull = 0.25 * f * q * q * sin(PI * u) / (PI * n);
47
+ c = getFromColor(vec2(uv.x - pull, 1.0 - v));
48
+
49
+ // light from the front and a bit above
50
+ float slope = 2.5 * g * cos(a);
51
+ float diffuse = (1.0 - 0.35 * slope) / sqrt(1.0 + slope * slope);
52
+ float crease = 0.5 + 0.5 * sin(a);
53
+ float light = mix(1.0, diffuse * (1.0 - 0.45 * crease * crease), shading * g);
54
+ // a soft sheen on the crest of each ruffle
55
+ light += 0.18 * shading * g * smoothstep(0.4, 1.0, -cos(a));
56
+ // each swag bulges toward the light in its middle and is pinched dark along the cords
57
+ float depth = f * q * (0.3 + 0.7 * q);
58
+ light *= 1.0 - shading * depth * (0.35 * u * u + 0.5 * exp(-(1.0 - abs(u)) * 14.0));
59
+ // the hem rolls under a little
60
+ light *= 1.0 - 0.35 * shading * f * exp(-(uv.y - hem) * 120.0);
61
+ c.rgb *= light;
62
+ if (inside >= 1.0) return c;
63
+ }
64
+ vec4 to = getToColor(uv);
65
+ // soft shadow of the curtain just under its hem
66
+ float below = max(hem - uv.y, 0.0);
67
+ float shadow = 0.6 * shading * exp(-below * 22.0) * smoothstep(0.0, 0.05, lift) * (1.0 - smoothstep(1.0, 1.06, lift - s));
68
+ to.rgb *= 1.0 - shadow;
69
+ return mix(to, c, inside);
70
+ }
@@ -0,0 +1,113 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image is cut into standing slats that topple backward like dominoes in a chain reaction across the frame, each one leaning onto the next and knocking it over, until they all lie flat and reveal the incoming image
4
+ // Tags: 3d, stripes, rotate
5
+
6
+ // @range(2, 40, 1) Number of slats
7
+ uniform int count; // = 12
8
+ // @param The chain runs from right to left instead of left to right
9
+ uniform bool reverse; // = false
10
+ // @range(0.05, 1) Part of a slat's fall after which it knocks the next one: lower runs the chain faster, with more slats falling at once
11
+ uniform float knock; // = 0.2
12
+ // @range(0, 1) How far each slat's top leans sideways onto the next one, as a part of a slat's width
13
+ uniform float lean; // = 0.8
14
+ // @range(0, 1) Strength of the perspective
15
+ uniform float perspective; // = 0.8
16
+ // @range(0, 1) How much the slats darken as they fall, and the shadows they cast
17
+ uniform float shading; // = 0.6
18
+
19
+ const float PI = 3.141592653589793;
20
+ // width of the anti-aliased edges, as a part of the frame's height
21
+ const float EDGE = 0.0015;
22
+
23
+ float knockPart() {
24
+ return clamp(knock, 0.05, 1.0);
25
+ }
26
+
27
+ // the fall of slat j, 0 standing to 1 lying flat
28
+ float fallTime(float j, float n) {
29
+ if (progress >= 1.0) return 1.0;
30
+ float k = knockPart();
31
+ // each slat falls during d and knocks the next one after k * d
32
+ float d = 1.0 / (1.0 + (n - 1.0) * k);
33
+ return clamp((progress - j * k * d) / d, 0.0, 1.0);
34
+ }
35
+
36
+ // the slat's angle: it starts with the push of the previous one, then gravity takes over
37
+ float fallAngle(float t) {
38
+ return 0.5 * PI * t * (0.2 + 0.8 * t);
39
+ }
40
+
41
+ // where slat j is seen at the point (xc, y) of the frame: (x across the slat, height on it, its fall, its angle),
42
+ // with a negative fall where it is not seen (its height can exceed 1, above its top)
43
+ vec4 slatPoint(float j, float n, float w, float xc, float y) {
44
+ vec4 none = vec4(0.0, 0.0, -1.0, 0.0);
45
+ if (j < 0.0 || j > n - 1.0) return none;
46
+ float t = fallTime(j, n);
47
+ if (t >= 1.0) return none;
48
+ float a = fallAngle(t);
49
+ float c = cos(a), s = sin(a);
50
+ // a camera in front of the slat goes down to the level of the hinge as the slat falls,
51
+ // so that the slat ends edge-on
52
+ vec3 eye = vec3((j + 0.5) * w, 0.5 * c, -1.0 / max(perspective, 0.01));
53
+ vec3 dir = vec3(xc, y, 0.0) - eye;
54
+ // cast a ray onto the slat turned back by a around its bottom edge
55
+ float den = dir.z * c - dir.y * s;
56
+ if (den <= 0.0) return none;
57
+ float r = (eye.y * s - eye.z * c) / den;
58
+ vec3 hit = eye + r * dir;
59
+ float h = hit.y * c + hit.z * s;
60
+ if (r <= 0.0 || h < 0.0) return none;
61
+ // the top leans sideways toward the next slat until it touches it
62
+ float side = clamp(lean, 0.0, 1.0) * w * min(t / knockPart(), 1.0) * h;
63
+ return vec4(hit.x - side - j * w, h, t, a);
64
+ }
65
+
66
+ // draws slat j, seen at pt, over color; front is where the next slat, which may stand in front of it, is seen
67
+ vec4 drawSlat(vec4 color, float j, vec4 pt, vec4 front, float w) {
68
+ float t = pt.z;
69
+ if (t < 0.0) return color;
70
+ float s = sin(pt.w);
71
+ float d = min(pt.x, w - pt.x);
72
+ float m;
73
+ if (t <= 0.0) {
74
+ // standing still: the slats tile the frame exactly
75
+ m = d >= 0.0 && pt.y <= 1.0 ? 1.0 : 0.0;
76
+ } else {
77
+ // anti-aliased edges, widened as the slat is seen narrower and shorter
78
+ float e = EDGE * min(10.0 * t, 1.0) * (1.0 + max(perspective, 0.0) * pt.y * s);
79
+ m = clamp(d / e + 0.5, 0.0, 1.0) * clamp((1.0 - pt.y) * max(cos(pt.w), 0.05) / e + 0.5, 0.0, 1.0);
80
+ }
81
+ if (m <= 0.0) return color;
82
+ float sx = (j * w + clamp(pt.x, 0.0, w)) / ratio;
83
+ vec4 img = getFromColor(vec2(reverse ? 1.0 - sx : sx, min(pt.y, 1.0)));
84
+ // darker as it falls away, more toward its top
85
+ float shade = 1.0 - shading * s * (0.4 + 0.6 * pt.y);
86
+ // the next slat, less fallen and so in front, shades the one leaning onto it along its edge, up to its top
87
+ if (front.z >= 0.0 && front.z < t && front.x < 0.0) {
88
+ float reach = clamp(1.0 - (front.y - 1.0) / 0.05, 0.0, 1.0);
89
+ shade *= 1.0 - 0.6 * shading * exp(front.x / (0.15 * w)) * reach;
90
+ }
91
+ img.rgb *= shade;
92
+ return mix(color, img, m);
93
+ }
94
+
95
+ vec4 transition (vec2 uv) {
96
+ float n = float(count < 1 ? 1 : count);
97
+ float w = ratio / n;
98
+ // x along the chain, in frame heights
99
+ float xc = (reverse ? 1.0 - uv.x : uv.x) * ratio;
100
+ float col = clamp(floor(xc / w), 0.0, n - 1.0);
101
+
102
+ vec4 color = getToColor(uv);
103
+ // the contact shadow of the falling slat on the floor
104
+ float t0 = fallTime(col, n);
105
+ color.rgb *= 1.0 - 2.4 * shading * t0 * (1.0 - t0) * exp(-40.0 * uv.y);
106
+
107
+ // the slats are seen narrower as they fall, and their tops lean over the next column at most:
108
+ // the slat before this column, behind, then the one of this column
109
+ vec4 cur = slatPoint(col, n, w, xc, uv.y);
110
+ color = drawSlat(color, col - 1.0, slatPoint(col - 1.0, n, w, xc, uv.y), cur, w);
111
+ color = drawSlat(color, col, cur, slatPoint(col + 1.0, n, w, xc, uv.y), w);
112
+ return color;
113
+ }
@@ -1,54 +1,90 @@
1
1
  // Author: gre
2
2
  // License: MIT
3
- // Description: The outgoing image opens like double doors as the incoming one comes forward, with a floor reflection
3
+ // Description: The outgoing image opens like double doors swinging toward the viewer, as the incoming one comes forward from the dark room behind, with a floor reflection
4
4
  // Tags: doors, 3d, reflection
5
- // @param Strength of the reflection
5
+
6
+ // @range(0, 1) Strength of the floor reflection under the incoming image
6
7
  uniform float reflection; // = 0.4
7
- // @param Amount of perspective
8
+ // @range(0, 1) Amount of perspective on the swinging doors
8
9
  uniform float perspective; // = 0.4
10
+ // @range(1, 10) How far back the incoming image starts (1: no distance)
9
11
  uniform float depth; // = 3
10
12
 
11
- const vec4 black = vec4(0.0); // where no image is drawn: transparent
12
- const vec2 boundMin = vec2(0.0, 0.0);
13
- const vec2 boundMax = vec2(1.0, 1.0);
13
+ const float PI = 3.141592653589793;
14
14
 
15
- bool inBounds (vec2 p) {
16
- return all(lessThan(boundMin, p)) && all(lessThan(p, boundMax));
15
+ // cast the view ray of screen point x (aspect units, the frame is 0..w) onto a leaf of
16
+ // width w/2 hinged on the left edge and turned toward the viewer by angle a.
17
+ // The eye is at (w/2, 0.5, -eye) and the frame at z = 0; returns (t, distance along the leaf)
18
+ // where t scales the ray so that t = 1 is the frame plane
19
+ vec2 leafHit (float x, float w, float eye, float a) {
20
+ float c = cos(a), s = sin(a);
21
+ float t = (eye * c - 0.5 * w * s) / (s * (x - 0.5 * w) + eye * c);
22
+ vec2 hit = vec2(0.5 * w + t * (x - 0.5 * w), eye * (t - 1.0));
23
+ return vec2(t, hit.x * c - hit.y * s);
17
24
  }
18
25
 
19
- vec2 project (vec2 p) {
20
- return p * vec2(1.0, -1.2) + vec2(0.0, -0.02);
26
+ // screen x of a point (x, z) seen from the eye
27
+ float project (vec2 p, float w, float eye) {
28
+ return 0.5 * w + (p.x - 0.5 * w) * eye / (eye + p.y);
21
29
  }
22
30
 
23
- vec4 bgColor (vec2 p, vec2 pto) {
24
- vec4 c = black;
25
- pto = project(pto);
26
- if (inBounds(pto)) {
27
- c += mix(black, getToColor(pto), reflection * mix(1.0, 0.0, pto.y));
28
- }
29
- return c;
31
+ float easeInOut (float t) {
32
+ return t < 0.5 ? 4.0 * t * t * t : 1.0 - 4.0 * (1.0 - t) * (1.0 - t) * (1.0 - t);
30
33
  }
31
34
 
32
-
33
- vec4 transition (vec2 p) {
34
- vec2 pfr = vec2(-1.), pto = vec2(-1.);
35
- float middleSlit = 2.0 * abs(p.x-0.5) - progress;
36
- if (middleSlit > 0.0) {
37
- pfr = p + (p.x > 0.5 ? -1.0 : 1.0) * vec2(0.5*progress, 0.0);
38
- float d = 1.0/(1.0+perspective*progress*(1.0-middleSlit));
39
- pfr.y -= d/2.;
40
- pfr.y *= d;
41
- pfr.y += d/2.;
42
- }
43
- float size = mix(1.0, depth, 1.-progress);
44
- pto = (p + vec2(-0.5, -0.5)) * vec2(size, size) + vec2(0.5, 0.5);
45
- if (inBounds(pfr)) {
46
- return getFromColor(pfr);
47
- }
48
- else if (inBounds(pto)) {
49
- return getToColor(pto);
50
- }
51
- else {
52
- return bgColor(p, pto);
35
+ // the room behind: the incoming image coming forward, and its reflection on the floor
36
+ vec4 room (vec2 uv, float x, float edgeL, float edgeR, float close, float dolly) {
37
+ float size = mix(max(depth, 1.0), 1.0, dolly);
38
+ vec2 p = (uv - 0.5) * size + 0.5;
39
+ // soft border while it is far, exactly sharp once it fills the frame
40
+ float soft = 0.004 * (size - 1.0) + 1e-6;
41
+ vec2 m = smoothstep(-soft, soft, p) * smoothstep(-soft, soft, 1.0 - p);
42
+ vec4 c = getToColor(clamp(p, 0.0, 1.0)) * (m.x * m.y);
43
+ if (p.y < 0.0) {
44
+ vec2 r = vec2(p.x, -1.2 * p.y - 0.02);
45
+ float f = reflection * (1.0 - r.y) * m.x * smoothstep(0.0, 0.01, r.y);
46
+ c += getToColor(clamp(r, 0.0, 1.0)) * f * (1.0 - m.y);
53
47
  }
48
+ // the lit room spills its light through the opening, and the leaves cast soft shadows
49
+ // along their edges; both settle as the doors open
50
+ float wl = 0.03 + 0.12 * close;
51
+ float shadow = (1.0 - smoothstep(0.0, wl, x - edgeL)) + (1.0 - smoothstep(0.0, wl, edgeR - x));
52
+ float light = (1.0 + 0.6 * close * close) * (1.0 - 0.7 * close * min(shadow, 1.0));
53
+ return vec4(min(c.rgb * light, vec3(c.a)), c.a);
54
+ }
55
+
56
+ vec4 transition (vec2 uv) {
57
+ float w = ratio;
58
+ float x = uv.x * w;
59
+ // camera distance: the leaves always stay in front of it
60
+ float eye = max(w, 1.0) * (0.5 + 0.2 / max(perspective, 0.01));
61
+ // the leaves swing until their free edges have just left the frame
62
+ float swing = progress * progress * (3.0 - 2.0 * progress);
63
+ float a = min(atan(2.0 * eye / w) + 0.1, 0.5 * PI) * swing;
64
+ float dolly = mix(easeInOut(progress), progress, 0.3);
65
+ // the free edge of the left leaf, front and back of its thickness, as (x, z)
66
+ float hw = 0.5 * w;
67
+ vec2 front = hw * vec2(cos(a), -sin(a));
68
+ float thick = 0.02 * w * (1.0 - smoothstep(0.8, 1.0, swing));
69
+ float edgeL = project(front, w, eye);
70
+ float backL = project(front + thick * vec2(sin(a), cos(a)), w, eye);
71
+ float close = 1.0 - swing;
72
+ vec4 back = room(uv, x, backL, w - backL, close, dolly);
73
+ // the leaf on this side of the frame (each one stays in its own half)
74
+ bool left = x < hw;
75
+ float lx = left ? x : w - x;
76
+ vec2 hit = leafHit(lx, w, eye, a);
77
+ float s = clamp(hit.y, 0.0, hw);
78
+ // the ray meets the leaf nearer to the eye, where it looks bigger
79
+ float v = 0.5 + (uv.y - 0.5) * hit.x;
80
+ vec4 leaf = getFromColor(clamp(vec2(left ? s / w : 1.0 - s / w, v), 0.0, 1.0));
81
+ // turned away from the light, and darker toward the free edge as the opening deepens
82
+ leaf.rgb *= 1.0 - 0.5 * (1.0 - cos(a)) - 0.25 * sin(a) * (s / hw);
83
+ // the edge of the leaf catches the light coming from the room
84
+ vec4 side = getFromColor(clamp(vec2(left ? 0.499 : 0.501, v), 0.0, 1.0));
85
+ side.rgb = min(side.rgb * 1.5, vec3(side.a));
86
+ // sharp at both ends, so that nothing of the doors is left at the start and the end
87
+ float aa = 0.003 * min(1.0, 20.0 * min(a, close)) + 1e-6;
88
+ vec4 c = mix(back, side, smoothstep(-aa, aa, backL - lx));
89
+ return mix(c, leaf, smoothstep(-aa, aa, edgeL - lx));
54
90
  }