|
|
|
@ -15,58 +15,58 @@ |
|
|
|
|
// - GLM core |
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
|
namespace glm{ |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T mod289(T const & x) |
|
|
|
|
namespace glm |
|
|
|
|
{ |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T mod289(T const & x) |
|
|
|
|
{ |
|
|
|
|
return x - floor(x * T(1.0 / 289.0)) * T(289.0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T permute(T const & x) |
|
|
|
|
{ |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T permute(T const & x) |
|
|
|
|
{ |
|
|
|
|
return mod289(((x * T(34)) + T(1)) * x); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, template<typename> class vecType> |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<T> permute(vecType<T> const & x) |
|
|
|
|
{ |
|
|
|
|
template <typename T, template<typename> class vecType> |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<T> permute(vecType<T> const & x) |
|
|
|
|
{ |
|
|
|
|
return mod289(((x * T(34)) + T(1)) * x); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T taylorInvSqrt(T const & r) |
|
|
|
|
{ |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T taylorInvSqrt(T const & r) |
|
|
|
|
{ |
|
|
|
|
return T(1.79284291400159) - T(0.85373472095314) * r; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, template<typename> class vecType> |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<T> taylorInvSqrt(vecType<T> const & r) |
|
|
|
|
{ |
|
|
|
|
template <typename T, template<typename> class vecType> |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<T> taylorInvSqrt(vecType<T> const & r) |
|
|
|
|
{ |
|
|
|
|
return T(1.79284291400159) - T(0.85373472095314) * r; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, template <typename> class vecType> |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<T> fade(vecType<T> const & t) |
|
|
|
|
{ |
|
|
|
|
template <typename T, template <typename> class vecType> |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<T> fade(vecType<T> const & t) |
|
|
|
|
{ |
|
|
|
|
return t * t * t * (t * (t * T(6) - T(15)) + T(10)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER detail::tvec4<T> grad4(T const & j, detail::tvec4<T> const & ip) |
|
|
|
|
{ |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER detail::tvec4<T> grad4(T const & j, detail::tvec4<T> const & ip) |
|
|
|
|
{ |
|
|
|
|
detail::tvec3<T> pXYZ = floor(fract(detail::tvec3<T>(j) * detail::tvec3<T>(ip)) * T(7)) * ip[2] - T(1); |
|
|
|
|
T pW = T(1.5) - dot(abs(pXYZ), detail::tvec3<T>(1)); |
|
|
|
|
detail::tvec4<T> s = detail::tvec4<T>(lessThan(detail::tvec4<T>(pXYZ, pW), detail::tvec4<T>(0.0))); |
|
|
|
|
pXYZ = pXYZ + (detail::tvec3<T>(s) * T(2) - T(1)) * s.w; |
|
|
|
|
return detail::tvec4<T>(pXYZ, pW); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Classic Perlin noise |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P) |
|
|
|
|
{ |
|
|
|
|
// Classic Perlin noise |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P) |
|
|
|
|
{ |
|
|
|
|
detail::tvec4<T> Pi = glm::floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0); |
|
|
|
|
detail::tvec4<T> Pf = glm::fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0); |
|
|
|
|
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation |
|
|
|
@ -102,12 +102,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P) |
|
|
|
|
detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x); |
|
|
|
|
T n_xy = mix(n_x.x, n_x.y, fade_xy.y); |
|
|
|
|
return T(2.3) * n_xy; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Classic Perlin noise |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P) |
|
|
|
|
{ |
|
|
|
|
// Classic Perlin noise |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P) |
|
|
|
|
{ |
|
|
|
|
detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing |
|
|
|
|
detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1 |
|
|
|
|
Pi0 = mod289(Pi0); |
|
|
|
@ -173,12 +173,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P) |
|
|
|
|
detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y); |
|
|
|
|
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); |
|
|
|
|
return T(2.2) * n_xyz; |
|
|
|
|
} |
|
|
|
|
/* |
|
|
|
|
// Classic Perlin noise |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
/* |
|
|
|
|
// Classic Perlin noise |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P) |
|
|
|
|
{ |
|
|
|
|
detail::tvec3<T> Pi0 = floor(P); // Integer part for indexing |
|
|
|
|
detail::tvec3<T> Pi1 = Pi0 + T(1); // Integer part + 1 |
|
|
|
|
Pi0 = mod(Pi0, T(289)); |
|
|
|
@ -246,12 +246,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P) |
|
|
|
|
detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y); |
|
|
|
|
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); |
|
|
|
|
return T(2.2) * n_xyz; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
// Classic Perlin noise |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
// Classic Perlin noise |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P) |
|
|
|
|
{ |
|
|
|
|
detail::tvec4<T> Pi0 = floor(P); // Integer part for indexing |
|
|
|
|
detail::tvec4<T> Pi1 = Pi0 + T(1); // Integer part + 1 |
|
|
|
|
Pi0 = mod(Pi0, T(289)); |
|
|
|
@ -382,12 +382,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P) |
|
|
|
|
detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y); |
|
|
|
|
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x); |
|
|
|
|
return T(2.2) * n_xyzw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Classic Perlin noise, periodic variant |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const & rep) |
|
|
|
|
{ |
|
|
|
|
// Classic Perlin noise, periodic variant |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const & rep) |
|
|
|
|
{ |
|
|
|
|
detail::tvec4<T> Pi = floor(detail::tvec4<T>(P.x, P.y, P.x, P.y)) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0); |
|
|
|
|
detail::tvec4<T> Pf = fract(detail::tvec4<T>(P.x, P.y, P.x, P.y)) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0); |
|
|
|
|
Pi = mod(Pi, detail::tvec4<T>(rep.x, rep.y, rep.x, rep.y)); // To create noise with explicit period |
|
|
|
@ -424,12 +424,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const & |
|
|
|
|
detail::tvec2<T> n_x = mix(detail::tvec2<T>(n00, n01), detail::tvec2<T>(n10, n11), fade_xy.x); |
|
|
|
|
T n_xy = mix(n_x.x, n_x.y, fade_xy.y); |
|
|
|
|
return T(2.3) * n_xy; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Classic Perlin noise, periodic variant |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P, detail::tvec3<T> const & rep) |
|
|
|
|
{ |
|
|
|
|
// Classic Perlin noise, periodic variant |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P, detail::tvec3<T> const & rep) |
|
|
|
|
{ |
|
|
|
|
detail::tvec3<T> Pi0 = mod(floor(P), rep); // Integer part, modulo period |
|
|
|
|
detail::tvec3<T> Pi1 = mod(Pi0 + detail::tvec3<T>(1.0), rep); // Integer part + 1, mod period |
|
|
|
|
Pi0 = mod(Pi0, T(289)); |
|
|
|
@ -495,12 +495,12 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> const & P, detail::tvec3<T> const & |
|
|
|
|
detail::tvec2<T> n_yz = mix(detail::tvec2<T>(n_z.x, n_z.y), detail::tvec2<T>(n_z.z, n_z.w), fade_xyz.y); |
|
|
|
|
T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); |
|
|
|
|
return T(2.2) * n_xyz; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Classic Perlin noise, periodic version |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P, detail::tvec4<T> const & rep) |
|
|
|
|
{ |
|
|
|
|
// Classic Perlin noise, periodic version |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P, detail::tvec4<T> const & rep) |
|
|
|
|
{ |
|
|
|
|
detail::tvec4<T> Pi0 = mod(floor(P), rep); // Integer part modulo rep |
|
|
|
|
detail::tvec4<T> Pi1 = mod(Pi0 + T(1), rep); // Integer part + 1 mod rep |
|
|
|
|
detail::tvec4<T> Pf0 = fract(P); // Fractional part for interpolation |
|
|
|
@ -629,11 +629,11 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P, detail::tvec4<T> const & |
|
|
|
|
detail::tvec2<T> n_yzw = mix(detail::tvec2<T>(n_zw.x, n_zw.y), detail::tvec2<T>(n_zw.z, n_zw.w), fade_xyzw.y); |
|
|
|
|
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x); |
|
|
|
|
return T(2.2) * n_xyzw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v) |
|
|
|
|
{ |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v) |
|
|
|
|
{ |
|
|
|
|
detail::tvec4<T> const C = detail::tvec4<T>( |
|
|
|
|
T( 0.211324865405187), // (3.0 - sqrt(3.0)) / 6.0 |
|
|
|
|
T( 0.366025403784439), // 0.5 * (sqrt(3.0) - 1.0) |
|
|
|
@ -686,11 +686,11 @@ GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v) |
|
|
|
|
g.y = a0.y * x12.x + h.y * x12.y; |
|
|
|
|
g.z = a0.z * x12.z + h.z * x12.w; |
|
|
|
|
return T(130) * dot(m, g); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v) |
|
|
|
|
{ |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v) |
|
|
|
|
{ |
|
|
|
|
detail::tvec2<T> const C(1.0 / 6.0, 1.0 / 3.0); |
|
|
|
|
detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0); |
|
|
|
|
|
|
|
|
@ -761,11 +761,11 @@ GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v) |
|
|
|
|
detail::tvec4<T> m = max(T(0.6) - detail::tvec4<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), T(0)); |
|
|
|
|
m = m * m; |
|
|
|
|
return T(42) * dot(m * m, detail::tvec4<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v) |
|
|
|
|
{ |
|
|
|
|
template <typename T> |
|
|
|
|
GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v) |
|
|
|
|
{ |
|
|
|
|
detail::tvec4<T> const C( |
|
|
|
|
0.138196601125011, // (5 - sqrt(5))/20 G4 |
|
|
|
|
0.276393202250021, // 2 * G4 |
|
|
|
@ -847,6 +847,5 @@ GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v) |
|
|
|
|
return T(49) * |
|
|
|
|
(dot(m0 * m0, detail::tvec3<T>(dot(p0, x0), dot(p1, x1), dot(p2, x2))) + |
|
|
|
|
dot(m1 * m1, detail::tvec2<T>(dot(p3, x3), dot(p4, x4)))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}//namespace glm |
|
|
|
|