shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_disabled;

//Wire color
uniform vec4 albedo_color : source_color = vec4(0.1, 0.1, 0.1, 1.0);

global uniform float global_wind_strength;
global uniform float global_wind_speed;
global uniform float global_wind_fade;

void vertex() {
    //COLOR.r is the drawing. 0 -> lampost (no move); 1.0 is the center of the wire
    float movement = COLOR.r;
    float wind_amount = global_wind_strength * global_wind_fade;

    //Create a wave (based on position and time to be random)
    float wind_wave = 0.0;
    float vertical_wave = 0.0;
    if (global_wind_speed > 0.0 && wind_amount > 0.0) {
        wind_wave = sin(TIME * global_wind_speed + NODE_POSITION_WORLD.x * 0.5 + NODE_POSITION_WORLD.z * 0.35) * wind_amount;
        vertical_wave = sin(TIME * global_wind_speed * 0.7 + NODE_POSITION_WORLD.z * 0.35) * wind_amount;
    }

    VERTEX.x += wind_wave * 0.28 * movement;
    VERTEX.y += vertical_wave * 0.125 * movement;
    VERTEX.z += wind_wave * 0.24 * movement;
}

void fragment() {
    ALBEDO = albedo_color.rgb;
    ROUGHNESS = 0.9;
}
