Last active
December 9, 2022 02:04
-
-
Save andrew-wilkes/683efb116133d5b73b0a56701d0fb052 to your computer and use it in GitHub Desktop.
godot spiral shader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type canvas_item; | |
const float PI = 3.14159265358979323846; | |
const float w = 0.1; // Width of line | |
void fragment() { | |
float dis = 0.1; // Displacement (spacing) of lines | |
// Get an angle value around a circle of 0.0 .. 1.0 | |
vec2 pt = (UV - vec2(0.5)) * 2.0; // +/-1.0 | |
float ang = (atan(pt.y / pt.x) / PI * 2.0 + 1.0) / 4.0; // 0.0 .. 0.5 | |
if (pt.x < 0.0) ang += 0.5; | |
// Get a color value based on a point on the spiral | |
float radius = ang * dis + length(pt); | |
float circles = fract(radius / dis); // 0 .. 1 | |
// Anti-alias the curve | |
if (radius < 1.0) | |
COLOR = (smoothstep(circles - w, circles, w) - smoothstep(circles, circles + w, w)) * vec4(0.0, 0.8, 0.4, 1.0); | |
else | |
COLOR.a = 0.0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment