draw.glsl 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #version 430 core
  2. struct particle_t {
  3. vec2 pos;
  4. vec2 dir;
  5. };
  6. struct cell_t {
  7. float pheromone;
  8. float result;
  9. int population;
  10. };
  11. layout(binding = 0, rgba8) writeonly uniform image2D canvas;
  12. uniform int map_width;
  13. uniform int map_height;
  14. uniform float display_population_value;
  15. uniform float display_pheromone_value;
  16. layout(std430, binding = 1) coherent buffer particles_buffer
  17. {
  18. particle_t particles[];
  19. };
  20. layout(std430, binding = 2) coherent buffer map_buffer
  21. {
  22. cell_t map[];
  23. };
  24. layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
  25. void main(){
  26. uint x = gl_GlobalInvocationID.x;
  27. uint y = gl_GlobalInvocationID.y;
  28. if(x >= map_width || y >= map_height){
  29. return;
  30. }
  31. uint cell_id = y * map_width + x;
  32. cell_t cell = map[cell_id];
  33. imageStore(canvas, ivec2(gl_GlobalInvocationID.xy),
  34. vec4(cell.population/display_population_value,
  35. cell.pheromone/display_pheromone_value,
  36. // 0,
  37. 0, 1));
  38. }