drawParticles = regl({
vert: `
precision mediump float;
attribute vec4 freq, phase;
attribute vec3 color;
uniform float time;
uniform mat4 view, projection;
varying vec3 fragColor;
void main() {
vec3 position = 8.0 * cos(freq.xyz * time + phase.xyz);
gl_PointSize = 5.0 * (1.0 + cos(freq.w * time + phase.w));
gl_Position = projection * view * vec4(position, 1);
fragColor = color;
}`,
frag: `
precision lowp float;
varying vec3 fragColor;
void main() {
if (length(gl_PointCoord.xy - 0.5) > 0.5) {
discard;
}
gl_FragColor = vec4(fragColor, 1);
}`,
attributes: {
freq: {
buffer: pointBuffer,
stride: VERT_SIZE,
offset: 0
},
phase: {
buffer: pointBuffer,
stride: VERT_SIZE,
offset: 16
},
color: {
buffer: pointBuffer,
stride: VERT_SIZE,
offset: 32
}
},
uniforms: {
view: ({tick}) => {
const t = 0.01 * tick
return mat4.lookAt([],
[30 * Math.cos(t), 2.5, 30 * Math.sin(t)],
[0, 0, 0],
[0, 1, 0])
},
projection: ({viewportWidth, viewportHeight}) =>
mat4.perspective([],
Math.PI / 4,
viewportWidth / viewportHeight,
0.01,
1000),
time: ({tick}) => tick * 0.001
},
count: NUM_POINTS,
primitive: 'points'
})