This is a shader that generates a wave effect.

I used this shader to create waves on a Line2D (node), allowing me to generate a persistent, wavy foam effect along the river’s path.

Shader code
shader_type canvas_item;

uniform float speed = 2.0;
uniform float frequency_y = 5.0;
uniform float frequency_x = 5.0;
uniform float amplitude_y = 10.0; // مقدار را کمتر کنید تا از کادر خارج نشود
uniform float amplitude_x = 10.0;
uniform float rotation_angle = 0.0;

void vertex() {
    // ۱. تبدیل زاویه به رادیان و ساخت ماتریس دوران
    float rad = radians(rotation_angle);
    mat2 rot = mat2(vec2(cos(rad), -sin(rad)), vec2(sin(rad), cos(rad)));

    // ۲. اعمال دوران اولیه به راس‌ها
    vec2 pos = VERTEX.xy;

    // ۳. محاسبه جابجایی متوازن (Wave)
    // حذف UV.x از انتهای فرمول باعث می‌شود کل بدنه‌ی اسپرایت به یک اندازه تکان بخورد
    float wave_y = sin((UV.x * frequency_y) + (TIME * speed)) * amplitude_y;
    float wave_x = cos((UV.y * frequency_x) + (TIME * speed)) * amplitude_x;

    // ۴. اضافه کردن نوسان به پوزیشن
    pos.x += wave_x;
    pos.y += wave_y;

    // ۵. بازگرداندن پوزیشن نهایی با احتساب دوران
    VERTEX.xy = rot * pos;
}
Live Preview
Tags
wave
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from mohsensd1373

This is a shader for river movement within a Line2D node

wave with rotate item

Related shaders

Rhythmic Color Pulse Shader (Sine Wave Brightness and Tint)

A simple shader of Mana Wave Circle

Wave Line Shader (with asymmetric falloff feature)

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments