Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 450 core
  2.  
  3. // --------------------------------- DO NOT TOUCH
  4.  
  5. uniform vec2 iResolution;
  6. uniform sampler2D iChannel0;
  7. uniform float iGlobalTime;
  8.  
  9. // - Other
  10. in vec4 out_color;
  11. in vec4 out_position;
  12.  
  13. // --------------------------------- USER DEFINED SHADER
  14. const float dots = 40.; //number of lights
  15. const float radius = .25; //radius of light ring
  16. const float brightness = 0.02;
  17.  
  18. //convert HSV to RGB
  19. vec3 hsv2rgb(vec3 c){
  20.     vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
  21.     vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
  22.     return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
  23. }
  24.  
  25. void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
  26.  
  27.     vec2 p=(fragCoord.xy-.5*iResolution.xy)/min(iResolution.x,iResolution.y);
  28.     vec3 c=vec3(0,0,0.1); //background color
  29.  
  30.     for(float i=0.;i<dots; i++){
  31.  
  32.         //read frequency for this dot from audio input channel
  33.         //based on its index in the circle
  34.         float vol =  texture2D(iChannel0, vec2(i/dots, 0.0)).x;
  35.         float b = vol * brightness;
  36.  
  37.         //get location of dot
  38.         float x = radius*cos(2.*3.14*float(i)/dots);
  39.         float y = radius*sin(2.*3.14*float(i)/dots);
  40.         vec2 o = vec2(x,y);
  41.  
  42.         //get color of dot based on its index in the
  43.         //circle + time to rotate colors
  44.         vec3 dotCol = hsv2rgb(vec3((i + iGlobalTime*10.)/dots,1.,1.0));
  45.  
  46.         //get brightness of this pixel based on distance to dot
  47.         c += b/(length(p-o))*dotCol;
  48.     }
  49.  
  50.     //black circle overlay
  51.     float dist = distance(p , vec2(0));
  52.     c = c * smoothstep(0.26, 0.28, dist);
  53.  
  54.     fragColor = vec4(c,1);
  55. }
  56. // ---------------------------------
  57.  
  58. void main(){
  59.  
  60.      mainImage(gl_FragColor, gl_FragCoord.xy);
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement