Clusterer.glsl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. // Contains functions for the clusterer
  6. #ifndef ANKI_SHADERS_CLUSTERER_GLSL
  7. #define ANKI_SHADERS_CLUSTERER_GLSL
  8. #pragma anki include "shaders/Common.glsl"
  9. //==============================================================================
  10. // Compute the cluster index using the tile index.
  11. uint computeClusterIndexUsingTileIdx(float near, float clustererMagic,
  12. float zVSpace, uint tileIdx, uint tileCountX, uint tileCountY)
  13. {
  14. float fk = sqrt((zVSpace + near) * clustererMagic);
  15. uint k = uint(fk);
  16. return tileIdx + k * (tileCountX * tileCountY);
  17. }
  18. //==============================================================================
  19. // Compute the cluster index using the gl_FragCoord.xy.
  20. uint computeClusterIndexUsingFragCoord(float near, float clustererMagic,
  21. float zVSpace, uint tileCountX, uint tileCountY)
  22. {
  23. // Compute tile idx
  24. uvec2 f = uvec2(gl_FragCoord.xy) >> 6;
  25. uint tileIdx = f.y * tileCountX + f.x;
  26. return computeClusterIndexUsingTileIdx(near, clustererMagic, zVSpace,
  27. tileIdx, tileCountX, tileCountY);
  28. }
  29. #endif