function circleRenderProgram(canvas) {
const regl = createRegl(canvas);
const drawCircle = regl({
frag: `
precision mediump float;
uniform vec4 color;
uniform vec2 pos;
uniform float r;
uniform vec2 resolution;
float sdCircle ( in vec2 p, in vec2 pos, in float r )
{
return length (p-pos) - r;
}
void main () {
vec2 p = (2.0*gl_FragCoord.xy-resolution)/resolution.y;
float d = sdCircle(p, pos, r);
if (d >= 0. && d <= 1.) {
float t = smoothstep(0.,0.005,d)-smoothstep(0.005,0.01,d);
gl_FragColor = vec4(color.xyz,(t+0.8*pow((1.-d),5.))*smoothstep(0.,0.1,r));
}
else discard;
}`,
vert: `
attribute vec2 position;
void main () {
gl_Position = vec4(position, 0., 1.);
}`,
attributes: {
position: [
[-1, -1],
[1, -1],
[1, 1],
[-1, 1]
]
},
depth: {
enable: false
},
primitive: "triangle fan",
blend: {
enable: true,
func: {
srcRGB: "src alpha",
srcAlpha: 1,
dstRGB: "one minus src alpha",
dstAlpha: 1
}
},
count: 4,
uniforms: {
resolution: [canvas.width, canvas.height],
r: regl.prop("r"),
pos: regl.prop("pos"),
color: regl.prop("color")
}
});
return { regl, drawCircle };
}