Created
August 14, 2018 00:51
-
-
Save aziis98/41fba40e8f4191d29790121b464daae0 to your computer and use it in GitHub Desktop.
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
| vec4 stroke(float distance, float linewidth, float antialias, vec4 stroke) | |
| { | |
| float t = linewidth / 2.0 - antialias; | |
| float signed_distance = distance; | |
| float border_distance = abs(signed_distance) - t; | |
| float alpha = border_distance / antialias; | |
| alpha = exp(-alpha * alpha); | |
| if( border_distance < 0.0 ) | |
| return stroke; | |
| else | |
| return vec4(stroke.rgb, stroke.a * alpha); | |
| } | |
| float eq_test_1(vec2 u, vec2 center, float radius) | |
| { | |
| vec2 v = u - center; | |
| return abs(sqrt(v.x * v.x + v.y * v.y * abs(v.y + v.x * v.x) / 20.0) - radius); | |
| } | |
| float eq_circle(vec2 u, vec2 center, float radius) | |
| { | |
| vec2 v = u - center; | |
| return abs(sqrt(v.x * v.x + v.y * v.y) - radius); | |
| } | |
| float eq_line(vec2 u, float a, float b, float c) | |
| { | |
| return a * u.x + b * u.y + c; | |
| } | |
| void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
| { | |
| //vec4 col = stroke(eq_line(fragCoord, 0.5, -1.0, 0.25), | |
| // 2.0, 1.0, vec4(0.5, 0.5, 0.5, 1.0)); | |
| vec4 col = stroke(eq_test_1(fragCoord, vec2(100.0, 100.0), 50.0), 2.0, 1.0, vec4(0.5, 0.5, 0.5, 1.0)); | |
| fragColor = vec4(1.0) * (1.0 - col.a) + col * col.a; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment