map_update.glsl 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #version 430 core
  2. struct cell_t {
  3. float pheromone;
  4. float result;
  5. int population;
  6. };
  7. uniform uint map_width;
  8. uniform uint map_height;
  9. uniform float increase;
  10. uniform float decay;
  11. uniform float diffusion;
  12. uniform float dt;
  13. layout(std430, binding = 2) coherent buffer map_buffer
  14. {
  15. cell_t map[];
  16. };
  17. uint cell_id(int x, int y){
  18. return uint(mod(y, map_height) * map_width + mod(x, map_width));
  19. }
  20. layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
  21. void main(){
  22. int x = int(gl_GlobalInvocationID.x);
  23. int y = int(gl_GlobalInvocationID.y);
  24. if(x >= map_width || y >= map_height){
  25. return;
  26. }
  27. float frac = diffusion * dt;
  28. float val = map[cell_id(x,y)].pheromone + map[cell_id(x,y)].population * increase * dt;
  29. val = val * (1 - 4 * frac)
  30. + (map[cell_id(x-1,y)].pheromone
  31. + map[cell_id(x+1,y)].pheromone
  32. + map[cell_id(x,y-1)].pheromone
  33. + map[cell_id(x,y+1)].pheromone) * frac;
  34. val = val * exp(-decay * dt);
  35. map[cell_id(x,y)].result = val;
  36. }