Rotating Radial Stripes

Rotating radial stripes.

Rotation center point, speed, divisions and color modifier can be set via shader parameters.

Shader code
shader_type canvas_item;

/** The center point of the effect. */
uniform vec2 center = vec2(0.5);

/** The number of stripes. */
uniform int stripes = 24;

/** The rotation speed. Set to 0 for a static effect. */ 
uniform float speed: hint_range(0.0, 5.0, 0.1) = 0.2;

/** Rotation direction: 1 for clockwise and -1 for counter-clockwise. */
uniform int direction: hint_range(-1, 1, 2) = 1;

/** The modifier to apply to the pixels when inside a stripe. The final color will be multiplied by this value. */
uniform vec3 color_modifier = vec3(0.9);


void fragment() {
	// Fix aspect ratio issue.
	vec2 uv_deriv = fwidthFine(UV);
	float aspect_ratio = uv_deriv.y / uv_deriv.x;
	vec2 corrected_uv = UV * vec2(aspect_ratio, 1.0);
	vec2 corrected_center = center * vec2(aspect_ratio, 1.0);
	
	// Get the angle between the center of the effect and the UV.
	vec2 dir = corrected_center - corrected_uv;
	float angle = atan(dir.y, dir.x) - (TIME * speed * float(direction));
	// Check if the angle is in a stripe or not.
	if (mod(floor(angle / (TAU / float(stripes))), 2) == 0.0) {
		// If yes, apply the modifier to the pixel.
		COLOR.rgb *= color_modifier;
	}
}
Tags
2d, radial, stripes
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 fruityfred

Two growing hexagons grids

Related shaders

Rotating Quadrant

Animated Stripes

Simple Radial Progress Bar

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments