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.
- package/CHANGELOG.md +80 -0
- package/compatibility.json +455 -11
- package/gl-transitions.js +1 -1
- package/gl-transitions.json +1 -1
- package/glsl3/BookFlip.glsl +124 -21
- package/glsl3/CircleBurst.glsl +77 -0
- package/glsl3/Clothesline.glsl +217 -0
- package/glsl3/CodeRain.glsl +114 -0
- package/glsl3/ComicPanels.glsl +174 -0
- package/glsl3/Cube.glsl +105 -52
- package/glsl3/CurtainRise.glsl +71 -0
- package/glsl3/DominoFall.glsl +114 -0
- package/glsl3/Doorway.glsl +74 -38
- package/glsl3/Drape.glsl +186 -0
- package/glsl3/DuotoneFade.glsl +58 -0
- package/glsl3/FacetedGlass.glsl +137 -0
- package/glsl3/FrostWipe.glsl +176 -0
- package/glsl3/Funnel.glsl +71 -0
- package/glsl3/GlitterDissolve.glsl +171 -0
- package/glsl3/GravityLens.glsl +66 -0
- package/glsl3/GridFlip.glsl +151 -56
- package/glsl3/HeartWipe.glsl +71 -11
- package/glsl3/InsideCube.glsl +114 -0
- package/glsl3/KeyholeWipe.glsl +104 -0
- package/glsl3/LedWall.glsl +127 -0
- package/glsl3/MoireWipe.glsl +75 -0
- package/glsl3/PaperFold.glsl +168 -0
- package/glsl3/PuzzleCube.glsl +205 -0
- package/glsl3/RibbonTwist.glsl +53 -0
- package/glsl3/RingSpin.glsl +112 -0
- package/glsl3/Shatter.glsl +231 -35
- package/glsl3/SketchDissolve.glsl +100 -0
- package/glsl3/SlotReels.glsl +118 -0
- package/glsl3/SplitFlap.glsl +124 -0
- package/glsl3/SpotlightWipe.glsl +63 -0
- package/glsl3/Swirl.glsl +52 -21
- package/glsl3/TruchetWipe.glsl +80 -0
- package/glsl3/Tumble.glsl +113 -0
- package/glsl3/WaterDrop.glsl +69 -13
- package/glsl3/WaveWipe.glsl +154 -0
- package/index.js +1 -1
- package/layouts.json +1232 -29
- package/llms-full.txt +890 -403
- package/llms.txt +225 -197
- package/msl/BookFlip.metal +575 -114
- package/msl/CircleBurst.metal +351 -0
- package/msl/Clothesline.metal +828 -0
- package/msl/CodeRain.metal +451 -0
- package/msl/ComicPanels.metal +959 -0
- package/msl/Cube.metal +466 -170
- package/msl/CurtainRise.metal +263 -0
- package/msl/DominoFall.metal +510 -0
- package/msl/Doorway.metal +350 -124
- package/msl/Drape.metal +767 -0
- package/msl/DuotoneFade.metal +218 -0
- package/msl/FacetedGlass.metal +529 -0
- package/msl/FrostWipe.metal +677 -0
- package/msl/Funnel.metal +276 -0
- package/msl/GlitterDissolve.metal +637 -0
- package/msl/GravityLens.metal +236 -0
- package/msl/GridFlip.metal +548 -191
- package/msl/HeartWipe.metal +230 -58
- package/msl/InsideCube.metal +537 -0
- package/msl/KeyholeWipe.metal +370 -0
- package/msl/LedWall.metal +437 -0
- package/msl/MoireWipe.metal +252 -0
- package/msl/PaperFold.metal +762 -0
- package/msl/PuzzleCube.metal +1179 -0
- package/msl/RibbonTwist.metal +235 -0
- package/msl/RingSpin.metal +474 -0
- package/msl/Shatter.metal +1136 -160
- package/msl/SketchDissolve.metal +446 -0
- package/msl/SlotReels.metal +436 -0
- package/msl/SplitFlap.metal +589 -0
- package/msl/SpotlightWipe.metal +217 -0
- package/msl/Swirl.metal +144 -77
- package/msl/TruchetWipe.metal +285 -0
- package/msl/Tumble.metal +466 -0
- package/msl/WaterDrop.metal +258 -49
- package/msl/WaveWipe.metal +618 -0
- package/package.json +1 -1
- package/skills/gl-transitions/references/catalog.md +115 -57
- package/sksl/BookFlip.sksl +117 -20
- package/sksl/CircleBurst.sksl +84 -0
- package/sksl/Clothesline.sksl +217 -0
- package/sksl/CodeRain.sksl +124 -0
- package/sksl/ComicPanels.sksl +176 -0
- package/sksl/Cube.sksl +99 -46
- package/sksl/CurtainRise.sksl +84 -0
- package/sksl/DominoFall.sksl +122 -0
- package/sksl/Doorway.sksl +65 -35
- package/sksl/Drape.sksl +192 -0
- package/sksl/DuotoneFade.sksl +71 -0
- package/sksl/FacetedGlass.sksl +148 -0
- package/sksl/FrostWipe.sksl +183 -0
- package/sksl/Funnel.sksl +83 -0
- package/sksl/GlitterDissolve.sksl +175 -0
- package/sksl/GravityLens.sksl +77 -0
- package/sksl/GridFlip.sksl +141 -52
- package/sksl/HeartWipe.sksl +60 -11
- package/sksl/InsideCube.sksl +123 -0
- package/sksl/KeyholeWipe.sksl +109 -0
- package/sksl/LedWall.sksl +137 -0
- package/sksl/MoireWipe.sksl +85 -0
- package/sksl/PaperFold.sksl +170 -0
- package/sksl/PuzzleCube.sksl +203 -0
- package/sksl/RibbonTwist.sksl +66 -0
- package/sksl/RingSpin.sksl +121 -0
- package/sksl/Shatter.sksl +218 -33
- package/sksl/SketchDissolve.sksl +111 -0
- package/sksl/SlotReels.sksl +127 -0
- package/sksl/SplitFlap.sksl +131 -0
- package/sksl/SpotlightWipe.sksl +74 -0
- package/sksl/Swirl.sksl +49 -20
- package/sksl/TruchetWipe.sksl +92 -0
- package/sksl/Tumble.sksl +122 -0
- package/sksl/WaterDrop.sksl +64 -10
- package/sksl/WaveWipe.sksl +165 -0
- package/sksl/index.js +1 -1
- package/transitions/BookFlip.glsl +124 -21
- package/transitions/CircleBurst.glsl +76 -0
- package/transitions/Clothesline.glsl +216 -0
- package/transitions/CodeRain.glsl +113 -0
- package/transitions/ComicPanels.glsl +173 -0
- package/transitions/Cube.glsl +105 -52
- package/transitions/CurtainRise.glsl +70 -0
- package/transitions/DominoFall.glsl +113 -0
- package/transitions/Doorway.glsl +74 -38
- package/transitions/Drape.glsl +185 -0
- package/transitions/DuotoneFade.glsl +57 -0
- package/transitions/FacetedGlass.glsl +136 -0
- package/transitions/FrostWipe.glsl +175 -0
- package/transitions/Funnel.glsl +70 -0
- package/transitions/GlitterDissolve.glsl +170 -0
- package/transitions/GravityLens.glsl +65 -0
- package/transitions/GridFlip.glsl +151 -56
- package/transitions/HeartWipe.glsl +71 -11
- package/transitions/InsideCube.glsl +113 -0
- package/transitions/KeyholeWipe.glsl +103 -0
- package/transitions/LedWall.glsl +126 -0
- package/transitions/MoireWipe.glsl +74 -0
- package/transitions/PaperFold.glsl +167 -0
- package/transitions/PuzzleCube.glsl +204 -0
- package/transitions/RibbonTwist.glsl +52 -0
- package/transitions/RingSpin.glsl +111 -0
- package/transitions/Shatter.glsl +231 -35
- package/transitions/SketchDissolve.glsl +99 -0
- package/transitions/SlotReels.glsl +117 -0
- package/transitions/SplitFlap.glsl +123 -0
- package/transitions/SpotlightWipe.glsl +62 -0
- package/transitions/Swirl.glsl +52 -21
- package/transitions/TruchetWipe.glsl +79 -0
- package/transitions/Tumble.glsl +112 -0
- package/transitions/WaterDrop.glsl +69 -13
- package/transitions/WaveWipe.glsl +153 -0
- package/wgsl/BookFlip.wgsl +552 -105
- package/wgsl/CircleBurst.wgsl +310 -0
- package/wgsl/Clothesline.wgsl +756 -0
- package/wgsl/CodeRain.wgsl +415 -0
- package/wgsl/ComicPanels.wgsl +886 -0
- package/wgsl/Cube.wgsl +461 -156
- package/wgsl/CurtainRise.wgsl +235 -0
- package/wgsl/DominoFall.wgsl +461 -0
- package/wgsl/Doorway.wgsl +333 -117
- package/wgsl/Drape.wgsl +715 -0
- package/wgsl/DuotoneFade.wgsl +185 -0
- package/wgsl/FacetedGlass.wgsl +476 -0
- package/wgsl/FrostWipe.wgsl +617 -0
- package/wgsl/Funnel.wgsl +248 -0
- package/wgsl/GlitterDissolve.wgsl +582 -0
- package/wgsl/GravityLens.wgsl +206 -0
- package/wgsl/GridFlip.wgsl +523 -188
- package/wgsl/HeartWipe.wgsl +225 -55
- package/wgsl/InsideCube.wgsl +496 -0
- package/wgsl/KeyholeWipe.wgsl +337 -0
- package/wgsl/LedWall.wgsl +397 -0
- package/wgsl/MoireWipe.wgsl +222 -0
- package/wgsl/PaperFold.wgsl +700 -0
- package/wgsl/PuzzleCube.wgsl +1087 -0
- package/wgsl/RibbonTwist.wgsl +206 -0
- package/wgsl/RingSpin.wgsl +426 -0
- package/wgsl/Shatter.wgsl +1091 -148
- package/wgsl/SketchDissolve.wgsl +409 -0
- package/wgsl/SlotReels.wgsl +391 -0
- package/wgsl/SplitFlap.wgsl +533 -0
- package/wgsl/SpotlightWipe.wgsl +186 -0
- package/wgsl/Swirl.wgsl +138 -77
- package/wgsl/TruchetWipe.wgsl +255 -0
- package/wgsl/Tumble.wgsl +424 -0
- package/wgsl/WaterDrop.wgsl +251 -49
- package/wgsl/WaveWipe.wgsl +581 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: The image twists like a ribbon around its horizontal center line, the twist travelling smoothly across its width, the outgoing image on its front and the incoming one on its back
|
|
4
|
+
// Tags: 3d, flip, rotate
|
|
5
|
+
|
|
6
|
+
// @range(0.1, 2) Length of the twisted section, as a part of the frame's width
|
|
7
|
+
uniform float spread; // = 0.8
|
|
8
|
+
// @range(0, 0.8) Amount of perspective: the edge turning toward the viewer grows
|
|
9
|
+
uniform float perspective; // = 0.4
|
|
10
|
+
// @range(0, 1) How much the ribbon darkens as it turns away
|
|
11
|
+
uniform float shading; // = 0.6
|
|
12
|
+
// @param Twist around the vertical center line instead, travelling from top to bottom
|
|
13
|
+
uniform bool vertical; // = false
|
|
14
|
+
// @color Color seen where the twisting ribbon leaves the frame uncovered
|
|
15
|
+
uniform vec4 backColor; // = vec4(0.0, 0.0, 0.0, 1.0)
|
|
16
|
+
|
|
17
|
+
const float PI = 3.141592653589793;
|
|
18
|
+
// width of the anti-aliased edges, in frame heights
|
|
19
|
+
const float EDGE = 0.002;
|
|
20
|
+
|
|
21
|
+
vec4 transition (vec2 uv) {
|
|
22
|
+
// q.x: along the ribbon, the way the twist travels; q.y: across the ribbon
|
|
23
|
+
vec2 q = vertical ? vec2(1.0 - uv.y, uv.x) : uv;
|
|
24
|
+
// the ribbon's half width across, in frame heights
|
|
25
|
+
float halfSize = vertical ? 0.5 * ratio : 0.5;
|
|
26
|
+
// each line across the ribbon turns half a turn, a little later than the one before
|
|
27
|
+
float t = smoothstep(0.0, 1.0, (progress * (1.0 + spread) - q.x) / spread);
|
|
28
|
+
// the visible face (outgoing front, incoming back) and its angle from its rest position
|
|
29
|
+
bool front = t < 0.5;
|
|
30
|
+
float angle = PI * (front ? t : t - 1.0);
|
|
31
|
+
float c = cos(angle);
|
|
32
|
+
float s = sin(angle);
|
|
33
|
+
// w: screen position across the ribbon, -1 to 1 at rest; v: the matching position on the face
|
|
34
|
+
// a point v of the face goes to v * c across and v * s in depth, nearer points look bigger
|
|
35
|
+
float w = 2.0 * q.y - 1.0;
|
|
36
|
+
float den = c + perspective * w * s;
|
|
37
|
+
if (den <= 0.0) return backColor;
|
|
38
|
+
float v = w / den;
|
|
39
|
+
if (abs(v) >= 1.0) return backColor;
|
|
40
|
+
// soft edges while twisting (sharp at rest, to keep the first and last frames exact)
|
|
41
|
+
float edge = max(EDGE * min(1.0, 20.0 * abs(s)), 1e-4);
|
|
42
|
+
float top = c / (1.0 - perspective * s);
|
|
43
|
+
float bottom = -c / (1.0 + perspective * s);
|
|
44
|
+
float cover = clamp(min(top - w, w - bottom) * halfSize / edge, 0.0, 1.0);
|
|
45
|
+
vec2 p = vec2(q.x, 0.5 + 0.5 * v);
|
|
46
|
+
p = vertical ? vec2(p.y, 1.0 - p.x) : p;
|
|
47
|
+
vec4 img = front ? getFromColor(p) : getToColor(p);
|
|
48
|
+
// lit from the front and slightly from one side of the axis
|
|
49
|
+
float lambert = clamp(c - 0.25 * s, 0.0, 1.0);
|
|
50
|
+
vec4 color = vec4(img.rgb * mix(1.0 - shading, 1.0, lambert), img.a);
|
|
51
|
+
return mix(backColor, color, cover);
|
|
52
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: The frame is cut into concentric rings that spin like the dials of a combination lock, in alternating directions and blurred with speed, one after another from the center outward; each ring overshoots a little and locks into place on the incoming image
|
|
4
|
+
// Tags: rotate, circle, rings, motion-blur
|
|
5
|
+
|
|
6
|
+
// @range(2, 12, 1) Number of rings, from the center to the farthest corner
|
|
7
|
+
uniform int rings; // = 6
|
|
8
|
+
// @param Square rings, like nested frames, instead of round ones
|
|
9
|
+
uniform bool square; // = false
|
|
10
|
+
// @range(1, 3, 1) Full turns made by each ring
|
|
11
|
+
uniform int turns; // = 1
|
|
12
|
+
// @range(0, 0.8) Delay between the first ring and the last one, as a part of the transition
|
|
13
|
+
uniform float stagger; // = 0.5
|
|
14
|
+
// @range(0, 1) Amount of angular motion blur while the rings spin fast
|
|
15
|
+
uniform float blur; // = 0.6
|
|
16
|
+
// @range(0, 1) Size of the overshoot when a ring locks
|
|
17
|
+
uniform float settle; // = 0.5
|
|
18
|
+
|
|
19
|
+
const float PI = 3.141592653589793;
|
|
20
|
+
// part of a ring's time spent overshooting and coming back
|
|
21
|
+
const float SETTLE = 0.2;
|
|
22
|
+
// half width of the gaps between the rings, width of their rims and of the anti-aliased edges, in frame heights
|
|
23
|
+
const float GAP = 0.0035;
|
|
24
|
+
const float RIM = 0.012;
|
|
25
|
+
const float EDGE = 0.0015;
|
|
26
|
+
|
|
27
|
+
vec2 mirrorUV(vec2 v) {
|
|
28
|
+
return 1.0 - abs(1.0 - mod(v, 2.0));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
vec2 rotate(vec2 v, float a) {
|
|
32
|
+
float c = cos(a), s = sin(a);
|
|
33
|
+
return vec2(c * v.x + s * v.y, c * v.y - s * v.x);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// the delay between two rings, kept shorter than the time a ring moves so that the motion never pauses
|
|
37
|
+
float ringDelay(float n) {
|
|
38
|
+
float m = max(n - 1.0, 1.0);
|
|
39
|
+
return min(clamp(stagger, 0.0, 0.8) / m, 0.7 / (1.0 + 0.7 * m));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// local time of ring i: 0 until it starts, 1 once it is locked
|
|
43
|
+
float ringTime(float i, float n) {
|
|
44
|
+
float d = ringDelay(n);
|
|
45
|
+
return progress >= 1.0 ? 1.0 : clamp((progress - d * i) / (1.0 - d * (n - 1.0)), 0.0, 1.0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// how much a ring is moving, which opens the gaps around it
|
|
49
|
+
float activity(float i, float n) {
|
|
50
|
+
float t = ringTime(i, n);
|
|
51
|
+
return smoothstep(0.0, 0.08, t) * (1.0 - smoothstep(0.88, 1.0, t));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// the ring's angle at its time t: it speeds up, reaches `total` a little fast, overshoots and springs back
|
|
55
|
+
float spin(float t, float total) {
|
|
56
|
+
float amp = 0.1 * settle * sign(total);
|
|
57
|
+
float stopT = 1.0 - SETTLE;
|
|
58
|
+
// speed at the stop, matched with the start of the overshoot
|
|
59
|
+
float v1 = amp * PI * stopT / (total * SETTLE);
|
|
60
|
+
float u = clamp(t / stopT, 0.0, 1.0);
|
|
61
|
+
float b = clamp((t - stopT) / SETTLE, 0.0, 1.0);
|
|
62
|
+
return total * (u * u * (3.0 - 2.0 * u) + v1 * (u * u * u - u * u)) + amp * sin(PI * b) * (1.0 - b) * (1.0 - b);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
vec4 transition(vec2 uv) {
|
|
66
|
+
vec2 aspect = vec2(ratio, 1.0);
|
|
67
|
+
vec2 c = (uv - 0.5) * aspect;
|
|
68
|
+
float r = square ? max(abs(c.x), abs(c.y)) : length(c);
|
|
69
|
+
float n = clamp(float(rings), 1.0, 12.0);
|
|
70
|
+
float w = (square ? 0.5 * max(ratio, 1.0) : length(0.5 * aspect)) / n;
|
|
71
|
+
float f = r / w;
|
|
72
|
+
float i = min(floor(f), n - 1.0);
|
|
73
|
+
float t = ringTime(i, n);
|
|
74
|
+
|
|
75
|
+
vec4 col;
|
|
76
|
+
if (t <= 0.0) col = getFromColor(uv);
|
|
77
|
+
else if (t >= 1.0) col = getToColor(uv);
|
|
78
|
+
else {
|
|
79
|
+
float total = 2.0 * PI * max(float(turns), 1.0) * (mod(i, 2.0) < 0.5 ? 1.0 : -1.0);
|
|
80
|
+
float a = spin(t, total);
|
|
81
|
+
// angular speed per unit of progress, without the small overshoot; the blur spans what the ring
|
|
82
|
+
// travels in about a frame, at most a short arc so that the 8 taps stay close together
|
|
83
|
+
float u = min(t / (1.0 - SETTLE), 1.0);
|
|
84
|
+
float omega = abs(total) * 6.0 * u * (1.0 - u) / ((1.0 - SETTLE) * (1.0 - ringDelay(n) * (n - 1.0)));
|
|
85
|
+
float span = blur * min(omega * 0.015, 0.1 / max(r, 0.01));
|
|
86
|
+
// the incoming image takes over at full speed, hidden by the blur; the whole turns bring it back upright
|
|
87
|
+
float m = smoothstep(0.3, 0.5, t);
|
|
88
|
+
col = vec4(0.0);
|
|
89
|
+
float ws = 0.0;
|
|
90
|
+
for (int k = 0; k < 8; k++) {
|
|
91
|
+
float x = float(k) / 7.0 - 0.5;
|
|
92
|
+
vec2 q = mirrorUV(rotate(c, a + span * x) / aspect + 0.5);
|
|
93
|
+
vec4 s = mix(getFromColor(q), getToColor(q), m);
|
|
94
|
+
col += (1.0 - abs(x)) * s;
|
|
95
|
+
ws += 1.0 - abs(x);
|
|
96
|
+
}
|
|
97
|
+
col /= ws;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// the nearest boundary between two rings, open while one of them moves: a dark gap
|
|
101
|
+
// with a bevelled rim on each side, lit from the top left
|
|
102
|
+
float bj = clamp(floor(f + 0.5), 1.0, max(n - 1.0, 1.0));
|
|
103
|
+
float act = n > 1.5 ? max(activity(bj - 1.0, n), activity(bj, n)) : 0.0;
|
|
104
|
+
float d = (f - bj) * w;
|
|
105
|
+
vec2 nr = square ? (abs(c.x) > abs(c.y) ? vec2(sign(c.x), 0.0) : vec2(0.0, sign(c.y))) : c / max(r, 1e-4);
|
|
106
|
+
// the outer ring's inner rim faces the center, the inner ring's outer rim faces away from it
|
|
107
|
+
float light = -sign(d) * dot(nr, vec2(-0.6, 0.8)) * (1.0 - smoothstep(GAP, GAP + RIM, abs(d))) * act;
|
|
108
|
+
col.rgb = light > 0.0 ? mix(col.rgb, vec3(col.a), 0.35 * light) : col.rgb * (1.0 + 0.45 * light);
|
|
109
|
+
col.rgb *= 1.0 - 0.85 * act * (1.0 - smoothstep(GAP - EDGE, GAP + EDGE, abs(d)));
|
|
110
|
+
return col;
|
|
111
|
+
}
|
package/transitions/Shatter.glsl
CHANGED
|
@@ -1,53 +1,249 @@
|
|
|
1
1
|
// Author: lbl
|
|
2
2
|
// License: MIT
|
|
3
|
-
// Description: The outgoing image
|
|
4
|
-
// Tags: shatter, fragments
|
|
3
|
+
// Description: The outgoing image cracks like a pane of glass from an impact point, then its shards break loose from the impact outward, tumbling in 3D and falling away with gravity to reveal the incoming image behind
|
|
4
|
+
// Tags: shatter, fragments, glass, 3d
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// @param Impact point where the cracks start, from (0, 0) at the bottom left to (1, 1) at the top right
|
|
7
|
+
uniform vec2 center; // = vec2(0.5, 0.5)
|
|
8
|
+
// @range(3, 8) Approximate number of rows of shards across the height of the frame
|
|
9
|
+
uniform float shards; // = 6.0
|
|
10
|
+
// @range(0.5, 3) Strength of the gravity: the shards fall faster, and break loose over a longer time
|
|
11
|
+
uniform float gravity; // = 1.0
|
|
12
|
+
// @param Random seed: another value gives other shards, tumbling another way
|
|
13
|
+
uniform float seed; // = 0.0
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
// distance from the camera to the pane, as a part of the frame's height
|
|
16
|
+
const float EYE = 2.5;
|
|
17
|
+
// how far the corners of the shards are moved from a regular grid, as a part of a cell
|
|
18
|
+
const float JITTER = 0.32;
|
|
19
|
+
// width of the anti-aliased edges, the crack lines and the bevels, as a part of the frame's height
|
|
20
|
+
const float EDGE = 0.0012;
|
|
21
|
+
const float CRACK_WIDTH = 0.0025;
|
|
22
|
+
const float BEVEL = 0.006;
|
|
23
|
+
|
|
24
|
+
vec3 hash32(vec2 p) {
|
|
25
|
+
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
|
|
26
|
+
p3 += dot(p3, p3.yxz + 33.33);
|
|
27
|
+
return fract((p3.xxy + p3.yzz) * p3.zyx);
|
|
10
28
|
}
|
|
11
29
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return vec2(rand, random(par + rand));
|
|
30
|
+
float cellSize() {
|
|
31
|
+
return 1.0 / clamp(shards, 3.0, 8.0);
|
|
15
32
|
}
|
|
16
33
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
vec2 seedOffset() {
|
|
35
|
+
return vec2(37.0, 17.0) * floor(seed);
|
|
36
|
+
}
|
|
20
37
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
// a corner of the cracks: the point p of a grid, moved at random
|
|
39
|
+
vec2 corner(vec2 p) {
|
|
40
|
+
return (p + JITTER * (2.0 * hash32(p + seedOffset()).xy - 1.0)) * cellSize();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// signed distance from q to the line a -> b, positive on its left
|
|
44
|
+
float side(vec2 q, vec2 a, vec2 b) {
|
|
45
|
+
vec2 d = b - a;
|
|
46
|
+
return (d.x * (q.y - a.y) - d.y * (q.x - a.x)) / length(d);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// the cell c is cut into two triangular shards along one of its diagonals, picked at random
|
|
50
|
+
bool diagonalUp(vec2 c) {
|
|
51
|
+
return hash32(c + seedOffset() + 0.5).z > 0.5;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// distance from q to the edges of the triangle p0 p1 p2 (counterclockwise), positive inside
|
|
55
|
+
float triangleDist(vec2 q, vec2 p0, vec2 p1, vec2 p2) {
|
|
56
|
+
return min(min(side(q, p0, p1), side(q, p1, p2)), side(q, p2, p0));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// the shard that contains q on the unbroken pane: (its cell, its triangle, the distance from q to its nearest crack)
|
|
60
|
+
vec4 locate(vec2 q) {
|
|
61
|
+
vec2 c = floor(q / cellSize());
|
|
62
|
+
// the cells' sides are not straight: step to the neighbor cell when q is beyond one of them
|
|
63
|
+
vec2 a, b, cc, d;
|
|
64
|
+
for (int i = 0; i < 2; i++) {
|
|
65
|
+
a = corner(c);
|
|
66
|
+
b = corner(c + vec2(1.0, 0.0));
|
|
67
|
+
cc = corner(c + 1.0);
|
|
68
|
+
d = corner(c + vec2(0.0, 1.0));
|
|
69
|
+
c.x += side(q, d, a) < 0.0 ? -1.0 : (side(q, b, cc) < 0.0 ? 1.0 : 0.0);
|
|
70
|
+
a = corner(c);
|
|
71
|
+
b = corner(c + vec2(1.0, 0.0));
|
|
72
|
+
cc = corner(c + 1.0);
|
|
73
|
+
d = corner(c + vec2(0.0, 1.0));
|
|
74
|
+
c.y += side(q, a, b) < 0.0 ? -1.0 : (side(q, cc, d) < 0.0 ? 1.0 : 0.0);
|
|
75
|
+
}
|
|
76
|
+
a = corner(c);
|
|
77
|
+
b = corner(c + vec2(1.0, 0.0));
|
|
78
|
+
cc = corner(c + 1.0);
|
|
79
|
+
d = corner(c + vec2(0.0, 1.0));
|
|
80
|
+
bool up = diagonalUp(c);
|
|
81
|
+
float d0 = up ? triangleDist(q, a, b, cc) : triangleDist(q, a, b, d);
|
|
82
|
+
float d1 = up ? triangleDist(q, a, cc, d) : triangleDist(q, b, cc, d);
|
|
83
|
+
return vec4(c, d1 > d0 ? 1.0 : 0.0, abs(max(d0, d1)));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Rodrigues' rotation of v around the unit axis k
|
|
87
|
+
vec3 rotate(vec3 v, vec3 k, float angle) {
|
|
88
|
+
float c = cos(angle), s = sin(angle);
|
|
89
|
+
return v * c + cross(k, v) * s + k * dot(k, v) * (1.0 - c);
|
|
90
|
+
}
|
|
27
91
|
|
|
28
|
-
|
|
92
|
+
vec2 impact() {
|
|
93
|
+
return clamp(center, 0.0, 1.0) * vec2(ratio, 1.0);
|
|
94
|
+
}
|
|
29
95
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
96
|
+
// distance from the impact to the farthest corner of the frame
|
|
97
|
+
float reach() {
|
|
98
|
+
vec2 c = impact();
|
|
99
|
+
return length(max(c, vec2(ratio, 1.0) - c));
|
|
100
|
+
}
|
|
35
101
|
|
|
36
|
-
|
|
102
|
+
// how far below its center a shard must fall to leave the frame
|
|
103
|
+
float fallMargin() {
|
|
104
|
+
return 0.1 + 1.5 * cellSize();
|
|
105
|
+
}
|
|
37
106
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
107
|
+
// the time a shard breaks loose: the nearer the impact the sooner, and late enough to fall out of the frame by the end
|
|
108
|
+
// (dn: its distance to the impact, as a part of the reach)
|
|
109
|
+
float releaseTime(vec2 mid, float dn, float h, float g, float margin) {
|
|
110
|
+
float latest = max(0.98 - sqrt(2.0 * (mid.y + margin) / g), 0.04);
|
|
111
|
+
return 0.04 + (latest - 0.04) * (0.8 * pow(dn, 0.8) + 0.2 * h);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// a flash at the impact, at the start
|
|
115
|
+
float flash(vec2 q) {
|
|
116
|
+
float f = sin(3.141592653589793 * clamp(progress / 0.12, 0.0, 1.0));
|
|
117
|
+
vec2 d = q - impact();
|
|
118
|
+
return 0.6 * f * exp(-dot(d, d) / (0.004 + 0.02 * progress));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
vec4 transition(vec2 uv) {
|
|
122
|
+
if (progress <= 0.0) return getFromColor(uv);
|
|
123
|
+
if (progress >= 1.0) return getToColor(uv);
|
|
124
|
+
float s = cellSize();
|
|
125
|
+
vec2 a = vec2(uv.x * ratio, uv.y);
|
|
126
|
+
vec3 eye = vec3(0.5 * ratio, 0.5, -EYE);
|
|
127
|
+
vec3 ray = vec3(a, 0.0) - eye;
|
|
128
|
+
vec3 light = normalize(vec3(-0.35, 0.55, -1.0));
|
|
129
|
+
vec3 halfway = normalize(light - normalize(ray));
|
|
130
|
+
float g = 12.0 * clamp(gravity, 0.5, 3.0);
|
|
131
|
+
vec2 imp = impact();
|
|
132
|
+
float rch = reach();
|
|
133
|
+
float margin = fallMargin();
|
|
134
|
+
// the cracks run from the impact to the farthest corner, before the last shards break loose
|
|
135
|
+
float crackTime = clamp(0.6 * (0.94 - sqrt(2.0 * (1.0 + margin) / g)), 0.05, 0.22);
|
|
136
|
+
|
|
137
|
+
// the part of the pane still in place, behind the loose shards
|
|
138
|
+
vec4 pane = vec4(0.0);
|
|
139
|
+
float paneDepth = 1e9;
|
|
140
|
+
vec4 here = locate(a);
|
|
141
|
+
vec2 hc = here.xy;
|
|
142
|
+
vec2 ha = corner(hc), hb = corner(hc + vec2(1.0, 0.0)), hcc = corner(hc + 1.0), hd = corner(hc + vec2(0.0, 1.0));
|
|
143
|
+
bool hup = diagonalUp(hc);
|
|
144
|
+
vec2 hcenter = here.z < 0.5 ? (hup ? ha + hb + hcc : ha + hb + hd) : (hup ? ha + hcc + hd : hb + hcc + hd);
|
|
145
|
+
vec3 hh = hash32(hc + vec2(0.31, 0.57) * (here.z + 1.0) + seedOffset());
|
|
146
|
+
hcenter /= 3.0;
|
|
147
|
+
if (progress < releaseTime(hcenter, clamp(length(hcenter - imp) / rch, 0.0, 1.0), hh.x, g, margin)) {
|
|
148
|
+
vec4 col = getFromColor(uv);
|
|
149
|
+
float crack = clamp((progress - crackTime * length(a - imp) / rch) / 0.03, 0.0, 1.0);
|
|
150
|
+
// cracked shards settle at slightly different angles (no change while flat: dot(n, light) = -light.z)
|
|
151
|
+
vec3 n = rotate(vec3(0.0, 0.0, -1.0), normalize(vec3(hh.yz - 0.5, 0.0) + 1e-4), 0.06 * crack * (hh.x - 0.5));
|
|
152
|
+
col.rgb *= 1.0 + 1.2 * (dot(n, light) + light.z);
|
|
153
|
+
col.rgb += crack * 0.35 * pow(max(dot(n, halfway), 0.0), 400.0) * col.a;
|
|
154
|
+
float line = crack * (1.0 - smoothstep(0.0, CRACK_WIDTH, here.w));
|
|
155
|
+
col.rgb = mix(col.rgb, vec3(0.95, 0.98, 1.0) * col.a, 0.85 * line);
|
|
156
|
+
pane = col;
|
|
157
|
+
paneDepth = 1.0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// the two nearest loose shards: depth along the ray, color, coverage
|
|
161
|
+
float t1 = 1e9, t2 = 1e9;
|
|
162
|
+
vec4 c1 = vec4(0.0), c2 = vec4(0.0);
|
|
163
|
+
float a1 = 0.0, a2 = 0.0;
|
|
164
|
+
float shadow = 0.0;
|
|
165
|
+
|
|
166
|
+
// the shards that broke loose, searched in the cells around and above the pixel since they fall,
|
|
167
|
+
// looking a bit toward the impact and the middle since they drift away and grow toward the camera
|
|
168
|
+
vec2 look = a - 0.06 * progress * (a - imp) / rch - (a - eye.xy) * 0.06 * progress;
|
|
169
|
+
vec2 g0 = floor(look / s) - 1.0;
|
|
170
|
+
float rows = ceil(1.0 / s);
|
|
171
|
+
for (int ri = 0; ri < 11; ri++) {
|
|
172
|
+
float j = g0.y + float(ri);
|
|
173
|
+
if (j > rows) break;
|
|
174
|
+
if (j < -1.0) continue;
|
|
175
|
+
for (int ci = 0; ci < 3; ci++) {
|
|
176
|
+
vec2 c = vec2(g0.x + float(ci), j);
|
|
177
|
+
vec2 ca = corner(c), cb = corner(c + vec2(1.0, 0.0)), ccc = corner(c + 1.0), cd = corner(c + vec2(0.0, 1.0));
|
|
178
|
+
bool up = diagonalUp(c);
|
|
179
|
+
for (int k = 0; k < 2; k++) {
|
|
180
|
+
// the corners of the triangle k of the cell, counterclockwise
|
|
181
|
+
vec2 p0 = (k == 1 && !up) ? cb : ca;
|
|
182
|
+
vec2 p1 = k == 0 ? cb : ccc;
|
|
183
|
+
vec2 p2 = (k == 0 && up) ? ccc : cd;
|
|
184
|
+
vec2 mid = (p0 + p1 + p2) / 3.0;
|
|
185
|
+
vec3 h1 = hash32(c + vec2(0.31, 0.57) * float(k + 1) + seedOffset());
|
|
186
|
+
vec2 away = mid - imp;
|
|
187
|
+
float dist = length(away);
|
|
188
|
+
float dn = clamp(dist / rch, 0.0, 1.0);
|
|
189
|
+
float e = progress - releaseTime(mid, dn, h1.x, g, margin);
|
|
190
|
+
if (e <= 0.0) continue;
|
|
191
|
+
vec3 h2 = hash32(c + vec2(0.73, 0.19) * float(k + 1) + seedOffset());
|
|
192
|
+
// pushed away from the impact and toward the camera, spinning around a random axis, falling
|
|
193
|
+
float near = 1.0 - dn;
|
|
194
|
+
vec3 vel = vec3(away / max(dist, 1e-3) * (0.03 + 0.08 * h1.y) * (0.4 + near), -(0.05 + 0.2 * near * h1.z));
|
|
195
|
+
vec3 pos = vec3(mid, 0.0) + vel * e - vec3(0.0, 0.5 * g * e * e, 0.0);
|
|
196
|
+
// already out of the frame
|
|
197
|
+
if (pos.y + 1.5 * s < -0.05) continue;
|
|
198
|
+
vec3 axis = normalize(vec3(h2.x - 0.5, h2.y - 0.5, 0.3 * (h2.z - 0.5)) + 1e-4);
|
|
199
|
+
float angle = (3.0 + 5.0 * h2.z) * (h2.x < 0.5 ? -1.0 : 1.0) * e;
|
|
200
|
+
vec3 n = rotate(vec3(0.0, 0.0, -1.0), axis, angle);
|
|
201
|
+
float rel = smoothstep(0.0, 0.04, e);
|
|
202
|
+
|
|
203
|
+
// the camera ray, hidden behind the pane still in place
|
|
204
|
+
float den = dot(ray, n);
|
|
205
|
+
float t = dot(pos - eye, n) / (abs(den) > 1e-4 ? den : 1e-4);
|
|
206
|
+
vec2 q = mid + rotate(eye + t * ray - pos, axis, -angle).xy;
|
|
207
|
+
float border = min(min(q.x, ratio - q.x), min(q.y, 1.0 - q.y));
|
|
208
|
+
float inside = triangleDist(q, p0, p1, p2);
|
|
209
|
+
float ed = min(inside, border);
|
|
210
|
+
if (t > 0.0 && t < t2 && t < paneDepth && ed > 0.0) {
|
|
211
|
+
vec3 nf = den > 0.0 ? -n : n;
|
|
212
|
+
vec4 col = getFromColor(vec2(q.x / ratio, q.y));
|
|
213
|
+
col.rgb *= mix(1.0, clamp(dot(nf, light) / -light.z, 0.45, 1.1), rel);
|
|
214
|
+
float glint = max(dot(nf, halfway), 0.0);
|
|
215
|
+
col.rgb += rel * 0.3 * pow(glint, 60.0) * col.a;
|
|
216
|
+
// the crack line it carried turns into a bright bevel
|
|
217
|
+
float line = 0.85 * (1.0 - smoothstep(0.0, CRACK_WIDTH, inside)) * (1.0 - rel);
|
|
218
|
+
float bevel = 0.8 * rel * (1.0 - smoothstep(0.0, BEVEL, ed)) * (0.3 + 0.7 * pow(glint, 6.0));
|
|
219
|
+
col.rgb = mix(col.rgb, vec3(0.92, 0.97, 0.97) * col.a, max(line, bevel));
|
|
220
|
+
float cover = mix(1.0, smoothstep(0.0, 2.0 * EDGE, ed), rel);
|
|
221
|
+
if (t < t1) {
|
|
222
|
+
t2 = t1; c2 = c1; a2 = a1;
|
|
223
|
+
t1 = t; c1 = col; a1 = cover;
|
|
224
|
+
} else {
|
|
225
|
+
t2 = t; c2 = col; a2 = cover;
|
|
226
|
+
}
|
|
45
227
|
}
|
|
46
228
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
229
|
+
// the shadow on the pane and on the incoming image behind
|
|
230
|
+
float lden = dot(light, n);
|
|
231
|
+
float ts = dot(pos - vec3(a, 0.0), n) / (abs(lden) > 1e-4 ? lden : 1e-4);
|
|
232
|
+
vec2 qs = mid + rotate(vec3(a, 0.0) + ts * light - pos, axis, -angle).xy;
|
|
233
|
+
float eds = min(triangleDist(qs, p0, p1, p2), min(min(qs.x, ratio - qs.x), min(qs.y, 1.0 - qs.y)));
|
|
234
|
+
if (ts > 0.0 && eds > 0.0) {
|
|
235
|
+
shadow = max(shadow, rel * smoothstep(0.0, 0.004 + 0.08 * ts, eds) * 0.45 * (1.0 - smoothstep(0.1, 0.9, ts)));
|
|
50
236
|
}
|
|
237
|
+
}
|
|
51
238
|
}
|
|
52
|
-
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// the incoming image behind, then the pane still in place, then the loose shards in front
|
|
242
|
+
vec4 back = getToColor(uv);
|
|
243
|
+
back.rgb *= 1.0 - shadow;
|
|
244
|
+
pane.rgb *= 1.0 - shadow;
|
|
245
|
+
if (paneDepth == 1.0) back = pane;
|
|
246
|
+
vec4 color = c1 * a1 + c2 * min(a2, 1.0 - a1) + back * max(1.0 - a1 - a2, 0.0);
|
|
247
|
+
color.rgb += flash(a) * color.a;
|
|
248
|
+
return color;
|
|
53
249
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: The outgoing image fades back to blank paper while the incoming one is drawn on it in pencil, outlines first and then hatching in the shadows, before its shading and colors fill in until the picture is complete
|
|
4
|
+
// Tags: pencil, drawing, sketch, edges, dissolve
|
|
5
|
+
|
|
6
|
+
// @range(0.5, 4) Thickness of the pencil outlines, in thousandths of the frame height
|
|
7
|
+
uniform float lineWidth; // = 1.5
|
|
8
|
+
// @range(0, 2) How many outlines are drawn: higher also traces the fainter edges of the picture
|
|
9
|
+
uniform float edges; // = 1.0
|
|
10
|
+
// @range(0, 1) Amount of diagonal hatching drawn in the shadows
|
|
11
|
+
uniform float hatching; // = 0.6
|
|
12
|
+
// @color Color of the paper
|
|
13
|
+
uniform vec4 paper; // = vec4(0.96, 0.94, 0.89, 1.0)
|
|
14
|
+
// @color Color of the pencil
|
|
15
|
+
uniform vec4 ink; // = vec4(0.16, 0.16, 0.2, 1.0)
|
|
16
|
+
|
|
17
|
+
float sdHash (vec2 p) {
|
|
18
|
+
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
|
|
19
|
+
p3 += dot(p3, p3.yzx + 33.33);
|
|
20
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
float sdNoise (vec2 p) {
|
|
24
|
+
vec2 i = floor(p);
|
|
25
|
+
vec2 f = fract(p);
|
|
26
|
+
f = f * f * (3.0 - 2.0 * f);
|
|
27
|
+
return mix(
|
|
28
|
+
mix(sdHash(i), sdHash(i + vec2(1.0, 0.0)), f.x),
|
|
29
|
+
mix(sdHash(i + vec2(0.0, 1.0)), sdHash(i + vec2(1.0, 1.0)), f.x),
|
|
30
|
+
f.y
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// luma and alpha of the incoming image: outlines follow both
|
|
35
|
+
vec2 sdTone (vec2 uv) {
|
|
36
|
+
vec4 c = getToColor(uv);
|
|
37
|
+
return vec2(dot(c.rgb, vec3(0.299, 0.587, 0.114)), c.a);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// one family of hatching strokes along direction d, as thick as the shadow is dark
|
|
41
|
+
float sdHatch (vec2 q, vec2 d, float dark) {
|
|
42
|
+
float s = dot(q, d) * 60.0 + 0.5 * sdNoise(q * 9.0 + d * 13.0);
|
|
43
|
+
float row = floor(s);
|
|
44
|
+
// each row is made of strokes of uneven length and pressure, with small gaps
|
|
45
|
+
float along = dot(q, vec2(-d.y, d.x)) * 8.0 + sdHash(vec2(row, d.y * 7.0)) * 5.0;
|
|
46
|
+
float cell = floor(along);
|
|
47
|
+
float k = sdHash(vec2(row, cell) + d * 31.0);
|
|
48
|
+
float gap = smoothstep(0.0, 0.12, fract(along)) * (1.0 - smoothstep(0.75 - 0.2 * k, 1.0, fract(along)));
|
|
49
|
+
float w = 0.5 * clamp(dark, 0.0, 1.0) * (0.7 + 0.3 * k);
|
|
50
|
+
return (1.0 - smoothstep(w - 0.24, w, abs(fract(s) - 0.5))) * gap * (0.6 + 0.4 * k);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
vec4 transition (vec2 uv) {
|
|
54
|
+
vec2 q = vec2(uv.x * ratio, uv.y);
|
|
55
|
+
// a slightly wobbly hand: the outlines are traced a bit off the real edges
|
|
56
|
+
vec2 wob = (vec2(sdNoise(q * 6.0), sdNoise(q * 6.0 + 17.0)) - 0.5) * 0.004;
|
|
57
|
+
vec2 su = uv + wob * (1.0 - progress);
|
|
58
|
+
vec2 dx = vec2(0.001 * lineWidth / ratio, 0.0);
|
|
59
|
+
vec2 dy = vec2(0.0, 0.001 * lineWidth);
|
|
60
|
+
vec2 tl = sdTone(su - dx + dy), tm = sdTone(su + dy), tr = sdTone(su + dx + dy);
|
|
61
|
+
vec2 ml = sdTone(su - dx), mr = sdTone(su + dx);
|
|
62
|
+
vec2 bl = sdTone(su - dx - dy), bm = sdTone(su - dy), br = sdTone(su + dx - dy);
|
|
63
|
+
vec2 gx = (tr + 2.0 * mr + br) - (tl + 2.0 * ml + bl);
|
|
64
|
+
vec2 gy = (tl + 2.0 * tm + tr) - (bl + 2.0 * bm + br);
|
|
65
|
+
float g = max(length(vec2(gx.x, gy.x)), length(vec2(gx.y, gy.y))) * max(edges, 0.0);
|
|
66
|
+
float outline = smoothstep(0.12, 0.5, g);
|
|
67
|
+
vec4 toC = getToColor(uv);
|
|
68
|
+
float l = clamp((tm.x + bm.x + ml.x + mr.x) * 0.25, 0.0, 1.0);
|
|
69
|
+
|
|
70
|
+
// graphite grain, and the order in which the strokes are laid down
|
|
71
|
+
float grain = 0.65 + 0.35 * sdNoise(q * vec2(180.0, 60.0));
|
|
72
|
+
float order = sdNoise(q * 3.0 + 4.0);
|
|
73
|
+
float fine = sdNoise(q * 24.0);
|
|
74
|
+
float drawOutline = smoothstep(0.0, 0.1, progress - (0.22 * order + 0.05 * fine));
|
|
75
|
+
float drawHatch = smoothstep(0.0, 0.12, progress - (0.2 + 0.2 * order + 0.05 * fine));
|
|
76
|
+
|
|
77
|
+
// the shading builds up from the darkest parts to the lightest, then the colors come in
|
|
78
|
+
float fill = smoothstep(0.0, 0.22, progress - (0.4 + 0.25 * l + 0.1 * order));
|
|
79
|
+
|
|
80
|
+
// hatching: one direction in the shadows, crossed in the darkest parts
|
|
81
|
+
float dark = 1.0 - l;
|
|
82
|
+
float h1 = sdHatch(q, vec2(0.7071, 0.7071), smoothstep(0.35, 0.9, dark));
|
|
83
|
+
float h2 = sdHatch(q, vec2(0.7071, -0.7071), smoothstep(0.65, 1.0, dark));
|
|
84
|
+
float hatch = hatching * 0.8 * max(h1, 0.8 * h2) * toC.a;
|
|
85
|
+
|
|
86
|
+
// the hatching is absorbed by the shading as it fills in
|
|
87
|
+
hatch *= drawHatch * (1.0 - 0.6 * fill);
|
|
88
|
+
float pencil = max(outline * drawOutline, hatch) * grain;
|
|
89
|
+
// the pencil lines give way to the finished picture at the end
|
|
90
|
+
pencil *= 1.0 - smoothstep(0.7, 1.0, progress);
|
|
91
|
+
|
|
92
|
+
// the outgoing image fades back to paper
|
|
93
|
+
vec4 base = mix(getFromColor(uv), paper, smoothstep(0.02, 0.38, progress));
|
|
94
|
+
float sat = smoothstep(0.55, 1.0, progress);
|
|
95
|
+
vec4 tone = vec4(paper.rgb * mix(0.3, 1.0, l), paper.a * toC.a);
|
|
96
|
+
vec4 col = mix(tone, toC, sat);
|
|
97
|
+
base = mix(base, col, fill);
|
|
98
|
+
return mix(base, ink, pencil);
|
|
99
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: The frame is cut into vertical reels that spin downward like drums, motion-blurred with speed, carrying the outgoing image then the incoming one, and stop one after another from left to right with a small mechanical bounce
|
|
4
|
+
// Tags: 3d, spin, stripes, motion-blur
|
|
5
|
+
|
|
6
|
+
// @range(1, 16, 1) Number of reels
|
|
7
|
+
uniform int reels; // = 5
|
|
8
|
+
// @range(0, 1) Amount of vertical motion blur while the reels spin fast
|
|
9
|
+
uniform float blur; // = 0.6
|
|
10
|
+
// @range(0, 0.9) Delay between the first and the last reel's stop, as a part of the transition
|
|
11
|
+
uniform float stagger; // = 0.45
|
|
12
|
+
// @range(0, 1) Size of the bounce when a reel stops
|
|
13
|
+
uniform float bounce; // = 0.5
|
|
14
|
+
// @color Color of the separators between the reels
|
|
15
|
+
uniform vec4 separator; // = vec4(0.04, 0.04, 0.05, 1.0)
|
|
16
|
+
|
|
17
|
+
const float PI = 3.141592653589793;
|
|
18
|
+
// half of the arc of the drum seen in the frame, in radians
|
|
19
|
+
const float ARC = 1.15;
|
|
20
|
+
// duration of the bounce, as a part of the transition
|
|
21
|
+
const float SETTLE = 0.1;
|
|
22
|
+
// width of the separators, in frame heights
|
|
23
|
+
const float LINE = 0.006;
|
|
24
|
+
// width of the anti-aliased edges, in frame heights
|
|
25
|
+
const float EDGE = 0.0015;
|
|
26
|
+
|
|
27
|
+
// the time at which the reel stops, before its bounce
|
|
28
|
+
float stopTime(float i, float n) {
|
|
29
|
+
float order = n > 1.0 ? i / (n - 1.0) : 1.0;
|
|
30
|
+
return (1.0 - SETTLE) * (1.0 - clamp(stagger, 0.0, 0.9) * (1.0 - order));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// how far the reel has turned at time t, in image heights: it speeds up, slows down to its stop
|
|
34
|
+
// a little past the incoming image and springs back onto it
|
|
35
|
+
float reelOffset(float t, float stopT, float turns) {
|
|
36
|
+
float amp = 0.07 * bounce;
|
|
37
|
+
// speed at the stop, matched with the start of the bounce
|
|
38
|
+
float v1 = amp * PI * stopT / (turns * SETTLE);
|
|
39
|
+
float u = clamp(t / stopT, 0.0, 1.0);
|
|
40
|
+
float g = u * u * (3.0 - 2.0 * u) + v1 * (u * u * u - u * u);
|
|
41
|
+
float b = clamp((t - stopT) / SETTLE, 0.0, 1.0);
|
|
42
|
+
return turns * g + amp * sin(PI * b) * (1.0 - b) * (1.0 - b);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// the reel's speed at time t, the derivative of reelOffset, in image heights per transition
|
|
46
|
+
float reelSpeed(float t, float stopT, float turns) {
|
|
47
|
+
float amp = 0.07 * bounce;
|
|
48
|
+
float v1 = amp * PI * stopT / (turns * SETTLE);
|
|
49
|
+
if (t < stopT) {
|
|
50
|
+
float u = max(t / stopT, 0.0);
|
|
51
|
+
return turns * (6.0 * u * (1.0 - u) + v1 * u * (3.0 * u - 2.0)) / stopT;
|
|
52
|
+
}
|
|
53
|
+
float b = min((t - stopT) / SETTLE, 1.0);
|
|
54
|
+
return amp * (1.0 - b) * (PI * cos(PI * b) * (1.0 - b) - 2.0 * sin(PI * b)) / SETTLE;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
vec4 transition (vec2 uv) {
|
|
58
|
+
float n = max(float(reels), 1.0);
|
|
59
|
+
float i = min(floor(uv.x * n), n - 1.0);
|
|
60
|
+
float lx = uv.x * n - i;
|
|
61
|
+
float stopT = stopTime(i, n);
|
|
62
|
+
// an odd number of turns, more for the reels that spin longer, so they land on the incoming image
|
|
63
|
+
float turns = 2.0 * floor(stopT * 4.0) + 1.0;
|
|
64
|
+
|
|
65
|
+
// the reel is a drum while it spins, and flattens back as it settles
|
|
66
|
+
float drum = smoothstep(0.0, 0.12, progress) * (1.0 - smoothstep(stopT, stopT + SETTLE, progress));
|
|
67
|
+
float y = 2.0 * uv.y - 1.0;
|
|
68
|
+
// theta: the angle around the drum's axis, 0 facing the viewer
|
|
69
|
+
float theta = asin(clamp(y * sin(ARC), -1.0, 1.0));
|
|
70
|
+
float v = mix(uv.y, 0.5 + theta / (2.0 * ARC), drum);
|
|
71
|
+
// the far edges of the drum look narrower
|
|
72
|
+
float depth = (1.0 - cos(theta)) * drum;
|
|
73
|
+
float px = 0.5 + (lx - 0.5) * (1.0 + 0.2 * depth);
|
|
74
|
+
|
|
75
|
+
// offset from the resting position, -turns at the start, 0 once landed
|
|
76
|
+
float off = reelOffset(progress, stopT, turns) - turns;
|
|
77
|
+
float speed = abs(reelSpeed(progress, stopT, turns));
|
|
78
|
+
// the blur spans the distance the reel travels in about a frame
|
|
79
|
+
float spread = blur * min(speed * 0.02, 0.22) * drum;
|
|
80
|
+
|
|
81
|
+
// up to 8 taps along the reel, weighted toward the middle, one when it stands still
|
|
82
|
+
vec4 c = vec4(0.0);
|
|
83
|
+
float wsum = 0.0;
|
|
84
|
+
for (int k = 0; k < 8; k++) {
|
|
85
|
+
float f = float(k) / 7.0 - 0.5;
|
|
86
|
+
float w = 1.0 - abs(f);
|
|
87
|
+
float vv = v + off + spread * f;
|
|
88
|
+
float seg = floor(vv);
|
|
89
|
+
vec2 q = vec2((i + clamp(px, 0.0, 1.0)) / n, vv - seg);
|
|
90
|
+
// the drum carries the incoming image on even segments, the outgoing one on odd segments
|
|
91
|
+
vec4 s = mod(seg, 2.0) < 0.5 ? getToColor(q) : getFromColor(q);
|
|
92
|
+
// a thin shadow at the seams between the images, not at the frame's top and bottom edges
|
|
93
|
+
s.rgb *= 1.0 - 0.6 * drum * (1.0 - y * y) * (1.0 - smoothstep(0.0, 0.02, min(q.y, 1.0 - q.y)));
|
|
94
|
+
c += w * s;
|
|
95
|
+
wsum += w;
|
|
96
|
+
if (spread < 1e-4) break;
|
|
97
|
+
}
|
|
98
|
+
c /= wsum;
|
|
99
|
+
|
|
100
|
+
// the drum's faces darken as they turn away, with a soft highlight above its middle
|
|
101
|
+
float facing = cos(theta);
|
|
102
|
+
c.rgb *= mix(1.0, 0.25 + 0.75 * facing * facing, drum);
|
|
103
|
+
c.rgb += drum * 0.07 * c.a * exp(-12.0 * (y - 0.3) * (y - 0.3));
|
|
104
|
+
|
|
105
|
+
// separators between the reels, and the background around the narrower far edges of the drums
|
|
106
|
+
float env = smoothstep(0.0, 0.1, progress) * (1.0 - smoothstep(0.9, 1.0, progress));
|
|
107
|
+
float reelW = ratio / n;
|
|
108
|
+
float persp = reelW / (1.0 + 0.2 * depth);
|
|
109
|
+
// distance to the reel's sides, and to its sides next to the other reels
|
|
110
|
+
float dSide = min(px, 1.0 - px) * persp;
|
|
111
|
+
float dInner = min(i > 0.5 ? px : 2.0, i < n - 1.5 ? 1.0 - px : 2.0) * persp;
|
|
112
|
+
float line = 1.0 - smoothstep(0.5 * LINE - EDGE, 0.5 * LINE + EDGE, dInner);
|
|
113
|
+
float outside = 1.0 - smoothstep(-EDGE, 0.0, dSide);
|
|
114
|
+
// a soft shadow cast by the separators on the reels
|
|
115
|
+
c.rgb *= 1.0 - 0.35 * env * (1.0 - smoothstep(0.0, 0.03 * reelW + LINE, dInner));
|
|
116
|
+
return mix(c, separator, max(line * env, outside));
|
|
117
|
+
}
|