Advertisement
Guest User

starfield.glsl

a guest
Sep 16th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. precision mediump float;
  2.  
  3.  
  4. varying vec2 vTextureCoord;
  5.  
  6.  
  7. uniform sampler2D uSampler;
  8. uniform vec2 resolution;
  9. uniform vec2 center;
  10. uniform vec4 randoms;
  11. uniform float time;
  12.  
  13.  
  14. float t = 10.0 * time;
  15.  
  16.  
  17. void main(void) {
  18. gl_FragColor = vec4(1);
  19.  
  20. t += 0.5 * (0.5 + 0.5 * sin(t));
  21.  
  22. vec2 xy = gl_FragCoord.xy - center;
  23.  
  24. // Distortion
  25. float size = 40.0 + 20.0 * cos(t * -0.1);
  26. xy = vec2(
  27. xy.x - size + size*(1.0 + 0.4*sin(time * 0.025 * xy.x + xy.y)),
  28. xy.y - size + size*(1.0 + 0.4*sin(time * 0.025 * xy.y + xy.x)));
  29.  
  30. // Spiral function.
  31. float a = degrees(atan(xy.y, xy.x));
  32. float amod = mod(a + 0.5 * t - 120.0 * log(length(xy)), 30.0) ;
  33.  
  34. if (amod < 15.0) {
  35. // Rotating color gradient.
  36. vec2 uv = gl_FragCoord.xy / resolution.xy;
  37. gl_FragColor *= vec4(uv, 0.5 + 0.5 * sin(0.1 * t * randoms.x), 1);
  38. }
  39.  
  40. // Sombrero function for opacity.
  41. float ringFrequency = sin(randoms.w * 0.15 * t),
  42. ringSize = (1.0 + 0.40 * ringFrequency) * 0.020,
  43. ringSpacing = (1.0 + 0.28 * ringFrequency);
  44.  
  45. float sombrero = sqrt(
  46. ringSpacing*pow(ringSize * xy.x, 2.0)
  47. + ringSpacing*pow(ringSize * xy.y, 2.0));
  48.  
  49. float alpha = sin(0.30 * t + sombrero) / sombrero;
  50.  
  51. float pulsingRadialOpacity = 13.0 - 12.0*(1.0 + 0.5*sin(0.15*t));
  52.  
  53. gl_FragColor *= pulsingRadialOpacity
  54. * (1.0 - 0.25*(sin(0.2*t)))
  55. * sin(0.0002 * alpha * t);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement