BsIBLUtility.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Renderer/BsIBLUtility.h"
  4. #include "Math/BsVector2I.h"
  5. namespace bs { namespace ct
  6. {
  7. const UINT32 IBLUtility::REFLECTION_CUBEMAP_SIZE = 256;
  8. const UINT32 IBLUtility::IRRADIANCE_CUBEMAP_SIZE = 32;
  9. /** Returns the size of the texture required to store the provided number of SH coefficients. */
  10. Vector2I IBLUtility::getSHCoeffTextureSize(UINT32 numCoeffSets, UINT32 shOrder)
  11. {
  12. UINT32 coeffsPerSet = shOrder * shOrder;
  13. // Assuming the texture maximum size is 4096
  14. UINT32 maxSetsPerRow = 4096 / coeffsPerSet;
  15. Vector2I output;
  16. output.x = (numCoeffSets > maxSetsPerRow ? maxSetsPerRow : numCoeffSets) * coeffsPerSet;
  17. output.y = 1 + numCoeffSets / (maxSetsPerRow + 1);
  18. return output;
  19. }
  20. /** Determines the position of a set of coefficients in the coefficient texture, depending on the coefficient index. */
  21. Vector2I IBLUtility::getSHCoeffXYFromIdx(UINT32 idx, UINT32 shOrder)
  22. {
  23. UINT32 coeffsPerSet = shOrder * shOrder;
  24. // Assuming the texture maximum size is 4096
  25. UINT32 maxSetsPerRow = 4096 / coeffsPerSet;
  26. Vector2I output;
  27. output.x = (idx % maxSetsPerRow) * coeffsPerSet;
  28. output.y = idx / maxSetsPerRow;
  29. return output;
  30. }
  31. const IBLUtility& gIBLUtility()
  32. {
  33. return IBLUtility::instance();
  34. }
  35. }}