From c9987349143987f5454f356dd6217e4932f35b9d Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 21 Sep 2011 09:01:04 +0100 Subject: [PATCH 1/5] Restore MS version of hvec* --- glm/core/type_vec2.hpp | 2 +- glm/core/type_vec3.hpp | 2 +- glm/core/type_vec4.hpp | 2 +- glm/gtc/half_float.hpp | 2 +- glm/gtc/half_float.inl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/glm/core/type_vec2.hpp b/glm/core/type_vec2.hpp index b9f7aebe..1973e7a3 100644 --- a/glm/core/type_vec2.hpp +++ b/glm/core/type_vec2.hpp @@ -67,9 +67,9 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - struct{value_type x, y;}; struct{value_type r, g;}; struct{value_type s, t;}; + struct{value_type x, y;}; }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; diff --git a/glm/core/type_vec3.hpp b/glm/core/type_vec3.hpp index 2b504cee..6d17b54e 100644 --- a/glm/core/type_vec3.hpp +++ b/glm/core/type_vec3.hpp @@ -67,9 +67,9 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - struct{value_type x, y, z;}; struct{value_type r, g, b;}; struct{value_type s, t, p;}; + struct{value_type x, y, z;}; }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; diff --git a/glm/core/type_vec4.hpp b/glm/core/type_vec4.hpp index 30c8ebce..21d326a7 100644 --- a/glm/core/type_vec4.hpp +++ b/glm/core/type_vec4.hpp @@ -67,9 +67,9 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - struct{value_type x, y, z, w;}; struct{value_type r, g, b, a;}; struct{value_type s, t, p, q;}; + struct{value_type x, y, z, w;}; }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; diff --git a/glm/gtc/half_float.hpp b/glm/gtc/half_float.hpp index 39a5abeb..8cb6689d 100644 --- a/glm/gtc/half_float.hpp +++ b/glm/gtc/half_float.hpp @@ -47,7 +47,7 @@ namespace glm{ namespace detail { -#if 1 //ndef _MSC_EXTENSIONS +#ifndef _MSC_EXTENSIONS template <> struct tvec2 { diff --git a/glm/gtc/half_float.inl b/glm/gtc/half_float.inl index 086c88fb..2d20f8a0 100644 --- a/glm/gtc/half_float.inl +++ b/glm/gtc/half_float.inl @@ -29,7 +29,7 @@ namespace glm{ namespace detail{ -#if 1 //ndef _MSC_EXTENSIONS +#ifndef _MSC_EXTENSIONS ////////////////////////////////////// // hvec2 From cec8665d16489722d7b069baf549f9d5cedb8e4e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 21 Sep 2011 10:50:54 +0100 Subject: [PATCH 2/5] Fixed ticket #128, bitfield based on vec types --- glm/core/func_integer.inl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/glm/core/func_integer.inl b/glm/core/func_integer.inl index 0e30aa2a..fb046708 100644 --- a/glm/core/func_integer.inl +++ b/glm/core/func_integer.inl @@ -285,8 +285,8 @@ namespace glm ) { return detail::tvec2( - bitfieldExtract(Value[0]), - bitfieldExtract(Value[1])); + bitfieldExtract(Value[0], Offset, Bits), + bitfieldExtract(Value[1], Offset, Bits)); } template @@ -298,9 +298,9 @@ namespace glm ) { return detail::tvec3( - bitfieldExtract(Value[0]), - bitfieldExtract(Value[1]), - bitfieldExtract(Value[2])); + bitfieldExtract(Value[0], Offset, Bits), + bitfieldExtract(Value[1], Offset, Bits), + bitfieldExtract(Value[2], Offset, Bits)); } template @@ -312,10 +312,10 @@ namespace glm ) { return detail::tvec4( - bitfieldExtract(Value[0]), - bitfieldExtract(Value[1]), - bitfieldExtract(Value[2]), - bitfieldExtract(Value[3])); + bitfieldExtract(Value[0], Offset, Bits), + bitfieldExtract(Value[1], Offset, Bits), + bitfieldExtract(Value[2], Offset, Bits), + bitfieldExtract(Value[3], Offset, Bits)); } // bitfieldInsert From 64453fd44eb27d37bbd41e61e54adb432492b51f Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 21 Sep 2011 10:53:10 +0100 Subject: [PATCH 3/5] Fixed half vectors on VC + MS lang ext --- glm/core/type_vec2.hpp | 2 +- glm/core/type_vec3.hpp | 2 +- glm/core/type_vec4.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/glm/core/type_vec2.hpp b/glm/core/type_vec2.hpp index b8d47b7b..ae266e15 100644 --- a/glm/core/type_vec2.hpp +++ b/glm/core/type_vec2.hpp @@ -48,9 +48,9 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - struct{value_type x, y;}; struct{value_type r, g;}; struct{value_type s, t;}; + struct{value_type x, y;}; }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; diff --git a/glm/core/type_vec3.hpp b/glm/core/type_vec3.hpp index 7b568789..1afb844f 100644 --- a/glm/core/type_vec3.hpp +++ b/glm/core/type_vec3.hpp @@ -48,9 +48,9 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - struct{value_type x, y, z;}; struct{value_type r, g, b;}; struct{value_type s, t, p;}; + struct{value_type x, y, z;}; }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; diff --git a/glm/core/type_vec4.hpp b/glm/core/type_vec4.hpp index 940b5c19..9ea08606 100644 --- a/glm/core/type_vec4.hpp +++ b/glm/core/type_vec4.hpp @@ -48,9 +48,9 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - struct{value_type x, y, z, w;}; struct{value_type r, g, b, a;}; struct{value_type s, t, p, q;}; + struct{value_type x, y, z, w;}; }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; From cd1df245bcb17a4f743136b88392827248b9a7de Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 21 Sep 2011 17:48:49 +0100 Subject: [PATCH 4/5] Added noise tests output --- test/gtx/gtx_noise.cpp | 172 +++++++++++++++++++++++++++++------------ 1 file changed, 121 insertions(+), 51 deletions(-) diff --git a/test/gtx/gtx_noise.cpp b/test/gtx/gtx_noise.cpp index 2fd16c29..c3f46a88 100644 --- a/test/gtx/gtx_noise.cpp +++ b/test/gtx/gtx_noise.cpp @@ -10,110 +10,180 @@ #include #include #include +#include #include int test_simplex() { + std::size_t const Size = 256; + { - float ImageData[256]; + std::vector ImageData(Size * Size * 3); - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) { - ImageData[x + y * 16] = glm::simplex(glm::vec2(x / 16.f, y / 16.f)); + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec2(x / 16.f, y / 16.f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_simplex2d_256.dds"); } { - float ImageData[256]; + std::vector ImageData(Size * Size * 3); - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) { - ImageData[x + y * 16] = glm::simplex(glm::vec3(x / 16.f, y / 16.f, 0.5f)); + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec3(x / 16.f, y / 16.f, 0.5f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_simplex3d_256.dds"); } { - float ImageData[256]; + std::vector ImageData(Size * Size * 3); - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) { - ImageData[x + y * 16] = glm::simplex(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)); + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; } - } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_simplex4d_256.dds"); + } return 0; } int test_perlin() { + std::size_t const Size = 256; + { - float ImageData[256]; + std::vector ImageData(Size * Size * 3); - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) { - ImageData[x + y * 16] = glm::perlin(glm::vec2(x / 16.f, y / 16.f)); + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 16.f, y / 16.f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_perlin2d_256.dds"); + } + + { + std::vector ImageData(Size * Size * 3); + + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) + { + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 16.f, y / 16.f, 0.5f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; + } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_perlin3d_256.dds"); } { - float ImageData[256]; + std::vector ImageData(Size * Size * 3); - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) { - ImageData[x + y * 16] = glm::perlin(glm::vec3(x / 16.f, y / 16.f, 0.5f)); + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_perlin4d_256.dds"); } - - { - float ImageData[256]; - - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) - { - ImageData[x + y * 16] = glm::perlin(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)); - } - } - + return 0; } int test_perlin_pedioric() { + std::size_t const Size = 256; + { - float ImageData[256]; + std::vector ImageData(Size * Size * 3); - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) { - ImageData[x + y * 16] = glm::perlin(glm::vec2(x / 16.f, y / 16.f), glm::vec2(0.5f)); + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 16.f, y / 16.f), glm::vec2(2.0f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_perlin_pedioric_2d_256.dds"); + } + + { + std::vector ImageData(Size * Size * 3); + + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) + { + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 16.f, y / 16.f, 0.5f), glm::vec3(2.0f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; + } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_perlin_pedioric_3d_256.dds"); } { - float ImageData[256]; + std::vector ImageData(Size * Size * 3); - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) + for(std::size_t y = 0; y < Size; ++y) + for(std::size_t x = 0; x < Size; ++x) { - ImageData[x + y * 16] = glm::perlin(glm::vec3(x / 16.f, y / 16.f, 0.5f), glm::vec3(0.5f)); + ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f), glm::vec4(2.0f)) * 128.f + 127.f); + ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0]; + ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0]; } + + gli::texture2D Texture(1); + Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U); + memcpy(Texture[0].data(), &ImageData[0], ImageData.size()); + gli::saveDDS9(Texture, "texture_perlin_pedioric_4d_256.dds"); } - - { - float ImageData[256]; - - for(std::size_t y = 0; y < 16; ++y) - for(std::size_t x = 0; x < 16; ++x) - { - ImageData[x + y * 16] = glm::perlin(glm::vec4(x / 16.f, y / 16.f, 0.5f, 0.5f), glm::vec4(0.5f)); - } - } - + return 0; } From b2b664e9d9fec7a7e5a621eae4ae7f9527ad09fd Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 21 Sep 2011 19:37:10 +0100 Subject: [PATCH 5/5] Updated simplex3d implementation --- glm/gtx/noise.inl | 145 +++++++++++++++++++++++++++++++++------------- 1 file changed, 105 insertions(+), 40 deletions(-) diff --git a/glm/gtx/noise.inl b/glm/gtx/noise.inl index ae8e03c2..50841c20 100644 --- a/glm/gtx/noise.inl +++ b/glm/gtx/noise.inl @@ -17,16 +17,22 @@ namespace glm{ +template +GLM_FUNC_QUALIFIER T mod289(T const & x) +{ + return x - floor(x * T(1.0 / 289.0)) * T(289.0); +} + template GLM_FUNC_QUALIFIER T permute(T const & x) { - return mod(((x * T(34)) + T(1)) * x, T(289)); + return mod289(((x * T(34)) + T(1)) * x); } template class vecType> GLM_FUNC_QUALIFIER vecType permute(vecType const & x) { - return mod(((x * T(34)) + T(1)) * x, T(289)); + return mod289(((x * T(34)) + T(1)) * x); } template @@ -98,6 +104,77 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec2 const & P) return T(2.3) * n_xy; } +// Classic Perlin noise +template +GLM_FUNC_QUALIFIER T perlin(detail::tvec3 const & P) +{ + detail::tvec3 Pi0 = floor(P); // Integer part for indexing + detail::tvec3 Pi1 = Pi0 + T(1); // Integer part + 1 + Pi0 = mod289(Pi0); + Pi1 = mod289(Pi1); + detail::tvec3 Pf0 = fract(P); // Fractional part for interpolation + detail::tvec3 Pf1 = Pf0 - T(1); // Fractional part - 1.0 + detail::tvec4 ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x); + detail::tvec4 iy = detail::tvec4(detail::tvec2(Pi0.y), detail::tvec2(Pi1.y)); + detail::tvec4 iz0(Pi0.z); + detail::tvec4 iz1(Pi1.z); + + detail::tvec4 ixy = permute(permute(ix) + iy); + detail::tvec4 ixy0 = permute(ixy + iz0); + detail::tvec4 ixy1 = permute(ixy + iz1); + + detail::tvec4 gx0 = ixy0 * T(1.0 / 7.0); + detail::tvec4 gy0 = fract(floor(gx0) * T(1.0 / 7.0)) - T(0.5); + gx0 = fract(gx0); + detail::tvec4 gz0 = detail::tvec4(0.5) - abs(gx0) - abs(gy0); + detail::tvec4 sz0 = step(gz0, detail::tvec4(0.0)); + gx0 -= sz0 * (step(T(0), gx0) - T(0.5)); + gy0 -= sz0 * (step(T(0), gy0) - T(0.5)); + + detail::tvec4 gx1 = ixy1 * T(1.0 / 7.0); + detail::tvec4 gy1 = fract(floor(gx1) * T(1.0 / 7.0)) - T(0.5); + gx1 = fract(gx1); + detail::tvec4 gz1 = detail::tvec4(0.5) - abs(gx1) - abs(gy1); + detail::tvec4 sz1 = step(gz1, detail::tvec4(0.0)); + gx1 -= sz1 * (step(T(0), gx1) - T(0.5)); + gy1 -= sz1 * (step(T(0), gy1) - T(0.5)); + + detail::tvec3 g000(gx0.x, gy0.x, gz0.x); + detail::tvec3 g100(gx0.y, gy0.y, gz0.y); + detail::tvec3 g010(gx0.z, gy0.z, gz0.z); + detail::tvec3 g110(gx0.w, gy0.w, gz0.w); + detail::tvec3 g001(gx1.x, gy1.x, gz1.x); + detail::tvec3 g101(gx1.y, gy1.y, gz1.y); + detail::tvec3 g011(gx1.z, gy1.z, gz1.z); + detail::tvec3 g111(gx1.w, gy1.w, gz1.w); + + detail::tvec4 norm0 = taylorInvSqrt(detail::tvec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110))); + g000 *= norm0.x; + g010 *= norm0.y; + g100 *= norm0.z; + g110 *= norm0.w; + detail::tvec4 norm1 = taylorInvSqrt(detail::tvec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111))); + g001 *= norm1.x; + g011 *= norm1.y; + g101 *= norm1.z; + g111 *= norm1.w; + + T n000 = dot(g000, Pf0); + T n100 = dot(g100, detail::tvec3(Pf1.x, Pf0.y, Pf0.z)); + T n010 = dot(g010, detail::tvec3(Pf0.x, Pf1.y, Pf0.z)); + T n110 = dot(g110, detail::tvec3(Pf1.x, Pf1.y, Pf0.z)); + T n001 = dot(g001, detail::tvec3(Pf0.x, Pf0.y, Pf1.z)); + T n101 = dot(g101, detail::tvec3(Pf1.x, Pf0.y, Pf1.z)); + T n011 = dot(g011, detail::tvec3(Pf0.x, Pf1.y, Pf1.z)); + T n111 = dot(g111, Pf1); + + detail::tvec3 fade_xyz = fade(Pf0); + detail::tvec4 n_z = mix(detail::tvec4(n000, n100, n010, n110), detail::tvec4(n001, n101, n011, n111), fade_xyz.z); + detail::tvec2 n_yz = mix(detail::tvec2(n_z.x, n_z.y), detail::tvec2(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 GLM_FUNC_QUALIFIER T perlin(detail::tvec3 const & P) @@ -170,7 +247,7 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec3 const & P) T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); return T(2.2) * n_xyz; } - +*/ // Classic Perlin noise template GLM_FUNC_QUALIFIER T perlin(detail::tvec4 const & P) @@ -614,18 +691,18 @@ GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2 const & v) template GLM_FUNC_QUALIFIER T simplex(detail::tvec3 const & v) { - detail::tvec2 const C = detail::tvec2(1.0 / 6.0, 1.0 / 3.0); - detail::tvec4 const D = detail::tvec4(0.0, 0.5, 1.0, 2.0); + detail::tvec2 const C(1.0 / 6.0, 1.0 / 3.0); + detail::tvec4 const D(0.0, 0.5, 1.0, 2.0); // First corner detail::tvec3 i = floor(v + dot(v, detail::tvec3(C.y))); - detail::tvec3 x0 = v - i + dot(i, detail::tvec3(C.x)); + detail::tvec3 x0 = v - i + dot(i, detail::tvec3(C.x)); // Other corners - detail::tvec3 g = step(detail::tvec3(x0.y, x0.z, x0.x), detail::tvec3(x0.x, x0.y, x0.z)); + detail::tvec3 g = step(detail::tvec3(x0.y, x0.z, x0.x), x0); detail::tvec3 l = T(1) - g; - detail::tvec3 i1 = min(detail::tvec3(g.x, g.y, g.z), detail::tvec3(l.z, l.x, l.y)); - detail::tvec3 i2 = max(detail::tvec3(g.x, g.y, g.z), detail::tvec3(l.z, l.x, l.y)); + detail::tvec3 i1 = min(g, detail::tvec3(l.z, l.x, l.y)); + detail::tvec3 i2 = max(g, detail::tvec3(l.z, l.x, l.y)); // x0 = x0 - 0.0 + 0.0 * C.xxx; // x1 = x0 - i1 + 1.0 * C.xxx; @@ -636,11 +713,11 @@ GLM_FUNC_QUALIFIER T simplex(detail::tvec3 const & v) detail::tvec3 x3 = x0 - D.y; // -1.0+3.0*C.x = -0.5 = -D.y // Permutations - i = mod(i, T(289)); + i = mod289(i); detail::tvec4 p = permute(permute(permute( - i.z + detail::tvec4(0.0, i1.z, i2.z, 1.0)) + - i.y + detail::tvec4(0.0, i1.y, i2.y, 1.0)) + - i.x + detail::tvec4(0.0, i1.x, i2.x, 1.0)); + i.z + detail::tvec4(T(0), i1.z, i2.z, T(1))) + + i.y + detail::tvec4(T(0), i1.y, i2.y, T(1))) + + i.x + detail::tvec4(T(0), i1.x, i2.x, T(1))); // Gradients: 7x7 points over a square, mapped onto an octahedron. // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) @@ -656,46 +733,34 @@ GLM_FUNC_QUALIFIER T simplex(detail::tvec3 const & v) detail::tvec4 y = y_ * ns.x + ns.y; detail::tvec4 h = T(1) - abs(x) - abs(y); - detail::tvec4 b0 = detail::tvec4(x.x, x.y, y.x, y.y); - detail::tvec4 b1 = detail::tvec4(x.z, x.w, y.z, y.w); + detail::tvec4 b0(x.x, x.y, y.x, y.y); + detail::tvec4 b1(x.z, x.w, y.z, y.w); - //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; - //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; + // vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; + // vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; detail::tvec4 s0 = floor(b0) * T(2) + T(1); detail::tvec4 s1 = floor(b1) * T(2) + T(1); - detail::tvec4 sh = -step(h, detail::tvec4(0)); + detail::tvec4 sh = -step(h, detail::tvec4(0.0)); - detail::tvec4 a0 = b0 + s0 * detail::tvec4(sh.x, sh.x, sh.y, sh.y); - detail::tvec4 a1 = b1 + s1 * detail::tvec4(sh.z, sh.z, sh.w, sh.w); + detail::tvec4 a0 = detail::tvec4(b0.x, b0.z, b0.y, b0.w) + detail::tvec4(s0.x, s0.z, s0.y, s0.w) * detail::tvec4(sh.x, sh.x, sh.y, sh.y); + detail::tvec4 a1 = detail::tvec4(b1.x, b1.z, b1.y, b1.w) + detail::tvec4(s1.x, s1.z, s1.y, s1.w) * detail::tvec4(sh.z, sh.z, sh.w, sh.w); - detail::tvec3 p0 = vec3(a0.x, a0.y, h.x); - detail::tvec3 p1 = vec3(a0.z, a0.w, h.y); - detail::tvec3 p2 = vec3(a1.x, a1.y, h.z); - detail::tvec3 p3 = vec3(a1.z, a1.w, h.w); + detail::tvec3 p0(a0.x, a0.y, h.x); + detail::tvec3 p1(a0.z, a0.w, h.y); + detail::tvec3 p2(a1.x, a1.y, h.z); + detail::tvec3 p3(a1.z, a1.w, h.w); - //Normalise gradients - detail::tvec4 norm = taylorInvSqrt(detail::tvec4( - dot(p0, p0), - dot(p1, p1), - dot(p2, p2), - dot(p3, p3))); + // Normalise gradients + detail::tvec4 norm = taylorInvSqrt(detail::tvec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w; // Mix final noise value - vec4 m = max(T(0.6) - detail::tvec4( - dot(x0, x0), - dot(x1, x1), - dot(x2, x2), - dot(x3, x3)), T(0)); + detail::tvec4 m = max(T(0.6) - detail::tvec4(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( - dot(p0, x0), - dot(p1, x1), - dot(p2, x2), - dot(p3, x3))); + return T(42) * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))); } template