Advertisement
Guest User

2D wind shader modified

a guest
Jan 7th, 2021
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // original wind shader from https://github.com/Maujoe/godot-simple-wind-shader-2d/tree/master/assets/maujoe.simple_wind_shader_2d
  2. // original script modified by HungryProton so that the assets are moving differently
  3. //
  4. // speed - The speed of the wind movement.
  5. // minStrength - The minimal strength of the wind movement.
  6. // maxStrength - The maximal strength of the wind movement.
  7. // strengthScale - Scalefactor for the wind strength.
  8. // interval - The time between minimal and maximal strength changes.
  9. // detail - The detail (number of waves) of the wind movement.
  10. // distortion - The strength of geometry distortion.
  11. // heightOffset - The height where the wind begins to move. By default 0.0.
  12.  
  13. shader_type canvas_item;
  14. render_mode blend_mix;
  15.  
  16. // Wind settings.
  17. uniform float speed = 1.0;
  18. uniform float minStrength : hint_range(0.0, 1.0);
  19. uniform float maxStrength : hint_range(0.0, 1.0);
  20. uniform float strengthScale = 100.0;
  21. uniform float interval = 3.5;
  22. uniform float detail = 1.0;
  23. uniform float distortion : hint_range(0.0, 1.0);
  24. uniform float heightOffset = 0.0;
  25.  
  26. float getWind(vec2 vertex, vec2 uv, float time){
  27.     float diff = pow(maxStrength - minStrength, 2.0);
  28.     float strength = clamp(minStrength + diff + sin(time / interval) * diff, minStrength, maxStrength) * strengthScale;
  29.     float wind = (sin(time) + cos(time * detail)) * strength * max(0.0, (1.0-uv.y) - heightOffset);
  30.    
  31.     return wind;
  32.     }
  33.  
  34. void vertex() {
  35.     vec4 pos = WORLD_MATRIX * vec4(0.0, 0.0, 0.0, 1.0);
  36.     float time = TIME * speed + pos.x * pos.y;
  37.     VERTEX.x += getWind(VERTEX.xy, UV, time);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement