shader_type canvas_item;

uniform float sway_speed : hint_range(0.1, 10.0) = 1.0;
uniform float sway_magnitude : hint_range(0.0, 50.0) = 10.0;
uniform float randomness_factor : hint_range(0.0, 1.0) = 0.5;
uniform sampler2D noise_texture ;


void vertex() {
    float time = TIME * sway_speed;

    // Sample the noise texture using the vertex position
    vec2 noise_uv = VERTEX.xy * 0.1;
    float noise_value = texture(noise_texture, noise_uv).r;
    float randomness = noise_value * randomness_factor;

    // Calculate the sway offset
    float sway_offset = sin(time + VERTEX.y * 0.1) * sway_magnitude + randomness * sway_magnitude;

    VERTEX.x += sway_offset;
}
