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

aurora_effect

By: a guest on Jan 30th, 2012  |  syntax: C  |  size: 1.06 KB  |  views: 143  |  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. /*
  2. Aurora Effect Frag Shader
  3.  
  4. by Eddie Lee (twitter: @eddietree)
  5. http://illogictree.com
  6. Jan 30, 2012
  7. */
  8.  
  9. #version 110
  10.  
  11. varying vec2 uv;
  12.  
  13. uniform sampler2D tex;
  14. uniform vec4 Misc;
  15. uniform vec4 Color;
  16.  
  17. const float PI = 3.14159;
  18.  
  19. void main(void)
  20. {
  21.         float time = Misc.x;            // current time
  22.         float timeOffset = Misc.y;      // if multiple auroras, have time offset
  23.         float direction = Misc.z;       // direction that the effect is fading
  24.        
  25.         // fetch perlin height
  26.         vec4 perlinTex =  texture2D(tex, vec2(uv.x, time*0.00003+timeOffset) );
  27.         float height = perlinTex.x;    
  28.         discard( height < uv.y );
  29.        
  30.         // gentle fading
  31.         float alphaBuffer = 0.3; // buffer from edge
  32.         float alpha = smoothstep(0.0, height*(1.0-alphaBuffer), uv.y );
  33.         alpha *= (1.0-smoothstep( height*(1.0-alphaBuffer*1.5), height, uv.y ));
  34.         alpha *= smoothstep(0.0, alphaBuffer, uv.x);
  35.         alpha *= 1.0-smoothstep(1.0-alphaBuffer, 1.0, uv.x);
  36.         alpha *= sin( PI*2.0*(uv.x+timeOffset)+direction*time*0.0009)*0.5+0.5;
  37.         alpha *= 0.2f;
  38.        
  39.         vec3 auroraColor = Color.xyz;
  40.         gl_FragColor = vec4(auroraColor, alpha);
  41. }