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
package/glsl3/Cube.glsl
CHANGED
|
@@ -1,71 +1,124 @@
|
|
|
1
1
|
// Cube — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/Cube.glsl
|
|
2
2
|
// Author: gre
|
|
3
3
|
// License: MIT
|
|
4
|
-
// Description: The two images are faces of a
|
|
4
|
+
// Description: The two images are faces of a box that turns a quarter turn in perspective, the outgoing face darkening as it turns away, above a reflective floor
|
|
5
5
|
// Tags: 3d, cube, rotate, reflection
|
|
6
6
|
// @range(0, 1) Amount of perspective
|
|
7
7
|
uniform float persp; // = 0.7
|
|
8
|
+
// @range(0, 1) How far the camera pulls back mid-turn, as a part of the frame
|
|
8
9
|
uniform float unzoom; // = 0.3
|
|
9
10
|
// @range(0, 1) Strength of the reflection
|
|
10
11
|
uniform float reflection; // = 0.4
|
|
12
|
+
// @range(0, 20) Gap between the box and its reflection, as a percentage of the frame height
|
|
11
13
|
uniform float floating; // = 3.0
|
|
14
|
+
// @range(0, 1) How much the faces darken as they turn away, and the shadow on the floor
|
|
15
|
+
uniform float shading; // = 0.5
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
bool inBounds (vec2 p) {
|
|
18
|
-
return all(lessThan(vec2(0.0), p)) && all(lessThan(p, vec2(1.0)));
|
|
19
|
-
}
|
|
17
|
+
const float PI = 3.141592653589793;
|
|
18
|
+
// width of the anti-aliased edges, as a part of the frame's height at the box's front
|
|
19
|
+
const float EDGE = 0.002;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
// the ray (eye, dir) in the box's frame, the box turned by (c, s) around its vertical axis:
|
|
22
|
+
// returns (distance along the ray, horizontal position on the face, height, face) with face 0 for
|
|
23
|
+
// the outgoing image's face, 1 for the incoming one's, and a negative distance where it misses
|
|
24
|
+
vec4 hitBox(vec3 eye, vec3 dir, float w, float c, float s) {
|
|
25
|
+
vec2 pivot = vec2(0.5 * w);
|
|
26
|
+
vec2 e = eye.xz - pivot;
|
|
27
|
+
vec2 o = vec2(e.x * c + e.y * s, -e.x * s + e.y * c) + pivot;
|
|
28
|
+
vec2 d = vec2(dir.x * c + dir.z * s, -dir.x * s + dir.z * c);
|
|
29
|
+
// the side faces seen from outside: the box spans [0, w] on x and z
|
|
30
|
+
vec2 inv = 1.0 / vec2(d.x < 0.0 ? min(d.x, -1e-6) : max(d.x, 1e-6), d.y < 0.0 ? min(d.y, -1e-6) : max(d.y, 1e-6));
|
|
31
|
+
vec2 t0 = (vec2(0.0) - o) * inv;
|
|
32
|
+
vec2 t1 = (vec2(w) - o) * inv;
|
|
33
|
+
vec2 tn = min(t0, t1);
|
|
34
|
+
vec2 tf = max(t0, t1);
|
|
35
|
+
float tin = max(tn.x, tn.y);
|
|
36
|
+
if (tin <= 0.0 || tin > min(tf.x, tf.y)) return vec4(-1.0);
|
|
37
|
+
vec2 hit = o + tin * d;
|
|
38
|
+
float y = eye.y + tin * dir.y;
|
|
39
|
+
if (y < 0.0 || y > 1.0) return vec4(-1.0);
|
|
40
|
+
// the face first entered: z = 0 is the outgoing face, x = 0 the incoming one, the others are hidden
|
|
41
|
+
if (tn.y >= tn.x) {
|
|
42
|
+
if (d.y <= 0.0) return vec4(-1.0);
|
|
43
|
+
return vec4(tin, hit.x / w, y, 0.0);
|
|
27
44
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
c += mix(vec4(0.0), getToColor(pto), reflection * mix(1.0, 0.0, pto.y));
|
|
31
|
-
}
|
|
32
|
-
return c;
|
|
45
|
+
if (d.x <= 0.0) return vec4(-1.0);
|
|
46
|
+
return vec4(tin, 1.0 - hit.y / w, y, 1.0);
|
|
33
47
|
}
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
float
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* vec2(0.5 / distance(center, 0.5) * (center<0.5 ? 1.0 : -1.0), 1.0)
|
|
46
|
-
+ vec2(center<0.5 ? 0.0 : 1.0, 0.0)
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
+
vec4 transition(vec2 uv) {
|
|
50
|
+
float w = ratio;
|
|
51
|
+
// the turn starts and ends softly
|
|
52
|
+
float turn = progress * progress * (3.0 - 2.0 * progress);
|
|
53
|
+
float a = 0.5 * PI * turn;
|
|
54
|
+
float c = cos(a), s = sin(a);
|
|
55
|
+
if (progress >= 1.0) { c = 0.0; s = 1.0; }
|
|
56
|
+
// 0 at both ends, for exact images and hard edges there
|
|
57
|
+
float motion = sin(PI * clamp(progress, 0.0, 1.0));
|
|
58
|
+
float zoom = 1.0 + max(unzoom, 0.0) * motion;
|
|
49
59
|
|
|
50
|
-
|
|
51
|
-
float
|
|
52
|
-
|
|
53
|
-
vec2
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
60
|
+
// the front of the box is the screen: the camera keeps it framed, pulling back mid-turn
|
|
61
|
+
float dist = 0.8 * max(w, 1.0) / clamp(persp, 0.01, 1.0);
|
|
62
|
+
vec3 eye = vec3(0.5 * w, 0.5, -dist);
|
|
63
|
+
vec2 sp = (uv - 0.5) * zoom + 0.5;
|
|
64
|
+
vec3 dir = vec3(sp.x * w, sp.y, 0.0) - eye;
|
|
65
|
+
|
|
66
|
+
// pixel footprint on the screen plane, for the anti-aliased edges
|
|
67
|
+
float px = EDGE * zoom * min(10.0 * motion, 1.0);
|
|
68
|
+
float shade0 = 1.0 - shading * (1.0 - c);
|
|
69
|
+
float shade1 = 1.0 - shading * (1.0 - s);
|
|
70
|
+
|
|
71
|
+
// the box in front, premultiplied
|
|
72
|
+
vec4 front = vec4(0.0);
|
|
73
|
+
vec4 b = hitBox(eye, dir, w, c, s);
|
|
74
|
+
if (b.x > 0.0) {
|
|
75
|
+
vec4 img = b.w < 0.5 ? getFromColor(vec2(b.y, b.z)) : getToColor(vec2(b.y, b.z));
|
|
76
|
+
float m = 1.0;
|
|
77
|
+
if (px > 0.0) {
|
|
78
|
+
// the silhouette: top, bottom and the outer vertical edge of the face, seen foreshortened
|
|
79
|
+
float e = px * b.x;
|
|
80
|
+
vec3 n = b.w < 0.5 ? vec3(s, 0.0, -c) : vec3(-c, 0.0, -s);
|
|
81
|
+
float fore = max(abs(dot(n, normalize(dir))), 0.05);
|
|
82
|
+
float edge = b.w < 0.5 ? 1.0 - b.y : b.y;
|
|
83
|
+
m = clamp(min(b.z, 1.0 - b.z) / e, 0.0, 1.0)
|
|
84
|
+
* clamp(edge * w * fore / e, 0.0, 1.0);
|
|
85
|
+
}
|
|
86
|
+
// where the box covers the pixel, nothing behind it shows: the exact image at both ends
|
|
87
|
+
if (m >= 1.0 && img.a >= 1.0) {
|
|
88
|
+
return vec4(img.rgb * (b.w < 0.5 ? shade0 : shade1), img.a);
|
|
89
|
+
}
|
|
90
|
+
front = vec4(img.rgb * (b.w < 0.5 ? shade0 : shade1) * img.a, img.a) * m;
|
|
66
91
|
}
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
|
|
93
|
+
// the floor, h below the box, premultiplied; it fades in and out with the motion
|
|
94
|
+
vec4 ground = vec4(0.0);
|
|
95
|
+
float h = 0.005 * max(floating, 0.0);
|
|
96
|
+
if (dir.y < 0.0 && motion > 0.0) {
|
|
97
|
+
float tf = -(eye.y + h) / dir.y;
|
|
98
|
+
vec3 f = eye + tf * dir;
|
|
99
|
+
// the reflection: the same ray mirrored by the floor, fading with the height on the box
|
|
100
|
+
vec3 meye = vec3(eye.x, -2.0 * h - eye.y, eye.z);
|
|
101
|
+
vec3 mdir = vec3(dir.x, -dir.y, dir.z);
|
|
102
|
+
vec4 r = hitBox(meye, mdir, w, c, s);
|
|
103
|
+
if (r.x > 0.0) {
|
|
104
|
+
vec4 img = r.w < 0.5 ? getFromColor(vec2(r.y, r.z)) : getToColor(vec2(r.y, r.z));
|
|
105
|
+
float k = clamp(reflection, 0.0, 1.0) * (1.0 - r.z) * (1.0 - r.z);
|
|
106
|
+
ground = vec4(img.rgb * (r.w < 0.5 ? shade0 : shade1) * img.a, img.a) * k;
|
|
107
|
+
}
|
|
108
|
+
// the contact shadow around the box, softer as it floats higher
|
|
109
|
+
vec2 q = f.xz - vec2(0.5 * w);
|
|
110
|
+
vec2 l = vec2(q.x * c + q.y * s, -q.x * s + q.y * c);
|
|
111
|
+
float soft = 0.03 + 1.5 * h;
|
|
112
|
+
float sh = shading * 0.7 * exp(-length(max(abs(l) - vec2(0.5 * w), 0.0)) / soft);
|
|
113
|
+
// only as opaque as the bottom of the nearest face
|
|
114
|
+
vec2 bl = l + vec2(0.5 * w);
|
|
115
|
+
sh *= l.y < l.x
|
|
116
|
+
? getFromColor(vec2(clamp(bl.x / w, 0.0, 1.0), 0.0)).a
|
|
117
|
+
: getToColor(vec2(clamp(1.0 - bl.y / w, 0.0, 1.0), 0.0)).a;
|
|
118
|
+
ground = ground * (1.0 - sh) + vec4(0.0, 0.0, 0.0, sh);
|
|
119
|
+
ground *= min(6.0 * motion, 1.0);
|
|
69
120
|
}
|
|
70
|
-
|
|
121
|
+
|
|
122
|
+
vec4 color = front + ground * (1.0 - front.a);
|
|
123
|
+
return color.a > 0.0 ? vec4(color.rgb / color.a, color.a) : vec4(0.0);
|
|
71
124
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// DominoFall — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/DominoFall.glsl
|
|
2
|
+
// Author: gre
|
|
3
|
+
// License: MIT
|
|
4
|
+
// Description: The outgoing image is cut into standing slats that topple backward like dominoes in a chain reaction across the frame, each one leaning onto the next and knocking it over, until they all lie flat and reveal the incoming image
|
|
5
|
+
// Tags: 3d, stripes, rotate
|
|
6
|
+
|
|
7
|
+
// @range(2, 40, 1) Number of slats
|
|
8
|
+
uniform int count; // = 12
|
|
9
|
+
// @param The chain runs from right to left instead of left to right
|
|
10
|
+
uniform bool reverse; // = false
|
|
11
|
+
// @range(0.05, 1) Part of a slat's fall after which it knocks the next one: lower runs the chain faster, with more slats falling at once
|
|
12
|
+
uniform float knock; // = 0.2
|
|
13
|
+
// @range(0, 1) How far each slat's top leans sideways onto the next one, as a part of a slat's width
|
|
14
|
+
uniform float lean; // = 0.8
|
|
15
|
+
// @range(0, 1) Strength of the perspective
|
|
16
|
+
uniform float perspective; // = 0.8
|
|
17
|
+
// @range(0, 1) How much the slats darken as they fall, and the shadows they cast
|
|
18
|
+
uniform float shading; // = 0.6
|
|
19
|
+
|
|
20
|
+
const float PI = 3.141592653589793;
|
|
21
|
+
// width of the anti-aliased edges, as a part of the frame's height
|
|
22
|
+
const float EDGE = 0.0015;
|
|
23
|
+
|
|
24
|
+
float knockPart() {
|
|
25
|
+
return clamp(knock, 0.05, 1.0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// the fall of slat j, 0 standing to 1 lying flat
|
|
29
|
+
float fallTime(float j, float n) {
|
|
30
|
+
if (progress >= 1.0) return 1.0;
|
|
31
|
+
float k = knockPart();
|
|
32
|
+
// each slat falls during d and knocks the next one after k * d
|
|
33
|
+
float d = 1.0 / (1.0 + (n - 1.0) * k);
|
|
34
|
+
return clamp((progress - j * k * d) / d, 0.0, 1.0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// the slat's angle: it starts with the push of the previous one, then gravity takes over
|
|
38
|
+
float fallAngle(float t) {
|
|
39
|
+
return 0.5 * PI * t * (0.2 + 0.8 * t);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// where slat j is seen at the point (xc, y) of the frame: (x across the slat, height on it, its fall, its angle),
|
|
43
|
+
// with a negative fall where it is not seen (its height can exceed 1, above its top)
|
|
44
|
+
vec4 slatPoint(float j, float n, float w, float xc, float y) {
|
|
45
|
+
vec4 none = vec4(0.0, 0.0, -1.0, 0.0);
|
|
46
|
+
if (j < 0.0 || j > n - 1.0) return none;
|
|
47
|
+
float t = fallTime(j, n);
|
|
48
|
+
if (t >= 1.0) return none;
|
|
49
|
+
float a = fallAngle(t);
|
|
50
|
+
float c = cos(a), s = sin(a);
|
|
51
|
+
// a camera in front of the slat goes down to the level of the hinge as the slat falls,
|
|
52
|
+
// so that the slat ends edge-on
|
|
53
|
+
vec3 eye = vec3((j + 0.5) * w, 0.5 * c, -1.0 / max(perspective, 0.01));
|
|
54
|
+
vec3 dir = vec3(xc, y, 0.0) - eye;
|
|
55
|
+
// cast a ray onto the slat turned back by a around its bottom edge
|
|
56
|
+
float den = dir.z * c - dir.y * s;
|
|
57
|
+
if (den <= 0.0) return none;
|
|
58
|
+
float r = (eye.y * s - eye.z * c) / den;
|
|
59
|
+
vec3 hit = eye + r * dir;
|
|
60
|
+
float h = hit.y * c + hit.z * s;
|
|
61
|
+
if (r <= 0.0 || h < 0.0) return none;
|
|
62
|
+
// the top leans sideways toward the next slat until it touches it
|
|
63
|
+
float side = clamp(lean, 0.0, 1.0) * w * min(t / knockPart(), 1.0) * h;
|
|
64
|
+
return vec4(hit.x - side - j * w, h, t, a);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// draws slat j, seen at pt, over color; front is where the next slat, which may stand in front of it, is seen
|
|
68
|
+
vec4 drawSlat(vec4 color, float j, vec4 pt, vec4 front, float w) {
|
|
69
|
+
float t = pt.z;
|
|
70
|
+
if (t < 0.0) return color;
|
|
71
|
+
float s = sin(pt.w);
|
|
72
|
+
float d = min(pt.x, w - pt.x);
|
|
73
|
+
float m;
|
|
74
|
+
if (t <= 0.0) {
|
|
75
|
+
// standing still: the slats tile the frame exactly
|
|
76
|
+
m = d >= 0.0 && pt.y <= 1.0 ? 1.0 : 0.0;
|
|
77
|
+
} else {
|
|
78
|
+
// anti-aliased edges, widened as the slat is seen narrower and shorter
|
|
79
|
+
float e = EDGE * min(10.0 * t, 1.0) * (1.0 + max(perspective, 0.0) * pt.y * s);
|
|
80
|
+
m = clamp(d / e + 0.5, 0.0, 1.0) * clamp((1.0 - pt.y) * max(cos(pt.w), 0.05) / e + 0.5, 0.0, 1.0);
|
|
81
|
+
}
|
|
82
|
+
if (m <= 0.0) return color;
|
|
83
|
+
float sx = (j * w + clamp(pt.x, 0.0, w)) / ratio;
|
|
84
|
+
vec4 img = getFromColor(vec2(reverse ? 1.0 - sx : sx, min(pt.y, 1.0)));
|
|
85
|
+
// darker as it falls away, more toward its top
|
|
86
|
+
float shade = 1.0 - shading * s * (0.4 + 0.6 * pt.y);
|
|
87
|
+
// the next slat, less fallen and so in front, shades the one leaning onto it along its edge, up to its top
|
|
88
|
+
if (front.z >= 0.0 && front.z < t && front.x < 0.0) {
|
|
89
|
+
float reach = clamp(1.0 - (front.y - 1.0) / 0.05, 0.0, 1.0);
|
|
90
|
+
shade *= 1.0 - 0.6 * shading * exp(front.x / (0.15 * w)) * reach;
|
|
91
|
+
}
|
|
92
|
+
img.rgb *= shade;
|
|
93
|
+
return mix(color, img, m);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
vec4 transition (vec2 uv) {
|
|
97
|
+
float n = float(count < 1 ? 1 : count);
|
|
98
|
+
float w = ratio / n;
|
|
99
|
+
// x along the chain, in frame heights
|
|
100
|
+
float xc = (reverse ? 1.0 - uv.x : uv.x) * ratio;
|
|
101
|
+
float col = clamp(floor(xc / w), 0.0, n - 1.0);
|
|
102
|
+
|
|
103
|
+
vec4 color = getToColor(uv);
|
|
104
|
+
// the contact shadow of the falling slat on the floor
|
|
105
|
+
float t0 = fallTime(col, n);
|
|
106
|
+
color.rgb *= 1.0 - 2.4 * shading * t0 * (1.0 - t0) * exp(-40.0 * uv.y);
|
|
107
|
+
|
|
108
|
+
// the slats are seen narrower as they fall, and their tops lean over the next column at most:
|
|
109
|
+
// the slat before this column, behind, then the one of this column
|
|
110
|
+
vec4 cur = slatPoint(col, n, w, xc, uv.y);
|
|
111
|
+
color = drawSlat(color, col - 1.0, slatPoint(col - 1.0, n, w, xc, uv.y), cur, w);
|
|
112
|
+
color = drawSlat(color, col, cur, slatPoint(col + 1.0, n, w, xc, uv.y), w);
|
|
113
|
+
return color;
|
|
114
|
+
}
|
package/glsl3/Doorway.glsl
CHANGED
|
@@ -1,55 +1,91 @@
|
|
|
1
1
|
// Doorway — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/Doorway.glsl
|
|
2
2
|
// Author: gre
|
|
3
3
|
// License: MIT
|
|
4
|
-
// Description: The outgoing image opens like double doors as the incoming one comes forward, with a floor reflection
|
|
4
|
+
// Description: The outgoing image opens like double doors swinging toward the viewer, as the incoming one comes forward from the dark room behind, with a floor reflection
|
|
5
5
|
// Tags: doors, 3d, reflection
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
// @range(0, 1) Strength of the floor reflection under the incoming image
|
|
7
8
|
uniform float reflection; // = 0.4
|
|
8
|
-
// @
|
|
9
|
+
// @range(0, 1) Amount of perspective on the swinging doors
|
|
9
10
|
uniform float perspective; // = 0.4
|
|
11
|
+
// @range(1, 10) How far back the incoming image starts (1: no distance)
|
|
10
12
|
uniform float depth; // = 3
|
|
11
13
|
|
|
12
|
-
const
|
|
13
|
-
const vec2 boundMin = vec2(0.0, 0.0);
|
|
14
|
-
const vec2 boundMax = vec2(1.0, 1.0);
|
|
14
|
+
const float PI = 3.141592653589793;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// cast the view ray of screen point x (aspect units, the frame is 0..w) onto a leaf of
|
|
17
|
+
// width w/2 hinged on the left edge and turned toward the viewer by angle a.
|
|
18
|
+
// The eye is at (w/2, 0.5, -eye) and the frame at z = 0; returns (t, distance along the leaf)
|
|
19
|
+
// where t scales the ray so that t = 1 is the frame plane
|
|
20
|
+
vec2 leafHit (float x, float w, float eye, float a) {
|
|
21
|
+
float c = cos(a), s = sin(a);
|
|
22
|
+
float t = (eye * c - 0.5 * w * s) / (s * (x - 0.5 * w) + eye * c);
|
|
23
|
+
vec2 hit = vec2(0.5 * w + t * (x - 0.5 * w), eye * (t - 1.0));
|
|
24
|
+
return vec2(t, hit.x * c - hit.y * s);
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
// screen x of a point (x, z) seen from the eye
|
|
28
|
+
float project (vec2 p, float w, float eye) {
|
|
29
|
+
return 0.5 * w + (p.x - 0.5 * w) * eye / (eye + p.y);
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
pto = project(pto);
|
|
27
|
-
if (inBounds(pto)) {
|
|
28
|
-
c += mix(black, getToColor(pto), reflection * mix(1.0, 0.0, pto.y));
|
|
29
|
-
}
|
|
30
|
-
return c;
|
|
32
|
+
float easeInOut (float t) {
|
|
33
|
+
return t < 0.5 ? 4.0 * t * t * t : 1.0 - 4.0 * (1.0 - t) * (1.0 - t) * (1.0 - t);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
vec4
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
pto = (p + vec2(-0.5, -0.5)) * vec2(size, size) + vec2(0.5, 0.5);
|
|
46
|
-
if (inBounds(pfr)) {
|
|
47
|
-
return getFromColor(pfr);
|
|
48
|
-
}
|
|
49
|
-
else if (inBounds(pto)) {
|
|
50
|
-
return getToColor(pto);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return bgColor(p, pto);
|
|
36
|
+
// the room behind: the incoming image coming forward, and its reflection on the floor
|
|
37
|
+
vec4 room (vec2 uv, float x, float edgeL, float edgeR, float close, float dolly) {
|
|
38
|
+
float size = mix(max(depth, 1.0), 1.0, dolly);
|
|
39
|
+
vec2 p = (uv - 0.5) * size + 0.5;
|
|
40
|
+
// soft border while it is far, exactly sharp once it fills the frame
|
|
41
|
+
float soft = 0.004 * (size - 1.0) + 1e-6;
|
|
42
|
+
vec2 m = smoothstep(-soft, soft, p) * smoothstep(-soft, soft, 1.0 - p);
|
|
43
|
+
vec4 c = getToColor(clamp(p, 0.0, 1.0)) * (m.x * m.y);
|
|
44
|
+
if (p.y < 0.0) {
|
|
45
|
+
vec2 r = vec2(p.x, -1.2 * p.y - 0.02);
|
|
46
|
+
float f = reflection * (1.0 - r.y) * m.x * smoothstep(0.0, 0.01, r.y);
|
|
47
|
+
c += getToColor(clamp(r, 0.0, 1.0)) * f * (1.0 - m.y);
|
|
54
48
|
}
|
|
49
|
+
// the lit room spills its light through the opening, and the leaves cast soft shadows
|
|
50
|
+
// along their edges; both settle as the doors open
|
|
51
|
+
float wl = 0.03 + 0.12 * close;
|
|
52
|
+
float shadow = (1.0 - smoothstep(0.0, wl, x - edgeL)) + (1.0 - smoothstep(0.0, wl, edgeR - x));
|
|
53
|
+
float light = (1.0 + 0.6 * close * close) * (1.0 - 0.7 * close * min(shadow, 1.0));
|
|
54
|
+
return vec4(min(c.rgb * light, vec3(c.a)), c.a);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
vec4 transition (vec2 uv) {
|
|
58
|
+
float w = ratio;
|
|
59
|
+
float x = uv.x * w;
|
|
60
|
+
// camera distance: the leaves always stay in front of it
|
|
61
|
+
float eye = max(w, 1.0) * (0.5 + 0.2 / max(perspective, 0.01));
|
|
62
|
+
// the leaves swing until their free edges have just left the frame
|
|
63
|
+
float swing = progress * progress * (3.0 - 2.0 * progress);
|
|
64
|
+
float a = min(atan(2.0 * eye / w) + 0.1, 0.5 * PI) * swing;
|
|
65
|
+
float dolly = mix(easeInOut(progress), progress, 0.3);
|
|
66
|
+
// the free edge of the left leaf, front and back of its thickness, as (x, z)
|
|
67
|
+
float hw = 0.5 * w;
|
|
68
|
+
vec2 front = hw * vec2(cos(a), -sin(a));
|
|
69
|
+
float thick = 0.02 * w * (1.0 - smoothstep(0.8, 1.0, swing));
|
|
70
|
+
float edgeL = project(front, w, eye);
|
|
71
|
+
float backL = project(front + thick * vec2(sin(a), cos(a)), w, eye);
|
|
72
|
+
float close = 1.0 - swing;
|
|
73
|
+
vec4 back = room(uv, x, backL, w - backL, close, dolly);
|
|
74
|
+
// the leaf on this side of the frame (each one stays in its own half)
|
|
75
|
+
bool left = x < hw;
|
|
76
|
+
float lx = left ? x : w - x;
|
|
77
|
+
vec2 hit = leafHit(lx, w, eye, a);
|
|
78
|
+
float s = clamp(hit.y, 0.0, hw);
|
|
79
|
+
// the ray meets the leaf nearer to the eye, where it looks bigger
|
|
80
|
+
float v = 0.5 + (uv.y - 0.5) * hit.x;
|
|
81
|
+
vec4 leaf = getFromColor(clamp(vec2(left ? s / w : 1.0 - s / w, v), 0.0, 1.0));
|
|
82
|
+
// turned away from the light, and darker toward the free edge as the opening deepens
|
|
83
|
+
leaf.rgb *= 1.0 - 0.5 * (1.0 - cos(a)) - 0.25 * sin(a) * (s / hw);
|
|
84
|
+
// the edge of the leaf catches the light coming from the room
|
|
85
|
+
vec4 side = getFromColor(clamp(vec2(left ? 0.499 : 0.501, v), 0.0, 1.0));
|
|
86
|
+
side.rgb = min(side.rgb * 1.5, vec3(side.a));
|
|
87
|
+
// sharp at both ends, so that nothing of the doors is left at the start and the end
|
|
88
|
+
float aa = 0.003 * min(1.0, 20.0 * min(a, close)) + 1e-6;
|
|
89
|
+
vec4 c = mix(back, side, smoothstep(-aa, aa, backL - lx));
|
|
90
|
+
return mix(c, leaf, smoothstep(-aa, aa, edgeL - lx));
|
|
55
91
|
}
|
package/glsl3/Drape.glsl
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Drape — GLSL ES 3.00, generated from https://github.com/gl-transitions/gl-transitions/blob/master/transitions/Drape.glsl
|
|
2
|
+
// Author: gre
|
|
3
|
+
// License: MIT
|
|
4
|
+
// Description: The outgoing image hangs like a sheet of fabric that is let go at the top: it collapses into soft, uneven folds that hide one another as the cloth bunches up and slides down out of the frame, revealing the incoming image behind it
|
|
5
|
+
// Tags: fabric, fold, vertical, 3d, shadow
|
|
6
|
+
|
|
7
|
+
// @range(1, 16, 1) Number of folds across the cloth (fewer in a portrait image)
|
|
8
|
+
uniform float folds; // = 6.0
|
|
9
|
+
// @range(0, 1) Depth of the folds and of their shading
|
|
10
|
+
uniform float depth; // = 0.7
|
|
11
|
+
// @range(0, 1) How much the cloth sways sideways as it falls
|
|
12
|
+
uniform float sway; // = 0.4
|
|
13
|
+
// @range(0, 1) Strength of the soft shadow cast by the cloth on the incoming image
|
|
14
|
+
uniform float shadow; // = 0.5
|
|
15
|
+
|
|
16
|
+
const float PI = 3.141592653589793;
|
|
17
|
+
const int STEPS = 24;
|
|
18
|
+
const float DEPTH = 0.8; // height of the deepest folds, times the fold width
|
|
19
|
+
|
|
20
|
+
// folds a coordinate back into 0..1, mirroring the image at its edges
|
|
21
|
+
vec2 mirror(vec2 v) {
|
|
22
|
+
return 1.0 - abs(1.0 - mod(v, 2.0));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// integer-free hash of an integer cell, smoothed into a 1D value noise in 0..1
|
|
26
|
+
float hash11(float p) {
|
|
27
|
+
p = fract(p * 0.1031);
|
|
28
|
+
p *= p + 33.33;
|
|
29
|
+
p *= p + p;
|
|
30
|
+
return fract(p);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
float noise1(float x) {
|
|
34
|
+
float i = floor(x);
|
|
35
|
+
float f = x - i;
|
|
36
|
+
return mix(hash11(i), hash11(i + 1.0), f * f * (3.0 - 2.0 * f));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// height of the top edge above x, sagging in the middle (m: see cloth)
|
|
40
|
+
float topEdge(float x, vec4 m) {
|
|
41
|
+
float c = 2.0 * x - 1.0;
|
|
42
|
+
return m.y - 0.08 * m.x * (1.0 - c * c);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// how far the sides are pulled in at the height sy, more so at the bunched top
|
|
46
|
+
float sidePull(float sy, float gT) {
|
|
47
|
+
return 0.035 * gT * (0.3 + 0.7 * clamp(sy, 0.0, 1.0));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// height of the cloth at the point (x, y) of the screen plane, toward the viewer,
|
|
51
|
+
// or -1 where there is no cloth. Also gives the cloth's own coordinates and fold phase.
|
|
52
|
+
// m: how far the folds have formed (0 at rest), height of the top edge, height of the hem, sideways swing
|
|
53
|
+
vec4 cloth(vec2 p, vec4 m, float foldN) {
|
|
54
|
+
float gT = m.x;
|
|
55
|
+
float botY = m.z;
|
|
56
|
+
float x = p.x - m.w;
|
|
57
|
+
float top = topEdge(x, m);
|
|
58
|
+
float sy = (p.y - botY) / max(top - botY, 1e-4); // 0 at the hem, 1 at the top edge
|
|
59
|
+
float pull = sidePull(sy, gT);
|
|
60
|
+
float xc = (x - pull) / (1.0 - 2.0 * pull);
|
|
61
|
+
// uneven folds: their width, depth and course along the cloth all wander
|
|
62
|
+
float wander = (noise1(0.5 * foldN * xc + 2.5 * sy + 5.3) - 0.5) * 2.4 * (1.0 - sy);
|
|
63
|
+
float ph = 2.0 * PI * (foldN * xc + 0.6 * noise1(0.7 * foldN * xc + 1.7)) + wander;
|
|
64
|
+
float d = 0.15 + 0.85 * noise1(1.1 * foldN * xc + 1.4 * sy + 7.0);
|
|
65
|
+
// deepest near the bunched top, relaxing toward the hem
|
|
66
|
+
float amp = DEPTH * depth * gT * (0.3 + 0.7 * sy * sqrt(max(sy, 0.0))) / max(foldN, 2.0);
|
|
67
|
+
// the free sides of the cloth hang flat
|
|
68
|
+
float w = 0.6 / foldN;
|
|
69
|
+
amp *= smoothstep(0.0, w, xc) * smoothstep(0.0, w, 1.0 - xc);
|
|
70
|
+
float prof = 0.5 - 0.5 * cos(ph); // 1 on a ridge, 0 in a valley
|
|
71
|
+
// small sagging creases where the fabric piles up under the top edge
|
|
72
|
+
float dt = (1.0 - sy) * (top - botY);
|
|
73
|
+
float crease = exp(-30.0 * dt) * (0.5 + 0.5 * sin(80.0 * dt + 0.7 * ph));
|
|
74
|
+
bool on = sy >= 0.0 && sy <= 1.0 && xc >= 0.0 && xc <= 1.0;
|
|
75
|
+
return on ? vec4(amp * (d * prof + 0.15 * crease), xc, sy, ph) : vec4(-1.0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
vec4 transition (vec2 uv) {
|
|
79
|
+
float t = progress;
|
|
80
|
+
// the top edge falls first and the hem follows later: the cloth collapses as it slides down
|
|
81
|
+
float topY = 1.0 - 1.06 * t * (0.35 + 0.65 * t);
|
|
82
|
+
float botY = -0.75 * t * t * t;
|
|
83
|
+
// the folds form as soon as the top is let go
|
|
84
|
+
float f = 1.0 - (1.0 - t) * (1.0 - t) * (1.0 - t);
|
|
85
|
+
float foldN = max(1.0, floor(folds * min(ratio, 1.0) + 0.5));
|
|
86
|
+
float shiftX = sway * 0.035 * sin(2.0 * PI * t) * f;
|
|
87
|
+
// the cloth is seen a little from the left and from above: ridges hide the valleys behind them
|
|
88
|
+
vec2 view = vec2(0.75 + 0.5 * sway * sin(PI * t) * f, -0.35);
|
|
89
|
+
float zMax = 1.15 * DEPTH * depth * f / max(foldN, 2.0); // a single fold is no deeper than two
|
|
90
|
+
vec4 m = vec4(f, topY, botY, shiftX);
|
|
91
|
+
// march from the front toward the screen plane, the first point inside the cloth is visible
|
|
92
|
+
float zA = zMax; // last step in front of the cloth
|
|
93
|
+
float zB = 0.0; // first step inside it
|
|
94
|
+
bool found = false;
|
|
95
|
+
float dA = 0.0;
|
|
96
|
+
float dB = 0.0;
|
|
97
|
+
bool onA = false; // whether the last step in front was over the cloth (else the ray came in through its edge)
|
|
98
|
+
for (int i = 0; i < STEPS; i++) {
|
|
99
|
+
if (!found) {
|
|
100
|
+
float z = max(zMax * (1.0 - float(i) / float(STEPS - 1)), 0.0);
|
|
101
|
+
vec4 s = cloth(uv - view * z, m, foldN);
|
|
102
|
+
float dz = s.x - z;
|
|
103
|
+
if (s.x >= 0.0 && dz >= 0.0) {
|
|
104
|
+
found = true;
|
|
105
|
+
zB = z;
|
|
106
|
+
dB = dz;
|
|
107
|
+
} else {
|
|
108
|
+
zA = z;
|
|
109
|
+
dA = dz;
|
|
110
|
+
onA = s.x >= 0.0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
float zHit = zB;
|
|
115
|
+
if (found && zA > zB) {
|
|
116
|
+
if (onA) {
|
|
117
|
+
// crossed the surface: refine between the last two steps
|
|
118
|
+
zHit = mix(zA, zB, dA / (dA - dB));
|
|
119
|
+
} else {
|
|
120
|
+
// came in through the top edge: find where the ray first meets the cloth,
|
|
121
|
+
// on its surface or through the edge (then it sees the inside of the fold)
|
|
122
|
+
float za = zA;
|
|
123
|
+
for (int j = 0; j < 5; j++) {
|
|
124
|
+
float zm = 0.5 * (za + zHit);
|
|
125
|
+
if (cloth(uv - view * zm, m, foldN).x >= zm) zHit = zm;
|
|
126
|
+
else za = zm;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
vec2 hp = uv - view * zHit;
|
|
131
|
+
vec4 hit = found ? cloth(hp, m, foldN) : vec4(-1.0);
|
|
132
|
+
if (found && hit.x < 0.0) {
|
|
133
|
+
zHit = zB;
|
|
134
|
+
hp = uv - view * zB;
|
|
135
|
+
hit = cloth(hp, m, foldN);
|
|
136
|
+
}
|
|
137
|
+
vec4 col = vec4(0.0);
|
|
138
|
+
float cover = 0.0;
|
|
139
|
+
if (hit.x >= 0.0) {
|
|
140
|
+
float xc = hit.y;
|
|
141
|
+
float sy = hit.z;
|
|
142
|
+
float ph = hit.w;
|
|
143
|
+
// the fabric is gathered: more of it goes into the slopes of the folds
|
|
144
|
+
float slope = PI * zMax * foldN;
|
|
145
|
+
// (capped so that the texture never runs backwards where the folds bunch up)
|
|
146
|
+
float mu = min(0.25 * slope * slope / (1.0 + 0.25 * slope * slope), 0.5);
|
|
147
|
+
float u = xc - mu * sin(2.0 * ph) / (4.0 * PI * foldN);
|
|
148
|
+
// and pushed together under the top edge
|
|
149
|
+
float h = max(topY - botY, 1e-4);
|
|
150
|
+
float comp = max(1.0 - h, 0.0);
|
|
151
|
+
float v = sy * (1.0 - comp) + comp * sy * sy * sy;
|
|
152
|
+
vec4 tex = getFromColor(mirror(vec2(u, v)));
|
|
153
|
+
float span = topEdge(hp.x - shiftX, m) - botY; // local height of the cloth
|
|
154
|
+
// surface normal from the height of the cloth around the visible point
|
|
155
|
+
float e = 0.002;
|
|
156
|
+
float hx = cloth(hp + vec2(e, 0.0), m, foldN).x;
|
|
157
|
+
float hy = cloth(hp + vec2(0.0, e), m, foldN).x;
|
|
158
|
+
float hx0 = hx >= 0.0 ? hx : hit.x;
|
|
159
|
+
float hy0 = hy >= 0.0 ? hy : hit.x;
|
|
160
|
+
vec3 nrm = normalize(vec3(-(hx0 - hit.x) / e, -(hy0 - hit.x) / e, 1.0));
|
|
161
|
+
vec3 light = normalize(vec3(-0.45, 0.35, 1.0));
|
|
162
|
+
float diffuse = mix(1.0, max(dot(nrm, light), 0.0) / light.z, min(1.0, 3.0 * f));
|
|
163
|
+
// soft ambient occlusion in the valleys, deeper where the folds are deep
|
|
164
|
+
float valley = 1.0 - (0.5 - 0.5 * cos(ph));
|
|
165
|
+
float ao = 1.0 - 0.6 * depth * f * valley * valley * (0.35 + 0.65 * sy);
|
|
166
|
+
// the rolled top edge gets less light
|
|
167
|
+
float rim = exp(-(1.0 - sy) * span * 70.0) * 0.35 * f;
|
|
168
|
+
// below the surface, the ray sees the shaded inside of a fold through the top edge
|
|
169
|
+
float under = max(hit.x - zHit, 0.0);
|
|
170
|
+
float back = min(1.0, under / max(0.1 * zMax, 1e-6));
|
|
171
|
+
tex.rgb *= diffuse * ao * (1.0 - rim) * (1.0 - 0.6 * back);
|
|
172
|
+
col = tex;
|
|
173
|
+
// anti-aliased outline, sharp at rest so the first frame is exact
|
|
174
|
+
float aa = 0.003 * f;
|
|
175
|
+
float inside = min((1.0 - sy) * span - view.y * under, min(xc, 1.0 - xc));
|
|
176
|
+
cover = aa > 0.0 ? clamp(inside / aa, 0.0, 1.0) : 1.0;
|
|
177
|
+
if (cover >= 1.0) return col;
|
|
178
|
+
}
|
|
179
|
+
// soft shadow of the cloth, held a little away from the incoming image, gone once it has left
|
|
180
|
+
vec4 to = getToColor(uv);
|
|
181
|
+
float x = uv.x - shiftX;
|
|
182
|
+
float pull = sidePull((uv.y - botY) / max(topEdge(x, m) - botY, 1e-4), f);
|
|
183
|
+
float outside = max(uv.y - topEdge(x, m), max(-x, x - 1.0) - pull);
|
|
184
|
+
float sh = shadow * exp(-max(outside, 0.0) * 16.0) * f * clamp(8.0 * (1.0 - t), 0.0, 1.0);
|
|
185
|
+
return mix(vec4(to.rgb * (1.0 - 0.8 * sh), to.a), col, cover);
|
|
186
|
+
}
|