Skip to content

Instantly share code, notes, and snippets.

@aziis98
Created August 14, 2018 00:51
Show Gist options
  • Select an option

  • Save aziis98/41fba40e8f4191d29790121b464daae0 to your computer and use it in GitHub Desktop.

Select an option

Save aziis98/41fba40e8f4191d29790121b464daae0 to your computer and use it in GitHub Desktop.
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