draw0.glsl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 uint map_width;
  13. uniform uint map_height;
  14. uniform float display_population_value;
  15. uniform float display_pheromone_value;
  16. layout(std430, binding = 1) readonly buffer particles_buffer
  17. {
  18. particle_t particles[];
  19. };
  20. layout(std430, binding = 2) readonly 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. float pop_value = cell.population / display_population_value / 2.5;
  34. float phe_value = cell.pheromone / display_pheromone_value;
  35. imageStore(canvas, ivec2(gl_GlobalInvocationID.xy),
  36. vec4(pop_value + phe_value,
  37. pop_value / 2,
  38. pop_value / 3,
  39. 1));
  40. // Particules rouges, phero bleues
  41. // imageStore(canvas, ivec2(gl_GlobalInvocationID.xy),
  42. // vec4(cell.population / display_population_value,
  43. // cell.pheromone / display_pheromone_value,
  44. // cell.pheromone / (display_pheromone_value),
  45. // 1));
  46. }