Created
November 2, 2023 18:14
-
-
Save marinho/9045ba5159dd014b85241f095bf328a7 to your computer and use it in GitHub Desktop.
SImple shaders in GLSL
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
/* | |
* http://editor.thebookofshaders.com/ | |
*/ | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
#define PI 3.14159265359 | |
uniform vec2 u_resolution; | |
uniform vec2 u_mouse; | |
uniform float u_time; | |
float TIME = u_time; | |
vec2 CENTER = vec2(.5, .5); | |
float direction = 1.; // if -.1 it moves from outside to inside | |
float drawSmoothLineCircle(vec2 p, float d, float stroke, float smooth, vec2 uv) | |
{ | |
float dist = distance(p, uv); | |
float half_stroke = stroke * .5; | |
float d1 = d - half_stroke; | |
float d2 = d + half_stroke; | |
float diff = abs(dist - d); | |
return (dist >= d1 && dist <= d2) ? smoothstep(1., smooth, diff / half_stroke) : .0; | |
} | |
float pulseCircle(vec2 p, float speed, vec2 uv) { | |
float pulse = fract(speed); | |
return drawSmoothLineCircle(p, .5 * pulse, .03, .0, uv) * (1.-pulse); | |
} | |
void main() { | |
vec2 UV = gl_FragCoord.xy/u_resolution; | |
vec3 ALBEDO = vec3(1.); | |
float ALPHA = .0; | |
ALPHA = pulseCircle(CENTER, (TIME - 1.2) * .3 * direction, UV) | |
+ pulseCircle(CENTER, (TIME - 0.4) * .3 * direction, UV) | |
+ pulseCircle(CENTER, (TIME + 0.4) * .3 * direction, UV) | |
+ pulseCircle(CENTER, (TIME + 1.2) * .3 * direction, UV); | |
gl_FragColor = vec4(ALBEDO, ALPHA); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment