1 /// @ref core 2 /// @file glm/detail/_noise.hpp 3 4 #pragma once 5 6 #include "../vec2.hpp" 7 #include "../vec3.hpp" 8 #include "../vec4.hpp" 9 #include "../common.hpp" 10 11 namespace glm{ 12 namespace detail 13 { 14 template <typename T> mod289(T const & x)15 GLM_FUNC_QUALIFIER T mod289(T const & x) 16 { 17 return x - floor(x * static_cast<T>(1.0) / static_cast<T>(289.0)) * static_cast<T>(289.0); 18 } 19 20 template <typename T> permute(T const & x)21 GLM_FUNC_QUALIFIER T permute(T const & x) 22 { 23 return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x); 24 } 25 26 template <typename T, precision P> permute(tvec2<T,P> const & x)27 GLM_FUNC_QUALIFIER tvec2<T, P> permute(tvec2<T, P> const & x) 28 { 29 return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x); 30 } 31 32 template <typename T, precision P> permute(tvec3<T,P> const & x)33 GLM_FUNC_QUALIFIER tvec3<T, P> permute(tvec3<T, P> const & x) 34 { 35 return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x); 36 } 37 38 template <typename T, precision P> permute(tvec4<T,P> const & x)39 GLM_FUNC_QUALIFIER tvec4<T, P> permute(tvec4<T, P> const & x) 40 { 41 return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x); 42 } 43 /* 44 template <typename T, precision P, template<typename> class vecType> 45 GLM_FUNC_QUALIFIER vecType<T, P> permute(vecType<T, P> const & x) 46 { 47 return mod289(((x * T(34)) + T(1)) * x); 48 } 49 */ 50 template <typename T> taylorInvSqrt(T const & r)51 GLM_FUNC_QUALIFIER T taylorInvSqrt(T const & r) 52 { 53 return T(1.79284291400159) - T(0.85373472095314) * r; 54 } 55 56 template <typename T, precision P> taylorInvSqrt(tvec2<T,P> const & r)57 GLM_FUNC_QUALIFIER tvec2<T, P> taylorInvSqrt(tvec2<T, P> const & r) 58 { 59 return T(1.79284291400159) - T(0.85373472095314) * r; 60 } 61 62 template <typename T, precision P> taylorInvSqrt(tvec3<T,P> const & r)63 GLM_FUNC_QUALIFIER tvec3<T, P> taylorInvSqrt(tvec3<T, P> const & r) 64 { 65 return T(1.79284291400159) - T(0.85373472095314) * r; 66 } 67 68 template <typename T, precision P> taylorInvSqrt(tvec4<T,P> const & r)69 GLM_FUNC_QUALIFIER tvec4<T, P> taylorInvSqrt(tvec4<T, P> const & r) 70 { 71 return T(1.79284291400159) - T(0.85373472095314) * r; 72 } 73 /* 74 template <typename T, precision P, template<typename> class vecType> 75 GLM_FUNC_QUALIFIER vecType<T, P> taylorInvSqrt(vecType<T, P> const & r) 76 { 77 return T(1.79284291400159) - T(0.85373472095314) * r; 78 } 79 */ 80 81 template <typename T, precision P> fade(tvec2<T,P> const & t)82 GLM_FUNC_QUALIFIER tvec2<T, P> fade(tvec2<T, P> const & t) 83 { 84 return (t * t * t) * (t * (t * T(6) - T(15)) + T(10)); 85 } 86 87 template <typename T, precision P> fade(tvec3<T,P> const & t)88 GLM_FUNC_QUALIFIER tvec3<T, P> fade(tvec3<T, P> const & t) 89 { 90 return (t * t * t) * (t * (t * T(6) - T(15)) + T(10)); 91 } 92 93 template <typename T, precision P> fade(tvec4<T,P> const & t)94 GLM_FUNC_QUALIFIER tvec4<T, P> fade(tvec4<T, P> const & t) 95 { 96 return (t * t * t) * (t * (t * T(6) - T(15)) + T(10)); 97 } 98 /* 99 template <typename T, precision P, template <typename> class vecType> 100 GLM_FUNC_QUALIFIER vecType<T, P> fade(vecType<T, P> const & t) 101 { 102 return (t * t * t) * (t * (t * T(6) - T(15)) + T(10)); 103 } 104 */ 105 }//namespace detail 106 }//namespace glm 107 108