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.
- package/CHANGELOG.md +64 -0
- package/compatibility.json +359 -11
- package/gl-transitions.js +1 -1
- package/gl-transitions.json +1 -1
- package/glsl3/BookFlip.glsl +124 -21
- package/glsl3/Clothesline.glsl +217 -0
- package/glsl3/ComicPanels.glsl +174 -0
- package/glsl3/Cube.glsl +105 -52
- 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/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/Shatter.glsl +231 -35
- package/glsl3/SketchDissolve.glsl +100 -0
- package/glsl3/SlotReels.glsl +118 -0
- package/glsl3/SplitFlap.glsl +124 -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 +991 -19
- package/llms-full.txt +791 -403
- package/llms.txt +219 -197
- package/msl/BookFlip.metal +575 -114
- package/msl/Clothesline.metal +828 -0
- package/msl/ComicPanels.metal +959 -0
- package/msl/Cube.metal +466 -170
- 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/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/Shatter.metal +1136 -160
- package/msl/SketchDissolve.metal +446 -0
- package/msl/SlotReels.metal +436 -0
- package/msl/SplitFlap.metal +589 -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 +97 -51
- package/sksl/BookFlip.sksl +117 -20
- package/sksl/Clothesline.sksl +217 -0
- package/sksl/ComicPanels.sksl +176 -0
- package/sksl/Cube.sksl +99 -46
- 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/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/Shatter.sksl +218 -33
- package/sksl/SketchDissolve.sksl +111 -0
- package/sksl/SlotReels.sksl +127 -0
- package/sksl/SplitFlap.sksl +131 -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/Clothesline.glsl +216 -0
- package/transitions/ComicPanels.glsl +173 -0
- package/transitions/Cube.glsl +105 -52
- 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/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/Shatter.glsl +231 -35
- package/transitions/SketchDissolve.glsl +99 -0
- package/transitions/SlotReels.glsl +117 -0
- package/transitions/SplitFlap.glsl +123 -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/Clothesline.wgsl +756 -0
- package/wgsl/ComicPanels.wgsl +886 -0
- package/wgsl/Cube.wgsl +461 -156
- 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/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/Shatter.wgsl +1091 -148
- package/wgsl/SketchDissolve.wgsl +409 -0
- package/wgsl/SlotReels.wgsl +391 -0
- package/wgsl/SplitFlap.wgsl +533 -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,75 @@
|
|
|
1
|
+
// MoireWipe — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/MoireWipe.glsl
|
|
2
|
+
// Author: gre
|
|
3
|
+
// License: MIT
|
|
4
|
+
// 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
|
|
5
|
+
// Tags: moire, rings, interference, pattern, graphic, reveal
|
|
6
|
+
|
|
7
|
+
// @range(10, 80) Number of rings per frame height in each set
|
|
8
|
+
uniform float density; // = 36.0
|
|
9
|
+
// @range(1, 8) How many moire bands the rings make at the start; they get fewer and wider as the centers come together
|
|
10
|
+
uniform float bands; // = 3.0
|
|
11
|
+
// @range(-1, 1) How far the two centers turn around each other, in turns
|
|
12
|
+
uniform float drift; // = 0.25
|
|
13
|
+
// @range(0, 1) Strength of the ring lines drawn over the image
|
|
14
|
+
uniform float lines; // = 0.5
|
|
15
|
+
|
|
16
|
+
const float PI = 3.141592653589793;
|
|
17
|
+
// half width of the antialiased edges, in frame heights
|
|
18
|
+
const float AA = 0.0012;
|
|
19
|
+
// half width of a ring line, in ring spacings
|
|
20
|
+
const float LINE = 0.1;
|
|
21
|
+
// widest antialiased edge of the bands, in bands, which also sets when they start and finish
|
|
22
|
+
// opening
|
|
23
|
+
const float EDGE = 0.05;
|
|
24
|
+
// angle of the line between the two centers at the start, in radians
|
|
25
|
+
const float START = 0.35;
|
|
26
|
+
// strength of the ring lines at lines = 1, so the image always shows through them
|
|
27
|
+
const float INK = 0.7;
|
|
28
|
+
|
|
29
|
+
// coverage of the ring lines at radius r, box-filtered over the antialiasing width, and
|
|
30
|
+
// faded to their mean coverage when the rings get too fine to resolve
|
|
31
|
+
float ringLines(float r, float f) {
|
|
32
|
+
float q = abs(fract(r * f + 0.5) - 0.5);
|
|
33
|
+
float aa = AA * f;
|
|
34
|
+
float c = clamp((LINE - q) / (2.0 * aa) + 0.5, 0.0, 1.0);
|
|
35
|
+
return mix(c, 2.0 * LINE, clamp(10.0 * aa - 0.5, 0.0, 1.0));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
vec4 transition(vec2 uv) {
|
|
39
|
+
vec4 a = getFromColor(uv);
|
|
40
|
+
vec4 b = getToColor(uv);
|
|
41
|
+
if (progress <= 0.0) return a;
|
|
42
|
+
if (progress >= 1.0) return b;
|
|
43
|
+
|
|
44
|
+
float t = progress * progress * (3.0 - 2.0 * progress);
|
|
45
|
+
float f = max(density, 1.0);
|
|
46
|
+
vec2 p = (uv - 0.5) * vec2(ratio, 1.0);
|
|
47
|
+
|
|
48
|
+
// the two centers turn around the middle of the frame and come together
|
|
49
|
+
float ang = 2.0 * PI * drift * t + START;
|
|
50
|
+
float k = max(bands, 1.0) * (1.0 - 0.75 * t);
|
|
51
|
+
vec2 axis = vec2(cos(ang), sin(ang)) * 0.5 * k / f;
|
|
52
|
+
float r1 = length(p - axis);
|
|
53
|
+
float r2 = length(p + axis);
|
|
54
|
+
// the second set is slightly finer than the first, which bends the bands into curves
|
|
55
|
+
float f2 = f + 1.2 * k;
|
|
56
|
+
|
|
57
|
+
// the beat of the two ring sets: wide bands where their rings line up, at this distance
|
|
58
|
+
// from the middle of the nearest band, in bands
|
|
59
|
+
float beat = abs(fract(f2 * r2 - f * r1 + 0.5) - 0.5);
|
|
60
|
+
// the bands open from their middles and widen until they cover the frame
|
|
61
|
+
// with an edge antialiased from the analytic gradient of the beat
|
|
62
|
+
vec2 grad = f2 * (p + axis) / max(r2, AA) - f * (p - axis) / max(r1, AA);
|
|
63
|
+
float s = min(AA * length(grad) + 0.004, EDGE);
|
|
64
|
+
float w = mix(-EDGE, 0.5 + EDGE, t);
|
|
65
|
+
float m = 1.0 - smoothstep(w - s, w + s, beat);
|
|
66
|
+
|
|
67
|
+
vec4 c = mix(vec4(a.rgb * a.a, a.a), vec4(b.rgb * b.a, b.a), m);
|
|
68
|
+
|
|
69
|
+
// the thin lines of both sets, dark over the outgoing image and light over the incoming
|
|
70
|
+
// one, fade in and out
|
|
71
|
+
float o = INK * clamp(lines, 0.0, 1.0) * sin(PI * t);
|
|
72
|
+
float l = 1.0 - (1.0 - o * ringLines(r1, f)) * (1.0 - o * ringLines(r2, f2));
|
|
73
|
+
c.rgb = mix(c.rgb, vec3(c.a * m), l);
|
|
74
|
+
return c.a > 0.0 ? vec4(c.rgb / c.a, c.a) : vec4(0.0);
|
|
75
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// PaperFold — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/PaperFold.glsl
|
|
2
|
+
// Author: gre
|
|
3
|
+
// License: MIT
|
|
4
|
+
// 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
|
|
5
|
+
// Tags: paper, fold, 3d, shadow
|
|
6
|
+
|
|
7
|
+
// @param Direction the folded packet flies off toward
|
|
8
|
+
uniform vec2 direction; // = vec2(1.0, 0.5)
|
|
9
|
+
// @range(0, 1) How much the sheet tilts and recedes while it folds, so that the folds are seen in 3D
|
|
10
|
+
uniform float tilt; // = 0.6
|
|
11
|
+
// @range(0, 1) How much the faces darken as they turn away from the light, and the shadows they cast
|
|
12
|
+
uniform float shading; // = 0.6
|
|
13
|
+
// @color Color of the back of the paper, through which the print faintly shows
|
|
14
|
+
uniform vec4 paper; // = vec4(0.95, 0.94, 0.9, 1.0)
|
|
15
|
+
|
|
16
|
+
const float PI = 3.141592653589793;
|
|
17
|
+
// width of the anti-aliased edges, as a part of the frame's height
|
|
18
|
+
const float EDGE = 0.0015;
|
|
19
|
+
// how much the print shows through the back of the paper
|
|
20
|
+
const float SHOW = 0.1;
|
|
21
|
+
// width of the shaded crease, in frame heights
|
|
22
|
+
const float CREASE = 0.02;
|
|
23
|
+
// direction of the light, from the top left and the front
|
|
24
|
+
const vec3 LIGHT = vec3(-0.3995, 0.4494, 0.799);
|
|
25
|
+
|
|
26
|
+
vec4 front(vec2 st) {
|
|
27
|
+
return getFromColor(st / vec2(ratio, 1.0));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
vec4 back(vec2 st) {
|
|
31
|
+
vec4 c = front(st);
|
|
32
|
+
return vec4(mix(paper.rgb, c.rgb, SHOW), c.a * paper.a);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// the face of the packet's top layer: the image itself during the first fold, then the back
|
|
36
|
+
// of the right half, laid mirrored over the left half
|
|
37
|
+
vec4 topFace(vec2 st, bool second) {
|
|
38
|
+
return second ? back(vec2(ratio - st.x, st.y)) : front(st);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// distance inside the rectangle [0, h] x [0, k] (negative outside)
|
|
42
|
+
float inside(vec2 p, float h, float k) {
|
|
43
|
+
return min(min(p.x, h - p.x), min(p.y, k - p.y));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The sheet in its own frame: a flat part [0, h] x [0, k] lying at z = 0 and a flap of the same
|
|
47
|
+
// size hinged on its edge x = h, turned toward the viewer so that it lies along `along`, with the
|
|
48
|
+
// normal n. During the second fold, x and y are swapped so that the crease is always along y.
|
|
49
|
+
// Where the ray o + t * v meets the flap's plane: (t, distance from the hinge, y), t < 0 if never.
|
|
50
|
+
vec3 hitFlap(vec3 o, vec3 v, float h, vec3 n, vec3 along) {
|
|
51
|
+
float den = dot(n, v);
|
|
52
|
+
if (abs(den) < 1e-5) return vec3(-1.0, 0.0, 0.0);
|
|
53
|
+
vec3 hinge = vec3(h, 0.0, 0.0);
|
|
54
|
+
float t = dot(n, hinge - o) / den;
|
|
55
|
+
vec3 q = o + t * v;
|
|
56
|
+
return vec3(t, dot(q - hinge, along), q.y);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// how much the point q is shaded, lit by l: by the flap, and by the flat part once it lifts
|
|
60
|
+
// above the incoming image
|
|
61
|
+
float shadowAt(vec3 q, vec3 l, float h, float k, vec3 n, vec3 along) {
|
|
62
|
+
float sh = 0.0;
|
|
63
|
+
if (q.z < -1e-4) {
|
|
64
|
+
float soft = 0.004 - 0.4 * q.z;
|
|
65
|
+
sh = smoothstep(-soft, soft, inside(q.xy - q.z / l.z * l.xy, h, k));
|
|
66
|
+
}
|
|
67
|
+
vec3 hit = hitFlap(q, l, h, n, along);
|
|
68
|
+
if (hit.x > 0.0) {
|
|
69
|
+
float height = hit.x * l.z;
|
|
70
|
+
float soft = 0.004 + 0.3 * height;
|
|
71
|
+
// the flap's shadow appears as it lifts and vanishes as it lands
|
|
72
|
+
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));
|
|
73
|
+
}
|
|
74
|
+
return sh;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// a vector of the frame into the frame of the sheet, turned by yaw (around y), pitch (around x)
|
|
78
|
+
// and spin (around z), each given as (cos, sin)
|
|
79
|
+
vec3 toSheet(vec3 v, vec2 yaw, vec2 pitch, vec2 spin) {
|
|
80
|
+
v = vec3(yaw.x * v.x + yaw.y * v.z, v.y, yaw.x * v.z - yaw.y * v.x);
|
|
81
|
+
v = vec3(v.x, pitch.x * v.y + pitch.y * v.z, pitch.x * v.z - pitch.y * v.y);
|
|
82
|
+
return vec3(spin.x * v.x + spin.y * v.y, spin.x * v.y - spin.y * v.x, v.z);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
vec4 transition(vec2 uv) {
|
|
86
|
+
float w = ratio;
|
|
87
|
+
float shade = clamp(shading, 0.0, 1.0);
|
|
88
|
+
// the two folds, one right after the other, then the flight of the packet
|
|
89
|
+
float s = 2.0 * smoothstep(0.0, 0.62, progress);
|
|
90
|
+
bool second = s > 1.0;
|
|
91
|
+
float x = second ? s - 1.0 : s;
|
|
92
|
+
float a = PI * mix(x, x * x * (3.0 - 2.0 * x), 0.6);
|
|
93
|
+
float f = clamp((progress - 0.5) / 0.47, 0.0, 1.0);
|
|
94
|
+
|
|
95
|
+
// the sheet tilts and recedes while it folds, so that the folds are seen in 3D, and lies flat
|
|
96
|
+
// again as the packet flies off
|
|
97
|
+
float turn = clamp(tilt, 0.0, 1.0) * (smoothstep(0.0, 0.25, progress) - smoothstep(0.4, 0.8, progress));
|
|
98
|
+
vec2 yaw = vec2(cos(0.45 * turn), sin(0.45 * turn));
|
|
99
|
+
vec2 pitch = vec2(cos(0.55 * turn), -sin(0.55 * turn));
|
|
100
|
+
float dist = 2.5 * max(w, 1.0);
|
|
101
|
+
float recede = dist * 0.35 * turn;
|
|
102
|
+
|
|
103
|
+
vec2 dir = length(direction) > 0.0 ? normalize(direction) : vec2(1.0, 0.0);
|
|
104
|
+
// the point of the sheet held in the middle of the frame slides to the middle of the packet
|
|
105
|
+
vec2 c = vec2(0.5 * w - 0.25 * w * min(s, 1.0), 0.5 - 0.25 * max(s - 1.0, 0.0));
|
|
106
|
+
// far enough for the packet and its shadow to leave the frame
|
|
107
|
+
float reach = 0.5 * (abs(dir.x) * w + abs(dir.y)) + length(vec2(0.25 * w, 0.25)) + 0.4;
|
|
108
|
+
float lift = 0.3 * smoothstep(0.0, 0.5, f);
|
|
109
|
+
float turned = (dir.x < 0.0 ? 0.7 : -0.7) * f * f;
|
|
110
|
+
vec2 spin = vec2(cos(turned), sin(turned));
|
|
111
|
+
|
|
112
|
+
// the eye, the ray toward the point of the frame and the light, in the frame of the sheet,
|
|
113
|
+
// where the sheet lies on the plane z = 0 and the incoming image on z = -lift
|
|
114
|
+
vec3 center = vec3(vec2(0.5 * w, 0.5) + dir * reach * f * f, -recede);
|
|
115
|
+
vec3 eye = vec3(0.5 * w, 0.5, dist);
|
|
116
|
+
vec3 e = toSheet(eye - center, yaw, pitch, spin) + vec3(c, 0.0);
|
|
117
|
+
vec3 d = toSheet(vec3(uv.x * w, uv.y, 0.0) - eye, yaw, pitch, spin);
|
|
118
|
+
vec3 l = toSheet(LIGHT, yaw, pitch, spin);
|
|
119
|
+
if (second) {
|
|
120
|
+
e.xy = e.yx;
|
|
121
|
+
d.xy = d.yx;
|
|
122
|
+
l.xy = l.yx;
|
|
123
|
+
}
|
|
124
|
+
float h = second ? 0.5 : 0.5 * w;
|
|
125
|
+
float k = second ? 0.5 * w : 1.0;
|
|
126
|
+
float creased = sin(a);
|
|
127
|
+
vec3 n = vec3(-creased, 0.0, cos(a));
|
|
128
|
+
vec3 along = vec3(cos(a), 0.0, creased);
|
|
129
|
+
|
|
130
|
+
vec4 col = getToColor(uv);
|
|
131
|
+
if (d.z < 0.0) {
|
|
132
|
+
vec3 g = e + d * (e.z + lift) / -d.z;
|
|
133
|
+
// the shadow fades as the packet flies higher
|
|
134
|
+
col.rgb *= 1.0 - 0.7 * shade * (1.0 - f * f) * shadowAt(g, l, h, k, n, along);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// the flat part
|
|
138
|
+
float t = d.z < 0.0 ? e.z / -d.z : -1.0;
|
|
139
|
+
vec3 p = e + t * d;
|
|
140
|
+
float m = clamp(inside(p.xy, h, k) / (EDGE * t) + 1.0, 0.0, 1.0);
|
|
141
|
+
if (t > 0.0 && m > 0.0) {
|
|
142
|
+
vec4 img = topFace(second ? p.yx : p.xy, second);
|
|
143
|
+
float sh = shadowAt(p, l, h, k, n, along);
|
|
144
|
+
img.rgb *= (1.0 - 0.7 * shade * sh) * (1.0 - 0.5 * shade * creased * exp(-abs(h - p.x) / CREASE));
|
|
145
|
+
col = mix(col, img, m);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// the flap
|
|
149
|
+
vec3 hit = hitFlap(e, d, h, n, along);
|
|
150
|
+
if (hit.x > 0.0) {
|
|
151
|
+
float r = hit.y;
|
|
152
|
+
// edges seen at a grazing angle are narrower on screen
|
|
153
|
+
float dr = dot(along, normalize(d));
|
|
154
|
+
float fore = sqrt(max(1.0 - dr * dr, 0.0025));
|
|
155
|
+
float mf = clamp(min(min(r, h - r) * fore, min(hit.z, k - hit.z)) / (EDGE * hit.x) + 1.0, 0.0, 1.0);
|
|
156
|
+
if (mf > 0.0) {
|
|
157
|
+
bool up = dot(n, e - vec3(h, 0.0, 0.0)) > 0.0;
|
|
158
|
+
vec2 st = vec2(h + r, hit.z);
|
|
159
|
+
if (second) st = st.yx;
|
|
160
|
+
vec4 img = up ? topFace(st, second) : back(st);
|
|
161
|
+
// lit by the light, relative to the sheet lying flat
|
|
162
|
+
float lit = dot(up ? n : -n, l) - l.z;
|
|
163
|
+
img.rgb *= max(1.0 + 0.6 * shade * lit, 0.0) * (1.0 - 0.5 * shade * creased * exp(-abs(r) / CREASE));
|
|
164
|
+
col = mix(col, img, mf);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return col;
|
|
168
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// PuzzleCube — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/PuzzleCube.glsl
|
|
2
|
+
// Author: gre
|
|
3
|
+
// License: MIT
|
|
4
|
+
// 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
|
|
5
|
+
// Tags: 3d, rotate, grid
|
|
6
|
+
|
|
7
|
+
// @range(2, 8, 1) Number of cubies along each side of the face
|
|
8
|
+
uniform int size; // = 3
|
|
9
|
+
// @range(0, 0.05) Width of the gaps between the cubies, as a part of the frame's height
|
|
10
|
+
uniform float gap; // = 0.012
|
|
11
|
+
// @range(0, 1) How much the turning sides darken away from the light, and the shadows inside the cube
|
|
12
|
+
uniform float shading; // = 0.6
|
|
13
|
+
// @color Color of the cubies' body, seen in the gaps, on their inner sides and around the cube
|
|
14
|
+
uniform vec4 background; // = vec4(0.04, 0.04, 0.05, 1.0)
|
|
15
|
+
|
|
16
|
+
const float PI = 3.141592653589793;
|
|
17
|
+
// delay between the turns of a group, as a part of a turn
|
|
18
|
+
const float STAGGER = 0.45;
|
|
19
|
+
// width of the anti-aliased edges, in frame heights
|
|
20
|
+
const float EDGE = 0.0012;
|
|
21
|
+
|
|
22
|
+
float gridSize() {
|
|
23
|
+
return float(size < 2 ? 2 : (size > 8 ? 8 : size));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// the turns run in 3 groups, one after the other: the even columns, the even rows (counted from the top),
|
|
27
|
+
// then the odd columns; the turns of a group overlap
|
|
28
|
+
float groupLength(float m) {
|
|
29
|
+
return m > 0.0 ? 1.0 + (m - 1.0) * STAGGER : 0.0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// the time in turn units, and the length of the groups of even and odd slices
|
|
33
|
+
vec3 timeline(float n) {
|
|
34
|
+
float lenEven = groupLength(floor((n + 1.0) * 0.5));
|
|
35
|
+
float lenOdd = groupLength(floor(n * 0.5));
|
|
36
|
+
float u = clamp((progress - 0.05) / 0.85, 0.0, 1.0) * (2.0 * lenEven + lenOdd);
|
|
37
|
+
return vec3(u, lenEven, lenOdd);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// the turn of a column (isCol) or of a row, 0 at rest to 1 turned
|
|
41
|
+
float turnTime(vec3 tl, bool isCol, float idx, float n) {
|
|
42
|
+
// rows are counted from the top
|
|
43
|
+
float k = isCol ? idx : n - 1.0 - idx;
|
|
44
|
+
bool odd = mod(k, 2.0) > 0.5;
|
|
45
|
+
// the odd rows never turn: the columns already brought the incoming image there
|
|
46
|
+
if (odd && !isCol) return 0.0;
|
|
47
|
+
float start = (odd ? 2.0 * tl.y : (isCol ? 0.0 : tl.y)) + floor(k * 0.5) * STAGGER;
|
|
48
|
+
return clamp(tl.x - start, 0.0, 1.0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// the turn's direction: +1 brings the side of the cube at higher coordinates to the front
|
|
52
|
+
float turnDir(bool isCol, float idx) {
|
|
53
|
+
return mod(idx + (isCol ? 0.0 : 1.0), 2.0) < 0.5 ? 1.0 : -1.0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// eased angle, landing with a little speed left like a click
|
|
57
|
+
float turnAngle(float t) {
|
|
58
|
+
return 0.5 * PI * mix(t, t * t * (3.0 - 2.0 * t), 0.8);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 1 on the cubies' faces, 0 in the gaps, at the point fp of the face (frame heights)
|
|
62
|
+
float faceMask(vec2 fp, float n, float g) {
|
|
63
|
+
if (g <= 0.0) return 1.0;
|
|
64
|
+
vec2 cell = vec2(ratio, 1.0) / n;
|
|
65
|
+
vec2 c = fp / cell;
|
|
66
|
+
vec2 r = floor(c + 0.5);
|
|
67
|
+
// distance to the nearest cubie edge inside the face (the face's own border has no gap)
|
|
68
|
+
vec2 d = abs(c - r) * cell;
|
|
69
|
+
d.x = (r.x < 0.5 || r.x > n - 0.5) ? 1.0 : d.x;
|
|
70
|
+
d.y = (r.y < 0.5 || r.y > n - 0.5) ? 1.0 : d.y;
|
|
71
|
+
float e = min(EDGE, 0.5 * g);
|
|
72
|
+
return smoothstep(0.5 * g - e, 0.5 * g + e, min(d.x, d.y));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// does the cubie of the face at fp show the incoming image, from the turns done so far
|
|
76
|
+
bool isDone(vec3 tl, vec2 fp, float n) {
|
|
77
|
+
vec2 cell = clamp(floor(fp / (vec2(ratio, 1.0) / n)), 0.0, n - 1.0);
|
|
78
|
+
return turnTime(tl, true, cell.x, n) >= 1.0 || turnTime(tl, false, cell.y, n) >= 1.0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
vec4 sticker(vec2 fp, bool incoming, float light, float n, float g) {
|
|
82
|
+
vec2 uv = clamp(fp / vec2(ratio, 1.0), 0.0, 1.0);
|
|
83
|
+
vec4 img = incoming ? getToColor(uv) : getFromColor(uv);
|
|
84
|
+
vec4 body = vec4(background.rgb * light, background.a);
|
|
85
|
+
return mix(body, vec4(img.rgb * light, img.a), faceMask(fp, n, g));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// brightness of a face of normal nrm (across the slices, along the turn, depth) in the turn's space, 1 facing the viewer
|
|
89
|
+
float lighting(vec3 nrm, bool isCol) {
|
|
90
|
+
vec3 l = normalize(vec3(-0.35, 0.55, 1.0));
|
|
91
|
+
if (isCol) l = l.yxz;
|
|
92
|
+
return 1.0 - shading * (1.0 - clamp(dot(nrm, l) / l.z, 0.0, 1.0));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
vec2 rot(vec2 v, float a) {
|
|
96
|
+
float c = cos(a), s = sin(a);
|
|
97
|
+
return vec2(c * v.x - s * v.y, s * v.x + c * v.y);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// casts the ray (o, d), in the turn's space (across the slices, along the turn, depth), onto the slice
|
|
101
|
+
// [a0, a0 + w] turned by the angle a around the middle of the cube (a square section of side S):
|
|
102
|
+
// returns the ray's parameter at the hit (or -1), the face hit (0 front, 1 back, 2 and 3 the sides
|
|
103
|
+
// at higher and lower coordinates along the turn at rest, 4 the slice's ends), and the point hit
|
|
104
|
+
// (across the slices, and across the face, -1 to 1)
|
|
105
|
+
vec4 sliceHit(vec3 o, vec3 d, float a0, float w, float S, float a) {
|
|
106
|
+
vec2 lo = rot(o.yz - vec2(0.5 * S, -0.5 * S), -a);
|
|
107
|
+
vec2 ld = rot(d.yz, -a);
|
|
108
|
+
ld = vec2(abs(ld.x) < 1e-6 ? 1e-6 : ld.x, abs(ld.y) < 1e-6 ? 1e-6 : ld.y);
|
|
109
|
+
float dx = abs(d.x) < 1e-6 ? 1e-6 : d.x;
|
|
110
|
+
vec3 t1 = vec3((a0 - o.x) / dx, (-0.5 * S - lo) / ld);
|
|
111
|
+
vec3 t2 = vec3((a0 + w - o.x) / dx, (0.5 * S - lo) / ld);
|
|
112
|
+
vec3 tn = min(t1, t2);
|
|
113
|
+
vec3 tf = max(t1, t2);
|
|
114
|
+
float tNear = max(tn.x, max(tn.y, tn.z));
|
|
115
|
+
float tFar = min(tf.x, min(tf.y, tf.z));
|
|
116
|
+
if (tNear > tFar || tNear <= 0.0) return vec4(-1.0);
|
|
117
|
+
vec2 q = (lo + tNear * ld) / (0.5 * S);
|
|
118
|
+
float across = o.x + tNear * d.x;
|
|
119
|
+
if (tn.x >= tn.y && tn.x >= tn.z) return vec4(tNear, 4.0, across, sign(-dx));
|
|
120
|
+
if (tn.y > tn.z) return vec4(tNear, ld.x < 0.0 ? 2.0 : 3.0, across, q.y);
|
|
121
|
+
return vec4(tNear, ld.y < 0.0 ? 0.0 : 1.0, across, q.x);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// the color of a turning slice at its hit
|
|
125
|
+
vec4 sliceColor(vec4 hit, vec3 tl, bool isCol, float a, float dir, float S, float n, float g) {
|
|
126
|
+
float f = hit.y;
|
|
127
|
+
if (f > 3.5) return vec4(background.rgb * lighting(vec3(hit.w, 0.0, 0.0), isCol), background.a);
|
|
128
|
+
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);
|
|
129
|
+
float light = lighting(vec3(0.0, rot(nl, a)), isCol);
|
|
130
|
+
// the front shows what the cubies showed before this turn, the side that comes to the front
|
|
131
|
+
// shows the incoming image where it lands
|
|
132
|
+
bool front = f < 0.5;
|
|
133
|
+
bool coming = nl.x * dir > 0.5;
|
|
134
|
+
if (!front && !coming) return vec4(background.rgb * light, background.a);
|
|
135
|
+
// on the side coming to the front, the point across lands at -dir times its depth
|
|
136
|
+
float r = 0.5 * S * (1.0 + (front ? hit.w : -dir * hit.w));
|
|
137
|
+
vec2 fp = isCol ? vec2(hit.z, r) : vec2(r, hit.z);
|
|
138
|
+
return sticker(fp, coming || isDone(tl, fp, n), light, n, g);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
vec4 transition(vec2 uv) {
|
|
142
|
+
float n = gridSize();
|
|
143
|
+
vec3 tl = timeline(n);
|
|
144
|
+
// the gaps open at the start and close at the end, after the last turn
|
|
145
|
+
float g = gap * smoothstep(0.0, 0.1, progress) * (1.0 - smoothstep(0.9, 1.0, progress));
|
|
146
|
+
vec2 P = vec2(uv.x * ratio, uv.y);
|
|
147
|
+
|
|
148
|
+
// the turns going on are of columns or of rows, never both
|
|
149
|
+
bool isCol = tl.x < tl.y || tl.x >= 2.0 * tl.y;
|
|
150
|
+
// the turn's space: (across the slices, along the turn, depth toward the viewer);
|
|
151
|
+
// a column turns around the horizontal axis through the middle of the cube, a row around the vertical one
|
|
152
|
+
float w = (isCol ? ratio : 1.0) / n;
|
|
153
|
+
float S = isCol ? 1.0 : ratio;
|
|
154
|
+
vec2 pp = isCol ? P : P.yx;
|
|
155
|
+
vec3 o = vec3(isCol ? vec2(0.5 * ratio, 0.5) : vec2(0.5, 0.5 * ratio), 1.2 + 0.6 * max(ratio, 1.0));
|
|
156
|
+
// the ray reaches the face (z = 0) at t = 1
|
|
157
|
+
vec3 d = vec3(pp, 0.0) - o;
|
|
158
|
+
|
|
159
|
+
float k0 = clamp(floor(pp.x / w), 0.0, n - 1.0);
|
|
160
|
+
float t0 = turnTime(tl, isCol, k0, n);
|
|
161
|
+
|
|
162
|
+
float nearest = 1.0;
|
|
163
|
+
vec4 color;
|
|
164
|
+
if (t0 <= 0.0 || t0 >= 1.0) {
|
|
165
|
+
// the face at rest: the exact image
|
|
166
|
+
color = isDone(tl, P, n) ? getToColor(uv) : getFromColor(uv);
|
|
167
|
+
color = mix(background, color, faceMask(P, n, g));
|
|
168
|
+
// the shade of the turning slices next to this one, deepest mid-turn
|
|
169
|
+
for (int j = -1; j <= 1; j += 2) {
|
|
170
|
+
float k = k0 + float(j);
|
|
171
|
+
if (k < 0.0 || k > n - 1.0) continue;
|
|
172
|
+
float tk = turnTime(tl, isCol, k, n);
|
|
173
|
+
if (tk <= 0.0 || tk >= 1.0) continue;
|
|
174
|
+
float dist = abs(pp.x - (k + 0.5) * w) - 0.5 * w;
|
|
175
|
+
color.rgb *= 1.0 - 0.5 * shading * sin(2.0 * turnAngle(tk)) * exp(-dist / (0.2 * w));
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
// inside the hollow left by the turning slice: the sides of the slices next to it and the cube's inside, in the dark
|
|
179
|
+
float tw = abs(d.x) < 1e-6 ? 1e6 : (d.x < 0.0 ? k0 * w - o.x : (k0 + 1.0) * w - o.x) / d.x;
|
|
180
|
+
float tb = (o.z + S) / -d.z;
|
|
181
|
+
nearest = min(tw, tb);
|
|
182
|
+
float along = o.y + nearest * d.y;
|
|
183
|
+
float depth = (o.z + nearest * d.z) / -S;
|
|
184
|
+
float light = tw < tb ? lighting(vec3(-sign(d.x), 0.0, 0.0), isCol) : 1.0;
|
|
185
|
+
light *= 1.0 - shading * (0.5 + 0.4 * clamp(depth, 0.0, 1.0));
|
|
186
|
+
// beyond the cube's edges: the background
|
|
187
|
+
color = along < 0.0 || along > S ? background : vec4(background.rgb * light, background.a);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// the turning slices, which come out in front of the face as they turn
|
|
191
|
+
for (int j = -1; j <= 1; j++) {
|
|
192
|
+
float k = k0 + float(j);
|
|
193
|
+
if (k < 0.0 || k > n - 1.0) continue;
|
|
194
|
+
float tk = turnTime(tl, isCol, k, n);
|
|
195
|
+
if (tk <= 0.0 || tk >= 1.0) continue;
|
|
196
|
+
float dir = turnDir(isCol, k);
|
|
197
|
+
float a = dir * turnAngle(tk);
|
|
198
|
+
vec4 hit = sliceHit(o, d, k * w, w, S, a);
|
|
199
|
+
if (hit.x > 0.0 && hit.x < nearest) {
|
|
200
|
+
nearest = hit.x;
|
|
201
|
+
color = sliceColor(hit, tl, isCol, a, dir, S, n, g);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return color;
|
|
205
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// RibbonTwist — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/RibbonTwist.glsl
|
|
2
|
+
// Author: gre
|
|
3
|
+
// License: MIT
|
|
4
|
+
// 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
|
|
5
|
+
// Tags: 3d, flip, rotate
|
|
6
|
+
|
|
7
|
+
// @range(0.1, 2) Length of the twisted section, as a part of the frame's width
|
|
8
|
+
uniform float spread; // = 0.8
|
|
9
|
+
// @range(0, 0.8) Amount of perspective: the edge turning toward the viewer grows
|
|
10
|
+
uniform float perspective; // = 0.4
|
|
11
|
+
// @range(0, 1) How much the ribbon darkens as it turns away
|
|
12
|
+
uniform float shading; // = 0.6
|
|
13
|
+
// @param Twist around the vertical center line instead, travelling from top to bottom
|
|
14
|
+
uniform bool vertical; // = false
|
|
15
|
+
// @color Color seen where the twisting ribbon leaves the frame uncovered
|
|
16
|
+
uniform vec4 backColor; // = vec4(0.0, 0.0, 0.0, 1.0)
|
|
17
|
+
|
|
18
|
+
const float PI = 3.141592653589793;
|
|
19
|
+
// width of the anti-aliased edges, in frame heights
|
|
20
|
+
const float EDGE = 0.002;
|
|
21
|
+
|
|
22
|
+
vec4 transition (vec2 uv) {
|
|
23
|
+
// q.x: along the ribbon, the way the twist travels; q.y: across the ribbon
|
|
24
|
+
vec2 q = vertical ? vec2(1.0 - uv.y, uv.x) : uv;
|
|
25
|
+
// the ribbon's half width across, in frame heights
|
|
26
|
+
float halfSize = vertical ? 0.5 * ratio : 0.5;
|
|
27
|
+
// each line across the ribbon turns half a turn, a little later than the one before
|
|
28
|
+
float t = smoothstep(0.0, 1.0, (progress * (1.0 + spread) - q.x) / spread);
|
|
29
|
+
// the visible face (outgoing front, incoming back) and its angle from its rest position
|
|
30
|
+
bool front = t < 0.5;
|
|
31
|
+
float angle = PI * (front ? t : t - 1.0);
|
|
32
|
+
float c = cos(angle);
|
|
33
|
+
float s = sin(angle);
|
|
34
|
+
// w: screen position across the ribbon, -1 to 1 at rest; v: the matching position on the face
|
|
35
|
+
// a point v of the face goes to v * c across and v * s in depth, nearer points look bigger
|
|
36
|
+
float w = 2.0 * q.y - 1.0;
|
|
37
|
+
float den = c + perspective * w * s;
|
|
38
|
+
if (den <= 0.0) return backColor;
|
|
39
|
+
float v = w / den;
|
|
40
|
+
if (abs(v) >= 1.0) return backColor;
|
|
41
|
+
// soft edges while twisting (sharp at rest, to keep the first and last frames exact)
|
|
42
|
+
float edge = max(EDGE * min(1.0, 20.0 * abs(s)), 1e-4);
|
|
43
|
+
float top = c / (1.0 - perspective * s);
|
|
44
|
+
float bottom = -c / (1.0 + perspective * s);
|
|
45
|
+
float cover = clamp(min(top - w, w - bottom) * halfSize / edge, 0.0, 1.0);
|
|
46
|
+
vec2 p = vec2(q.x, 0.5 + 0.5 * v);
|
|
47
|
+
p = vertical ? vec2(p.y, 1.0 - p.x) : p;
|
|
48
|
+
vec4 img = front ? getFromColor(p) : getToColor(p);
|
|
49
|
+
// lit from the front and slightly from one side of the axis
|
|
50
|
+
float lambert = clamp(c - 0.25 * s, 0.0, 1.0);
|
|
51
|
+
vec4 color = vec4(img.rgb * mix(1.0 - shading, 1.0, lambert), img.a);
|
|
52
|
+
return mix(backColor, color, cover);
|
|
53
|
+
}
|