Simple spirals demo
This demo shows off a few nice one-line spiral formulas.
I know there are already some great spiral effects posted here, but these show a few different easy ways to get some interesting looking spirals. Also illustrates the importance of happy accidents in discovery! This can just be placed on a plane white ColorRect object, and adjust the parameters to your liking.
The spiral_type
uniform lets you select from five different formulas.
Spirals 1-4 work by modulating the alpha on a single color.
- Spiral 1 creates a standard spiral with one hard edge and one soft edge.
- Spiral 2 is also a standard spiral but with both edges softer.
- Spiral 3 was a happy accident. I hadn’t lined up my radius and angle properly for the basic spiral, and in effort to fix it I went in the wrong (but a good) direction and came up with some nice “tiered” spirals that have interesting radial discontinuities. (Can get pretty close to a nice “fan”-like effect with right parameters. E.g.,
fade
=1.25,thickness
=0.3,tiers
=3,stretch
=3.) - Spiral 4 is another happy accident which gets another look. (To emphasize the difference in both, look at them both with a smaller
tier
value.
Spiral 5 shows how you can use the same formulas to make a two-color spiral by mixing, instead of changing the alpha.
Parameters:
spiral_type
– Select one of the above formulas.color
– The color of the spiral, or for spiral 5, the first color.rays
– (Spirals 1 and 2 only.) The number of rays eminating from the center. Also adjusts the tightness and thickness of each ray.speed
– How fast the spiral rotates.fade
– Exponent for decreasing alpha as approaching edge of texture — something like this may be necessary to avoid seeing edge of texture.thickness
– how thick each ray is.clockwise
– vs counterclockwise.tiers
– (Spirals 3 and 4 only) These spirals have a “concentric circle” effect, and this adjusts that.stretch
– (Spirals 3 and 4 only) adjusts the transparency fading within each circle.s5color2
– (Spiral 5 only) Second color for two color blending.
Shader code
shader_type canvas_item;
uniform int spiral_type : hint_range(1,5) = 1;
uniform vec3 color : source_color;
uniform float rays : hint_range(0.,20., 1) = 6;
uniform float speed : hint_range(0., 20., .01) = .5;
uniform float fade : hint_range(0., 3., .01) = .1;
uniform float thickness : hint_range(0., 1., .01) = .3;
uniform bool clockwise = true;
// not used by all sprials
uniform float tiers: hint_range(0., 20., 1) = 4;
uniform float stretch : hint_range(0., 10., .1) = 6.28;
uniform vec3 s5color2 : source_color;
void fragment() {
float r = length(.5 - UV);
float angle = atan(UV.y-.5, UV.x-.5);
COLOR.rgb = color;
if (spiral_type == 1)
COLOR.a = 1. - smoothstep(-.1, .1, fract((2.*r-(angle+PI)/TAU)*rays +
(clockwise?1.:-1.)* TIME*speed)-thickness);
if (spiral_type == 2)
COLOR.a = 1. - smoothstep(0., thickness, abs(.5 - fract((2.*r-(angle+PI)/TAU)*rays + (clockwise?1.:-1.)* TIME*speed) ) );
if (spiral_type == 3)
COLOR.a *= 1. - smoothstep(0.0, thickness, fract(tiers*(2.*r))/tiers - mod(tiers*(angle+PI)- (clockwise?1.:-1.)*TIME,TAU)/(stretch*tiers) );
if (spiral_type == 4)
COLOR.a *= 1. - smoothstep(0.0, thickness, abs(fract(tiers*(2.*r))/tiers - mod(tiers*(angle+PI)- (clockwise?1.:-1.)*TIME,TAU)/(stretch*tiers)) );
if (spiral_type == 5)
COLOR.rgb = mix(color, s5color2, thickness*fract((2.*r-(angle+PI)/TAU)*rays +
(clockwise?1.:-1.)* TIME*speed) );
COLOR.a *= pow(2.*(.5 - r), fade*4.);
}
[…] “happy accidents” along the way. The shader code and full explanation is posted to GodotShaders.com. Or you can skip to the shader […]