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;
}