Advertisement
Outside_of_Awareness

Godot Grass Shader to Add Colour and Wind

Feb 18th, 2024 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type spatial;
  2. // Show rear-facing grass
  3. render_mode cull_disabled, world_vertex_coords;
  4.  
  5. // Grass Colour Shader
  6. uniform vec3 colour: source_color;
  7. uniform vec3 colour2: source_color;
  8. uniform sampler2D noise2;
  9. uniform float noiseScale = 20.0;
  10.  
  11. varying vec3 worldPos;
  12.  
  13. //  Godot Simple Wind Vertex Shader
  14. group_uniforms wind;
  15. uniform sampler2D noise_tex;
  16. uniform float wind_speed = .1;
  17. uniform float wind_strength = .2;
  18.  
  19. void vertex() {
  20.     // Called for every vertex the material is visible on.
  21.     worldPos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
  22.  
  23.     float offset = TIME * wind_speed;
  24.     float noise = texture(noise_tex, NODE_POSITION_WORLD.xz-offset).r;
  25.     noise -= .5;
  26.     noise *= wind_strength;
  27.     VERTEX.x += noise * length(VERTEX.y - NODE_POSITION_WORLD.y) * length(VERTEX.xz);
  28. }
  29.  
  30. void fragment() {
  31.     // Called for every pixel the material is visible on.
  32.     vec3 noiseLevel = texture(noise2, worldPos.xz / noiseScale).rgb;
  33.     ALBEDO = mix(colour, colour2, UV.y) * mix(colour, colour2, noiseLevel.r);
  34.     if (!FRONT_FACING) {
  35.         NORMAL = -NORMAL;
  36.     }
  37. }
  38.  
  39. //void light() {
  40.     // Called for every pixel for every light affecting the material.
  41.     // Uncomment to replace the default light processing function with this one.
  42. //}
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement