I'm trying to write some GLSL fragment shaders to model physarum bacteria. The simulation works as follows:
initiate a 2D array of intensities, all zeroed to start with
initiate a certain number of agents at arbitrary positions
for each iteration:
- move each agent to its next position according to some movement function (the movement function isn't important for this question)
- increase the intensity at each agent's new position by 1
- dampen all the intensities by a constant factor
Simulating this and treating the intensity values as a grayscale color yields interesting visuals like those in this demo.
I'm not sure how to model this correctly with textures and fragment shaders though.
To move each agent to its next position in a fragment shader, I need a texture where each pixel is an agent, and the R and G color values are the agent's x and y position.
However, to increase the intensity at each agent's new position by 1, I need to be able to query, for each position, "is there an agent there?", which I can't do with the model above.
Thanks for any help!