Rotate Texture

Rotate or spin a texture around its center. For best results, use textures that don’t have pixels on the edges.

Shader code
shader_type canvas_item;

uniform sampler2D spin_texture;
uniform bool clockwise = true;
uniform float speed : hint_range(0.0, 2.0) = 1.0;

vec2 rotate(vec2 uv, vec2 pivot, float angle)
{
	mat2 rotation = mat2(vec2(sin(angle), -cos(angle)),
			vec2(cos(angle), sin(angle)));
    
    uv -= pivot;
    uv = uv * rotation;
    uv += pivot;
    return uv;
}

void fragment()
{
	float direction = clockwise ? 1.0 : -1.0;
	vec2 rotated_uv = rotate(UV, vec2(0.5), TIME * speed * direction);
	COLOR = texture(spin_texture, rotated_uv);
}
Tags
rotate, rotation, spin
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

wave with rotate item

math – rotate uv

Texture population using Texture

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments