-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ls_Contacts.glsl
86 lines (76 loc) · 2.45 KB
/
Ls_Contacts.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
// Tiles the inputs into a grid for impressing clients
// lewis@lewissaunders.com
// TODO:
// o Nonsquare pixels support... eek
// o Variable width borders look gross, how can we get a nice even spacing?
uniform sampler2D in1, in2, in3, in4, in5, in6;
uniform int rows, cols, randomcount, seed;
uniform bool random, perframe, filltiles;
uniform float scale;
uniform float adsk_result_w, adsk_result_h, adsk_time;
// Mysterious dirty random number generator
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main() {
vec2 coords = gl_FragCoord.xy / vec2(adsk_result_w, adsk_result_h);
vec2 tilecoords = vec2(0.0, 0.0);
vec4 o = vec4(0.0);
float aspectdiff, tilew, tileh;
int tilex, tiley, tileidx;
// Figure out how big each tile will be, and which tile we're in
tilew = adsk_result_w / float(cols);
tileh = adsk_result_h / float(rows);
tilex = int(gl_FragCoord.x / tilew);
tiley = int((adsk_result_h - gl_FragCoord.y) / tileh);
tileidx = tiley * cols + tilex;
// Randomize the tile index
if(random) {
if(perframe) {
tileidx = int(rand(vec2(float(tilex - seed), float(tiley) + 1234.0 * adsk_time)) * float(randomcount));
} else {
tileidx = int(rand(vec2(float(tilex - seed), float(tiley))) * float(randomcount));
}
}
// Get current coordinates within this tile
tilecoords.x = mod(gl_FragCoord.x, tilew) / tilew;
tilecoords.y = mod(gl_FragCoord.y, tileh) / tileh;
// Scale coordinates about the centre of each tile to maintain proportions and do fit/fill
tilecoords -= vec2(0.5);
tilecoords *= 100.0 / scale;
aspectdiff = (tilew / tileh) / (adsk_result_w / adsk_result_h);
if(aspectdiff > 1.0) {
tilecoords.x *= aspectdiff;
if(filltiles) {
tilecoords /= aspectdiff;
}
} else {
tilecoords.y /= aspectdiff;
if(filltiles) {
tilecoords *= aspectdiff;
}
}
tilecoords += vec2(0.5);
// Finally grab input for the tile we're in
if(tileidx == 0) {
o = texture2D(in1, tilecoords);
} else if(tileidx == 1) {
o = texture2D(in2, tilecoords);
} else if(tileidx == 2) {
o = texture2D(in3, tilecoords);
} else if(tileidx == 3) {
o = texture2D(in4, tilecoords);
} else if(tileidx == 4) {
o = texture2D(in5, tilecoords);
} else if(tileidx == 5) {
o = texture2D(in6, tilecoords);
}
// Draw black if we're in a border area
if((tilecoords.x <= 0.0) || (tilecoords.x > 1.0)) {
o = vec4(0.0);
}
if((tilecoords.y <= 0.0) || (tilecoords.y > 1.0)) {
o = vec4(0.0);
}
gl_FragColor = o;
}