| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #version 430 core
- struct cell_t {
- float pheromone;
- float result;
- int population;
- };
- uniform int map_width;
- uniform int 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(uint x, uint y){
- return uint(mod(y + map_height, map_height) * map_width + mod(x + map_width, map_width));
- }
- layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
- void main(){
- uint x = gl_GlobalInvocationID.x;
- uint y = 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;
- }
|