Advertisement
signalxnoise

1464216359.glsl

May 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //******************************************************************************\\
  2. //                                                                              \\
  3. //                                 SIGNALxNOISE                                 \\
  4. //                                                                              \\
  5. //  a procedurally generated noise based glsl shader for making terrible gifs   \\
  6. //                                by @innesmck                                  \\
  7. //                                                                              \\
  8. //******************************************************************************\\
  9.  
  10. //Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. //The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  12. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13.  
  14. //#define D_SHADERTOY // define this to try this shader on shadertoy
  15.  
  16. #ifndef D_SHADERTOY
  17.     uniform vec2  iResolution;
  18.     uniform float iGlobalTime;
  19. #endif
  20.  
  21.  
  22. // Array and textureless GLSL 2D/3D/4D simplex noise functions.
  23. // Authors: Ian McEwan, Ashima Arts.
  24. // License : Copyright (C) 2011 Ashima Arts. All rights reserved. Distributed under the MIT License.
  25. // github . com / ashima / webgl-noise
  26.  
  27. vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
  28. vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
  29. vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); }
  30. vec4 taylorInvSqrt(vec4 r){ return 1.79284291400159 - 0.85373472095314 * r; }
  31.  
  32. float snoise(vec3 v)
  33. {
  34.   const vec2  C = vec2(1.0/6.0, 1.0/3.0) ;
  35.   const vec4  D = vec4(0.0, 0.5, 1.0, 2.0);
  36.   vec3 i  = floor(v + dot(v, C.yyy) );
  37.   vec3 x0 =   v - i + dot(i, C.xxx) ;
  38.   vec3 g = step(x0.yzx, x0.xyz);
  39.   vec3 l = 1.0 - g;
  40.   vec3 i1 = min( g.xyz, l.zxy );
  41.   vec3 i2 = max( g.xyz, l.zxy );
  42.   vec3 x1 = x0 - i1 + C.xxx;
  43.   vec3 x2 = x0 - i2 + C.yyy;
  44.   vec3 x3 = x0 - D.yyy;
  45.  
  46.   i = mod289(i);
  47.   vec4 p = permute( permute( permute(
  48.              i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
  49.            + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
  50.            + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
  51.  
  52.   float n_ = 0.142857142857;
  53.   vec3  ns = n_ * D.wyz - D.xzx;
  54.   vec4 j = p - 49.0 * floor(p * ns.z * ns.z);
  55.   vec4 x_ = floor(j * ns.z);
  56.   vec4 y_ = floor(j - 7.0 * x_ );
  57.   vec4 x = x_ *ns.x + ns.yyyy;
  58.   vec4 y = y_ *ns.x + ns.yyyy;
  59.   vec4 h = 1.0 - abs(x) - abs(y);
  60.   vec4 b0 = vec4( x.xy, y.xy );
  61.   vec4 b1 = vec4( x.zw, y.zw );
  62.   vec4 s0 = floor(b0)*2.0 + 1.0;
  63.   vec4 s1 = floor(b1)*2.0 + 1.0;
  64.   vec4 sh = -step(h, vec4(0.0));
  65.   vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
  66.   vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
  67.   vec3 p0 = vec3(a0.xy,h.x);
  68.   vec3 p1 = vec3(a0.zw,h.y);
  69.   vec3 p2 = vec3(a1.xy,h.z);
  70.   vec3 p3 = vec3(a1.zw,h.w);
  71.   vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
  72.   p0 *= norm.x;
  73.   p1 *= norm.y;
  74.   p2 *= norm.z;
  75.   p3 *= norm.w;
  76.   vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
  77.   m = m * m;
  78.   return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
  79.                                 dot(p2,x2), dot(p3,x3) ) );
  80.   }
  81.  
  82.  
  83. //
  84. // Utility functions
  85. //
  86.  
  87. float snoise( float v ) { return snoise( vec3( v ) ); }
  88.  
  89. float vnoise( float v ) { return snoise( vec3( v, v + 100.0, v + 10000.0 ) ); }
  90. vec2  vnoise( vec2 v )  { return vec2( vnoise( v.x ), vnoise( v.y ) ); }
  91. vec3  vnoise( vec3 v )  { return vec3( vnoise( v.x ), vnoise( v.y ), vnoise( v.z ) ); }
  92.  
  93. float worm( float low, float high, float x ) { if( x < min(low,high) || x > max(low,high) ) return 0.0; return x; }
  94. vec2  worm( float low, float high, vec2 x )  { if( ( x.x + x.y ) / 2.0 < min(low,high) || ( x.x + x.y ) / 2.0  > max(low,high) ) return vec2( 0.0 ); return vec2( x ); }
  95. vec3  worm( float low, float high, vec3 x )  { if( ( x.x + x.y + x.z ) / 3.0 < min(low,high) || ( x.x + x.y + x.z ) / 3.0  > max(low,high) ) return vec3( 0.0 ); return vec3( x ); }
  96.  
  97. float ss( float low, float high, float x ) { return smoothstep( min(low,high), max(low,high), x ); }
  98. vec2  ss( float low, float high, vec2 x )  { return smoothstep( min(low,high), max(low,high), x ); }
  99. vec3  ss( float low, float high, vec3 x )  { return smoothstep( min(low,high), max(low,high), x ); }
  100.  
  101. float pixelate( float x, float y ) { return ceil( x * y ) / y; }
  102. vec3  pixelate( vec3 x, float y )  { return ceil( x * y ) / y; }
  103. vec2  pixelate( vec2 x, float y )  { return ceil( x * y ) / y; }
  104.  
  105. vec2 rotate( float a, vec2 x ) { mat2 m = mat2( cos( a ), -sin( a ), sin( a ), cos( a ) ); return m * x; }
  106.  
  107. vec3 neg( vec3 x ) { return vec3( 1.0 ) - x; }
  108. vec3 inv( vec3 x ) { return vec3( 1.0 ) / x; }
  109.  
  110. vec3 rgb2hsv( vec3 c )
  111. {
  112.     vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  113.     vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
  114.     vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
  115.  
  116.     float d = q.x - min(q.w, q.y);
  117.     float e = 1.0e-10;
  118.     return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
  119. }
  120.  
  121. vec3 hsv2rgb( vec3 c )
  122. {
  123.     vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
  124.     vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
  125.     return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
  126. }
  127.  
  128. vec3 getRandomHue( float h, float s, float v )
  129. {
  130.     return hsv2rgb( vec3( h, s, v * 0.1 + 0.9 ) ) ;
  131. }
  132.  
  133. vec3 getRandomBrightHue( float h, float s, float v )
  134. {
  135.     return hsv2rgb( vec3( h, s * 0.3 + 0.7, v * 0.6 + 0.4 ) ) ;
  136. }
  137.  
  138. vec3 getRandomDarkHue( float h, float s, float v )
  139. {
  140.     return hsv2rgb( vec3( h, s * 0.5, v * 0.2 ) ) ;
  141. }float gold = 0.618033988749895;
  142. vec3 getGoldenRatio( float i, float s, float v )
  143. {
  144.     float h = gold * i;
  145.     h       = mod( 0.35654 + h, 1.0 );
  146.     return hsv2rgb( vec3( h, s * 0.3 + 0.7, v * 0.2 + 0.8 ) ) ;
  147. }
  148.  
  149. //
  150. // Generated code
  151. //
  152.  
  153. void mainImage( out vec4 fragColor, in vec2 fragCoord )
  154. {
  155.     vec2  tc = fragCoord / iResolution.xy;
  156.     tc.x = (1.0 - tc.x);
  157.     tc.y = (1.0 - tc.y);
  158.  
  159.     vec2  tc2 = (tc - vec2( 0.5));
  160.     float l = length( tc2 ), l2 = length( tc2 );
  161.  
  162.     float t  = iGlobalTime / 12.0;
  163.     t = (1.0 - t);
  164.  
  165.     float t2 = t;
  166.     t2 = 5.78311 / t2; t2 = mix( clamp( t2, -0.79995, 0.663809 ), t2, tc.x );
  167.     float t3 = t;
  168.     ;
  169.  
  170.     tc2 *= vec2( mix( 0.56881, 0.77995, clamp(max( tc.x, tc.y ) * t, 0.0, 1.0) ), mix( 0.14354, 0.67658, clamp( tc2.x * tc2.y, 0.0, 1.0 ) ) ) + vec2( 0.5 );
  171.     tc2 = ( tc2 + 0.60522 * vec2( mix( mix( 0.99154, 0.20201, clamp(l * t2, 0.0, 1.0) ), 0.36409, clamp(abs(l) * t2, 0.0, 1.0) ), mix( mix( 0.86032, 0.56691, clamp(max( abs( tc2.x ), abs( tc2.y ) ) * t2, 0.0, 1.0) ), 0.04452, clamp(0.0 * t, 0.0, 1.0) ) ) );
  172.     l = length( tc2 );
  173.    
  174.                            tc2 = tc2; tc2.x = tc2.x; tc2.y = mix( mix( abs(tc2.y), mix( clamp( tc2.y, -0.59511, 0.804546 ), mix( clamp( tc2.y, -0.98941, 0.837602 ), tc2.y*tc2.y*tc2.y, tc.x ), tc.x ), tc.x ), clamp( tc2.y, -0.11180, 0.550428 ), clamp(min( tc.x, tc.y ) * t, 0.0, 1.0) );;
  175.                            tc2.x += tc2.y * pixelate(t,10.0) * 45.10730;
  176.                        
  177.     l2 = length( tc2 );
  178.  
  179.     vec3 inpos = vec3( tc2, t3 );
  180.     vec3 color = mix( getRandomBrightHue( 0.75592 + clamp( l, 0.0, 1.0 ) * 0.2 - 0.1, mix( mix( 0.42682, 0.01559, clamp(tc.x * t, 0.0, 1.0) ), mix( 0.53072, 0.13226, clamp(t * t, 0.0, 1.0) ), clamp(pixelate(tc.x,51.0) * t, 0.0, 1.0) ), mix( 0.91033, 0.05134, clamp( t, 0.0, 1.0 ) ) ), getRandomBrightHue( mix( mix( 0.20353, 0.04549, clamp(( l * mix( 0.851616, 6.79458, clamp(t2 * t, 0.0, 1.0) ) ) * t2, 0.0, 1.0) ), 0.99292, clamp( (clamp( tc, -0.06653, 0.956963 )).y, 0.0, 1.0 ) ), mix( 0.22843, 0.20808, clamp(1.0 - tc.x * t2, 0.0, 1.0) ), mix( mix( 0.13199, 0.38972, clamp( min( tc.x, tc.y ), 0.0, 1.0 ) ), mix( 0.59177, 0.30271, clamp(tc2.x * tc2.y * t2, 0.0, 1.0) ), clamp(ss(0.24665,0.76127,l2) * t, 0.0, 1.0) ) ), clamp(t2 * t2, 0.0, 1.0) ), pos = inpos;
  181.     float test = 0.0; vec3 pos2 = pos; pos2.xy *= 7.47828; color = mix( mix( getRandomBrightHue( 0.77460 + clamp(t * t, 0.0, 1.0) * 0.2 - 0.1, mix( 0.23412, 0.74623, clamp(t * t2, 0.0, 1.0) ), mix( mix( 0.39085, 0.24710, clamp(worm(0.482232, 0.542753, tc.y ) * t2, 0.0, 1.0) ), 0.83914, clamp(1.0 - tc.y * t, 0.0, 1.0) ) ), getRandomBrightHue( 0.37834, mix( 0.36722, 0.80442, clamp(1.0 - tc2.y * t, 0.0, 1.0) ), mix( mix( 0.75257, 0.76282, clamp(1.0 * t, 0.0, 1.0) ), 0.75262, clamp( l*l, 0.0, 1.0 ) ) ), clamp(max( abs( tc2.x ), abs( tc2.y ) ) * t, 0.0, 1.0) ), mix( getRandomHue( 0.39065 + clamp(min( tc.x, tc.y ) * t2, 0.0, 1.0) * 0.2 - 0.1, mix( 0.94017, 0.27305, clamp(l2 * l2 * t2, 0.0, 1.0) ), mix( 0.14513, 0.03958, clamp(l * l * t2, 0.0, 1.0) ) ), getRandomDarkHue( mix( mix( 0.36864, 0.50955, clamp(t2 * t, 0.0, 1.0) ), 0.25260, clamp(1.0 - tc.x * t2, 0.0, 1.0) ), mix( mix( 0.22387, 0.07702, clamp(tc2.y * t2, 0.0, 1.0) ), mix( 0.16419, 0.80450, clamp(t * t, 0.0, 1.0) ), clamp(tc2.x * tc2.y * t, 0.0, 1.0) ), mix( 0.25227, 0.22741, clamp( 1.0, 0.0, 1.0 ) ) ), clamp( max( abs( tc2.x ), abs( tc2.y ) ), 0.0, 1.0 ) ), clamp(t2 * t2, 0.0, 1.0) );  if( test > clamp(0.0 * t2, 0.0, 1.0) ) {
  182.             {
  183.                 vec3 pos2 = pos;
  184.                 pos2.xy *= 8.88202;    
  185.                
  186.                 {
  187.                     float s = 0.0, m = 0.0, a = 1.0;
  188.                     for( int i=0; i < 3; i++ ){
  189.                         float x = snoise( pos2 );
  190.                        
  191.                         s += a * x;
  192.                         m += a;
  193.                         a  = a * mix( 0.5, 0.69200, clamp(worm(0.159698, 0.791962, l ) * t, 0.0, 1.0) );
  194.                         pos2.xy *= 2.0;
  195.                     }
  196.                     test = s/m;
  197.                 }
  198.            
  199.                 test *= 0.98910;
  200.                
  201.             }
  202.          } else {
  203.             {
  204.                 vec3 pos2 = pos;
  205.                 pos2.xy *= 8.08357;    
  206.                
  207.                 {
  208.                     float y = 0.0;
  209.                     pos2 = inpos + vec3( 100.0 * 8 );
  210.                    
  211.                 {
  212.                     float s = 0.0, m = 0.0, a = 1.0;
  213.                     for( int i=0; i < 6; i++ ){
  214.                         float x = snoise( inpos );
  215.                         ;
  216.                         s += a * x;
  217.                         m += a;
  218.                         a  = a * mix( mix( 0.5, 0.488241, clamp(min( abs( tc2.x ), abs( tc2.y ) ) * t2, 0.0, 1.0) ), 0.682129, clamp( l2 * l2, 0.0, 1.0 ) );
  219.                         inpos.xy *= 2.71132;
  220.                     }
  221.                     test = s/m;
  222.                 }
  223.            
  224.                    
  225.                 {
  226.                     float s = 0.0, m = 0.0, a = 1.0;
  227.                     for( int i=0; i < 4; i++ ){
  228.                         float x = snoise( pos2 );
  229.                        
  230.                         s += a * x;
  231.                         m += a;
  232.                         a  = a * mix( mix( 0.5, 0.30125, clamp(1.0 - tc.y * t2, 0.0, 1.0) ), 0.593270, clamp( min( abs( tc2.x ), abs( tc2.y ) ), 0.0, 1.0 ) );
  233.                         pos2.xy *= 0.888326;
  234.                     }
  235.                     y = s/m;
  236.                 }
  237.            
  238.                     pos2 = vec3( test * 8.55904, y * 4.0, (test + y) * 8.72685 );
  239.                    
  240.                 {
  241.                     float s = 0.0, m = 0.0, a = 1.0;
  242.                     for( int i=0; i < 5; i++ ){
  243.                         float x = snoise( pos2 );
  244.                        
  245.                         s += a * x;
  246.                         m += a;
  247.                         a  = a * mix( 0.673136, 0.26057, clamp(tc.x * tc.y * t2, 0.0, 1.0) );
  248.                         pos2    *= mix( mix( 1.17342, 2.0, clamp( 0.15877, 0.0, 1.0 ) ), mix( 2.0, 1.19377, clamp(tc2.x * tc2.y * t, 0.0, 1.0) ), clamp( pixelate(t,69.0), 0.0, 1.0 ) );
  249.                     }
  250.                     test = s/m;
  251.                 }
  252.             ;
  253.                 }
  254.            
  255.                 test *= 0.00708;
  256.                
  257.             }
  258.          }; color  = mix( mix( getRandomBrightHue( 0.55099, mix( mix( 0.85069, 0.38298, clamp( l2 * l2, 0.0, 1.0 ) ), 0.41142, clamp(t*t*t * t2, 0.0, 1.0) ), mix( 0.53643, 0.81554, clamp( max( abs( fract(tc.x * 7.65456 ) - 0.5 ), abs( fract(tc.y * 6.44845 ) - 0.5 ) ), 0.0, 1.0 ) ) ), getRandomHue( mix( mix( 0.58922, 0.94825, clamp(mix( clamp( l, -0.08171, 0.898588 ), pixelate(l,99.0), tc.x ) * t2, 0.0, 1.0) ), mix( 0.58278, 0.54250, clamp( max( abs( fract(tc.x * 7.25074 ) - 0.5 ), abs( fract(tc.y * 2.68539 ) - 0.5 ) ), 0.0, 1.0 ) ), clamp( tc2.y, 0.0, 1.0 ) ), mix( mix( 0.34169, 0.68168, clamp(l * l * t2, 0.0, 1.0) ), mix( 0.85640, 0.79762, clamp(abs(tc.y) * t, 0.0, 1.0) ), clamp(mix( l*l*l, l, tc.x ) * t, 0.0, 1.0) ), mix( 0.06194, 0.45471, clamp(max( abs( fract(tc.x * 7.66083 ) - 0.5 ), abs( fract(tc.y * 7.95865 ) - 0.5 ) ) * t2, 0.0, 1.0) ) ), clamp( t2, 0.0, 1.0 ) ), mix( mix( getRandomBrightHue( 0.78683, mix( 0.06319, 0.40920, clamp(l * l * t2, 0.0, 1.0) ), mix( mix( 0.98756, 0.18989, clamp(t2 * t2, 0.0, 1.0) ), 0.69911, clamp( ( tc.y * mix( 0.992531, 5.39647, clamp( t2, 0.0, 1.0 ) ) ), 0.0, 1.0 ) ) ), getRandomBrightHue( 0.49905 + clamp( tc.x * tc.y, 0.0, 1.0 ) * 0.2 - 0.1, mix( 0.00932, 0.47917, clamp(1.0 - tc.y * t2, 0.0, 1.0) ), mix( mix( 0.01611, 0.00381, clamp(max( abs( fract(tc.x * 4.22798 ) - 0.5 ), abs( fract(tc.y * 2.78688 ) - 0.5 ) ) * t, 0.0, 1.0) ), mix( 0.61219, 0.63190, clamp(t * t, 0.0, 1.0) ), clamp( l * l, 0.0, 1.0 ) ) ), clamp(tc2.x * tc2.y * t, 0.0, 1.0) ), mix( getRandomHue( mix( mix( 0.64718, 0.58388, clamp( t, 0.0, 1.0 ) ), mix( 0.13320, 0.11722, clamp(tc2.x * t, 0.0, 1.0) ), clamp(l2 * l2 * t2, 0.0, 1.0) ), mix( mix( 0.27884, 0.84051, clamp( max( abs( fract(tc.x * 3.00840 ) - 0.5 ), abs( fract(tc.y * 3.94605 ) - 0.5 ) ), 0.0, 1.0 ) ), 0.87182, clamp( t, 0.0, 1.0 ) ), mix( 0.36724, 0.85921, clamp(clamp( t, -0.72894, 0.720378 ) * t2, 0.0, 1.0) ) ), getRandomBrightHue( 0.99984 + clamp(t * t2, 0.0, 1.0) * 0.2 - 0.1, mix( 0.49280, 0.30187, clamp( abs(t), 0.0, 1.0 ) ), mix( mix( 0.93132, 0.92204, clamp(min( abs( tc2.x ), abs( tc2.y ) ) * t2, 0.0, 1.0) ), mix( 0.67522, 0.46062, clamp(0.32869 * t2, 0.0, 1.0) ), clamp(0.79660 * t, 0.0, 1.0) ) ), clamp((tc).y * t2, 0.0, 1.0) ), clamp(0.92151 * t, 0.0, 1.0) ), test );
  259.     color = color;color = color;color = ss(0.90319,0.21962,color);color = color*color*color;;;
  260.     fragColor = vec4( color, 1.0 );
  261. }
  262.  
  263. #ifndef D_SHADERTOY
  264.     void main (void )
  265.     {
  266.         vec4 fragColor;
  267.         mainImage( fragColor, gl_FragCoord.xy );
  268.         gl_FragColor = fragColor;
  269.     }
  270. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement