Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: xoryouyou on Oct 25th, 2011  |  syntax: C  |  size: 2.39 KB  |  views: 363  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4. uniform float time;
  5. uniform vec2 resolution;
  6.  
  7. /// Thx to ASHIMA https://github.com/ashima/webgl-noise/wiki
  8.  
  9. vec3 mod289(vec3 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
  10. vec2 mod289(vec2 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
  11. vec3 permute(vec3 x){return mod289(((x*34.0)+1.0)*x);}
  12. float snoise(vec2 v){
  13.   const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
  14.                       0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
  15.                      -0.577350269189626, // -1.0 + 2.0 * C.x
  16.                       0.024390243902439); // 1.0 / 41.0
  17.   vec2 i = floor(v + dot(v, C.yy) );
  18.   vec2 x0 = v - i + dot(i, C.xx);
  19.   vec2 i1;
  20.   //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
  21.   //i1.y = 1.0 - i1.x;
  22.   i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
  23.   // x0 = x0 - 0.0 + 0.0 * C.xx ;
  24.   // x1 = x0 - i1 + 1.0 * C.xx ;
  25.   // x2 = x0 - 1.0 + 2.0 * C.xx ;
  26.   vec4 x12 = x0.xyxy + C.xxzz;
  27.   x12.xy -= i1;
  28.   i = mod289(i);
  29.   vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) + i.x + vec3(0.0, i1.x, 1.0 ));
  30.   vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
  31.   m = m*m ;
  32.   m = m*m ;
  33.   vec3 x = 2.0 * fract(p * C.www) - 1.0;
  34.   vec3 h = abs(x) - 0.5;
  35.   vec3 ox = floor(x + 0.5);
  36.   vec3 a0 = x - ox;
  37.   m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
  38.   vec3 g;
  39.   g.x = a0.x * x0.x + h.x * x0.y;
  40.   g.yz = a0.yz * x12.xz + h.yz * x12.yw;
  41.   return 130.0 * dot(m, g);
  42. }
  43.  
  44. float f(float x,float z){float t=time*0.5;float d=distance(vec2(1.0,1.0),vec2(x,z))*.55;return (x*x)*0.015*z+(d+(sin(d/16.0)*d)+(sin(x*1.2+t*1.7)*sin(z*0.85-t*1.5)*sin(t)*.5+sin(x*0.12-t*1.2)*sin(z*1.45+t*1.3)*sin(t*1.2)*.5+sin(x*6.36-t*0.16)*sin(z*5.73+t*1.63)*.25+sin(x*4.14+t*0.13)*sin(z*4.14-t*0.14)*.25));}
  45. float r(vec3 o, vec3 d){const float delT=0.01;const float minT=0.1;const float maxT=10.0;float l=10.0;float s=0.0;vec3 tp=o+d*l/2.0;if(tp.y<f(tp.x,tp.z)){tp=o+d*l/4.0;s=l/4.0;}else{tp=o+d*(l/2.0+l/4.0);if(tp.y<f(tp.x,tp.z)){s=l/2.0;}else{s=l/2.0+l/4.0;}}vec3 p;for(float t=minT;t<maxT;t+=delT){p=o+d*(t+s);if(p.y<f(p.x,p.z)){return max(dot(vec3(-p.y,p.x,p.z),vec3((sin(time*6.5)/4.0)-.65,0.0,0.15)),0.0);}}return snoise(vec2(p.x,p.z)*(time/64.0));}void main(void){vec2 p=-1.0+2.0*gl_FragCoord.xy/resolution.xy;float v=r(vec3(0.0,20.0,.0),vec3(p.x,p.y-0.95,-1.0));gl_FragColor =vec4(v/8.0,v/4.0,v,1.0);}