mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 10:14:35 +00:00
Updated noise extension API
This commit is contained in:
parent
b80a6bb251
commit
7fad31404d
@ -41,20 +41,20 @@ namespace glm
|
||||
//! Classic perlin noise.
|
||||
//! From GLM_GTX_noise extension.
|
||||
template <typename T, template<typename> class vecType>
|
||||
T cnoise(
|
||||
T perlin(
|
||||
vecType<T> const & p);
|
||||
|
||||
//! Periodic perlin noise.
|
||||
//! From GLM_GTX_noise extension.
|
||||
template <typename T, template<typename> class vecType>
|
||||
T pnoise(
|
||||
T perlin(
|
||||
vecType<T> const & p,
|
||||
vecType<T> const & rep);
|
||||
|
||||
//! Simplex noise.
|
||||
//! From GLM_GTX_noise extension.
|
||||
template <typename T, template<typename> class vecType>
|
||||
T snoise(
|
||||
T simplex(
|
||||
vecType<T> const & p);
|
||||
|
||||
///@}
|
||||
|
@ -62,7 +62,7 @@ namespace noise
|
||||
{
|
||||
// Classic Perlin noise
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T cnoise(detail::tvec2<T> const & P)
|
||||
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P)
|
||||
{
|
||||
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);
|
||||
@ -103,7 +103,7 @@ namespace noise
|
||||
|
||||
// Classic Perlin noise
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T cnoise(detail::tvec3<T> const & P)
|
||||
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
|
||||
@ -176,7 +176,7 @@ namespace noise
|
||||
|
||||
// Classic Perlin noise
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T cnoise(detail::tvec4<T> const & P)
|
||||
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
|
||||
@ -312,10 +312,10 @@ namespace noise
|
||||
|
||||
// Classic Perlin noise, periodic variant
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T pnoise(detail::tvec2<T> const & P, detail::tvec2<T> const & rep)
|
||||
GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P, detail::tvec2<T> const & rep)
|
||||
{
|
||||
detail::tvec4<T> Pi = floor(P.x, P.y, P.x, P.y) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
|
||||
detail::tvec4<T> Pf = fract(P.x, P.y, P.x, P.y) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
|
||||
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
|
||||
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation
|
||||
detail::tvec4<T> ix(Pi.x, Pi.z, Pi.x, Pi.z);
|
||||
@ -354,7 +354,7 @@ namespace noise
|
||||
|
||||
// Classic Perlin noise, periodic variant
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T pnoise(detail::tvec3<T> const & P, detail::tvec3<T> const & rep)
|
||||
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
|
||||
@ -425,7 +425,7 @@ namespace noise
|
||||
|
||||
// Classic Perlin noise, periodic version
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T pnoise(detail::tvec4<T> const & P, detail::tvec4<T> const & rep)
|
||||
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
|
||||
@ -558,7 +558,7 @@ namespace noise
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T snoise(glm::detail::tvec2<T> const & v)
|
||||
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
|
||||
@ -615,7 +615,7 @@ namespace noise
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T snoise(detail::tvec3<T> const & v)
|
||||
GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v)
|
||||
{
|
||||
detail::tvec2<T> const C = detail::tvec2<T>(1.0 / 6.0, 1.0 / 3.0);
|
||||
detail::tvec4<T> const D = detail::tvec4<T>(0.0, 0.5, 1.0, 2.0);
|
||||
@ -702,7 +702,7 @@ namespace noise
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T snoise(detail::tvec4<T> const & v)
|
||||
GLM_FUNC_QUALIFIER T simplex(detail::tvec4<T> const & v)
|
||||
{
|
||||
detail::tvec4<T> const C(
|
||||
0.138196601125011, // (5 - sqrt(5))/20 G4
|
||||
|
@ -20,4 +20,8 @@ int main()
|
||||
float ValueCNoise2D = glm::cnoise(glm::vec2(0.5f));
|
||||
float ValueCNoise3D = glm::cnoise(glm::vec3(0.5f));
|
||||
float ValueCNoise4D = glm::cnoise(glm::vec4(0.5f));
|
||||
|
||||
float ValuePNoise2D = glm::pnoise(glm::vec2(0.5f), glm::vec2(0.5f));
|
||||
float ValuePNoise3D = glm::pnoise(glm::vec3(0.5f), glm::vec3(0.5f));
|
||||
float ValuePNoise4D = glm::pnoise(glm::vec4(0.5f), glm::vec4(0.5f));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user