Merge branch '0.9.3' of git://ogl-math.git.sourceforge.net/gitroot/ogl-math/ogl-math

This commit is contained in:
athile 2011-09-23 14:10:59 -04:00
commit 1245dc51f3
4 changed files with 497 additions and 100 deletions

View File

@ -52,11 +52,35 @@ namespace glm
{
/// @addtogroup gtc_random
/// @{
/// Generate random numbers in the interval [Min, Max], according a linear distribution
///
/// @param Min
/// @param Max
/// @tparam genType Value type. Currently supported: half (not recommanded), float or double scalars and vectors.
/// @see gtc_random
template <typename genType>
genType linearRand(
genType const & Min,
genType const & Max);
/// Generate a random number in the interval [-1, 1], according a linear distribution.
/// From GLM_GTC_random extension.
template <typename T> T signedRand1();
/// Generate random numbers in the interval [Min, Max], according a gaussian distribution
/// (From GLM_GTX_random extension)
template <typename T, template <typename> class vecType>
vecType<T> gaussRand(
vecType<T> const & Mean,
vecType<T> const & Deviation);
/// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius
/// (From GLM_GTX_random extension)
template <typename T>
detail::tvec2<T> circularRand(T const & Radius);
/// Generate a random 3D vector which coordinates are regulary distributed on a sphere of a given radius
/// (From GLM_GTX_random extension)
template <typename T>
detail::tvec3<T> sphericalRand(T const & Radius);
/// @}
}//namespace glm

View File

@ -17,16 +17,22 @@
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)
{
return mod(((x * T(34)) + T(1)) * x, T(289));
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)
{
return mod(((x * T(34)) + T(1)) * x, T(289));
return mod289(((x * T(34)) + T(1)) * x);
}
template <typename T>
@ -98,6 +104,77 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec2<T> const & P)
return T(2.3) * n_xy;
}
// 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);
Pi1 = mod289(Pi1);
detail::tvec3<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec3<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(detail::tvec2<T>(Pi0.y), detail::tvec2<T>(Pi1.y));
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> ixy = permute(permute(ix) + iy);
detail::tvec4<T> ixy0 = permute(ixy + iz0);
detail::tvec4<T> ixy1 = permute(ixy + iz1);
detail::tvec4<T> gx0 = ixy0 * T(1.0 / 7.0);
detail::tvec4<T> gy0 = fract(floor(gx0) * T(1.0 / 7.0)) - T(0.5);
gx0 = fract(gx0);
detail::tvec4<T> gz0 = detail::tvec4<T>(0.5) - abs(gx0) - abs(gy0);
detail::tvec4<T> sz0 = step(gz0, detail::tvec4<T>(0.0));
gx0 -= sz0 * (step(T(0), gx0) - T(0.5));
gy0 -= sz0 * (step(T(0), gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 * T(1.0 / 7.0);
detail::tvec4<T> gy1 = fract(floor(gx1) * T(1.0 / 7.0)) - T(0.5);
gx1 = fract(gx1);
detail::tvec4<T> gz1 = detail::tvec4<T>(0.5) - abs(gx1) - abs(gy1);
detail::tvec4<T> sz1 = step(gz1, detail::tvec4<T>(0.0));
gx1 -= sz1 * (step(T(0), gx1) - T(0.5));
gy1 -= sz1 * (step(T(0), gy1) - T(0.5));
detail::tvec3<T> g000(gx0.x, gy0.x, gz0.x);
detail::tvec3<T> g100(gx0.y, gy0.y, gz0.y);
detail::tvec3<T> g010(gx0.z, gy0.z, gz0.z);
detail::tvec3<T> g110(gx0.w, gy0.w, gz0.w);
detail::tvec3<T> g001(gx1.x, gy1.x, gz1.x);
detail::tvec3<T> g101(gx1.y, gy1.y, gz1.y);
detail::tvec3<T> g011(gx1.z, gy1.z, gz1.z);
detail::tvec3<T> g111(gx1.w, gy1.w, gz1.w);
detail::tvec4<T> norm0 = taylorInvSqrt(detail::tvec4<T>(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<T> norm1 = taylorInvSqrt(detail::tvec4<T>(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<T>(Pf1.x, Pf0.y, Pf0.z));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.x, Pf1.y, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.x, Pf0.y, Pf1.z));
T n101 = dot(g101, detail::tvec3<T>(Pf1.x, Pf0.y, Pf1.z));
T n011 = dot(g011, detail::tvec3<T>(Pf0.x, Pf1.y, Pf1.z));
T n111 = dot(g111, Pf1);
detail::tvec3<T> fade_xyz = fade(Pf0);
detail::tvec4<T> n_z = mix(detail::tvec4<T>(n000, n100, n010, n110), detail::tvec4<T>(n001, n101, n011, n111), fade_xyz.z);
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)
@ -170,7 +247,7 @@ GLM_FUNC_QUALIFIER T perlin(detail::tvec3<T> 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 <typename T>
GLM_FUNC_QUALIFIER T perlin(detail::tvec4<T> const & P)
@ -614,18 +691,18 @@ GLM_FUNC_QUALIFIER T simplex(glm::detail::tvec2<T> const & v)
template <typename T>
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);
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);
// First corner
detail::tvec3<T> i = floor(v + dot(v, detail::tvec3<T>(C.y)));
detail::tvec3<T> x0 = v - i + dot(i, detail::tvec3<T>(C.x));
detail::tvec3<T> x0 = v - i + dot(i, detail::tvec3<T>(C.x));
// Other corners
detail::tvec3<T> g = step(detail::tvec3<T>(x0.y, x0.z, x0.x), detail::tvec3<T>(x0.x, x0.y, x0.z));
detail::tvec3<T> g = step(detail::tvec3<T>(x0.y, x0.z, x0.x), x0);
detail::tvec3<T> l = T(1) - g;
detail::tvec3<T> i1 = min(detail::tvec3<T>(g.x, g.y, g.z), detail::tvec3<T>(l.z, l.x, l.y));
detail::tvec3<T> i2 = max(detail::tvec3<T>(g.x, g.y, g.z), detail::tvec3<T>(l.z, l.x, l.y));
detail::tvec3<T> i1 = min(g, detail::tvec3<T>(l.z, l.x, l.y));
detail::tvec3<T> i2 = max(g, detail::tvec3<T>(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<T> const & v)
detail::tvec3<T> 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<T> p = permute(permute(permute(
i.z + detail::tvec4<T>(0.0, i1.z, i2.z, 1.0)) +
i.y + detail::tvec4<T>(0.0, i1.y, i2.y, 1.0)) +
i.x + detail::tvec4<T>(0.0, i1.x, i2.x, 1.0));
i.z + detail::tvec4<T>(T(0), i1.z, i2.z, T(1))) +
i.y + detail::tvec4<T>(T(0), i1.y, i2.y, T(1))) +
i.x + detail::tvec4<T>(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<T> const & v)
detail::tvec4<T> y = y_ * ns.x + ns.y;
detail::tvec4<T> h = T(1) - abs(x) - abs(y);
detail::tvec4<T> b0 = detail::tvec4<T>(x.x, x.y, y.x, y.y);
detail::tvec4<T> b1 = detail::tvec4<T>(x.z, x.w, y.z, y.w);
detail::tvec4<T> b0(x.x, x.y, y.x, y.y);
detail::tvec4<T> 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<T> s0 = floor(b0) * T(2) + T(1);
detail::tvec4<T> s1 = floor(b1) * T(2) + T(1);
detail::tvec4<T> sh = -step(h, detail::tvec4<T>(0));
detail::tvec4<T> sh = -step(h, detail::tvec4<T>(0.0));
detail::tvec4<T> a0 = b0 + s0 * detail::tvec4<T>(sh.x, sh.x, sh.y, sh.y);
detail::tvec4<T> a1 = b1 + s1 * detail::tvec4<T>(sh.z, sh.z, sh.w, sh.w);
detail::tvec4<T> a0 = detail::tvec4<T>(b0.x, b0.z, b0.y, b0.w) + detail::tvec4<T>(s0.x, s0.z, s0.y, s0.w) * detail::tvec4<T>(sh.x, sh.x, sh.y, sh.y);
detail::tvec4<T> a1 = detail::tvec4<T>(b1.x, b1.z, b1.y, b1.w) + detail::tvec4<T>(s1.x, s1.z, s1.y, s1.w) * detail::tvec4<T>(sh.z, sh.z, sh.w, sh.w);
detail::tvec3<T> p0 = vec3(a0.x, a0.y, h.x);
detail::tvec3<T> p1 = vec3(a0.z, a0.w, h.y);
detail::tvec3<T> p2 = vec3(a1.x, a1.y, h.z);
detail::tvec3<T> p3 = vec3(a1.z, a1.w, h.w);
detail::tvec3<T> p0(a0.x, a0.y, h.x);
detail::tvec3<T> p1(a0.z, a0.w, h.y);
detail::tvec3<T> p2(a1.x, a1.y, h.z);
detail::tvec3<T> p3(a1.z, a1.w, h.w);
//Normalise gradients
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(
dot(p0, p0),
dot(p1, p1),
dot(p2, p2),
dot(p3, p3)));
// Normalise gradients
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(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<T>(
dot(x0, x0),
dot(x1, x1),
dot(x2, x2),
dot(x3, x3)), T(0));
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)));
return T(42) * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
}
template <typename T>

View File

@ -90,41 +90,211 @@ int test_half_ctor_mat2x3()
{
int Error = 0;
return Error;
{
glm::hvec3 A(1, 2, 3);
glm::hvec3 B(4, 5, 6);
glm::hmat2x3 C(A, B);
glm::hmat2x3 D(1, 2, 3, 4, 5, 6);
Error += C[0] == D[0] ? 0 : 1;
Error += C[1] == D[1] ? 0 : 1;
}
{
glm::hvec3 A(1.0, 2.0f, 3u);
glm::hvec3 B(4, 5u, 6u);
glm::hmat2x3 C(A, B);
glm::hmat2x3 D(1, 2.0, 3u, 4.0f, 5.0, 6);
Error += C[0] == D[0] ? 0 : 1;
Error += C[1] == D[1] ? 0 : 1;
}
{
glm::hmat2x3 A(1);
glm::mat2x3 B(1);
glm::hmat2x3 C(A);
Error += A == C ? 0 : 1;
}
return Error;
}
int test_half_ctor_mat2x4()
{
int Error = 0;
return Error;
{
glm::hvec4 A(1, 2, 3, 4);
glm::hvec4 B(5, 6, 7, 8);
glm::hmat2x4 C(A, B);
glm::hmat2x4 D(1, 2, 3, 4, 5, 6, 7, 8);
Error += C[0] == D[0] ? 0 : 1;
Error += C[1] == D[1] ? 0 : 1;
}
{
glm::hvec4 A(1.0, 2.0f, 3u, 4u);
glm::hvec4 B(5u, 6u, 7.0, 8.0);
glm::hmat2x4 C(A, B);
glm::hmat2x4 D(1, 2.0, 3u, 4.0f, 5.0, 6, 7.0f, 8.0f);
Error += C[0] == D[0] ? 0 : 1;
Error += C[1] == D[1] ? 0 : 1;
}
{
glm::hmat2x4 A(1);
glm::mat2x4 B(1);
glm::hmat2x4 C(A);
Error += A == C ? 0 : 1;
}
return Error;
}
int test_half_ctor_mat3x2()
{
int Error = 0;
return Error;
{
glm::hvec2 A(1, 2);
glm::hvec2 B(3, 4);
glm::hvec2 C(5, 6);
glm::hmat3x2 M(A, B, C);
glm::hmat3x2 N(1, 2, 3, 4, 5, 6);
Error += M == N ? 0 : 1;
}
{
glm::hvec2 A(1, 2.0);
glm::hvec2 B(3, 4.0f);
glm::hvec2 C(5u, 6.0f);
glm::hmat3x2 M(A, B, C);
glm::hmat3x2 N(1, 2.0, 3u, 4.0f, 5, 6);
Error += M == N ? 0 : 1;
}
{
glm::hmat3x2 A(1);
glm::mat3x2 B(1);
glm::hmat3x2 C(A);
Error += A == C ? 0 : 1;
}
return Error;
}
int test_half_ctor_mat3x3()
{
int Error = 0;
return Error;
{
glm::hvec3 A(1, 2, 3);
glm::hvec3 B(4, 5, 6);
glm::hvec3 C(7, 8, 9);
glm::hmat3x3 M(A, B, C);
glm::hmat3x3 N(1, 2, 3, 4, 5, 6, 7, 8, 9);
Error += M == N ? 0 : 1;
}
{
glm::hvec3 A(1, 2.0, 3.0f);
glm::hvec3 B(4, 5.0f, 6.0);
glm::hvec3 C(7u, 8.0f, 9);
glm::hmat3x3 M(A, B, C);
glm::hmat3x3 N(1, 2.0, 3u, 4.0f, 5, 6, 7.0f, 8.0, 9u);
Error += M == N ? 0 : 1;
}
{
glm::hmat3x3 A(1);
glm::mat3x3 B(1);
glm::hmat3x3 C(A);
Error += A == C ? 0 : 1;
}
return Error;
}
int test_half_ctor_mat3x4()
{
int Error = 0;
return Error;
{
glm::hvec4 A(1, 2, 3, 4);
glm::hvec4 B(5, 6, 7, 8);
glm::hvec4 C(9, 10, 11, 12);
glm::hmat3x4 M(A, B, C);
glm::hmat3x4 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
Error += M == N ? 0 : 1;
}
{
glm::hvec4 A(1, 2.0, 3.0f, 4u);
glm::hvec4 B(5, 6.0f, 7.0, 8);
glm::hvec4 C(9u, 10.0f, 11, 12.f);
glm::hmat3x4 M(A, B, C);
glm::hmat3x4 N(1, 2.0, 3u, 4.0f, 5, 6, 7.0f, 8.0, 9u, 10, 11.f, 12.0);
Error += M == N ? 0 : 1;
}
{
glm::hmat3x4 A(1);
glm::mat3x4 B(1);
glm::hmat3x4 C(A);
Error += A == C ? 0 : 1;
}
return Error;
}
int test_half_ctor_mat4x2()
{
int Error = 0;
{
glm::hvec2 A(1, 2);
glm::hvec2 B(3, 4);
glm::hvec2 C(5, 6);
glm::hvec2 D(7, 8);
glm::hmat4x2 M(A, B, C, D);
glm::hmat4x2 N(1, 2, 3, 4, 5, 6, 7, 8);
Error += M == N ? 0 : 1;
}
{
glm::hvec2 A(1, 2.0);
glm::hvec2 B(3.0f, 4);
glm::hvec2 C(5.0, 6u);
glm::hvec2 D(7, 8u);
glm::hmat4x2 M(A, B, C, D);
glm::hmat4x2 N(1, 2.0, 3u, 4.0f, 5u, 6.0, 7, 8.0f);
Error += M == N ? 0 : 1;
}
{
glm::hmat4x2 A(1);
glm::mat4x2 B(1);
glm::hmat4x2 C(A);
Error += A == C ? 0 : 1;
}
return Error;
}
@ -132,6 +302,36 @@ int test_half_ctor_mat4x3()
{
int Error = 0;
{
glm::hvec3 A(1, 2, 3);
glm::hvec3 B(4, 5, 6);
glm::hvec3 C(7, 8, 9);
glm::hvec3 D(10, 11, 12);
glm::hmat4x3 M(A, B, C, D);
glm::hmat4x3 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
Error += M == N ? 0 : 1;
}
{
glm::hvec3 A(1, 2.0, 3u);
glm::hvec3 B(4.0f, 5, 6u);
glm::hvec3 C(7.0, 8u, 9.f);
glm::hvec3 D(10, 11u, 12.0);
glm::hmat4x3 M(A, B, C, D);
glm::hmat4x3 N(1, 2.0, 3u, 4.0f, 5u, 6.0, 7, 8.0f, 9, 10u, 11.f, 12.0);
Error += M == N ? 0 : 1;
}
{
glm::hmat4x3 A(1);
glm::mat4x3 B(1);
glm::hmat4x3 C(A);
Error += A == C ? 0 : 1;
}
return Error;
}
@ -139,6 +339,36 @@ int test_half_ctor_mat4x4()
{
int Error = 0;
{
glm::hvec4 A(1, 2, 3, 4);
glm::hvec4 B(5, 6, 7, 8);
glm::hvec4 C(9, 10, 11, 12);
glm::hvec4 D(13, 14, 15, 16);
glm::hmat4x4 M(A, B, C, D);
glm::hmat4x4 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
Error += M == N ? 0 : 1;
}
{
glm::hvec4 A(1, 2.0, 3u, 4);
glm::hvec4 B(5.0f, 6, 7u, 8.0);
glm::hvec4 C(9.0, 10u, 11.f, 12);
glm::hvec4 D(13, 14u, 15.0, 16u);
glm::hmat4x4 M(A, B, C, D);
glm::hmat4x4 N(1, 2.0, 3u, 4.0f, 5u, 6.0, 7, 8.0f, 9, 10u, 11.f, 12.0, 13, 14u, 15.0f, 16.0);
Error += M == N ? 0 : 1;
}
{
glm::hmat4x4 A(1);
glm::mat4x4 B(1);
glm::hmat4x4 C(A);
Error += A == C ? 0 : 1;
}
return Error;
}
@ -288,6 +518,14 @@ int main()
Error += test_half_ctor_vec3();
Error += test_half_ctor_vec4();
Error += test_half_ctor_mat2x2();
Error += test_half_ctor_mat2x3();
Error += test_half_ctor_mat2x4();
Error += test_half_ctor_mat3x2();
Error += test_half_ctor_mat3x3();
Error += test_half_ctor_mat3x4();
Error += test_half_ctor_mat4x2();
Error += test_half_ctor_mat4x3();
Error += test_half_ctor_mat4x4();
Error += test_half_precision_scalar();
Error += test_half_precision_vec();
Error += test_half_precision_mat();

View File

@ -10,110 +10,180 @@
#include <glm/glm.hpp>
#include <glm/gtx/noise.hpp>
#include <gli/gli.hpp>
#include <gli/gtx/loader.hpp>
#include <iostream>
int test_simplex()
{
std::size_t const Size = 256;
{
float ImageData[256];
std::vector<glm::byte> 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<glm::byte> 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<glm::byte> 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<glm::byte> 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<glm::byte> 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<glm::byte> 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<glm::byte> 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<glm::byte> 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<glm::byte> 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;
}