-
Notifications
You must be signed in to change notification settings - Fork 1
/
tile_transition.glsl
143 lines (120 loc) · 3.98 KB
/
tile_transition.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// License: MIT
// Author: TimDonselaar
// ported by gre from https://gist.github.com/TimDonselaar/9bcd1c4b5934ba60087bdb55c2ea92e5
// modified by tshirtman from https://gl-transitions.com/editor/GridFlip
#version 130
$HEADER$
uniform float t;
uniform sampler2D tex_in;
uniform sampler2D tex_out;
// screen aspect ratio
ivec2 size = ivec2(16, 16);
float pause= 0.1;
const float s2 = sqrt(2.);
vec2 resolution = textureSize(tex_out, 0);
float AR = resolution.x / resolution.y;
vec4 bgcolor = vec4(1.0, 1.0, 1.0, 1.0);
float randomness = 0.0;
float rand (vec2 co) {
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
}
float dist_to_line(vec2 pt1, vec2 pt2, vec2 testPt) {
vec2 lineDir = pt2 - pt1;
vec2 perpDir = vec2(lineDir.y, -lineDir.x);
vec2 dirToPt1 = pt1 - testPt;
return (dot(normalize(perpDir), dirToPt1));
}
vec2 my_tile(vec2 p, vec2 grid) {
// return current tile's position
//
// NOT TO SCALE __
// / |
// / |
// / |
// / |
// / |
// / |
// / |
// / |
// / |
// X reference line |
// / |
// / |
// / |AR
// / |
// / |
// / |
// / |
// / |
// / |
// 0/__________________1_v_
//0|\11/\22/\33/\44/\55| ^
// |1\/21\/32\/43\/54\/| |
// -1/\ /\ /\ /\ /\| |
// |/2 \/31\/42\/53\/64| |
// |\-1/\ /\ /\ /\ | |
// | \/3 \/41\/52\/63\/| |
// |_/\-1/\ _/\__/\__/\| |
//1 \ |
// \ |
// \ |AR
// \ |
// y reference line |
// \ |
// \ |
// \ |
// \ |
// \ |
// \ |
// \__v
vec2 A = vec2(0.0, 0.0);
vec2 B = vec2(1.0, -1.0);
float x = floor(dist_to_line(A, B, p / vec2(1.0, AR) * grid) / s2);
A = vec2(0.0, 0.0);
B = vec2(1.0, 1.0);
// vflip to switch coords system
float y = - floor(dist_to_line(A, B, p / vec2(1.0, AR) * grid) / s2) + 1.0;
return vec2(x, y);
}
void main() {
vec2 p = gl_FragCoord.xy / resolution.xy;
float currentProg = (t - pause) / (1.0 - pause * 2.0);
vec2 q = p;
vec2 dp = 1. / resolution;
vec2 t1 = my_tile(p, vec2(float(size.x), float(size.y)));
float r = rand(vec2(t1)) - randomness;
float cp = smoothstep(0.0, 1.0 - r, currentProg);
// XXX pretty sure the issue is here now, computing this value
// correctly should fix the issue, the current value is pretty weird
vec2 rectanglePos = vec2(
t1.x / float(size.x) + t1.y / float(size.y),
t1.x / float(size.y) + t1.y / float(size.x)
);
float rectangleSize = 2. / (float(size.x));
float offset = rectanglePos.x - .5 * rectangleSize;
p.x = (p.x - offset) / abs(cp - 0.5) * 0.5 + offset;
vec2 t2 = my_tile(p, vec2(float(size.x), float(size.y)));
if (t1.x != t2.x || t1.y != t2.y)
gl_FragColor = bgcolor;
else {
vec4 a = texture2D(tex_out, p);
vec4 b = texture2D(tex_in, p);
float s = 1.;
float sr = 1.;
if (t < pause) {
sr = t / pause;
}
else if (t > 1.0 - pause) {
sr = 1. - (t - (1. - pause)) / pause;
}
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
vec2 np = p + vec2(float(x), float(y)) * dp;
vec2 t3 = my_tile(np, vec2(float(size.x), float(size.y)));
if (t3.x != t2.x || t3.y != t2.y)
s -= sr * 1. / 9.;
}
}
gl_FragColor = mix(bgcolor, mix(b, a, step(cp, 0.5)), s);
}
}