• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////////
2 /// OpenGL Mathematics (glm.g-truc.net)
3 ///
4 /// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
5 /// Permission is hereby granted, free of charge, to any person obtaining a copy
6 /// of this software and associated documentation files (the "Software"), to deal
7 /// in the Software without restriction, including without limitation the rights
8 /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 /// copies of the Software, and to permit persons to whom the Software is
10 /// furnished to do so, subject to the following conditions:
11 ///
12 /// The above copyright notice and this permission notice shall be included in
13 /// all copies or substantial portions of the Software.
14 ///
15 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 /// THE SOFTWARE.
22 ///
23 /// @ref core
24 /// @file glm/detail/_noise.hpp
25 /// @date 2013-12-24 / 2013-12-24
26 /// @author Christophe Riccio
27 ///////////////////////////////////////////////////////////////////////////////////
28 
29 #ifndef GLM_DETAIL_NOISE_INCLUDED
30 #define GLM_DETAIL_NOISE_INCLUDED
31 
32 namespace glm{
33 namespace detail
34 {
35 	template <typename T>
mod289(T const & x)36 	GLM_FUNC_QUALIFIER T mod289(T const & x)
37 	{
38 		return x - floor(x * static_cast<T>(1.0) / static_cast<T>(289.0)) * static_cast<T>(289.0);
39 	}
40 
41 	template <typename T>
permute(T const & x)42 	GLM_FUNC_QUALIFIER T permute(T const & x)
43 	{
44 		return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x);
45 	}
46 
47 	template <typename T, precision P>
permute(tvec2<T,P> const & x)48 	GLM_FUNC_QUALIFIER tvec2<T, P> permute(tvec2<T, P> const & x)
49 	{
50 		return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x);
51 	}
52 
53 	template <typename T, precision P>
permute(tvec3<T,P> const & x)54 	GLM_FUNC_QUALIFIER tvec3<T, P> permute(tvec3<T, P> const & x)
55 	{
56 		return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x);
57 	}
58 
59 	template <typename T, precision P>
permute(tvec4<T,P> const & x)60 	GLM_FUNC_QUALIFIER tvec4<T, P> permute(tvec4<T, P> const & x)
61 	{
62 		return mod289(((x * static_cast<T>(34)) + static_cast<T>(1)) * x);
63 	}
64 /*
65 	template <typename T, precision P, template<typename> class vecType>
66 	GLM_FUNC_QUALIFIER vecType<T, P> permute(vecType<T, P> const & x)
67 	{
68 		return mod289(((x * T(34)) + T(1)) * x);
69 	}
70 */
71 	template <typename T>
taylorInvSqrt(T const & r)72 	GLM_FUNC_QUALIFIER T taylorInvSqrt(T const & r)
73 	{
74 		return T(1.79284291400159) - T(0.85373472095314) * r;
75 	}
76 
77 	template <typename T, precision P>
taylorInvSqrt(detail::tvec2<T,P> const & r)78 	GLM_FUNC_QUALIFIER detail::tvec2<T, P> taylorInvSqrt(detail::tvec2<T, P> const & r)
79 	{
80 		return T(1.79284291400159) - T(0.85373472095314) * r;
81 	}
82 
83 	template <typename T, precision P>
taylorInvSqrt(detail::tvec3<T,P> const & r)84 	GLM_FUNC_QUALIFIER detail::tvec3<T, P> taylorInvSqrt(detail::tvec3<T, P> const & r)
85 	{
86 		return T(1.79284291400159) - T(0.85373472095314) * r;
87 	}
88 
89 	template <typename T, precision P>
taylorInvSqrt(detail::tvec4<T,P> const & r)90 	GLM_FUNC_QUALIFIER detail::tvec4<T, P> taylorInvSqrt(detail::tvec4<T, P> const & r)
91 	{
92 		return T(1.79284291400159) - T(0.85373472095314) * r;
93 	}
94 /*
95 	template <typename T, precision P, template<typename> class vecType>
96 	GLM_FUNC_QUALIFIER vecType<T, P> taylorInvSqrt(vecType<T, P> const & r)
97 	{
98 		return T(1.79284291400159) - T(0.85373472095314) * r;
99 	}
100 */
101 
102 	template <typename T, precision P>
fade(detail::tvec2<T,P> const & t)103 	GLM_FUNC_QUALIFIER detail::tvec2<T, P> fade(detail::tvec2<T, P> const & t)
104 	{
105 		return (t * t * t) * (t * (t * T(6) - T(15)) + T(10));
106 	}
107 
108 	template <typename T, precision P>
fade(detail::tvec3<T,P> const & t)109 	GLM_FUNC_QUALIFIER detail::tvec3<T, P> fade(detail::tvec3<T, P> const & t)
110 	{
111 		return (t * t * t) * (t * (t * T(6) - T(15)) + T(10));
112 	}
113 
114 	template <typename T, precision P>
fade(detail::tvec4<T,P> const & t)115 	GLM_FUNC_QUALIFIER detail::tvec4<T, P> fade(detail::tvec4<T, P> const & t)
116 	{
117 		return (t * t * t) * (t * (t * T(6) - T(15)) + T(10));
118 	}
119 /*
120 	template <typename T, precision P, template <typename> class vecType>
121 	GLM_FUNC_QUALIFIER vecType<T, P> fade(vecType<T, P> const & t)
122 	{
123 		return (t * t * t) * (t * (t * T(6) - T(15)) + T(10));
124 	}
125 */
126 }//namespace detail
127 }//namespace glm
128 
129 #endif//GLM_DETAIL_NOISE_INCLUDED
130 
131