commandUpdate = regl({
frag: `
precision highp float;
uniform sampler2D space;
const int radius = ${radius};
const float invRadius = ${(1 / radius).toPrecision(5)};
varying vec2 uv;
varying vec2 cellPosition;
uniform sampler2D ants;
const int antCount = ${antCount};
void main() {
gl_FragColor =
texture2D(space, (cellPosition + vec2(-1.0, -1.0)) * invRadius) * 1.0
+ texture2D(space, (cellPosition + vec2(-1.0, 0.0)) * invRadius) * 2.0
+ texture2D(space, (cellPosition + vec2(-1.0, 1.0)) * invRadius) * 1.0
+ texture2D(space, (cellPosition + vec2(0.0, -1.0)) * invRadius) * 2.0
+ texture2D(space, (cellPosition + vec2(0.0, 0.0)) * invRadius) * 4.0
+ texture2D(space, (cellPosition + vec2(0.0, 1.0)) * invRadius) * 2.0
+ texture2D(space, (cellPosition + vec2(1.0, -1.0)) * invRadius) * 1.0
+ texture2D(space, (cellPosition + vec2(1.0, 0.0)) * invRadius) * 2.0
+ texture2D(space, (cellPosition + vec2(1.0, 1.0)) * invRadius) * 1.0;
gl_FragColor /= 16.0;
gl_FragColor *= 0.9;
for (int i = 0; i < antCount; i++) {
vec4 ant = texture2D(ants, vec2(float(i) / float(antCount), 0));
if (distance(ant.xy, uv) < invRadius) {
gl_FragColor += 1.0;
}
}
}`,
vert: `
precision mediump float;
const int radius = ${radius};
const float invRadius = ${(1 / radius).toPrecision(5)};
attribute vec2 position;
varying vec2 uv;
varying vec2 cellPosition;
void main() {
uv = 0.5 * (position + 1.0);
cellPosition = uv * float(radius);
gl_Position = vec4(position, 0, 1);
}`,
uniforms: {
space: (_, { space }) => space,
ants: (_, { ants }) => ants
},
framebuffer: (_, { nextSpace }) => nextSpace,
attributes: { position: [-3, -1, 3, -1, 0, 2] },
count: 3,
depth: { enable: false }
})