Advertisement
KAR98S

AllColors.frag

Jun 1st, 2020 (edited)
523
0
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.  
  5. uniform vec2 u_resolution;
  6. uniform vec2 u_mouse;
  7. uniform float u_time;
  8.  
  9. const float PI = 3.14159;
  10.  
  11. float gradient (float point,float x1, float x2){
  12.     return ((point - x1) / (x2 - x1));
  13. }
  14.  
  15. bool liesIn(float x, float left, float right){
  16.     return ((x >= left) && (x <= right));
  17. }
  18.  
  19. void main() {
  20.     vec2 st,res = u_resolution, coord = gl_FragCoord.xy;
  21.     float   R = 0.0,
  22.             G = 0.0,
  23.             B = 0.0,
  24.             yGradient,
  25.             oneThirdResX = res.x/3.0, oneSixthResX = res.x/6.0, sinTime = sin(u_time);
  26.     vec3 color;
  27.    
  28.     if(liesIn(coord.x, 0.0, oneSixthResX)){                         //1st segment
  29.         R = 1.0;
  30.         G = gradient(coord.x,0.0,oneSixthResX);
  31.         B = 0.0;
  32.     }
  33.     else if(liesIn(coord.x, oneSixthResX, 2.0*oneSixthResX)){       //2nd segment
  34.         R = 1.0 - gradient(coord.x, oneSixthResX, 2.0*oneSixthResX);
  35.         G = 1.0;
  36.         B = 0.0;
  37.     }
  38.     else if(liesIn(coord.x, 2.0*oneSixthResX, 3.0*oneSixthResX)){   //3rd segment
  39.         R = 0.0;
  40.         G = 1.0;
  41.         B = gradient(coord.x, 2.0*oneSixthResX, 3.0*oneSixthResX);
  42.     }
  43.     else if(liesIn(coord.x, 3.0*oneSixthResX, 4.0*oneSixthResX)){   //4th segment
  44.         R = 0.0;
  45.         G = 1.0 - gradient(coord.x, 3.0*oneSixthResX, 4.0*oneSixthResX);
  46.         B = 1.0;
  47.     }
  48.     else if(liesIn(coord.x, 4.0*oneSixthResX, 5.0*oneSixthResX)){   //5th segment
  49.         R = gradient(coord.x, 4.0*oneSixthResX, 5.0*oneSixthResX);
  50.         G = 0.0;
  51.         B = 1.0;
  52.     }
  53.     else if(liesIn(coord.x, 5.0*oneSixthResX, 6.0*oneSixthResX)){   //6th segment
  54.         R = 1.0;
  55.         G = 0.0;
  56.         B = 1.0 - gradient(coord.x, 5.0*oneSixthResX, 6.0*oneSixthResX);
  57.     }
  58.    
  59.     sinTime = (sinTime+1.0)/2.0 + 1.0;
  60.    
  61.     yGradient = (coord.y/(res.y));     
  62.     R = mix(R,yGradient,sinTime);  
  63.     G = mix(G,yGradient,sinTime);
  64.     B = mix(B,yGradient,sinTime);
  65.    
  66.     color = vec3(R,G,B);
  67.     gl_FragColor = vec4(color,1.0);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement