#version 430 core struct cell_t { float pheromone; float result; int population; }; uniform uint map_width; uniform uint map_height; uniform float increase; uniform float decay; uniform float diffusion; uniform float dt; layout(std430, binding = 2) coherent buffer map_buffer { cell_t map[]; }; uint cell_id(int x, int y){ return uint(mod(y, map_height) * map_width + mod(x, map_width)); } layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in; void main(){ int x = int(gl_GlobalInvocationID.x); int y = int(gl_GlobalInvocationID.y); if(x >= map_width || y >= map_height){ return; } float frac = diffusion * dt; float val = map[cell_id(x,y)].pheromone + map[cell_id(x,y)].population * increase * dt; val = val * (1 - 4 * frac) + (map[cell_id(x-1,y)].pheromone + map[cell_id(x+1,y)].pheromone + map[cell_id(x,y-1)].pheromone + map[cell_id(x,y+1)].pheromone) * frac; val = val * exp(-decay * dt); map[cell_id(x,y)].result = val; }