I was thinking of recreating this ant colony simulation using webgl.
I was planning of storing the state(x,y,direction) of the all ant agents inside a single texture using its rgba channels. During a draw call, each pixel of this texture would be read, and based on the pixel's values, certain positions in another texture would be written into.
Is this any way to do this using webgl? Preferably I would like not to use gl.readPixel and keep everything running the simulation on the gpu.
You can use point splatting:
gl.drawArrays(gl.POINTS,0,antDataTexture.width*antDataTexture.height)In the vertex shader:
gl_PointSizeto the size of the sprite you want to render(or 1 if you want to write a single pixel of data)gl_Positionby reading the texture in the vertex shader by either usingIn the fragment shader:
gl_PointCoordor put whatever data you likeFinally
That being said for the simulation portion itself you wouldn't need to write to arbitrary positions, you can just ping-pong between two data texture, only for output you'd want to render the things(ants in this case) where they actually are.