Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Simple passthrough fragment shader
  3. //
  4. varying vec2 v_vTexcoord;
  5. varying vec4 v_vColour;
  6.  
  7. const int octaves = 4;
  8.  
  9. //you can change these to uniforms
  10. const float size = 40.0;
  11. const float speed = 0.002;
  12. const float strength = 0.01;
  13.  
  14. //pass in current_time
  15. uniform float time;
  16.  
  17.  
  18. float rand(vec2 coord){
  19.     return fract(sin(dot(coord, vec2(56,78))*1000.0)*1000.0);
  20. }
  21.  
  22. float noise(vec2 coord){
  23.     vec2 i = floor(coord);
  24.     vec2 f = fract(coord);
  25.    
  26.     float a = rand(i);
  27.     float b = rand(i + vec2(1.0,0.0));
  28.     float c = rand(i + vec2(0.0,1.0));
  29.     float d = rand(i + vec2(1.0, 1.0));
  30.    
  31.     vec2 cubic = f * f * (3.0 - 2.0 * f);
  32.    
  33.     return mix( a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x *cubic.y;
  34. }
  35.  
  36. float fbm(vec2 coord){
  37.     float value = 0.0;
  38.     float scale = 0.5;
  39.    
  40.     for(int i = 0; i < octaves; i++){
  41.         value += noise(coord) * scale;
  42.         coord *= 2.0;
  43.         scale *= 0.5;
  44.     }
  45.     return value;
  46. }
  47.  
  48. void main()
  49. {  
  50.     vec2 coord = v_vTexcoord * size;
  51.    
  52.     vec2 noise;
  53.     noise.x = fract(fbm(coord + time * speed)) * strength;
  54.     noise.y = fract(fbm(coord + time * speed)) * strength;
  55.    
  56.    
  57.     gl_FragColor = texture2D( gm_BaseTexture, v_vTexcoord + noise);
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement