Created
June 1, 2024 20:41
-
-
Save arceryz/3c8cad4c81af0965d5251010111390d5 to your computer and use it in GitHub Desktop.
Godot Loading Circle Shader
This file contains 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; | |
uniform vec3 rings[5]; // X=innerRadius, Y=outerRadius, Z=speed | |
uniform float timeScale = 1.0f; | |
uniform float blur = 1.0f; | |
void fragment() { | |
vec2 p = 2.0*UV.xy - vec2(1.0); | |
float radius = length(p); | |
float angle = (atan(p.y, p.x)+PI) / (2.0*PI); | |
float t = TIME*timeScale; | |
float alpha = 0.0f; | |
for (int i = 0; i < rings.length(); i++) { | |
vec3 ring = rings[i]; | |
if (ring.z == 0.0) continue; | |
bool flip = int(abs(ring.z*t))%2 - 1 == 0; | |
float f = mod(ring.z*t,1.0); | |
float lower = flip ? f: 0.0f; | |
float upper = flip ? 1.0f: f; | |
float dist = abs((ring.x+ring.y)/2.0 - radius) - (ring.y-ring.x)/2.0; | |
if (dist < blur && lower < angle && angle < upper) { | |
alpha = max(alpha, 1.0 - dist/blur * 100.0); | |
} | |
} | |
COLOR.rgb = vec3(1.0f); | |
COLOR.a = alpha; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment