-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glut_251.frag
40 lines (33 loc) · 899 Bytes
/
glut_251.frag
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
//precision highp float;
varying vec2 vTexCoord;
const int number_of_balls = 20;
uniform vec3 metaballs[number_of_balls];
const float WIDTH = 1280.0;
const float HEIGHT = 800.0;
vec3 hsv2rgb (vec3 c)
{
vec4 K = vec4 (1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs (fract (c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix (K.xxx, clamp (p - K.xxx, 0.0, 1.0), c.y);
}
void main ()
{
float x = vTexCoord.x * WIDTH;
float y = vTexCoord.y * HEIGHT;
float v = 0.0;
for (int i = 0; i < number_of_balls; i++)
{
vec3 ball = metaballs[i];
float dx = ball.x - x;
float dy = ball.y - y;
float r = ball.z;
v += r * r / (dx * dx + dy * dy);
}
if (0.9 < v && v < 1.1)
{
float a = (v - 0.9) * 4.0;
gl_FragColor = vec4 (hsv2rgb (vec3 (a, 1.0, 1.0)), 1.0);
}
else
gl_FragColor = vec4 (0.0, 0.0, 0.0, 1.0);
}