Simple sine wave shader

Usage

  1. Add the shader to a Color Rect or a Sprite
  2. Adjust the values to your usecase
Shader code
shader_type canvas_item;

uniform float time;
uniform float amplitude : hint_range(0.0, 100.0) = 20.0;
uniform float frequency : hint_range(0.1, 10.0) = 2.0;
uniform float speed : hint_range(0.0, 10.0) = 2.0;
uniform float thickness : hint_range(0.5, 100.0) = 2.0;
uniform vec4 line_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec2 resolution = vec2(256.0, 256.0); // width, height of the rect or texture

void fragment() {
    float x = UV.x;
    float y = UV.y;

    float wave_y = 0.5 + amplitude * sin(x * frequency * 6.2831 + time * speed) / resolution.y;

    float distance = abs(y - wave_y);
    if (distance < thickness / resolution.y) {
        COLOR = line_color;
    } else {
        discard;
    }
}
Live Preview
Tags
curve, 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.

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments