IsUpdateTiles.glsl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Compute shader that bins lights to the tiles
  2. #pragma anki start computeShader
  3. // Set number of work items
  4. layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
  5. #pragma anki include "shaders/IsCommon.glsl"
  6. //
  7. // Data
  8. //
  9. // The tilegrid input buffer
  10. layout(std140, binding = 0) buffer tilegridBuffer
  11. {
  12. Tilegrid tilegrid;
  13. };
  14. // The lights input buffers
  15. layout(std140, binding = 1) buffer lightsBuffer
  16. {
  17. Lights lights;
  18. };
  19. // The output buffer
  20. layout(std430, binding = 2) buffer tilesBuffer
  21. {
  22. Tile tiles[TILES_Y_COUNT][TILES_X_COUNT];
  23. };
  24. // Buffers with atomic counters for each tile
  25. layout(std430, binding = 1) buffer pointLightsCountBuffer
  26. {
  27. atomic_uint pointLightsCount[TILES_Y_COUNT][TILES_X_COUNT];
  28. };
  29. layout(std430, binding = 2) buffer spotLightsCountBuffer
  30. {
  31. atomic_uint spotLightsCount[TILES_Y_COUNT][TILES_X_COUNT];
  32. };
  33. layout(std430, binding = 3) buffer spotTexLightsCountBuffer
  34. {
  35. atomic_uint spotTexLightsCount[TILES_Y_COUNT][TILES_X_COUNT];
  36. };
  37. //
  38. // Functions
  39. //
  40. // Return true if spere is in the half space defined by the plane
  41. bool pointLightInsidePlane(in PointLight light, in Plane plane)
  42. {
  43. // Result of the plane test. Distance of
  44. float dist = dot(plane.normalOffset.xyz, light.posRadius.xyz)
  45. - plane.normalOffset.w;
  46. return dist >= 0.0;
  47. }
  48. // Spot light inside plane
  49. bool spotLightInsidePlane(in SpotLight light, in Plane plane)
  50. {
  51. if(pointLightInsidePlane(light.lightBase, plane))
  52. {
  53. return true;
  54. }
  55. for(uint i = 0U; i < 4; i++)
  56. {
  57. float dist = dot(plane.normalOffset.xyz, light.extendPoints[i].xyz)
  58. - plane.normalOffset.w;
  59. if(dist >= 0.0)
  60. {
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. // Spot tex light inside plane
  67. bool spotTexLightInsidePlane(in SpotTexLight light, in Plane plane)
  68. {
  69. return pointLightInsidePlane(light.spotLightBase, plane);
  70. }
  71. // main
  72. void main()
  73. {
  74. // First the point lights
  75. for(uint i = 0U; i < lights.count.x; i++)
  76. {
  77. }
  78. }