2023-12-09 15:18:11 +00:00
|
|
|
uniform lowp float opacity;
|
2023-12-06 12:32:38 +00:00
|
|
|
// arc
|
|
|
|
uniform lowp float radius; // arc's radius [0.0, 1.0]
|
2023-12-09 15:18:11 +00:00
|
|
|
uniform lowp float thickness; // arc's thickness [0.0, 1.0]
|
|
|
|
uniform lowp float startAngle; // arc's start angle [rad]
|
|
|
|
uniform lowp float spanAngle; // arc's span angle [rad]
|
2023-12-06 12:32:38 +00:00
|
|
|
// shadow
|
|
|
|
uniform lowp vec4 color; // shadow's color
|
|
|
|
uniform lowp vec2 offset; // shadow's offset (x,y) : [-1.0, +1.0]x[-1.0,+1.0]
|
2023-12-09 15:18:11 +00:00
|
|
|
uniform lowp float extend; // shadow length [0.0, 1.0]
|
|
|
|
// position
|
|
|
|
varying lowp vec2 coord; // [-1.0,+1.0]x[-1.0,+1.0]
|
2023-12-04 16:33:28 +00:00
|
|
|
|
|
|
|
float sdRing( in vec2 p, in vec2 n, in float r, in float th )
|
|
|
|
{
|
|
|
|
p.x = abs(p.x);
|
|
|
|
|
|
|
|
p = mat2(n.x,n.y,-n.y,n.x)*p;
|
|
|
|
|
|
|
|
return max( abs(length(p)-r)-th*0.5,
|
|
|
|
length(vec2(p.x,max(0.0,abs(r-p.y)-th*0.5)))*sign(p.x) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
2023-12-09 15:18:11 +00:00
|
|
|
{
|
2023-12-04 16:33:28 +00:00
|
|
|
// rotation
|
2023-12-09 15:18:11 +00:00
|
|
|
vec2 p = coord + offset;
|
|
|
|
float ra = -startAngle - spanAngle / 2.0;
|
2023-12-05 14:13:31 +00:00
|
|
|
{
|
2023-12-04 16:33:28 +00:00
|
|
|
float sin_ra = sin(ra);
|
|
|
|
float cos_ra = cos(ra);
|
2023-12-05 14:13:31 +00:00
|
|
|
mat2 transform = mat2
|
|
|
|
(
|
|
|
|
cos_ra, -sin_ra,
|
|
|
|
sin_ra, cos_ra
|
|
|
|
);
|
2023-12-09 15:18:11 +00:00
|
|
|
|
2023-12-05 14:13:31 +00:00
|
|
|
p = transform * p;
|
2023-12-04 16:33:28 +00:00
|
|
|
}
|
2023-12-09 15:18:11 +00:00
|
|
|
|
|
|
|
float t = abs(spanAngle) / 2.0; // half span angle
|
|
|
|
vec2 cs = vec2(cos(t),sin(t));
|
|
|
|
float d = sdRing(p, cs, radius / 2.0, thickness);
|
|
|
|
|
|
|
|
float a = 1.0 - smoothstep(0.0, extend, d);
|
|
|
|
gl_FragColor = vec4(color.rgb, 1.0) * a * opacity;
|
2023-12-04 16:33:28 +00:00
|
|
|
}
|