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,103 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: A keyhole grows steadily from the center until the incoming image fills the frame, its bevelled rim and inner shadow making it read as a hole cut in a plate
|
|
4
|
+
// Tags: shape, wipe, keyhole, iris, reveal
|
|
5
|
+
|
|
6
|
+
// @param Center of the keyhole
|
|
7
|
+
uniform vec2 center; // = vec2(0.5, 0.5)
|
|
8
|
+
// @range(0, 1) Strength of the bevelled rim around the keyhole and the shadow inside it (0 for a clean cut)
|
|
9
|
+
uniform float rim; // = 0.6
|
|
10
|
+
// @range(0, 0.05) Softness of the keyhole's edge
|
|
11
|
+
uniform float smoothness; // = 0.002
|
|
12
|
+
|
|
13
|
+
// The keyhole, in its own units (0.85 tall, from y = -0.4 to 0.45): a round head on top of a slot
|
|
14
|
+
// that widens downward.
|
|
15
|
+
#define HEAD vec2(0.0, 0.2)
|
|
16
|
+
#define HEAD_R 0.25
|
|
17
|
+
#define SLOT_Y -0.17
|
|
18
|
+
const float SLOT_HE = 0.23;
|
|
19
|
+
const float SLOT_TOP = 0.085;
|
|
20
|
+
const float SLOT_BOTTOM = 0.165;
|
|
21
|
+
const float SLOT_ROUND = 0.025;
|
|
22
|
+
// height of the point the keyhole grows around, in its head
|
|
23
|
+
const float GROW_Y = 0.1;
|
|
24
|
+
// widths of the bevel and of the rim's shadows, in keyhole units
|
|
25
|
+
const float BEVEL = 0.028;
|
|
26
|
+
const float SHADE = 0.05;
|
|
27
|
+
|
|
28
|
+
float dot2(vec2 v) { return dot(v, v); }
|
|
29
|
+
|
|
30
|
+
// Signed distance to the slot, a trapezoid with rounded corners
|
|
31
|
+
float sdSlot(vec2 p) {
|
|
32
|
+
p.y -= SLOT_Y;
|
|
33
|
+
float r1 = SLOT_BOTTOM - SLOT_ROUND;
|
|
34
|
+
float r2 = SLOT_TOP - SLOT_ROUND;
|
|
35
|
+
float he = SLOT_HE - SLOT_ROUND;
|
|
36
|
+
vec2 k1 = vec2(r2, he);
|
|
37
|
+
vec2 k2 = vec2(r2 - r1, 2.0 * he);
|
|
38
|
+
p.x = abs(p.x);
|
|
39
|
+
vec2 ca = vec2(p.x - min(p.x, p.y < 0.0 ? r1 : r2), abs(p.y) - he);
|
|
40
|
+
vec2 cb = p - k1 + k2 * clamp(dot(k1 - p, k2) / dot2(k2), 0.0, 1.0);
|
|
41
|
+
float s = (cb.x < 0.0 && ca.y < 0.0) ? -1.0 : 1.0;
|
|
42
|
+
return s * sqrt(min(dot2(ca), dot2(cb))) - SLOT_ROUND;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
float sdKeyhole(vec2 p) {
|
|
46
|
+
return min(length(p - HEAD) - HEAD_R, sdSlot(p));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Scale at which the keyhole's head, a disk, reaches the point p (seen from the growth point):
|
|
50
|
+
// the root of |p - s h| = s HEAD_R, h being the head's center
|
|
51
|
+
float reach(vec2 p) {
|
|
52
|
+
vec2 h = HEAD - vec2(0.0, GROW_Y);
|
|
53
|
+
float k = HEAD_R * HEAD_R - dot2(h);
|
|
54
|
+
float b = dot(p, h);
|
|
55
|
+
return (sqrt(b * b + k * dot2(p)) - b) / k;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
vec4 transition (vec2 uv) {
|
|
59
|
+
vec4 a = getFromColor(uv);
|
|
60
|
+
vec4 b = getToColor(uv);
|
|
61
|
+
vec2 asp = vec2(ratio, 1.0);
|
|
62
|
+
vec2 c = center * asp;
|
|
63
|
+
float sm = max(smoothness, 0.0005);
|
|
64
|
+
|
|
65
|
+
// The keyhole grows around a point of its head, at the center. It covers the frame (grown by a
|
|
66
|
+
// margin, so the soft edge is past it) once its head, a disk, reaches the frame's corners.
|
|
67
|
+
vec2 o = c;
|
|
68
|
+
vec2 lo = -o - 2.5 * sm;
|
|
69
|
+
vec2 hi = asp - o + 2.5 * sm;
|
|
70
|
+
float full = max(max(reach(lo), reach(hi)), max(reach(vec2(lo.x, hi.y)), reach(vec2(hi.x, lo.y))));
|
|
71
|
+
|
|
72
|
+
// The keyhole grows linearly until it fills the frame
|
|
73
|
+
float p = progress;
|
|
74
|
+
float s = full * p;
|
|
75
|
+
if (s <= 0.0) return a;
|
|
76
|
+
|
|
77
|
+
vec2 q = (uv * asp - o) / s + vec2(0.0, GROW_Y);
|
|
78
|
+
float d = sdKeyhole(q);
|
|
79
|
+
// the soft edge is just inside the outline, so a tiny keyhole shows nothing
|
|
80
|
+
float hole = 1.0 - smoothstep(-sm, sm, d * s + sm);
|
|
81
|
+
|
|
82
|
+
float fade = smoothstep(0.0, 0.08, p) * (1.0 - smoothstep(0.7, 1.0, p));
|
|
83
|
+
float rimA = rim * fade;
|
|
84
|
+
if (rimA > 0.0) {
|
|
85
|
+
// Plate around the hole: a bevel lit from above going down into the hole, and a soft shadow
|
|
86
|
+
// on its rim
|
|
87
|
+
vec2 e = vec2(0.002, 0.0);
|
|
88
|
+
vec2 n = vec2(sdKeyhole(q + e) - sdKeyhole(q - e), sdKeyhole(q + e.yx) - sdKeyhole(q - e.yx));
|
|
89
|
+
float lit = -dot(n / max(length(n), 1e-6), vec2(-0.35, 0.94));
|
|
90
|
+
float bevel = 1.0 - smoothstep(0.0, BEVEL, d);
|
|
91
|
+
float shade = exp(-max(d, 0.0) / SHADE);
|
|
92
|
+
a.rgb *= 1.0 - rimA * (0.35 * shade + bevel * 0.4 * max(-lit, 0.0));
|
|
93
|
+
a.rgb += rimA * bevel * bevel * 0.3 * max(lit, 0.0) * a.a;
|
|
94
|
+
|
|
95
|
+
// Inside the hole: the plate's thickness shades the incoming image under the top of the rim,
|
|
96
|
+
// with a softer vignette all around the edge
|
|
97
|
+
float wall = smoothstep(-0.03, 0.03, sdKeyhole(q + vec2(0.0, 0.05)));
|
|
98
|
+
float vign = exp(min(d, 0.0) / SHADE);
|
|
99
|
+
b.rgb *= 1.0 - rimA * (0.5 * wall + 0.3 * vign);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return mix(a, b, hole);
|
|
103
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: The picture zooms into a giant LED screen of round glowing diodes on a dark panel; a refresh wave sweeps across it, each diode flicking with a bright pop as it switches to the incoming image, then the diodes melt back into the plain picture
|
|
4
|
+
// Tags: dots, glow, grid, wave
|
|
5
|
+
|
|
6
|
+
// @range(6, 80) Number of diodes across the shorter side
|
|
7
|
+
uniform float cells; // = 24.0
|
|
8
|
+
// @range(0, 1) Strength of the glow bleeding from the diodes into the dark panel
|
|
9
|
+
uniform float glow; // = 0.6
|
|
10
|
+
// @range(0, 1) Brightness of the flash of each diode as it switches
|
|
11
|
+
uniform float flash; // = 0.7
|
|
12
|
+
// @range(0, 0.5) How much the picture zooms in while it is a screen
|
|
13
|
+
uniform float zoom; // = 0.15
|
|
14
|
+
// @param Each diode is made of red, green and blue sub-diodes
|
|
15
|
+
uniform bool triads; // = false
|
|
16
|
+
// @param Direction in which the refresh wave sweeps across the screen
|
|
17
|
+
uniform vec2 direction; // = vec2(1.0, 0.0)
|
|
18
|
+
// @color Color of the panel between the diodes
|
|
19
|
+
uniform vec4 panel; // = vec4(0.02, 0.02, 0.025, 1.0)
|
|
20
|
+
|
|
21
|
+
// radius of a lit diode, in cells
|
|
22
|
+
const float RADIUS = 0.36;
|
|
23
|
+
// width of the soft edge of the diodes, in cells
|
|
24
|
+
const float EDGE = 0.05;
|
|
25
|
+
|
|
26
|
+
float hash12(vec2 p) {
|
|
27
|
+
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
|
|
28
|
+
p3 += dot(p3, p3.yzx + 33.33);
|
|
29
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// folds uv back into 0..1, so the frame stays filled
|
|
33
|
+
vec2 mirrored(vec2 v) {
|
|
34
|
+
vec2 m = mod(v, 2.0);
|
|
35
|
+
return mix(m, 2.0 - m, step(1.0, m));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 1 inside a disc of radius r, with a soft edge
|
|
39
|
+
float disc(float d, float r) {
|
|
40
|
+
return 1.0 - smoothstep(r - EDGE, r + EDGE, d);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
vec4 transition(vec2 uv) {
|
|
44
|
+
// how much the picture is a screen: it resolves into diodes until 0.3, and back from 0.7
|
|
45
|
+
float led = smoothstep(0.0, 0.3, progress) * (1.0 - smoothstep(0.7, 1.0, progress));
|
|
46
|
+
float z = 1.0 + max(zoom, 0.0) * smoothstep(0.0, 0.45, progress) * (1.0 - smoothstep(0.55, 1.0, progress));
|
|
47
|
+
vec2 p = 0.5 + (uv - 0.5) / z;
|
|
48
|
+
|
|
49
|
+
// the grid of diodes, in cells, with a diode at the center of the frame
|
|
50
|
+
vec2 aspect = vec2(ratio, 1.0);
|
|
51
|
+
vec2 toCells = aspect * max(cells, 1.0) / min(ratio, 1.0);
|
|
52
|
+
vec2 q = (p - 0.5) * toCells;
|
|
53
|
+
vec2 id = floor(q + 0.5);
|
|
54
|
+
vec2 local = q - id;
|
|
55
|
+
vec2 side = vec2(local.x < 0.0 ? -1.0 : 1.0, local.y < 0.0 ? -1.0 : 1.0);
|
|
56
|
+
|
|
57
|
+
// the refresh wave runs along dir, from 0 to 1 across the frame
|
|
58
|
+
vec2 dir = length(direction) > 1e-4 ? normalize(direction) : vec2(1.0, 0.0);
|
|
59
|
+
float extent = abs(dir.x) * ratio + abs(dir.y);
|
|
60
|
+
|
|
61
|
+
vec4 own = vec4(0.0);
|
|
62
|
+
float ownSwitch = 0.0;
|
|
63
|
+
vec4 halo = vec4(0.0);
|
|
64
|
+
float haloWeight = 0.0;
|
|
65
|
+
// this diode and the three nearest ones, whose glow reaches this point
|
|
66
|
+
for (int i = 0; i < 4; i++) {
|
|
67
|
+
// without glow, only this diode matters
|
|
68
|
+
if (i > 0 && glow * led <= 0.0) break;
|
|
69
|
+
vec2 o = vec2(mod(float(i), 2.0), floor(float(i) / 2.0)) * side;
|
|
70
|
+
vec2 c = id + o;
|
|
71
|
+
vec2 cuv = c / toCells + 0.5;
|
|
72
|
+
// where the diode is seen in the frame, so that the wave crosses the visible screen
|
|
73
|
+
float s = clamp(dot((cuv - 0.5) * z * aspect, dir) / extent + 0.5, 0.0, 1.0);
|
|
74
|
+
float when = 0.2 + 0.52 * s + 0.05 * (hash12(c + 71.0) - 0.5);
|
|
75
|
+
float sw = smoothstep(when - 0.012, when + 0.012, progress);
|
|
76
|
+
// the diode blinks off just before it switches, then pops bright
|
|
77
|
+
float x = (progress - when) / 0.018;
|
|
78
|
+
float pop = exp(-x * x) - 0.5 * exp(-(x + 1.6) * (x + 1.6));
|
|
79
|
+
vec2 suv = mirrored(cuv);
|
|
80
|
+
vec4 col = mix(getFromColor(suv), getToColor(suv), sw);
|
|
81
|
+
col.rgb = col.rgb * (1.0 + 1.4 * flash * pop) + 0.2 * flash * max(pop, 0.0);
|
|
82
|
+
if (i == 0) {
|
|
83
|
+
own = col;
|
|
84
|
+
ownSwitch = sw;
|
|
85
|
+
}
|
|
86
|
+
float d = length(local - o);
|
|
87
|
+
float w = 0.9 * glow * exp(-6.0 * max(d - RADIUS, 0.0)) * (1.0 + 0.8 * flash * max(pop, 0.0));
|
|
88
|
+
// the neighbors fade out where the next ones in the other direction take over, so the glow has no seam
|
|
89
|
+
if (o.x != 0.0) w *= smoothstep(0.0, 0.2, abs(local.x));
|
|
90
|
+
if (o.y != 0.0) w *= smoothstep(0.0, 0.2, abs(local.y));
|
|
91
|
+
halo += w * col;
|
|
92
|
+
haloWeight += w;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// the plain picture, switched along with its diode
|
|
96
|
+
vec4 plain = mix(getFromColor(p), getToColor(p), ownSwitch);
|
|
97
|
+
float d = length(local);
|
|
98
|
+
// the diodes cover their whole cell with the plain picture when led = 0: the dark panel
|
|
99
|
+
// shows up first between them, then they light up with the color of their center
|
|
100
|
+
float r = mix(0.8, RADIUS, smoothstep(0.0, 0.6, led));
|
|
101
|
+
vec4 gap = vec4(panel.rgb, panel.a * own.a);
|
|
102
|
+
if (haloWeight > 0.0) {
|
|
103
|
+
gap = mix(gap, halo / haloWeight, clamp(haloWeight * led, 0.0, 1.0));
|
|
104
|
+
}
|
|
105
|
+
vec4 body = own;
|
|
106
|
+
if (triads) {
|
|
107
|
+
// three sub-diodes on the panel, red at the top, green and blue below
|
|
108
|
+
vec3 sub = vec3(
|
|
109
|
+
disc(length(local - vec2(0.0, 0.15)), 0.2),
|
|
110
|
+
disc(length(local - vec2(-0.13, -0.075)), 0.2),
|
|
111
|
+
disc(length(local - vec2(0.13, -0.075)), 0.2));
|
|
112
|
+
float m = max(sub.r, max(sub.g, sub.b));
|
|
113
|
+
body = vec4(gap.rgb * (1.0 - m) + own.rgb * 1.5 * sub, mix(gap.a, own.a, m));
|
|
114
|
+
// the sub-diodes reach out to 0.4 cells
|
|
115
|
+
r = max(r, 0.45);
|
|
116
|
+
} else {
|
|
117
|
+
// brighter at the core of the diode
|
|
118
|
+
float k = clamp(d / RADIUS, 0.0, 1.0);
|
|
119
|
+
body.rgb *= 0.8 + 0.45 * (1.0 - k * k);
|
|
120
|
+
}
|
|
121
|
+
// the color of the center spreads from it over the diode
|
|
122
|
+
float lit = smoothstep(0.0, 0.8, led);
|
|
123
|
+
body = mix(plain, body, lit * mix(1.0, lit, smoothstep(0.0, 0.7, d)));
|
|
124
|
+
vec4 color = mix(gap, body, disc(d, r));
|
|
125
|
+
return clamp(color, 0.0, 1.0);
|
|
126
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: Two sets of fine concentric rings, centered on two points that drift toward each other, overlay the image and interfere into a shifting moire of wide bands; the bands open onto the incoming image and widen until it fills the frame, while the thin dark and light ring lines fade away
|
|
4
|
+
// Tags: moire, rings, interference, pattern, graphic, reveal
|
|
5
|
+
|
|
6
|
+
// @range(10, 80) Number of rings per frame height in each set
|
|
7
|
+
uniform float density; // = 36.0
|
|
8
|
+
// @range(1, 8) How many moire bands the rings make at the start; they get fewer and wider as the centers come together
|
|
9
|
+
uniform float bands; // = 3.0
|
|
10
|
+
// @range(-1, 1) How far the two centers turn around each other, in turns
|
|
11
|
+
uniform float drift; // = 0.25
|
|
12
|
+
// @range(0, 1) Strength of the ring lines drawn over the image
|
|
13
|
+
uniform float lines; // = 0.5
|
|
14
|
+
|
|
15
|
+
const float PI = 3.141592653589793;
|
|
16
|
+
// half width of the antialiased edges, in frame heights
|
|
17
|
+
const float AA = 0.0012;
|
|
18
|
+
// half width of a ring line, in ring spacings
|
|
19
|
+
const float LINE = 0.1;
|
|
20
|
+
// widest antialiased edge of the bands, in bands, which also sets when they start and finish
|
|
21
|
+
// opening
|
|
22
|
+
const float EDGE = 0.05;
|
|
23
|
+
// angle of the line between the two centers at the start, in radians
|
|
24
|
+
const float START = 0.35;
|
|
25
|
+
// strength of the ring lines at lines = 1, so the image always shows through them
|
|
26
|
+
const float INK = 0.7;
|
|
27
|
+
|
|
28
|
+
// coverage of the ring lines at radius r, box-filtered over the antialiasing width, and
|
|
29
|
+
// faded to their mean coverage when the rings get too fine to resolve
|
|
30
|
+
float ringLines(float r, float f) {
|
|
31
|
+
float q = abs(fract(r * f + 0.5) - 0.5);
|
|
32
|
+
float aa = AA * f;
|
|
33
|
+
float c = clamp((LINE - q) / (2.0 * aa) + 0.5, 0.0, 1.0);
|
|
34
|
+
return mix(c, 2.0 * LINE, clamp(10.0 * aa - 0.5, 0.0, 1.0));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
vec4 transition(vec2 uv) {
|
|
38
|
+
vec4 a = getFromColor(uv);
|
|
39
|
+
vec4 b = getToColor(uv);
|
|
40
|
+
if (progress <= 0.0) return a;
|
|
41
|
+
if (progress >= 1.0) return b;
|
|
42
|
+
|
|
43
|
+
float t = progress * progress * (3.0 - 2.0 * progress);
|
|
44
|
+
float f = max(density, 1.0);
|
|
45
|
+
vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
|
|
46
|
+
|
|
47
|
+
// the two centers turn around the middle of the frame and come together
|
|
48
|
+
float ang = 2.0 * PI * drift * t + START;
|
|
49
|
+
float k = max(bands, 1.0) * (1.0 - 0.75 * t);
|
|
50
|
+
vec2 axis = vec2(cos(ang), sin(ang)) * 0.5 * k / f;
|
|
51
|
+
float r1 = length(p - axis);
|
|
52
|
+
float r2 = length(p + axis);
|
|
53
|
+
// the second set is slightly finer than the first, which bends the bands into curves
|
|
54
|
+
float f2 = f + 1.2 * k;
|
|
55
|
+
|
|
56
|
+
// the beat of the two ring sets: wide bands where their rings line up, at this distance
|
|
57
|
+
// from the middle of the nearest band, in bands
|
|
58
|
+
float beat = abs(fract(f2 * r2 - f * r1 + 0.5) - 0.5);
|
|
59
|
+
// the bands open from their middles and widen until they cover the frame
|
|
60
|
+
// with an edge antialiased from the analytic gradient of the beat
|
|
61
|
+
vec2 grad = f2 * (p + axis) / max(r2, AA) - f * (p - axis) / max(r1, AA);
|
|
62
|
+
float s = min(AA * length(grad) + 0.004, EDGE);
|
|
63
|
+
float w = mix(-EDGE, 0.5 + EDGE, t);
|
|
64
|
+
float m = 1.0 - smoothstep(w - s, w + s, beat);
|
|
65
|
+
|
|
66
|
+
vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), m);
|
|
67
|
+
|
|
68
|
+
// the thin lines of both sets, dark over the outgoing image and light over the incoming
|
|
69
|
+
// one, fade in and out
|
|
70
|
+
float o = INK * clamp(lines, 0.0, 1.0) * sin(PI * t);
|
|
71
|
+
float l = 1.0 - (1.0 - o * ringLines(r1, f)) * (1.0 - o * ringLines(r2, f2));
|
|
72
|
+
c.rgb = mix(c.rgb, vec3(c.a * m), l);
|
|
73
|
+
return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
|
|
74
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: The outgoing image is a sheet of paper that folds in half in 3D along a vertical crease, then in half again along a horizontal one, its lit and shaded faces turning to show the back of the paper, and the small folded packet flies off the frame, leaving its shadow on the incoming image underneath
|
|
4
|
+
// Tags: paper, fold, 3d, shadow
|
|
5
|
+
|
|
6
|
+
// @param Direction the folded packet flies off toward
|
|
7
|
+
uniform vec2 direction; // = vec2(1.0, 0.5)
|
|
8
|
+
// @range(0, 1) How much the sheet tilts and recedes while it folds, so that the folds are seen in 3D
|
|
9
|
+
uniform float tilt; // = 0.6
|
|
10
|
+
// @range(0, 1) How much the faces darken as they turn away from the light, and the shadows they cast
|
|
11
|
+
uniform float shading; // = 0.6
|
|
12
|
+
// @color Color of the back of the paper, through which the print faintly shows
|
|
13
|
+
uniform vec4 paper; // = vec4(0.95, 0.94, 0.9, 1.0)
|
|
14
|
+
|
|
15
|
+
const float PI = 3.141592653589793;
|
|
16
|
+
// width of the anti-aliased edges, as a part of the frame's height
|
|
17
|
+
const float EDGE = 0.0015;
|
|
18
|
+
// how much the print shows through the back of the paper
|
|
19
|
+
const float SHOW = 0.1;
|
|
20
|
+
// width of the shaded crease, in frame heights
|
|
21
|
+
const float CREASE = 0.02;
|
|
22
|
+
// direction of the light, from the top left and the front
|
|
23
|
+
const vec3 LIGHT = vec3(-0.3995, 0.4494, 0.799);
|
|
24
|
+
|
|
25
|
+
vec4 front(vec2 st) {
|
|
26
|
+
return getFromColor(st / vec2(ratio, 1.0));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
vec4 back(vec2 st) {
|
|
30
|
+
vec4 c = front(st);
|
|
31
|
+
return vec4(mix(paper.rgb, c.rgb, SHOW), c.a * paper.a);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// the face of the packet's top layer: the image itself during the first fold, then the back
|
|
35
|
+
// of the right half, laid mirrored over the left half
|
|
36
|
+
vec4 topFace(vec2 st, bool second) {
|
|
37
|
+
return second ? back(vec2(ratio - st.x, st.y)) : front(st);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// distance inside the rectangle [0, h] x [0, k] (negative outside)
|
|
41
|
+
float inside(vec2 p, float h, float k) {
|
|
42
|
+
return min(min(p.x, h - p.x), min(p.y, k - p.y));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The sheet in its own frame: a flat part [0, h] x [0, k] lying at z = 0 and a flap of the same
|
|
46
|
+
// size hinged on its edge x = h, turned toward the viewer so that it lies along `along`, with the
|
|
47
|
+
// normal n. During the second fold, x and y are swapped so that the crease is always along y.
|
|
48
|
+
// Where the ray o + t * v meets the flap's plane: (t, distance from the hinge, y), t < 0 if never.
|
|
49
|
+
vec3 hitFlap(vec3 o, vec3 v, float h, vec3 n, vec3 along) {
|
|
50
|
+
float den = dot(n, v);
|
|
51
|
+
if (abs(den) < 1e-5) return vec3(-1.0, 0.0, 0.0);
|
|
52
|
+
vec3 hinge = vec3(h, 0.0, 0.0);
|
|
53
|
+
float t = dot(n, hinge - o) / den;
|
|
54
|
+
vec3 q = o + t * v;
|
|
55
|
+
return vec3(t, dot(q - hinge, along), q.y);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// how much the point q is shaded, lit by l: by the flap, and by the flat part once it lifts
|
|
59
|
+
// above the incoming image
|
|
60
|
+
float shadowAt(vec3 q, vec3 l, float h, float k, vec3 n, vec3 along) {
|
|
61
|
+
float sh = 0.0;
|
|
62
|
+
if (q.z < -1e-4) {
|
|
63
|
+
float soft = 0.004 - 0.4 * q.z;
|
|
64
|
+
sh = smoothstep(-soft, soft, inside(q.xy - q.z / l.z * l.xy, h, k));
|
|
65
|
+
}
|
|
66
|
+
vec3 hit = hitFlap(q, l, h, n, along);
|
|
67
|
+
if (hit.x > 0.0) {
|
|
68
|
+
float height = hit.x * l.z;
|
|
69
|
+
float soft = 0.004 + 0.3 * height;
|
|
70
|
+
// the flap's shadow appears as it lifts and vanishes as it lands
|
|
71
|
+
sh = max(sh, min(4.0 * n.x * n.x, 1.0) * smoothstep(-soft, soft, inside(hit.yz, h, k)) / (1.0 + 3.0 * height));
|
|
72
|
+
}
|
|
73
|
+
return sh;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// a vector of the frame into the frame of the sheet, turned by yaw (around y), pitch (around x)
|
|
77
|
+
// and spin (around z), each given as (cos, sin)
|
|
78
|
+
vec3 toSheet(vec3 v, vec2 yaw, vec2 pitch, vec2 spin) {
|
|
79
|
+
v = vec3(yaw.x * v.x + yaw.y * v.z, v.y, yaw.x * v.z - yaw.y * v.x);
|
|
80
|
+
v = vec3(v.x, pitch.x * v.y + pitch.y * v.z, pitch.x * v.z - pitch.y * v.y);
|
|
81
|
+
return vec3(spin.x * v.x + spin.y * v.y, spin.x * v.y - spin.y * v.x, v.z);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
vec4 transition(vec2 uv) {
|
|
85
|
+
float w = ratio;
|
|
86
|
+
float shade = clamp(shading, 0.0, 1.0);
|
|
87
|
+
// the two folds, one right after the other, then the flight of the packet
|
|
88
|
+
float s = 2.0 * smoothstep(0.0, 0.62, progress);
|
|
89
|
+
bool second = s > 1.0;
|
|
90
|
+
float x = second ? s - 1.0 : s;
|
|
91
|
+
float a = PI * mix(x, x * x * (3.0 - 2.0 * x), 0.6);
|
|
92
|
+
float f = clamp((progress - 0.5) / 0.47, 0.0, 1.0);
|
|
93
|
+
|
|
94
|
+
// the sheet tilts and recedes while it folds, so that the folds are seen in 3D, and lies flat
|
|
95
|
+
// again as the packet flies off
|
|
96
|
+
float turn = clamp(tilt, 0.0, 1.0) * (smoothstep(0.0, 0.25, progress) - smoothstep(0.4, 0.8, progress));
|
|
97
|
+
vec2 yaw = vec2(cos(0.45 * turn), sin(0.45 * turn));
|
|
98
|
+
vec2 pitch = vec2(cos(0.55 * turn), -sin(0.55 * turn));
|
|
99
|
+
float dist = 2.5 * max(w, 1.0);
|
|
100
|
+
float recede = dist * 0.35 * turn;
|
|
101
|
+
|
|
102
|
+
vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
|
|
103
|
+
// the point of the sheet held in the middle of the frame slides to the middle of the packet
|
|
104
|
+
vec2 c = vec2(0.5 * w - 0.25 * w * min(s, 1.0), 0.5 - 0.25 * max(s - 1.0, 0.0));
|
|
105
|
+
// far enough for the packet and its shadow to leave the frame
|
|
106
|
+
float reach = 0.5 * (abs(dir.x) * w + abs(dir.y)) + length(vec2(0.25 * w, 0.25)) + 0.4;
|
|
107
|
+
float lift = 0.3 * smoothstep(0.0, 0.5, f);
|
|
108
|
+
float turned = (dir.x < 0.0 ? 0.7 : -0.7) * f * f;
|
|
109
|
+
vec2 spin = vec2(cos(turned), sin(turned));
|
|
110
|
+
|
|
111
|
+
// the eye, the ray toward the point of the frame and the light, in the frame of the sheet,
|
|
112
|
+
// where the sheet lies on the plane z = 0 and the incoming image on z = -lift
|
|
113
|
+
vec3 center = vec3(vec2(0.5 * w, 0.5) + dir * reach * f * f, -recede);
|
|
114
|
+
vec3 eye = vec3(0.5 * w, 0.5, dist);
|
|
115
|
+
vec3 e = toSheet(eye - center, yaw, pitch, spin) + vec3(c, 0.0);
|
|
116
|
+
vec3 d = toSheet(vec3(uv.x * w, uv.y, 0.0) - eye, yaw, pitch, spin);
|
|
117
|
+
vec3 l = toSheet(LIGHT, yaw, pitch, spin);
|
|
118
|
+
if (second) {
|
|
119
|
+
e.xy = e.yx;
|
|
120
|
+
d.xy = d.yx;
|
|
121
|
+
l.xy = l.yx;
|
|
122
|
+
}
|
|
123
|
+
float h = second ? 0.5 : 0.5 * w;
|
|
124
|
+
float k = second ? 0.5 * w : 1.0;
|
|
125
|
+
float creased = sin(a);
|
|
126
|
+
vec3 n = vec3(-creased, 0.0, cos(a));
|
|
127
|
+
vec3 along = vec3(cos(a), 0.0, creased);
|
|
128
|
+
|
|
129
|
+
vec4 col = getToColor(uv);
|
|
130
|
+
if (d.z < 0.0) {
|
|
131
|
+
vec3 g = e + d * (e.z + lift) / -d.z;
|
|
132
|
+
// the shadow fades as the packet flies higher
|
|
133
|
+
col.rgb *= 1.0 - 0.7 * shade * (1.0 - f * f) * shadowAt(g, l, h, k, n, along);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// the flat part
|
|
137
|
+
float t = d.z < 0.0 ? e.z / -d.z : -1.0;
|
|
138
|
+
vec3 p = e + t * d;
|
|
139
|
+
float m = clamp(inside(p.xy, h, k) / (EDGE * t) + 1.0, 0.0, 1.0);
|
|
140
|
+
if (t > 0.0 && m > 0.0) {
|
|
141
|
+
vec4 img = topFace(second ? p.yx : p.xy, second);
|
|
142
|
+
float sh = shadowAt(p, l, h, k, n, along);
|
|
143
|
+
img.rgb *= (1.0 - 0.7 * shade * sh) * (1.0 - 0.5 * shade * creased * exp(-abs(h - p.x) / CREASE));
|
|
144
|
+
col = mix(col, img, m);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// the flap
|
|
148
|
+
vec3 hit = hitFlap(e, d, h, n, along);
|
|
149
|
+
if (hit.x > 0.0) {
|
|
150
|
+
float r = hit.y;
|
|
151
|
+
// edges seen at a grazing angle are narrower on screen
|
|
152
|
+
float dr = dot(along, normalize(d));
|
|
153
|
+
float fore = sqrt(max(1.0 - dr * dr, 0.0025));
|
|
154
|
+
float mf = clamp(min(min(r, h - r) * fore, min(hit.z, k - hit.z)) / (EDGE * hit.x) + 1.0, 0.0, 1.0);
|
|
155
|
+
if (mf > 0.0) {
|
|
156
|
+
bool up = dot(n, e - vec3(h, 0.0, 0.0)) > 0.0;
|
|
157
|
+
vec2 st = vec2(h + r, hit.z);
|
|
158
|
+
if (second) st = st.yx;
|
|
159
|
+
vec4 img = up ? topFace(st, second) : back(st);
|
|
160
|
+
// lit by the light, relative to the sheet lying flat
|
|
161
|
+
float lit = dot(up ? n : -n, l) - l.z;
|
|
162
|
+
img.rgb *= max(1.0 + 0.6 * shade * lit, 0.0) * (1.0 - 0.5 * shade * creased * exp(-abs(r) / CREASE));
|
|
163
|
+
col = mix(col, img, mf);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return col;
|
|
167
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// Author: gre
|
|
2
|
+
// License: MIT
|
|
3
|
+
// Description: The frame becomes the face of a twisty cube puzzle: dark gaps open between its cubies, then whole columns and rows of cubies turn a quarter turn around the cube one after another in 3D, each bringing the incoming image from the cube's side to the front, until the gaps close on the incoming image
|
|
4
|
+
// Tags: 3d, rotate, grid
|
|
5
|
+
|
|
6
|
+
// @range(2, 8, 1) Number of cubies along each side of the face
|
|
7
|
+
uniform int size; // = 3
|
|
8
|
+
// @range(0, 0.05) Width of the gaps between the cubies, as a part of the frame's height
|
|
9
|
+
uniform float gap; // = 0.012
|
|
10
|
+
// @range(0, 1) How much the turning sides darken away from the light, and the shadows inside the cube
|
|
11
|
+
uniform float shading; // = 0.6
|
|
12
|
+
// @color Color of the cubies' body, seen in the gaps, on their inner sides and around the cube
|
|
13
|
+
uniform vec4 background; // = vec4(0.04, 0.04, 0.05, 1.0)
|
|
14
|
+
|
|
15
|
+
const float PI = 3.141592653589793;
|
|
16
|
+
// delay between the turns of a group, as a part of a turn
|
|
17
|
+
const float STAGGER = 0.45;
|
|
18
|
+
// width of the anti-aliased edges, in frame heights
|
|
19
|
+
const float EDGE = 0.0012;
|
|
20
|
+
|
|
21
|
+
float gridSize() {
|
|
22
|
+
return float(size < 2 ? 2 : (size > 8 ? 8 : size));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// the turns run in 3 groups, one after the other: the even columns, the even rows (counted from the top),
|
|
26
|
+
// then the odd columns; the turns of a group overlap
|
|
27
|
+
float groupLength(float m) {
|
|
28
|
+
return m > 0.0 ? 1.0 + (m - 1.0) * STAGGER : 0.0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// the time in turn units, and the length of the groups of even and odd slices
|
|
32
|
+
vec3 timeline(float n) {
|
|
33
|
+
float lenEven = groupLength(floor((n + 1.0) * 0.5));
|
|
34
|
+
float lenOdd = groupLength(floor(n * 0.5));
|
|
35
|
+
float u = clamp((progress - 0.05) / 0.85, 0.0, 1.0) * (2.0 * lenEven + lenOdd);
|
|
36
|
+
return vec3(u, lenEven, lenOdd);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// the turn of a column (isCol) or of a row, 0 at rest to 1 turned
|
|
40
|
+
float turnTime(vec3 tl, bool isCol, float idx, float n) {
|
|
41
|
+
// rows are counted from the top
|
|
42
|
+
float k = isCol ? idx : n - 1.0 - idx;
|
|
43
|
+
bool odd = mod(k, 2.0) > 0.5;
|
|
44
|
+
// the odd rows never turn: the columns already brought the incoming image there
|
|
45
|
+
if (odd && !isCol) return 0.0;
|
|
46
|
+
float start = (odd ? 2.0 * tl.y : (isCol ? 0.0 : tl.y)) + floor(k * 0.5) * STAGGER;
|
|
47
|
+
return clamp(tl.x - start, 0.0, 1.0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// the turn's direction: +1 brings the side of the cube at higher coordinates to the front
|
|
51
|
+
float turnDir(bool isCol, float idx) {
|
|
52
|
+
return mod(idx + (isCol ? 0.0 : 1.0), 2.0) < 0.5 ? 1.0 : -1.0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// eased angle, landing with a little speed left like a click
|
|
56
|
+
float turnAngle(float t) {
|
|
57
|
+
return 0.5 * PI * mix(t, t * t * (3.0 - 2.0 * t), 0.8);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 1 on the cubies' faces, 0 in the gaps, at the point fp of the face (frame heights)
|
|
61
|
+
float faceMask(vec2 fp, float n, float g) {
|
|
62
|
+
if (g <= 0.0) return 1.0;
|
|
63
|
+
vec2 cell = vec2(ratio, 1.0) / n;
|
|
64
|
+
vec2 c = fp / cell;
|
|
65
|
+
vec2 r = floor(c + 0.5);
|
|
66
|
+
// distance to the nearest cubie edge inside the face (the face's own border has no gap)
|
|
67
|
+
vec2 d = abs(c - r) * cell;
|
|
68
|
+
d.x = (r.x < 0.5 || r.x > n - 0.5) ? 1.0 : d.x;
|
|
69
|
+
d.y = (r.y < 0.5 || r.y > n - 0.5) ? 1.0 : d.y;
|
|
70
|
+
float e = min(EDGE, 0.5 * g);
|
|
71
|
+
return smoothstep(0.5 * g - e, 0.5 * g + e, min(d.x, d.y));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// does the cubie of the face at fp show the incoming image, from the turns done so far
|
|
75
|
+
bool isDone(vec3 tl, vec2 fp, float n) {
|
|
76
|
+
vec2 cell = clamp(floor(fp / (vec2(ratio, 1.0) / n)), 0.0, n - 1.0);
|
|
77
|
+
return turnTime(tl, true, cell.x, n) >= 1.0 || turnTime(tl, false, cell.y, n) >= 1.0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
vec4 sticker(vec2 fp, bool incoming, float light, float n, float g) {
|
|
81
|
+
vec2 uv = clamp(fp / vec2(ratio, 1.0), 0.0, 1.0);
|
|
82
|
+
vec4 img = incoming ? getToColor(uv) : getFromColor(uv);
|
|
83
|
+
vec4 body = vec4(background.rgb * light, background.a);
|
|
84
|
+
return mix(body, vec4(img.rgb * light, img.a), faceMask(fp, n, g));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// brightness of a face of normal nrm (across the slices, along the turn, depth) in the turn's space, 1 facing the viewer
|
|
88
|
+
float lighting(vec3 nrm, bool isCol) {
|
|
89
|
+
vec3 l = normalize(vec3(-0.35, 0.55, 1.0));
|
|
90
|
+
if (isCol) l = l.yxz;
|
|
91
|
+
return 1.0 - shading * (1.0 - clamp(dot(nrm, l) / l.z, 0.0, 1.0));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
vec2 rot(vec2 v, float a) {
|
|
95
|
+
float c = cos(a), s = sin(a);
|
|
96
|
+
return vec2(c * v.x - s * v.y, s * v.x + c * v.y);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// casts the ray (o, d), in the turn's space (across the slices, along the turn, depth), onto the slice
|
|
100
|
+
// [a0, a0 + w] turned by the angle a around the middle of the cube (a square section of side S):
|
|
101
|
+
// returns the ray's parameter at the hit (or -1), the face hit (0 front, 1 back, 2 and 3 the sides
|
|
102
|
+
// at higher and lower coordinates along the turn at rest, 4 the slice's ends), and the point hit
|
|
103
|
+
// (across the slices, and across the face, -1 to 1)
|
|
104
|
+
vec4 sliceHit(vec3 o, vec3 d, float a0, float w, float S, float a) {
|
|
105
|
+
vec2 lo = rot(o.yz - vec2(0.5 * S, -0.5 * S), -a);
|
|
106
|
+
vec2 ld = rot(d.yz, -a);
|
|
107
|
+
ld = vec2(abs(ld.x) < 1e-6 ? 1e-6 : ld.x, abs(ld.y) < 1e-6 ? 1e-6 : ld.y);
|
|
108
|
+
float dx = abs(d.x) < 1e-6 ? 1e-6 : d.x;
|
|
109
|
+
vec3 t1 = vec3((a0 - o.x) / dx, (-0.5 * S - lo) / ld);
|
|
110
|
+
vec3 t2 = vec3((a0 + w - o.x) / dx, (0.5 * S - lo) / ld);
|
|
111
|
+
vec3 tn = min(t1, t2);
|
|
112
|
+
vec3 tf = max(t1, t2);
|
|
113
|
+
float tNear = max(tn.x, max(tn.y, tn.z));
|
|
114
|
+
float tFar = min(tf.x, min(tf.y, tf.z));
|
|
115
|
+
if (tNear > tFar || tNear <= 0.0) return vec4(-1.0);
|
|
116
|
+
vec2 q = (lo + tNear * ld) / (0.5 * S);
|
|
117
|
+
float across = o.x + tNear * d.x;
|
|
118
|
+
if (tn.x >= tn.y && tn.x >= tn.z) return vec4(tNear, 4.0, across, sign(-dx));
|
|
119
|
+
if (tn.y > tn.z) return vec4(tNear, ld.x < 0.0 ? 2.0 : 3.0, across, q.y);
|
|
120
|
+
return vec4(tNear, ld.y < 0.0 ? 0.0 : 1.0, across, q.x);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// the color of a turning slice at its hit
|
|
124
|
+
vec4 sliceColor(vec4 hit, vec3 tl, bool isCol, float a, float dir, float S, float n, float g) {
|
|
125
|
+
float f = hit.y;
|
|
126
|
+
if (f > 3.5) return vec4(background.rgb * lighting(vec3(hit.w, 0.0, 0.0), isCol), background.a);
|
|
127
|
+
vec2 nl = f < 0.5 ? vec2(0.0, 1.0) : f < 1.5 ? vec2(0.0, -1.0) : f < 2.5 ? vec2(1.0, 0.0) : vec2(-1.0, 0.0);
|
|
128
|
+
float light = lighting(vec3(0.0, rot(nl, a)), isCol);
|
|
129
|
+
// the front shows what the cubies showed before this turn, the side that comes to the front
|
|
130
|
+
// shows the incoming image where it lands
|
|
131
|
+
bool front = f < 0.5;
|
|
132
|
+
bool coming = nl.x * dir > 0.5;
|
|
133
|
+
if (!front && !coming) return vec4(background.rgb * light, background.a);
|
|
134
|
+
// on the side coming to the front, the point across lands at -dir times its depth
|
|
135
|
+
float r = 0.5 * S * (1.0 + (front ? hit.w : -dir * hit.w));
|
|
136
|
+
vec2 fp = isCol ? vec2(hit.z, r) : vec2(r, hit.z);
|
|
137
|
+
return sticker(fp, coming || isDone(tl, fp, n), light, n, g);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
vec4 transition(vec2 uv) {
|
|
141
|
+
float n = gridSize();
|
|
142
|
+
vec3 tl = timeline(n);
|
|
143
|
+
// the gaps open at the start and close at the end, after the last turn
|
|
144
|
+
float g = gap * smoothstep(0.0, 0.1, progress) * (1.0 - smoothstep(0.9, 1.0, progress));
|
|
145
|
+
vec2 P = vec2(uv.x * ratio, uv.y);
|
|
146
|
+
|
|
147
|
+
// the turns going on are of columns or of rows, never both
|
|
148
|
+
bool isCol = tl.x < tl.y || tl.x >= 2.0 * tl.y;
|
|
149
|
+
// the turn's space: (across the slices, along the turn, depth toward the viewer);
|
|
150
|
+
// a column turns around the horizontal axis through the middle of the cube, a row around the vertical one
|
|
151
|
+
float w = (isCol ? ratio : 1.0) / n;
|
|
152
|
+
float S = isCol ? 1.0 : ratio;
|
|
153
|
+
vec2 pp = isCol ? P : P.yx;
|
|
154
|
+
vec3 o = vec3(isCol ? vec2(0.5 * ratio, 0.5) : vec2(0.5, 0.5 * ratio), 1.2 + 0.6 * max(ratio, 1.0));
|
|
155
|
+
// the ray reaches the face (z = 0) at t = 1
|
|
156
|
+
vec3 d = vec3(pp, 0.0) - o;
|
|
157
|
+
|
|
158
|
+
float k0 = clamp(floor(pp.x / w), 0.0, n - 1.0);
|
|
159
|
+
float t0 = turnTime(tl, isCol, k0, n);
|
|
160
|
+
|
|
161
|
+
float nearest = 1.0;
|
|
162
|
+
vec4 color;
|
|
163
|
+
if (t0 <= 0.0 || t0 >= 1.0) {
|
|
164
|
+
// the face at rest: the exact image
|
|
165
|
+
color = isDone(tl, P, n) ? getToColor(uv) : getFromColor(uv);
|
|
166
|
+
color = mix(background, color, faceMask(P, n, g));
|
|
167
|
+
// the shade of the turning slices next to this one, deepest mid-turn
|
|
168
|
+
for (int j = -1; j <= 1; j += 2) {
|
|
169
|
+
float k = k0 + float(j);
|
|
170
|
+
if (k < 0.0 || k > n - 1.0) continue;
|
|
171
|
+
float tk = turnTime(tl, isCol, k, n);
|
|
172
|
+
if (tk <= 0.0 || tk >= 1.0) continue;
|
|
173
|
+
float dist = abs(pp.x - (k + 0.5) * w) - 0.5 * w;
|
|
174
|
+
color.rgb *= 1.0 - 0.5 * shading * sin(2.0 * turnAngle(tk)) * exp(-dist / (0.2 * w));
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
// inside the hollow left by the turning slice: the sides of the slices next to it and the cube's inside, in the dark
|
|
178
|
+
float tw = abs(d.x) < 1e-6 ? 1e6 : (d.x < 0.0 ? k0 * w - o.x : (k0 + 1.0) * w - o.x) / d.x;
|
|
179
|
+
float tb = (o.z + S) / -d.z;
|
|
180
|
+
nearest = min(tw, tb);
|
|
181
|
+
float along = o.y + nearest * d.y;
|
|
182
|
+
float depth = (o.z + nearest * d.z) / -S;
|
|
183
|
+
float light = tw < tb ? lighting(vec3(-sign(d.x), 0.0, 0.0), isCol) : 1.0;
|
|
184
|
+
light *= 1.0 - shading * (0.5 + 0.4 * clamp(depth, 0.0, 1.0));
|
|
185
|
+
// beyond the cube's edges: the background
|
|
186
|
+
color = along < 0.0 || along > S ? background : vec4(background.rgb * light, background.a);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// the turning slices, which come out in front of the face as they turn
|
|
190
|
+
for (int j = -1; j <= 1; j++) {
|
|
191
|
+
float k = k0 + float(j);
|
|
192
|
+
if (k < 0.0 || k > n - 1.0) continue;
|
|
193
|
+
float tk = turnTime(tl, isCol, k, n);
|
|
194
|
+
if (tk <= 0.0 || tk >= 1.0) continue;
|
|
195
|
+
float dir = turnDir(isCol, k);
|
|
196
|
+
float a = dir * turnAngle(tk);
|
|
197
|
+
vec4 hit = sliceHit(o, d, k * w, w, S, a);
|
|
198
|
+
if (hit.x > 0.0 && hit.x < nearest) {
|
|
199
|
+
nearest = hit.x;
|
|
200
|
+
color = sliceColor(hit, tl, isCol, a, dir, S, n, g);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return color;
|
|
204
|
+
}
|