-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrag.glsl
44 lines (39 loc) · 907 Bytes
/
frag.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
struct Ball {
vec3 pos;
vec3 rgb;
float r;
};
const int MAX_BALLS = 50;
const float threshold = 3.4;
uniform Ball balls[MAX_BALLS];
uniform int n_balls;
varying vec4 vertColor;
void main() {
float total = 0;
int idx = 0;
float highest = 0;
for(int i=0; i<n_balls; i++) {
Ball b = balls[i];
float dst = distance(b.pos.xy, gl_FragCoord.xy);
float val = b.r / dst;
total += val;
if(val > highest) {
idx = i;
highest = val;
}
}
if(total < threshold) {
gl_FragColor = vec4(vec3(1.0), 1.0);
} else if(total < threshold + 0.05) {
gl_FragColor = vec4(vec3(0.0), 1.0);
} else {
gl_FragColor = vec4(balls[idx].rgb, 1.0);
}
// create dots in middle of ball
float dot_rad = 4;
for(int i=0; i<n_balls; i++) {
if(distance(balls[i].pos.xy, gl_FragCoord.xy) < sqrt(dot_rad)) {
gl_FragColor = vec4(vec3(0.0), 1.0);
}
}
}