Advertisement
KAR98S

RainbowScreenSaver.frag

May 31st, 2020 (edited)
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //TODO: RGB -> square instead fix RGB -> triangle
  2. #ifdef GL_ES
  3. precision mediump float;
  4. #endif
  5.  
  6. const float PI = 3.14159;
  7.  
  8. uniform vec2 u_resolution;
  9. uniform vec2 u_mouse;
  10. uniform float u_time;
  11.  
  12. float diatance(vec2 p1, vec2 p2){
  13.     return (
  14.         sqrt(
  15.             pow((p2.y - p1.y),2.0) + pow((p2.x - p1.x),2.0)
  16.     ));
  17. }
  18.  
  19. //Translating Points at an angle w.r.t center point using polar form of a straight line
  20. //Also **note :
  21.  
  22. void main() {
  23.     vec2 res = u_resolution.xy;
  24.     vec2 st, center = vec2(res.x/2.0,res.y/2.0);
  25.     center.x += res.x * 0.5 * sin(u_time*3.0);center.y += res.y * 0.5 * cos(u_time*3.0);    //--rotating the center
  26.     float dist = distance (gl_FragCoord.xy,center);                                         //   in circlular path
  27.     float angle = atan((gl_FragCoord.y - center.y) / (gl_FragCoord.x - center.x));
  28.    
  29.     angle = (angle + u_time/2.0);   //--small increment to angle to show animation, negate addition to
  30.                                     //  rotate counter Clockwise
  31.     if((gl_FragCoord.x - center.x) < 0.0)   //--atan() does not return angles in 2nd and 3rd quadrant
  32.         angle += PI;                        //  so we need to write seperate code to implement that logic
  33.     else if((gl_FragCoord.y - center.y) < 0.0)
  34.         angle += 2.0*PI;
  35.    
  36.     st.x = (dist * cos(angle)) / res.x; //--New color intensity after adding change to angle
  37.     st.y = (dist * sin(angle)) / res.y;
  38.    
  39.     st.x*= 1.0+st.x;
  40.     st.y*= 1.0+st.y;
  41.    
  42.     vec3 color;
  43.     color = vec3(   //--passing color intensities as a multiple of positive sin() R[0,1] as a function of time to animate
  44.         (1.0 - (st.y - st.x)*1.0)* abs(sin(u_time/2.0)),
  45.         (1.0 - (st.x - st.y)*1.0)* abs(sin(u_time/2.0 + 2.0*PI/3.0)),
  46.         (1.0 - ((st.x + st.y)/2.0)) * abs(sin(u_time/2.0 + 4.0*PI/3.0))
  47.     );
  48.  
  49.     gl_FragColor = vec4(color,1.0);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement