prosperon/source/shaders/circle.sglsl

66 lines
1.1 KiB
Plaintext
Raw Normal View History

@vs circle_vs
in vec2 vertex;
in vec2 apos;
in float aradius;
in vec4 acolor;
in float asegsize;
in float afill;
2022-06-21 23:16:14 -05:00
out vec2 coords;
out vec4 fcolor;
out float segsize;
out float fill;
out float radius;
2022-06-21 23:16:14 -05:00
uniform cvs_params { mat4 proj; };
2023-05-24 20:45:50 -05:00
void main()
{
gl_Position = proj * vec4((vertex * aradius) + apos, 0.0, 1.0);
coords = vertex;
fcolor = acolor;
segsize = asegsize;
fill = afill;
radius = aradius;
}
@end
@fs circle_fs
2022-06-21 23:16:14 -05:00
out vec4 color;
in vec2 coords;
in vec4 fcolor;
2023-05-24 20:45:50 -05:00
in float segsize;
in float fill;
in float radius;
2023-05-24 20:45:50 -05:00
#define PI 3.14
2022-06-21 23:16:14 -05:00
void main()
{
2023-05-24 20:45:50 -05:00
float px = 1/radius;
float R1 = 1.f;
float R2 = 1.0 - fill;
float dist = sqrt(pow(coords.x,2) + pow(coords.y,2));
color = fcolor;
// if (dist < R2 || dist > R1)
// discard;
float sm = 1 - smoothstep(R1-px,R1,dist);
float sm2 = smoothstep(R2-px,R2,dist);
float a = sm*sm2;
color = mix(vec4(0,0,0,0), fcolor, a);
if (segsize<0)
return;
float f = atan(coords.y, coords.x) + PI;
if (mod(f, segsize) < segsize/2)
discard;
}
@end
@program circle circle_vs circle_fs