Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. //CBS
  2. //Parallax scrolling fractal galaxy.
  3. //Inspired by JoshP's Simplicity shader: https://www.shadertoy.com/view/lslGWr
  4.  
  5. // http://www.fractalforums.com/new-theories-and-research/very-simple-formula-for-fractal-patterns/
  6. float field(in vec3 p,float s) {
  7. float strength = 7. + .03 * log(1.e-6 + fract(sin(iTime) * 4373.11));
  8. float accum = s/4.;
  9. float prev = 0.;
  10. float tw = 0.;
  11. for (int i = 0; i < 26; ++i) {
  12. float mag = dot(p, p);
  13. p = abs(p) / mag + vec3(-.5, -.4, -1.5);
  14. float w = exp(-float(i) / 7.);
  15. accum += w * exp(-strength * pow(abs(mag - prev), 2.2));
  16. tw += w;
  17. prev = mag;
  18. }
  19. return max(0., 5. * accum / tw - .7);
  20. }
  21.  
  22. // Less iterations for second layer
  23. float field2(in vec3 p, float s) {
  24. float strength = 15. + .03 * log(1.e-6 + fract(sin(iTime) * 4373.11));
  25. float accum = s/4.;
  26. float prev = 0.;
  27. float tw = 0.;
  28. for (int i = 0; i < 18; ++i) {
  29. float mag = dot(p, p);
  30. p = abs(p) / mag + vec3(-.5, -.4, -1.5);
  31. float w = exp(-float(i) / 7.);
  32. accum += w * exp(-strength * pow(abs(mag - prev), 2.2));
  33. tw += w;
  34. prev = mag;
  35. }
  36. return max(0., 5. * accum / tw - .7);
  37. }
  38.  
  39. vec3 nrand3( vec2 co )
  40. {
  41. vec3 a = fract( cos( co.x*8.3e-3 + co.y )*vec3(1.3e5, 4.7e5, 2.9e5) );
  42. vec3 b = fract( sin( co.x*0.3e-3 + co.y )*vec3(8.1e5, 1.0e5, 0.1e5) );
  43. vec3 c = mix(a, b, 0.5);
  44. return c;
  45. }
  46.  
  47.  
  48. void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
  49. vec2 uv = 2. * fragCoord.xy / iResolution.xy - 1.;
  50. vec2 uvs = uv * iResolution.xy / max(iResolution.x, iResolution.y);
  51. vec3 p = vec3(uvs / 4., 0) + vec3(1., -1.3, 0.);
  52. p += .2 * vec3(sin(iTime / 16.), sin(iTime / 12.), sin(iTime / 128.));
  53.  
  54. float freqs[4];
  55. //Sound
  56. freqs[0] = texture( iChannel0, vec2( 0.10, 0.05 ) ).x;
  57. freqs[1] = texture( iChannel0, vec2( 0.27, 0.05 ) ).x;
  58. freqs[2] = texture( iChannel0, vec2( 0.35, 0.55 ) ).x;
  59. freqs[3] = texture( iChannel0, vec2( 0.30, 0.50 ) ).x;
  60.  
  61. float t = field(p,freqs[2]);
  62. float v = (1. - exp((abs(uv.x) - 1.) * 6.)) * (1. - exp((abs(uv.y) - 1.) * 6.));
  63.  
  64. //Second Layer
  65. vec3 p2 = vec3(uvs / (4.+sin(iTime*0.0001)*0.2+0.2+sin(iTime*0.15)*0.3+0.4), 1.5) + vec3(2., -1.3, -1.);
  66. p2 += 0.25 * vec3(sin(iTime / 16.), sin(iTime / 16.), sin(iTime / 128.));
  67. float t2 = field2(p2,freqs[3]);
  68. vec4 c2 = mix(.4, 1., v) * vec4(1.3 * t2 * t2 * t2 ,1.8 * t2 * t2 , t2* freqs[0], t2);
  69.  
  70.  
  71. //Let's add some stars
  72. //Thanks to http://glsl.heroku.com/e#6904.0
  73. vec2 seed = p.xy * 2.0;
  74. seed = floor(seed * iResolution.x);
  75. vec3 rnd = nrand3( seed );
  76. vec4 starcolor = vec4(pow(rnd.y,30.0));
  77.  
  78. //Second Layer
  79. vec2 seed2 = p2.xy * 2.0;
  80. seed2 = floor(seed2 * iResolution.x);
  81. vec3 rnd2 = nrand3( seed2 );
  82. starcolor += vec4(pow(rnd2.y,40.0));
  83.  
  84. fragColor = mix(freqs[3]-.3, 1., v) * vec4(1.5*freqs[2] * t * t* t , 1.2*freqs[1] * t * t, freqs[3]*t, 1.0)+c2+starcolor;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement