_noise.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include "../common.hpp"
  3. namespace glm{
  4. namespace detail
  5. {
  6. template<typename T>
  7. GLM_FUNC_QUALIFIER T mod289(T const& x)
  8. {
  9. return x - floor(x * (static_cast<T>(1.0) / static_cast<T>(289.0))) * static_cast<T>(289.0);
  10. }
  11. template<typename T>
  12. GLM_FUNC_QUALIFIER T permute(T const& x)
  13. {
  14. return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x);
  15. }
  16. template<typename T, qualifier Q>
  17. GLM_FUNC_QUALIFIER vec<2, T, Q> permute(vec<2, T, Q> const& x)
  18. {
  19. return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x);
  20. }
  21. template<typename T, qualifier Q>
  22. GLM_FUNC_QUALIFIER vec<3, T, Q> permute(vec<3, T, Q> const& x)
  23. {
  24. return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x);
  25. }
  26. template<typename T, qualifier Q>
  27. GLM_FUNC_QUALIFIER vec<4, T, Q> permute(vec<4, T, Q> const& x)
  28. {
  29. return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x);
  30. }
  31. template<typename T>
  32. GLM_FUNC_QUALIFIER T taylorInvSqrt(T const& r)
  33. {
  34. return static_cast<T>(1.79284291400159) - static_cast<T>(0.85373472095314) * r;
  35. }
  36. template<typename T, qualifier Q>
  37. GLM_FUNC_QUALIFIER vec<2, T, Q> taylorInvSqrt(vec<2, T, Q> const& r)
  38. {
  39. return static_cast<T>(1.79284291400159) - static_cast<T>(0.85373472095314) * r;
  40. }
  41. template<typename T, qualifier Q>
  42. GLM_FUNC_QUALIFIER vec<3, T, Q> taylorInvSqrt(vec<3, T, Q> const& r)
  43. {
  44. return static_cast<T>(1.79284291400159) - static_cast<T>(0.85373472095314) * r;
  45. }
  46. template<typename T, qualifier Q>
  47. GLM_FUNC_QUALIFIER vec<4, T, Q> taylorInvSqrt(vec<4, T, Q> const& r)
  48. {
  49. return static_cast<T>(1.79284291400159) - static_cast<T>(0.85373472095314) * r;
  50. }
  51. template<typename T, qualifier Q>
  52. GLM_FUNC_QUALIFIER vec<2, T, Q> fade(vec<2, T, Q> const& t)
  53. {
  54. return (t * t * t) * (t * (t * static_cast<T>(6) - static_cast<T>(15)) + static_cast<T>(10));
  55. }
  56. template<typename T, qualifier Q>
  57. GLM_FUNC_QUALIFIER vec<3, T, Q> fade(vec<3, T, Q> const& t)
  58. {
  59. return (t * t * t) * (t * (t * static_cast<T>(6) - static_cast<T>(15)) + static_cast<T>(10));
  60. }
  61. template<typename T, qualifier Q>
  62. GLM_FUNC_QUALIFIER vec<4, T, Q> fade(vec<4, T, Q> const& t)
  63. {
  64. return (t * t * t) * (t * (t * static_cast<T>(6) - static_cast<T>(15)) + static_cast<T>(10));
  65. }
  66. }//namespace detail
  67. }//namespace glm