2
0

ClusteredShadingFunctions.h 1.1 KB

123456789101112131415161718192021222324252627282930
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
  7. ANKI_BEGIN_NAMESPACE
  8. // Compute the far plane of a shadow cascade. "p" is the power that defines the distance curve.
  9. // "effectiveShadowDistance" is the far plane of the last cascade.
  10. ANKI_SHADER_FUNC_INLINE F32 computeShadowCascadeDistance(U32 cascadeIdx, F32 p, F32 effectiveShadowDistance,
  11. U32 shadowCascadeCount)
  12. {
  13. return pow((F32(cascadeIdx) + 1.0f) / F32(shadowCascadeCount), p) * effectiveShadowDistance;
  14. }
  15. // The reverse of computeShadowCascadeDistance().
  16. ANKI_SHADER_FUNC_INLINE U32 computeShadowCascadeIndex(F32 distance, F32 p, F32 effectiveShadowDistance,
  17. U32 shadowCascadeCount)
  18. {
  19. const F32 shadowCascadeCountf = F32(shadowCascadeCount);
  20. F32 idx = pow(distance / effectiveShadowDistance, 1.0f / p) * shadowCascadeCountf;
  21. idx = min(idx, shadowCascadeCountf - 1.0f);
  22. return U32(idx);
  23. }
  24. ANKI_END_NAMESPACE