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,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,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
  }
@@ -0,0 +1,185 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image hangs like a sheet of fabric that is let go at the top: it collapses into soft, uneven folds that hide one another as the cloth bunches up and slides down out of the frame, revealing the incoming image behind it
4
+ // Tags: fabric, fold, vertical, 3d, shadow
5
+
6
+ // @range(1, 16, 1) Number of folds across the cloth (fewer in a portrait image)
7
+ uniform float folds; // = 6.0
8
+ // @range(0, 1) Depth of the folds and of their shading
9
+ uniform float depth; // = 0.7
10
+ // @range(0, 1) How much the cloth sways sideways as it falls
11
+ uniform float sway; // = 0.4
12
+ // @range(0, 1) Strength of the soft shadow cast by the cloth on the incoming image
13
+ uniform float shadow; // = 0.5
14
+
15
+ const float PI = 3.141592653589793;
16
+ const int STEPS = 24;
17
+ const float DEPTH = 0.8; // height of the deepest folds, times the fold width
18
+
19
+ // folds a coordinate back into 0..1, mirroring the image at its edges
20
+ vec2 mirror(vec2 v) {
21
+ return 1.0 - abs(1.0 - mod(v, 2.0));
22
+ }
23
+
24
+ // integer-free hash of an integer cell, smoothed into a 1D value noise in 0..1
25
+ float hash11(float p) {
26
+ p = fract(p * 0.1031);
27
+ p *= p + 33.33;
28
+ p *= p + p;
29
+ return fract(p);
30
+ }
31
+
32
+ float noise1(float x) {
33
+ float i = floor(x);
34
+ float f = x - i;
35
+ return mix(hash11(i), hash11(i + 1.0), f * f * (3.0 - 2.0 * f));
36
+ }
37
+
38
+ // height of the top edge above x, sagging in the middle (m: see cloth)
39
+ float topEdge(float x, vec4 m) {
40
+ float c = 2.0 * x - 1.0;
41
+ return m.y - 0.08 * m.x * (1.0 - c * c);
42
+ }
43
+
44
+ // how far the sides are pulled in at the height sy, more so at the bunched top
45
+ float sidePull(float sy, float gT) {
46
+ return 0.035 * gT * (0.3 + 0.7 * clamp(sy, 0.0, 1.0));
47
+ }
48
+
49
+ // height of the cloth at the point (x, y) of the screen plane, toward the viewer,
50
+ // or -1 where there is no cloth. Also gives the cloth's own coordinates and fold phase.
51
+ // m: how far the folds have formed (0 at rest), height of the top edge, height of the hem, sideways swing
52
+ vec4 cloth(vec2 p, vec4 m, float foldN) {
53
+ float gT = m.x;
54
+ float botY = m.z;
55
+ float x = p.x - m.w;
56
+ float top = topEdge(x, m);
57
+ float sy = (p.y - botY) / max(top - botY, 1e-4); // 0 at the hem, 1 at the top edge
58
+ float pull = sidePull(sy, gT);
59
+ float xc = (x - pull) / (1.0 - 2.0 * pull);
60
+ // uneven folds: their width, depth and course along the cloth all wander
61
+ float wander = (noise1(0.5 * foldN * xc + 2.5 * sy + 5.3) - 0.5) * 2.4 * (1.0 - sy);
62
+ float ph = 2.0 * PI * (foldN * xc + 0.6 * noise1(0.7 * foldN * xc + 1.7)) + wander;
63
+ float d = 0.15 + 0.85 * noise1(1.1 * foldN * xc + 1.4 * sy + 7.0);
64
+ // deepest near the bunched top, relaxing toward the hem
65
+ float amp = DEPTH * depth * gT * (0.3 + 0.7 * sy * sqrt(max(sy, 0.0))) / max(foldN, 2.0);
66
+ // the free sides of the cloth hang flat
67
+ float w = 0.6 / foldN;
68
+ amp *= smoothstep(0.0, w, xc) * smoothstep(0.0, w, 1.0 - xc);
69
+ float prof = 0.5 - 0.5 * cos(ph); // 1 on a ridge, 0 in a valley
70
+ // small sagging creases where the fabric piles up under the top edge
71
+ float dt = (1.0 - sy) * (top - botY);
72
+ float crease = exp(-30.0 * dt) * (0.5 + 0.5 * sin(80.0 * dt + 0.7 * ph));
73
+ bool on = sy >= 0.0 && sy <= 1.0 && xc >= 0.0 && xc <= 1.0;
74
+ return on ? vec4(amp * (d * prof + 0.15 * crease), xc, sy, ph) : vec4(-1.0);
75
+ }
76
+
77
+ vec4 transition (vec2 uv) {
78
+ float t = progress;
79
+ // the top edge falls first and the hem follows later: the cloth collapses as it slides down
80
+ float topY = 1.0 - 1.06 * t * (0.35 + 0.65 * t);
81
+ float botY = -0.75 * t * t * t;
82
+ // the folds form as soon as the top is let go
83
+ float f = 1.0 - (1.0 - t) * (1.0 - t) * (1.0 - t);
84
+ float foldN = max(1.0, floor(folds * min(ratio, 1.0) + 0.5));
85
+ float shiftX = sway * 0.035 * sin(2.0 * PI * t) * f;
86
+ // the cloth is seen a little from the left and from above: ridges hide the valleys behind them
87
+ vec2 view = vec2(0.75 + 0.5 * sway * sin(PI * t) * f, -0.35);
88
+ float zMax = 1.15 * DEPTH * depth * f / max(foldN, 2.0); // a single fold is no deeper than two
89
+ vec4 m = vec4(f, topY, botY, shiftX);
90
+ // march from the front toward the screen plane, the first point inside the cloth is visible
91
+ float zA = zMax; // last step in front of the cloth
92
+ float zB = 0.0; // first step inside it
93
+ bool found = false;
94
+ float dA = 0.0;
95
+ float dB = 0.0;
96
+ bool onA = false; // whether the last step in front was over the cloth (else the ray came in through its edge)
97
+ for (int i = 0; i < STEPS; i++) {
98
+ if (!found) {
99
+ float z = max(zMax * (1.0 - float(i) / float(STEPS - 1)), 0.0);
100
+ vec4 s = cloth(uv - view * z, m, foldN);
101
+ float dz = s.x - z;
102
+ if (s.x >= 0.0 && dz >= 0.0) {
103
+ found = true;
104
+ zB = z;
105
+ dB = dz;
106
+ } else {
107
+ zA = z;
108
+ dA = dz;
109
+ onA = s.x >= 0.0;
110
+ }
111
+ }
112
+ }
113
+ float zHit = zB;
114
+ if (found && zA > zB) {
115
+ if (onA) {
116
+ // crossed the surface: refine between the last two steps
117
+ zHit = mix(zA, zB, dA / (dA - dB));
118
+ } else {
119
+ // came in through the top edge: find where the ray first meets the cloth,
120
+ // on its surface or through the edge (then it sees the inside of the fold)
121
+ float za = zA;
122
+ for (int j = 0; j < 5; j++) {
123
+ float zm = 0.5 * (za + zHit);
124
+ if (cloth(uv - view * zm, m, foldN).x >= zm) zHit = zm;
125
+ else za = zm;
126
+ }
127
+ }
128
+ }
129
+ vec2 hp = uv - view * zHit;
130
+ vec4 hit = found ? cloth(hp, m, foldN) : vec4(-1.0);
131
+ if (found && hit.x < 0.0) {
132
+ zHit = zB;
133
+ hp = uv - view * zB;
134
+ hit = cloth(hp, m, foldN);
135
+ }
136
+ vec4 col = vec4(0.0);
137
+ float cover = 0.0;
138
+ if (hit.x >= 0.0) {
139
+ float xc = hit.y;
140
+ float sy = hit.z;
141
+ float ph = hit.w;
142
+ // the fabric is gathered: more of it goes into the slopes of the folds
143
+ float slope = PI * zMax * foldN;
144
+ // (capped so that the texture never runs backwards where the folds bunch up)
145
+ float mu = min(0.25 * slope * slope / (1.0 + 0.25 * slope * slope), 0.5);
146
+ float u = xc - mu * sin(2.0 * ph) / (4.0 * PI * foldN);
147
+ // and pushed together under the top edge
148
+ float h = max(topY - botY, 1e-4);
149
+ float comp = max(1.0 - h, 0.0);
150
+ float v = sy * (1.0 - comp) + comp * sy * sy * sy;
151
+ vec4 tex = getFromColor(mirror(vec2(u, v)));
152
+ float span = topEdge(hp.x - shiftX, m) - botY; // local height of the cloth
153
+ // surface normal from the height of the cloth around the visible point
154
+ float e = 0.002;
155
+ float hx = cloth(hp + vec2(e, 0.0), m, foldN).x;
156
+ float hy = cloth(hp + vec2(0.0, e), m, foldN).x;
157
+ float hx0 = hx >= 0.0 ? hx : hit.x;
158
+ float hy0 = hy >= 0.0 ? hy : hit.x;
159
+ vec3 nrm = normalize(vec3(-(hx0 - hit.x) / e, -(hy0 - hit.x) / e, 1.0));
160
+ vec3 light = normalize(vec3(-0.45, 0.35, 1.0));
161
+ float diffuse = mix(1.0, max(dot(nrm, light), 0.0) / light.z, min(1.0, 3.0 * f));
162
+ // soft ambient occlusion in the valleys, deeper where the folds are deep
163
+ float valley = 1.0 - (0.5 - 0.5 * cos(ph));
164
+ float ao = 1.0 - 0.6 * depth * f * valley * valley * (0.35 + 0.65 * sy);
165
+ // the rolled top edge gets less light
166
+ float rim = exp(-(1.0 - sy) * span * 70.0) * 0.35 * f;
167
+ // below the surface, the ray sees the shaded inside of a fold through the top edge
168
+ float under = max(hit.x - zHit, 0.0);
169
+ float back = min(1.0, under / max(0.1 * zMax, 1e-6));
170
+ tex.rgb *= diffuse * ao * (1.0 - rim) * (1.0 - 0.6 * back);
171
+ col = tex;
172
+ // anti-aliased outline, sharp at rest so the first frame is exact
173
+ float aa = 0.003 * f;
174
+ float inside = min((1.0 - sy) * span - view.y * under, min(xc, 1.0 - xc));
175
+ cover = aa > 0.0 ? clamp(inside / aa, 0.0, 1.0) : 1.0;
176
+ if (cover >= 1.0) return col;
177
+ }
178
+ // soft shadow of the cloth, held a little away from the incoming image, gone once it has left
179
+ vec4 to = getToColor(uv);
180
+ float x = uv.x - shiftX;
181
+ float pull = sidePull((uv.y - botY) / max(topEdge(x, m) - botY, 1e-4), f);
182
+ float outside = max(uv.y - topEdge(x, m), max(-x, x - 1.0) - pull);
183
+ float sh = shadow * exp(-max(outside, 0.0) * 16.0) * f * clamp(8.0 * (1.0 - t), 0.0, 1.0);
184
+ return mix(vec4(to.rgb * (1.0 - 0.8 * sh), to.a), col, cover);
185
+ }
@@ -0,0 +1,57 @@
1
+ // Author: gre
2
+ // License: MIT
3
+ // Description: The outgoing image is printed in two inks, shadows first, as a bold high-contrast duotone; the incoming image is printed over it in the same two inks, its dark tones landing before its highlights, then its own colors come back, highlights first
4
+ // Tags: color, duotone, print, poster, gradient-map, luminance
5
+
6
+ // @color Ink printed in the shadows (its alpha is its strength)
7
+ uniform vec4 shadowInk; // = vec4(0.11, 0.09, 0.46, 1.0)
8
+ // @color Ink printed in the highlights (its alpha is its strength)
9
+ uniform vec4 highlightInk; // = vec4(1.0, 0.45, 0.62, 1.0)
10
+ // @range(0, 1) How hard the tones are pushed apart toward the two inks
11
+ uniform float contrast; // = 0.6
12
+ // @range(0, 1) Amount of print grain in the inks and along the handoff
13
+ uniform float grain; // = 0.4
14
+
15
+ float dfHash(vec2 v) {
16
+ vec3 v3 = fract(vec3(v.xyx) * 0.1031);
17
+ v3 += dot(v3, v3.yzx + 33.33);
18
+ return fract((v3.x + v3.y) * v3.z);
19
+ }
20
+
21
+ float dfLuma(vec4 c) {
22
+ return clamp(dot(c.rgb, vec3(0.299, 0.587, 0.114)), 0.0, 1.0);
23
+ }
24
+
25
+ vec4 transition(vec2 uv) {
26
+ vec4 a = getFromColor(uv);
27
+ vec4 b = getToColor(uv);
28
+ float la = dfLuma(a);
29
+ float lb = dfLuma(b);
30
+ // fixed print grain, in cells of about 1/360 of the shorter side
31
+ vec2 q = uv * 360.0 * vec2(max(ratio, 1.0), max(1.0 / ratio, 1.0));
32
+ float g = dfHash(floor(q)) - 0.5;
33
+
34
+ // the inks land on the outgoing image (shadows first), then lift off the incoming one (highlights first)
35
+ float inks = smoothstep(0.0, 0.35, progress);
36
+ float lift = smoothstep(0.65, 1.0, progress);
37
+ float amount = min(
38
+ clamp(inks * 1.35 - 0.35 * la, 0.0, 1.0),
39
+ clamp((1.0 - lift) * 1.35 - 0.35 * lb, 0.0, 1.0)
40
+ );
41
+ amount = amount * amount * (3.0 - 2.0 * amount);
42
+
43
+ // the incoming image is printed over the outgoing one, darkest tones first, along a grainy edge
44
+ float x = smoothstep(0.25, 0.75, progress) * 1.6 - 0.3;
45
+ float t = lb + 0.2 * grain * g;
46
+ float s = smoothstep(t - 0.15, t + 0.15, x);
47
+
48
+ // gradient map on luminance, with the tones pushed toward the two inks
49
+ float c = 0.4 * contrast;
50
+ float tone = smoothstep(c + 0.03, 1.03 - c, mix(la, lb, s) + 0.08 * grain * g);
51
+ vec4 ink = mix(shadowInk, highlightInk, tone);
52
+
53
+ // the images are blended with premultiplied alpha, and where neither is drawn nothing is printed
54
+ vec4 base = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), s);
55
+ if (base.a <= 0.0) return vec4(0.0);
56
+ return vec4(mix(base.rgb / base.a, ink.rgb, amount * ink.a), base.a);
57
+ }