prosperon/source/shaders/circle.sglsl

66 lines
1.1 KiB
Plaintext

@vs circle_vs
in vec2 vertex;
in vec2 apos;
in float aradius;
in vec4 acolor;
in float asegsize;
in float afill;
out vec2 coords;
out vec4 fcolor;
out float segsize;
out float fill;
out float radius;
uniform cvs_params { mat4 proj; };
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
out vec4 color;
in vec2 coords;
in vec4 fcolor;
in float segsize;
in float fill;
in float radius;
#define PI 3.14
void main()
{
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