Advertisement
Guest User

aurora_effect

a guest
Jan 30th, 2012
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement