gl-transitions 2.5.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 (257) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +16 -1
  3. package/compatibility.json +383 -149
  4. package/gl-transitions.js +1 -1
  5. package/gl-transitions.json +1 -1
  6. package/glsl3/BandWipe.glsl +67 -0
  7. package/glsl3/BookFlip.glsl +124 -21
  8. package/glsl3/BowTie.glsl +1 -1
  9. package/glsl3/Clothesline.glsl +217 -0
  10. package/glsl3/ComicPanels.glsl +174 -0
  11. package/glsl3/Cube.glsl +105 -52
  12. package/glsl3/DirectionalWipe.glsl +1 -1
  13. package/glsl3/DominoFall.glsl +114 -0
  14. package/glsl3/Doorway.glsl +74 -38
  15. package/glsl3/Drape.glsl +186 -0
  16. package/glsl3/DuotoneFade.glsl +58 -0
  17. package/glsl3/FacetedGlass.glsl +137 -0
  18. package/glsl3/FrostWipe.glsl +176 -0
  19. package/glsl3/Funnel.glsl +71 -0
  20. package/glsl3/GlintDissolve.glsl +125 -0
  21. package/glsl3/GlitterDissolve.glsl +171 -0
  22. package/glsl3/GridFlip.glsl +151 -56
  23. package/glsl3/HeartWipe.glsl +71 -11
  24. package/glsl3/InsetWipe.glsl +58 -0
  25. package/glsl3/InsideCube.glsl +114 -0
  26. package/glsl3/KeyholeWipe.glsl +104 -0
  27. package/glsl3/LedWall.glsl +127 -0
  28. package/glsl3/LightningFlash.glsl +200 -0
  29. package/glsl3/MoireWipe.glsl +75 -0
  30. package/glsl3/PaperFold.glsl +168 -0
  31. package/glsl3/PuzzleCube.glsl +205 -0
  32. package/glsl3/RibbonTwist.glsl +53 -0
  33. package/glsl3/Shatter.glsl +231 -35
  34. package/glsl3/SketchDissolve.glsl +100 -0
  35. package/glsl3/SlotReels.glsl +118 -0
  36. package/glsl3/SplitFlap.glsl +124 -0
  37. package/glsl3/Swirl.glsl +52 -21
  38. package/glsl3/TruchetWipe.glsl +80 -0
  39. package/glsl3/Tumble.glsl +113 -0
  40. package/glsl3/WarpSpeed.glsl +120 -0
  41. package/glsl3/WaterDrop.glsl +69 -13
  42. package/glsl3/WaveWipe.glsl +154 -0
  43. package/index.js +1 -1
  44. package/layouts.json +1158 -193
  45. package/llms-full.txt +865 -540
  46. package/llms.txt +219 -204
  47. package/msl/BandWipe.metal +353 -0
  48. package/msl/BookFlip.metal +575 -114
  49. package/msl/BowTie.metal +1 -1
  50. package/msl/Clothesline.metal +828 -0
  51. package/msl/ComicPanels.metal +959 -0
  52. package/msl/Cube.metal +466 -170
  53. package/msl/DirectionalWipe.metal +1 -1
  54. package/msl/DominoFall.metal +510 -0
  55. package/msl/Doorway.metal +350 -124
  56. package/msl/Drape.metal +767 -0
  57. package/msl/DuotoneFade.metal +218 -0
  58. package/msl/FacetedGlass.metal +529 -0
  59. package/msl/FrostWipe.metal +677 -0
  60. package/msl/Funnel.metal +276 -0
  61. package/msl/GlintDissolve.metal +558 -0
  62. package/msl/GlitterDissolve.metal +637 -0
  63. package/msl/GridFlip.metal +548 -191
  64. package/msl/HeartWipe.metal +230 -58
  65. package/msl/InsetWipe.metal +232 -0
  66. package/msl/InsideCube.metal +537 -0
  67. package/msl/KeyholeWipe.metal +370 -0
  68. package/msl/LedWall.metal +437 -0
  69. package/msl/LightningFlash.metal +1038 -0
  70. package/msl/MoireWipe.metal +252 -0
  71. package/msl/PaperFold.metal +762 -0
  72. package/msl/PuzzleCube.metal +1179 -0
  73. package/msl/RibbonTwist.metal +235 -0
  74. package/msl/Shatter.metal +1136 -160
  75. package/msl/SketchDissolve.metal +446 -0
  76. package/msl/SlotReels.metal +436 -0
  77. package/msl/SplitFlap.metal +589 -0
  78. package/msl/Swirl.metal +144 -77
  79. package/msl/TruchetWipe.metal +285 -0
  80. package/msl/Tumble.metal +466 -0
  81. package/msl/WarpSpeed.metal +549 -0
  82. package/msl/WaterDrop.metal +258 -49
  83. package/msl/WaveWipe.metal +618 -0
  84. package/package.json +1 -1
  85. package/skills/gl-transitions/references/catalog.md +119 -74
  86. package/sksl/BandWipe.sksl +77 -0
  87. package/sksl/BookFlip.sksl +117 -20
  88. package/sksl/BowTie.sksl +1 -1
  89. package/sksl/Clothesline.sksl +217 -0
  90. package/sksl/ComicPanels.sksl +176 -0
  91. package/sksl/Cube.sksl +99 -46
  92. package/sksl/DirectionalWipe.sksl +1 -1
  93. package/sksl/DominoFall.sksl +122 -0
  94. package/sksl/Doorway.sksl +65 -35
  95. package/sksl/Drape.sksl +192 -0
  96. package/sksl/DuotoneFade.sksl +71 -0
  97. package/sksl/FacetedGlass.sksl +148 -0
  98. package/sksl/FrostWipe.sksl +183 -0
  99. package/sksl/Funnel.sksl +83 -0
  100. package/sksl/GlintDissolve.sksl +136 -0
  101. package/sksl/GlitterDissolve.sksl +175 -0
  102. package/sksl/GridFlip.sksl +141 -52
  103. package/sksl/HeartWipe.sksl +60 -11
  104. package/sksl/InsetWipe.sksl +70 -0
  105. package/sksl/InsideCube.sksl +123 -0
  106. package/sksl/KeyholeWipe.sksl +109 -0
  107. package/sksl/LedWall.sksl +137 -0
  108. package/sksl/LightningFlash.sksl +202 -0
  109. package/sksl/MoireWipe.sksl +85 -0
  110. package/sksl/PaperFold.sksl +170 -0
  111. package/sksl/PuzzleCube.sksl +203 -0
  112. package/sksl/RibbonTwist.sksl +66 -0
  113. package/sksl/Shatter.sksl +218 -33
  114. package/sksl/SketchDissolve.sksl +111 -0
  115. package/sksl/SlotReels.sksl +127 -0
  116. package/sksl/SplitFlap.sksl +131 -0
  117. package/sksl/Swirl.sksl +49 -20
  118. package/sksl/TruchetWipe.sksl +92 -0
  119. package/sksl/Tumble.sksl +122 -0
  120. package/sksl/WarpSpeed.sksl +131 -0
  121. package/sksl/WaterDrop.sksl +64 -10
  122. package/sksl/WaveWipe.sksl +165 -0
  123. package/sksl/index.js +1 -1
  124. package/transitions/BandWipe.glsl +66 -0
  125. package/transitions/BookFlip.glsl +124 -21
  126. package/transitions/BowTie.glsl +1 -1
  127. package/transitions/Clothesline.glsl +216 -0
  128. package/transitions/ComicPanels.glsl +173 -0
  129. package/transitions/Cube.glsl +105 -52
  130. package/transitions/DirectionalWipe.glsl +1 -1
  131. package/transitions/DominoFall.glsl +113 -0
  132. package/transitions/Doorway.glsl +74 -38
  133. package/transitions/Drape.glsl +185 -0
  134. package/transitions/DuotoneFade.glsl +57 -0
  135. package/transitions/FacetedGlass.glsl +136 -0
  136. package/transitions/FrostWipe.glsl +175 -0
  137. package/transitions/Funnel.glsl +70 -0
  138. package/transitions/GlintDissolve.glsl +124 -0
  139. package/transitions/GlitterDissolve.glsl +170 -0
  140. package/transitions/GridFlip.glsl +151 -56
  141. package/transitions/HeartWipe.glsl +71 -11
  142. package/transitions/InsetWipe.glsl +57 -0
  143. package/transitions/InsideCube.glsl +113 -0
  144. package/transitions/KeyholeWipe.glsl +103 -0
  145. package/transitions/LedWall.glsl +126 -0
  146. package/transitions/LightningFlash.glsl +199 -0
  147. package/transitions/MoireWipe.glsl +74 -0
  148. package/transitions/PaperFold.glsl +167 -0
  149. package/transitions/PuzzleCube.glsl +204 -0
  150. package/transitions/RibbonTwist.glsl +52 -0
  151. package/transitions/Shatter.glsl +231 -35
  152. package/transitions/SketchDissolve.glsl +99 -0
  153. package/transitions/SlotReels.glsl +117 -0
  154. package/transitions/SplitFlap.glsl +123 -0
  155. package/transitions/Swirl.glsl +52 -21
  156. package/transitions/TruchetWipe.glsl +79 -0
  157. package/transitions/Tumble.glsl +112 -0
  158. package/transitions/WarpSpeed.glsl +119 -0
  159. package/transitions/WaterDrop.glsl +69 -13
  160. package/transitions/WaveWipe.glsl +153 -0
  161. package/wgsl/BandWipe.wgsl +319 -0
  162. package/wgsl/BookFlip.wgsl +552 -105
  163. package/wgsl/BowTie.wgsl +1 -1
  164. package/wgsl/Clothesline.wgsl +756 -0
  165. package/wgsl/ComicPanels.wgsl +886 -0
  166. package/wgsl/Cube.wgsl +461 -156
  167. package/wgsl/DirectionalWipe.wgsl +1 -1
  168. package/wgsl/DominoFall.wgsl +461 -0
  169. package/wgsl/Doorway.wgsl +333 -117
  170. package/wgsl/Drape.wgsl +715 -0
  171. package/wgsl/DuotoneFade.wgsl +185 -0
  172. package/wgsl/FacetedGlass.wgsl +476 -0
  173. package/wgsl/FrostWipe.wgsl +617 -0
  174. package/wgsl/Funnel.wgsl +248 -0
  175. package/wgsl/GlintDissolve.wgsl +519 -0
  176. package/wgsl/GlitterDissolve.wgsl +582 -0
  177. package/wgsl/GridFlip.wgsl +523 -188
  178. package/wgsl/HeartWipe.wgsl +225 -55
  179. package/wgsl/InsetWipe.wgsl +200 -0
  180. package/wgsl/InsideCube.wgsl +496 -0
  181. package/wgsl/KeyholeWipe.wgsl +337 -0
  182. package/wgsl/LedWall.wgsl +397 -0
  183. package/wgsl/LightningFlash.wgsl +964 -0
  184. package/wgsl/MoireWipe.wgsl +222 -0
  185. package/wgsl/PaperFold.wgsl +700 -0
  186. package/wgsl/PuzzleCube.wgsl +1087 -0
  187. package/wgsl/RibbonTwist.wgsl +206 -0
  188. package/wgsl/Shatter.wgsl +1091 -148
  189. package/wgsl/SketchDissolve.wgsl +409 -0
  190. package/wgsl/SlotReels.wgsl +391 -0
  191. package/wgsl/SplitFlap.wgsl +533 -0
  192. package/wgsl/Swirl.wgsl +138 -77
  193. package/wgsl/TruchetWipe.wgsl +255 -0
  194. package/wgsl/Tumble.wgsl +424 -0
  195. package/wgsl/WarpSpeed.wgsl +497 -0
  196. package/wgsl/WaterDrop.wgsl +251 -49
  197. package/wgsl/WaveWipe.wgsl +581 -0
  198. package/glsl3/BlockDissolve.glsl +0 -16
  199. package/glsl3/BowTieVertical.glsl +0 -117
  200. package/glsl3/Box.glsl +0 -33
  201. package/glsl3/LinearBlur.glsl +0 -30
  202. package/glsl3/MosaicBlend.glsl +0 -21
  203. package/glsl3/MosaicFade.glsl +0 -20
  204. package/glsl3/RotateFade.glsl +0 -22
  205. package/glsl3/ScaleIn.glsl +0 -18
  206. package/glsl3/WipeDown.glsl +0 -12
  207. package/glsl3/WipeLeft.glsl +0 -12
  208. package/glsl3/WipeRight.glsl +0 -12
  209. package/glsl3/WipeUp.glsl +0 -12
  210. package/msl/BlockDissolve.metal +0 -108
  211. package/msl/BowTieVertical.metal +0 -375
  212. package/msl/Box.metal +0 -204
  213. package/msl/LinearBlur.metal +0 -169
  214. package/msl/MosaicBlend.metal +0 -136
  215. package/msl/MosaicFade.metal +0 -137
  216. package/msl/RotateFade.metal +0 -116
  217. package/msl/ScaleIn.metal +0 -111
  218. package/msl/WipeDown.metal +0 -105
  219. package/msl/WipeLeft.metal +0 -105
  220. package/msl/WipeRight.metal +0 -105
  221. package/msl/WipeUp.metal +0 -105
  222. package/sksl/BlockDissolve.sksl +0 -29
  223. package/sksl/BowTieVertical.sksl +0 -130
  224. package/sksl/Box.sksl +0 -47
  225. package/sksl/LinearBlur.sksl +0 -44
  226. package/sksl/MosaicBlend.sksl +0 -34
  227. package/sksl/MosaicFade.sksl +0 -33
  228. package/sksl/RotateFade.sksl +0 -34
  229. package/sksl/ScaleIn.sksl +0 -32
  230. package/sksl/WipeDown.sksl +0 -26
  231. package/sksl/WipeLeft.sksl +0 -26
  232. package/sksl/WipeRight.sksl +0 -26
  233. package/sksl/WipeUp.sksl +0 -26
  234. package/transitions/BlockDissolve.glsl +0 -15
  235. package/transitions/BowTieVertical.glsl +0 -116
  236. package/transitions/Box.glsl +0 -32
  237. package/transitions/LinearBlur.glsl +0 -29
  238. package/transitions/MosaicBlend.glsl +0 -20
  239. package/transitions/MosaicFade.glsl +0 -19
  240. package/transitions/RotateFade.glsl +0 -21
  241. package/transitions/ScaleIn.glsl +0 -17
  242. package/transitions/WipeDown.glsl +0 -11
  243. package/transitions/WipeLeft.glsl +0 -11
  244. package/transitions/WipeRight.glsl +0 -11
  245. package/transitions/WipeUp.glsl +0 -11
  246. package/wgsl/BlockDissolve.wgsl +0 -78
  247. package/wgsl/BowTieVertical.wgsl +0 -331
  248. package/wgsl/Box.wgsl +0 -176
  249. package/wgsl/LinearBlur.wgsl +0 -131
  250. package/wgsl/MosaicBlend.wgsl +0 -108
  251. package/wgsl/MosaicFade.wgsl +0 -107
  252. package/wgsl/RotateFade.wgsl +0 -85
  253. package/wgsl/ScaleIn.wgsl +0 -79
  254. package/wgsl/WipeDown.wgsl +0 -77
  255. package/wgsl/WipeLeft.wgsl +0 -77
  256. package/wgsl/WipeRight.wgsl +0 -77
  257. package/wgsl/WipeUp.wgsl +0 -77
@@ -0,0 +1,170 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The image becomes a shimmering field of tiny diamond sequins that flip over in 3D at random moments, each lifting and tilting on its own axis and flashing a glint of light, and land on the incoming image
4
+ // Tags: tiles, flip, 3d, sparkle, dissolve
5
+
6
+ // @range(6, 60) Number of tiles stacked across the height of the frame
7
+ uniform float tiles; // = 20.0
8
+ // @param Hexagonal tiles instead of diamonds
9
+ uniform bool hexagons; // = false
10
+ // @range(0, 2) Strength of the glints the tiles catch as they turn
11
+ uniform float sparkle; // = 1.0
12
+ // @color Color of the glints, added as light
13
+ uniform vec3 glint; // = vec3(1.0, 0.97, 0.9)
14
+ // @range(0, 100) Changes the order and the axes of the flips (whole numbers)
15
+ uniform float seed; // = 0.0
16
+ // @color Color seen behind a tile while it is edge-on
17
+ uniform vec4 backColor; // = vec4(0.04, 0.04, 0.05, 1.0)
18
+
19
+ // share of the transition each tile takes to flip over
20
+ const float FLIP = 0.28;
21
+ // how much a tile grows as it lifts toward the viewer, halfway through its flip
22
+ const float LIFT = 0.3;
23
+ // width of the soft edge of the tiles, in tiles
24
+ const float EDGE = 0.04;
25
+ // the grid is shifted off the pixel centers, so that no pixel sits right on the border of two tiles
26
+ const vec2 SHIFT = vec2(0.37, 0.21);
27
+ const float PI = 3.14159265;
28
+
29
+ float hash12(vec2 p) {
30
+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);
31
+ p3 += dot(p3, p3.yzx + 33.33);
32
+ return fract((p3.x + p3.y) * p3.z);
33
+ }
34
+
35
+ // folds uv back into 0..1, so the tiles on the border of the frame stay filled
36
+ vec2 mirrored(vec2 v) {
37
+ vec2 m = mod(v, 2.0);
38
+ return mix(m, 2.0 - m, step(1.0, m));
39
+ }
40
+
41
+ // how far the tile has flipped, 0 before it starts and 1 once it has landed
42
+ float flipOf(vec2 id) {
43
+ float t = clamp((progress - hash12(id) * (1.0 - FLIP)) / FLIP, 0.0, 1.0);
44
+ return t * t * (3.0 - 2.0 * t);
45
+ }
46
+
47
+ // the direction perpendicular to the axis the tile turns around
48
+ vec2 axisOf(vec2 id) {
49
+ float a = 2.0 * PI * hash12(id + 41.7);
50
+ return vec2(cos(a), sin(a));
51
+ }
52
+
53
+ // the point of the flat tile seen at offset s from its center, through the foreshortening and the lift
54
+ vec2 unproject(vec2 s, vec2 n, float f) {
55
+ float c = abs(cos(PI * f));
56
+ float along = dot(s, n);
57
+ return (s + n * (along / max(c, 1e-4) - along)) / (1.0 + LIFT * sin(PI * f));
58
+ }
59
+
60
+ // 0.5 on the edges of a tile one unit tall: a diamond one unit wide, or a flat-top hexagon
61
+ float shape(vec2 v) {
62
+ v = abs(v);
63
+ return hexagons ? max(v.y, dot(v, vec2(0.8660254, 0.5))) : v.x + v.y;
64
+ }
65
+
66
+ // the id of the tile centered at center
67
+ vec2 idOf(vec2 center) {
68
+ // the centers sit on multiples of (0.866, 0.5) for hexagons, of (0.5, 0.5) for diamonds
69
+ vec2 grid = hexagons ? vec2(1.1547005, 2.0) : vec2(2.0);
70
+ return floor(center * grid + 0.5) + vec2(13.0, 7.0) * floor(seed) + 3.0;
71
+ }
72
+
73
+ // how much of the flipping tile centered at center covers the point p, with an edge soft on screen
74
+ float coverOf(vec2 p, vec2 center) {
75
+ vec2 id = idOf(center);
76
+ float f = flipOf(id);
77
+ if (f <= 0.0 || f >= 1.0) return 0.0;
78
+ float z = sin(PI * f);
79
+ // the tile is foreshortened by |cos| along its axis and grown by the lift
80
+ float onScreen = (1.0 + LIFT * z) * max(abs(cos(PI * f)), 0.15);
81
+ // the edge softens in as the tile starts turning, so that nothing pops
82
+ float edge = EDGE * min(1.0, 4.0 * z) + 1e-4;
83
+ return clamp((0.5 - shape(unproject(p - center, axisOf(id), f))) * onScreen / edge, 0.0, 1.0);
84
+ }
85
+
86
+ // the flipping tile centered at center, seen at the point p: shaded, with its glint
87
+ vec4 tileColor(vec2 p, vec2 center) {
88
+ vec2 id = idOf(center);
89
+ float f = flipOf(id);
90
+ vec2 n = axisOf(id);
91
+ float c = cos(PI * f);
92
+ float z = sin(PI * f);
93
+ vec2 s0 = unproject(p - center, n, f);
94
+ vec2 suv = mirrored((center + s0 - SHIFT) / tiles / vec2(ratio, 1.0) + 0.5);
95
+ vec4 col = c > 0.0 ? getFromColor(suv) : getToColor(suv);
96
+ // the face turned to the viewer, slightly cupped like a sequin, lit from the top left
97
+ vec3 nrm = normalize(vec3(n * z * (c < 0.0 ? -1.0 : 1.0) + 0.5 * s0, abs(c)));
98
+ vec3 L = normalize(vec3(-0.3, 0.4, 1.0));
99
+ float shade = 0.45 + 0.55 * clamp(dot(nrm, L) / L.z, 0.0, 1.6);
100
+ // a glint where the face mirrors the light toward the viewer, and on the rim when edge-on
101
+ vec3 H = normalize(vec3(-0.45, 0.55, 1.0));
102
+ float spec = smoothstep(0.94, 0.995, dot(nrm, H)) * 2.0 + pow(1.0 - abs(c), 6.0) * 0.6;
103
+ vec3 light = clamp(glint * sparkle * spec * z, 0.0, 1.0);
104
+ vec3 base = clamp(col.rgb * mix(1.0, shade, z), 0.0, 1.0);
105
+ return vec4(base + light - base * light, col.a);
106
+ }
107
+
108
+ vec4 transition(vec2 uv) {
109
+ if (progress <= 0.0) return getFromColor(uv);
110
+ if (progress >= 1.0) return getToColor(uv);
111
+
112
+ // in units where the tiles are one unit tall
113
+ vec2 p = (uv - 0.5) * vec2(ratio, 1.0) * tiles + SHIFT;
114
+ // the center of the tile of the pixel
115
+ vec2 home;
116
+ if (hexagons) {
117
+ vec2 s = vec2(1.7320508, 1.0);
118
+ vec2 a = mod(p, s) - 0.5 * s;
119
+ vec2 b = mod(p - 0.5 * s, s) - 0.5 * s;
120
+ home = dot(a, a) < dot(b, b) ? p - a : p - b;
121
+ } else {
122
+ // a square grid turned by 45 degrees
123
+ vec2 q = floor(vec2(p.x + p.y, p.y - p.x)) + 0.5;
124
+ home = vec2(q.x - q.y, q.x + q.y) * 0.5;
125
+ }
126
+
127
+ // what lies under the flipping tiles: the image while the own tile rests, else the backing
128
+ float fHome = flipOf(idOf(home));
129
+ vec4 under = fHome <= 0.0 ? getFromColor(uv) : fHome >= 1.0 ? getToColor(uv) : backColor;
130
+
131
+ // the two topmost flipping tiles at the pixel, among its own and the lifted neighbours
132
+ // reaching over it: the higher a tile is in its flip, the closer it is to the viewer
133
+ float z1 = -1.0;
134
+ float z2 = -1.0;
135
+ float cover1 = 0.0;
136
+ float cover2 = 0.0;
137
+ vec2 center1 = home;
138
+ vec2 center2 = home;
139
+ for (int k = 0; k < 9; k++) {
140
+ float fk = float(k);
141
+ vec2 off;
142
+ if (hexagons) {
143
+ if (k > 6) break;
144
+ off = k == 0 ? vec2(0.0) : k < 3 ? vec2(0.0, fk * 2.0 - 3.0) : vec2(mod(fk, 2.0) * 1.7320508 - 0.8660254, fk < 5.0 ? -0.5 : 0.5);
145
+ } else {
146
+ vec2 o = vec2(mod(fk, 3.0) - 1.0, floor(fk / 3.0) - 1.0);
147
+ off = vec2(o.x - o.y, o.x + o.y) * 0.5;
148
+ }
149
+ vec2 center = home + off;
150
+ float cover = coverOf(p, center);
151
+ if (cover <= 0.0) continue;
152
+ float z = sin(PI * flipOf(idOf(center)));
153
+ if (z > z1) {
154
+ z2 = z1;
155
+ cover2 = cover1;
156
+ center2 = center1;
157
+ z1 = z;
158
+ cover1 = cover;
159
+ center1 = center;
160
+ } else if (z > z2) {
161
+ z2 = z;
162
+ cover2 = cover;
163
+ center2 = center;
164
+ }
165
+ }
166
+ if (z1 < 0.0) return under;
167
+ vec4 c = under;
168
+ if (z2 >= 0.0 && cover1 < 1.0) c = mix(c, tileColor(p, center2), cover2);
169
+ return mix(c, tileColor(p, center1), cover1);
170
+ }
@@ -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,57 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: A rectangle anchored in a corner, on an edge or in the center grows until the incoming image fills the frame, revealing it in place without scaling it; in reverse, the outgoing image shrinks into the rectangle
4
+ // Tags: wipe, shape, box
5
+
6
+ // @param Where the rectangle grows from: (0, 0) bottom left, (1, 1) top right, (0.5, 0) middle of the bottom edge, (0.5, 0.5) center
7
+ uniform vec2 anchor; // = vec2(1.0, 1.0)
8
+ // @range(0, 0.2) Softness of the rectangle's edge
9
+ uniform float smoothness; // = 0.0
10
+ // @range(0, 0.1) Width of a border drawn around the rectangle, in frame heights (0: no border)
11
+ uniform float borderWidth; // = 0.0
12
+ // @color Color of the border
13
+ uniform vec4 borderColor; // = vec4(1.0, 1.0, 1.0, 1.0)
14
+ // @param The outgoing image shrinks into the rectangle instead, toward the anchor
15
+ uniform bool reverse; // = false
16
+
17
+ // half width of the antialiased edge, in frame heights
18
+ const float AA = 0.001;
19
+
20
+ vec4 premultiplied(vec4 c) {
21
+ return vec4(c.rgb * c.a, c.a);
22
+ }
23
+
24
+ vec4 transition(vec2 uv) {
25
+ vec4 a = getFromColor(uv);
26
+ vec4 b = getToColor(uv);
27
+ if (progress <= 0.0) return a;
28
+ if (progress >= 1.0) return b;
29
+
30
+ vec2 an = clamp(anchor, 0.0, 1.0);
31
+ vec2 sq = vec2(ratio, 1.0);
32
+ // the rectangle keeps the proportions that make it reach every far side of the frame
33
+ // at once; measured in square pixels so its edge and border have an even width
34
+ vec2 ext = max(an, 1.0 - an) * sq;
35
+ vec2 d = abs(uv - an) * sq;
36
+ float s = max(smoothness, AA);
37
+ float bw = max(borderWidth, 0.0);
38
+
39
+ // eased growth, from a rectangle whose border is not yet in the frame to one whose
40
+ // soft edge has left it on every side
41
+ float t = reverse ? 1.0 - progress : progress;
42
+ float p = mix(t, t * t * (3.0 - 2.0 * t), 0.3);
43
+ vec2 size = p * ext + mix(-(bw + s), s, p);
44
+ // signed distance to the rectangle's edge, square-cornered, < 0 inside
45
+ float e = max(d.x - size.x, d.y - size.y);
46
+
47
+ // the rectangle shows the incoming image, or the outgoing one in reverse
48
+ vec4 inside = reverse ? a : b;
49
+ vec4 c = premultiplied(reverse ? b : a);
50
+ if (bw > 0.0) {
51
+ // laid over the image outside the rectangle, so a translucent border tints it
52
+ float m = 1.0 - smoothstep(bw - s, bw + s, e);
53
+ c = premultiplied(borderColor) * m + c * (1.0 - borderColor.a * m);
54
+ }
55
+ c = mix(c, premultiplied(inside), 1.0 - smoothstep(-s, s, e));
56
+ return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
57
+ }
@@ -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
+ }