Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
  2. vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
  3. vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
  4. vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }
  5. vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); }
  6.  
  7. /// <summary>
  8. /// 2D Noise by Ian McEwan, Ashima Arts.
  9. /// <summary>
  10. float snoise_2D (vec2 v)
  11. {
  12. const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
  13. 0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
  14. -0.577350269189626, // -1.0 + 2.0 * C.x
  15. 0.024390243902439); // 1.0 / 41.0
  16.  
  17. // First corner
  18. vec2 i = floor(v + dot(v, C.yy) );
  19. vec2 x0 = v - i + dot(i, C.xx);
  20.  
  21. // Other corners
  22. vec2 i1;
  23. i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
  24. vec4 x12 = x0.xyxy + C.xxzz;
  25. x12.xy -= i1;
  26.  
  27. // Permutations
  28. i = mod289(i); // Avoid truncation effects in permutation
  29. vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
  30. + i.x + vec3(0.0, i1.x, 1.0 ));
  31.  
  32. vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
  33. m = m*m ;
  34. m = m*m ;
  35.  
  36. // Gradients: 41 points uniformly over a line, mapped onto a diamond.
  37. // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
  38.  
  39. vec3 x = 2.0 * fract(p * C.www) - 1.0;
  40. vec3 h = abs(x) - 0.5;
  41. vec3 ox = floor(x + 0.5);
  42. vec3 a0 = x - ox;
  43.  
  44. // Normalise gradients implicitly by scaling m
  45. // Approximation of: m *= inversesqrt( a0*a0 + h*h );
  46. m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
  47.  
  48. // Compute final noise value at P
  49. vec3 g;
  50. g.x = a0.x * x0.x + h.x * x0.y;
  51. g.yz = a0.yz * x12.xz + h.yz * x12.yw;
  52. return 130.0 * dot(m, g);
  53. }
  54. //DEBUG
  55. #define DROPS_TURBSIZE 15.f
  56. #define DROPS_TURBSHIFT vec4(0.35, 1, 0, 1)
  57. #define DROPS_TURBTIME sin(0.1/3.f)
  58. #define DROPS_TURBCOF 0.33
  59.  
  60.  
  61. vec2 l_jh2(vec2 f, vec4 s, float l)
  62. {
  63. vec2 x = s.xy, V = s.zw;
  64. float y = snoise_2D(f * vec2(DROPS_TURBSIZE, DROPS_TURBSIZE))*.5;
  65. vec4 r = vec4(y, y, y, 1);
  66. r.xy = vec2(r.x + r.z/4.f, r.y + r.x/2.f);
  67. r -= 1.5;
  68. r *= l;
  69. return (f + (x + V) *r.xy);
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. float noise(float t)
  89. {
  90. return fract(sin(t*10.0)*10.0);
  91. }
  92.  
  93. float noise2(vec2 p)
  94. {
  95. return noise(p.x + noise(p.y));
  96. }
  97.  
  98. float raindot(vec2 uv, vec2 id, float t)
  99. {
  100. vec2 p = 0.25 + 0.25 * vec2(noise2(id), noise2(id + vec2(1.0, 0.0)));
  101. float r = clamp(0.5 - mod(t + noise2(id), 1.0), 0.0, 1.0);
  102. return smoothstep(0.3 * r, 0.0, length(p - uv));
  103. }
  104.  
  105. /////////////////////////////////////////////////////////////////////////////
  106. //rain pass
  107. #define r_size 5.f //raindrops size
  108. #define r_intensity 1.0
  109.  
  110. void mainImage( out vec4 fragColor, in vec2 fragCoord )
  111. {
  112. //clean img and coords
  113. vec4 final;
  114. vec2 uv = fragCoord.xy / iResolution.xy;
  115.  
  116. final = texture( iChannel0, uv);
  117.  
  118. //rain pass
  119. float v = raindot(fract(mix(uv, l_jh2(uv, DROPS_TURBSHIFT, DROPS_TURBTIME), DROPS_TURBCOF) * r_size + vec2(0, 0.1 * iTime)), floor(uv * r_size + vec2(0, 0.1 * iTime)), iTime);
  120. vec2 rain = vec2(vec2(dFdx(v*0.5f), dFdy(v*0.5f)) / (v + r_size))*r_intensity;
  121. vec4 mask_rain = texture(iChannel0, uv+rain);
  122.  
  123.  
  124. /////////////////////////////////////////////////////////////////////////////
  125. //final combine
  126.  
  127. final = mask_rain;
  128. fragColor = final;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement