Rotation Displacement Vertex Shader

When this shader is applied to a Polygon2D’s material, each vertex is displaced away from a point given in local space. Each vertex will oscillate its displacement, moving slightly towards and away from the given position in accordance to a sine wave. These oscillations create a wave effect that travels around the polygon if the given position is the center of the polygon in local space. A sprite can be set to the texture of this polygon to apply this effect to an image of your choice.

Shader code
shader_type canvas_item;

uniform vec2 center = vec2(50.0, 50.0); // Set this to your polygon's center in local space.
uniform float amplitude : hint_range(0.0, 1.0) = 0.1;
uniform float frequency = 1.0;

void vertex() {
    // Translate vertex position so the center is at (0, 0).
    vec2 pos = VERTEX - center;
    
    // Compute the angle of the vertex relative to the center.
    // This angle will be used to offset the sine wave phase.
    float angle = atan(pos.y, pos.x);
    
    // Create a sine wave where each vertex is offset by its angle.
    // You can adjust the formula as desired.
    float wave = sin(TIME * frequency - angle);
    
    // Use the wave value to scale the vertex's distance from the center.
    pos *= 1.0 + amplitude * wave;
    
    // Move the vertex back to the original coordinate space.
    VERTEX = pos + center;
}
Tags
displacement, rotation, rotational, vertex
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

Vertex Displacement/Height Material

Noise vertex displacement

3D Rotation in 2D

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments