drawPoints = regl({
vert: `
precision highp float;
attribute vec2 xy;
uniform float pointSize, minimumPointDeviceSize;
uniform mat3 view3;
void main () {
gl_Position = vec4((view3 * vec3(xy, 1)).xy, 0, 1);
// Add 0.5 to the point size so that we can apply a +/-0.5px linear step and simulate antialiasing
gl_PointSize = max(minimumPointDeviceSize, pointSize) + 0.5;
}`,
frag: `
precision highp float;
uniform float opacity, pointSize;
uniform vec3 invertedPointColor;
float linearstep(float edge0, float edge1, float x) {
return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
}
void main () {
float alpha = opacity;
vec2 c = gl_PointCoord * 2.0 - 1.0;
#if ${circularPoints ? '1' : '0'}
// Opacity contributed by Kari Lavikka: https://twitter.com/KariLavikka/status/1335928770423910400
float sdf = length(c);
#else
float sdf = max(abs(c.x), abs(c.y));
#endif
alpha *= linearstep(pointSize + 0.5, pointSize - 0.5, sdf * pointSize);
gl_FragColor = vec4(invertedPointColor, alpha);
}`,
attributes: {
xy: regl.prop('pointsBuffer')
},
blend: {
enable: true,
func: {
srcRGB: 'src alpha',
dstRGB: 1,
srcAlpha: 1,
dstAlpha: 1
},
equation: {
rgb: 'reverse subtract',
alpha: 'add'
}
},
uniforms: {
invertedPointColor: (ctx, props) => [
1 - props.pointColorLinearRGB[0],
1 - props.pointColorLinearRGB[1],
1 - props.pointColorLinearRGB[2]
],
minimumPointDeviceSize: regl.prop('minimumPointDeviceSize'),
opacity: pointOpacity,
pointSize: pointSizeDevicePixels
},
primitive: 'points',
count: regl.prop('N'),
depth: { enable: false }
})