RainbowDisco.frag

May 31st, 2020 (edited)
257
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #ifdef GL_ES
2. precision mediump float;
3. #endif
4. //#define ABC
5. #define PI 3.14159
6.
7. const float PI_by_three = 1.04720;
8. const float two_PI_by_three = 2.09440;
9.
10. uniform vec2 u_resolution;
11. uniform vec2 u_mouse;
12. uniform float u_time;
13.
14. vec2 res = u_resolution;
15.
16. float diatance(vec2 p1, vec2 p2){
17.     return (
18.         sqrt(
19.             pow((p2.y - p1.y),2.0) + pow((p2.x - p1.x),2.0)
20.     ));
21. }
22.
23. void main() {
24.     float time = u_time * 5.0 + (u_mouse.x/25.);
25.     float R,G,B,A, size, tmp, distanceFromCenter = res.x/3.0;
26.     vec2 center = vec2(res.x/2.0,res.y/2.0),//center
27.             p1,p2,p3;
28.     vec3 color;
29.
30.     p1 = p2 = p3 = center;
31.     p1.y += distanceFromCenter;
32.     p2.x -= distanceFromCenter * sin(PI_by_three);
33.     p2.y -= distanceFromCenter * cos(PI_by_three);
34.     p3.x += distanceFromCenter * sin(PI_by_three);
35.     p3.y -= distanceFromCenter * cos(PI_by_three);
36.
37.     size = distance(p1,p2)*((u_mouse.x/res.x) + 0.5);
38.     //size1 *= 0.2 + abs(sin(u_time));
39.     p1.x = center.x + (size * cos(time)) / 2.0;
40.     p1.y = center.y + (size * sin(time)) / 2.0;
41.
42.     p2.x = center.x + (size * cos(time + two_PI_by_three)) / 2.0;
43.     p2.y = center.y + (size * sin(time + two_PI_by_three)) / 2.0;
44.
45.     p3.x = center.x + (size * cos(time + 2.0*two_PI_by_three)) / 2.0;
46.     p3.y = center.y + (size * sin(time + 2.0*two_PI_by_three)) / 2.0;
47.     float dist;
48.
49.     dist = distance(p1,gl_FragCoord.xy);
50.     if(dist <= size*2.0){
51.         tmp = (dist)/(size*2.0);
52.         B = 1.0-tmp;
53.     }
54.     else
55.         B = 0.0;
56.
57.     dist = distance(p2,gl_FragCoord.xy);
58.     if(dist <= size*2.0){
59.         tmp = (dist)/(size*2.0);
60.         R = 1.0-tmp;
61.     }
62.     else
63.         R = 0.0;
64.
65.     dist = distance(p3,gl_FragCoord.xy);
66.     if(dist <= size*2.){
67.         tmp = (dist)/(size*2.0);
68.         G = 1.0-tmp;
69.     }
70.     else
71.         G = 0.0;
72.
73.     dist = distance(center,gl_FragCoord.xy);
74.     if(dist <= size*3.0){
75.         tmp = (dist)/(size*3.0);
76.         R += (1.0 - tmp)*0.3;
77.         G += (1.0 - tmp)*0.3;
78.         B += (1.0 - tmp)*0.3;
79.     }
80.
81.
82.     color = vec3(R,G,B);
83.     A = 1.0;
84.     gl_FragColor = vec4(color,A);
85. }
RAW Paste Data