wind_sway.tres 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. [gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://djwm5nol3d801"]
  2. [sub_resource type="Shader" id="1"]
  3. code = "// original wind shader from https://github.com/Maujoe/godot-simple-wind-shader-2d/tree/master/assets/maujoe.simple_wind_shader_2d
  4. // original script modified by HungryProton so that the assets are moving differently : https://pastebin.com/VL3AfV8D
  5. //
  6. // speed - The speed of the wind movement.
  7. // minStrength - The minimal strength of the wind movement.
  8. // maxStrength - The maximal strength of the wind movement.
  9. // strengthScale - Scalefactor for the wind strength.
  10. // interval - The time between minimal and maximal strength changes.
  11. // detail - The detail (number of waves) of the wind movement.
  12. // distortion - The strength of geometry distortion.
  13. // heightOffset - The height where the wind begins to move. By default 0.0.
  14. shader_type canvas_item;
  15. render_mode blend_mix;
  16. // Wind settings.
  17. uniform float speed = 1.0;
  18. uniform float minStrength : hint_range(0.0, 1.0) = 0.05;
  19. uniform float maxStrength : hint_range(0.0, 1.0) = 0.01;
  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 : hint_range(0.0, 1.0);
  25. // With the offset value, you can if you want different moves for each asset. Just put a random value (1, 2, 3) in the editor. Don't forget to mark the material as unique if you use this
  26. uniform float offset = 0;
  27. float getWind(vec2 vertex, vec2 uv, float time){
  28. float diff = pow(maxStrength - minStrength, 2.0);
  29. float strength = clamp(minStrength + diff + sin(time / interval) * diff, minStrength, maxStrength) * strengthScale;
  30. float wind = (sin(time) + cos(time * detail)) * strength * max(0.0, (1.0-uv.y) - heightOffset);
  31. return wind;
  32. }
  33. void vertex() {
  34. vec4 pos = MODEL_MATRIX * vec4(0.0, 0.0, 0.0, 1.0);
  35. float time = TIME * speed + offset;
  36. //float time = TIME * speed + pos.x * pos.y ; not working when moving...
  37. VERTEX.x += getWind(VERTEX.xy, UV, time);
  38. }"
  39. [resource]
  40. shader = SubResource("1")
  41. shader_parameter/speed = 1.0
  42. shader_parameter/minStrength = 0.05
  43. shader_parameter/maxStrength = 0.01
  44. shader_parameter/strengthScale = 100.0
  45. shader_parameter/interval = 3.5
  46. shader_parameter/detail = 1.0
  47. shader_parameter/distortion = null
  48. shader_parameter/heightOffset = null
  49. shader_parameter/offset = 0.0