Added draft implementations for all noise functions

This commit is contained in:
Christophe Riccio 2011-04-27 17:29:11 +01:00
parent 082d9151d8
commit d78ffa1d15

View File

@ -176,6 +176,584 @@ namespace noise
dot(p3, x3))); dot(p3, x3)));
} }
template <typename T>
inline T snoise(detail::tvec4<T> const & v)
{
detail::tvec4<T> const C(
0.138196601125011, // (5 - sqrt(5))/20 G4
0.276393202250021, // 2 * G4
0.414589803375032, // 3 * G4
-0.447213595499958); // -1 + 4 * G4
// (sqrt(5) - 1)/4 = F4, used once below
T const F4(0.309016994374947451);
// First corner
detail::tvec4<T> i = floor(v + dot(v, vec4(F4)));
detail::tvec4<T> x0 = v - i + dot(i, vec4(C.x));
// Other corners
// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
detail::tvec4<T> i0;
detail::tvec3<T> isX = step(x0.yzw, x0.xxx);
detail::tvec3<T> isYZ = step(x0.zww, x0.yyz);
// i0.x = dot( isX, vec3( 1.0 ) );
i0.x = isX.x + isX.y + isX.z;
i0.yzw = 1.0 - isX;
// i0.y += dot( isYZ.xy, vec2( 1.0 ) );
i0.y += isYZ.x + isYZ.y;
i0.zw += 1.0 - isYZ.xy;
i0.z += isYZ.z;
i0.w += 1.0 - isYZ.z;
// i0 now contains the unique values 0,1,2,3 in each channel
detail::tvec4<T> i3 = clamp(i0, 0.0, 1.0);
detail::tvec4<T> i2 = clamp(i0 - 1.0, 0.0, 1.0);
detail::tvec4<T> i1 = clamp(i0 - 2.0, 0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xxxx
// x1 = x0 - i1 + 0.0 * C.xxxx
// x2 = x0 - i2 + 0.0 * C.xxxx
// x3 = x0 - i3 + 0.0 * C.xxxx
// x4 = x0 - 1.0 + 4.0 * C.xxxx
detail::tvec4<T> x1 = x0 - i1 + C.x;
detail::tvec4<T> x2 = x0 - i2 + C.y;
detail::tvec4<T> x3 = x0 - i3 + C.z;
detail::tvec4<T> x4 = x0 + C.w;
// Permutations
i = mod(i, T(289));
T j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x);
detail::tvec4<T> j1 = permute(permute(permute(permute(
i.w + detail::tvec4<T>(i1.w, i2.w, i3.w, T(1)))
+ i.z + detail::tvec4<T>(i1.z, i2.z, i3.z, T(1)))
+ i.y + detail::tvec4<T>(i1.y, i2.y, i3.y, T(1)))
+ i.x + detail::tvec4<T>(i1.x, i2.x, i3.x, T(1)));
// Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
detail::tvec4<T> ip = detail::tvec4<T>(T(1) / T(294), T(1) / T(49), T(1) / T(7), T(0));
detail::tvec4<T> p0 = grad4(j0, ip);
detail::tvec4<T> p1 = grad4(j1.x, ip);
detail::tvec4<T> p2 = grad4(j1.y, ip);
detail::tvec4<T> p3 = grad4(j1.z, ip);
detail::tvec4<T> p4 = grad4(j1.w, ip);
// 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;
p4 *= taylorInvSqrt(dot(p4, p4));
// Mix contributions from the five corners
detail::tvec3<T> m0 = max(T(0.6) - detail::tvec3<T>(dot(x0, x0), dot(x1, x1), dot(x2, x2)), T(0));
detail::tvec2<T> m1 = max(T(0.6) - detail::tvec2<T>(dot(x3, x3), dot(x4, x4) ), T(0));
m0 = m0 * m0;
m1 = m1 * m1;
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))));
}
// Classic Perlin noise
template <typename T>
inline T cnoise(detail::tvec2<T> const & P)
{
detail::tvec4<T> Pi = floor(P.xyxy) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
detail::tvec4<T> Pf = fract(P.xyxy) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation
detail::tvec4<T> ix = Pi.xzxz;
detail::tvec4<T> iy = Pi.yyww;
detail::tvec4<T> fx = Pf.xzxz;
detail::tvec4<T> fy = Pf.yyww;
detail::tvec4<T> i = permute(permute(ix) + iy);
detail::tvec4<T> gx = T(2) * fract(i / T(41)) - T(1);
detail::tvec4<T> gy = abs(gx) - T(0.5);
detail::tvec4<T> tx = floor(gx + T(0.5));
gx = gx - tx;
detail::tvec2<T> g00 = detail::tvec2<T>(gx.x,gy.x);
detail::tvec2<T> g10 = detail::tvec2<T>(gx.y,gy.y);
detail::tvec2<T> g01 = detail::tvec2<T>(gx.z,gy.z);
detail::tvec2<T> g11 = detail::tvec2<T>(gx.w,gy.w);
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
T n00 = dot(g00, detail::tvec2<T>(fx.x, fy.x));
T n10 = dot(g10, detail::tvec2<T>(fx.y, fy.y));
T n01 = dot(g01, detail::tvec2<T>(fx.z, fy.z));
T n11 = dot(g11, detail::tvec2<T>(fx.w, fy.w));
detail::tvec2<T> fade_xy = fade(Pf.xy);
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>
inline T pnoise(detail::tvec2<T> const & P, detail::tvec2<T> const & rep)
{
detail::tvec4<T> Pi = floor(P.xyxy) + detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
detail::tvec4<T> Pf = fract(P.xyxy) - detail::tvec4<T>(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, rep.xyxy); // To create noise with explicit period
Pi = mod(Pi, T(289)); // To avoid truncation effects in permutation
detail::tvec4<T> ix = Pi.xzxz;
detail::tvec4<T> iy = Pi.yyww;
detail::tvec4<T> fx = Pf.xzxz;
detail::tvec4<T> fy = Pf.yyww;
detail::tvec4<T> i = permute(permute(ix) + iy);
detail::tvec4<T> gx = T(2) * fract(i / T(41)) - T(1);
detail::tvec4<T> gy = abs(gx) - T(0.5);
detail::tvec4<T> tx = floor(gx + T(0.5));
gx = gx - tx;
detail::tvec2<T> g00(gx.x,gy.x);
detail::tvec2<T> g10(gx.y,gy.y);
detail::tvec2<T> g01(gx.z,gy.z);
detail::tvec2<T> g11(gx.w,gy.w);
detail::tvec4<T> norm = taylorInvSqrt(detail::tvec4<T>(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
T n00 = dot(g00, detail::tvec2<T>(fx.x, fy.x));
T n10 = dot(g10, detail::tvec2<T>(fx.y, fy.y));
T n01 = dot(g01, detail::tvec2<T>(fx.z, fy.z));
T n11 = dot(g11, detail::tvec2<T>(fx.w, fy.w));
detail::tvec2<T> fade_xy = fade(Pf.xy);
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>
inline T cnoise(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));
Pi1 = mod(Pi1, T(289));
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(Pi0.yy, Pi1.yy);
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(7);
detail::tvec4<T> gy0 = fract(floor(gx0) / T(7)) - 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(0.0, gx0) - T(0.5));
gy0 -= sz0 * (step(0.0, gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 / T(7);
detail::tvec4<T> gy1 = fract(floor(gx1) / T(7)) - 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.yz));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.xy, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.xy, 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.yz));
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(n_z.xy, n_z.zw, 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 variant
template <typename T>
inline T pnoise(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));
Pi1 = mod(Pi1, T(289));
detail::tvec3<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec3<T> Pf1 = Pf0 - detail::tvec3<T>(1.0); // Fractional part - 1.0
detail::tvec4<T> ix = detail::tvec4<T>(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(Pi0.yy, Pi1.yy);
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(7);
detail::tvec4<T> gy0 = fract(floor(gx0) / T(7)) - 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));
gx0 -= sz0 * (step(0.0, gx0) - T(0.5));
gy0 -= sz0 * (step(0.0, gy0) - T(0.5));
detail::tvec4<T> gx1 = ixy1 / T(7);
detail::tvec4<T> gy1 = fract(floor(gx1) / T(7)) - 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(0.0, gx1) - T(0.5));
gy1 -= sz1 * (step(0.0, gy1) - T(0.5));
detail::tvec3<T> g000 = detail::tvec3<T>(gx0.x, gy0.x, gz0.x);
detail::tvec3<T> g100 = detail::tvec3<T>(gx0.y, gy0.y, gz0.y);
detail::tvec3<T> g010 = detail::tvec3<T>(gx0.z, gy0.z, gz0.z);
detail::tvec3<T> g110 = detail::tvec3<T>(gx0.w, gy0.w, gz0.w);
detail::tvec3<T> g001 = detail::tvec3<T>(gx1.x, gy1.x, gz1.x);
detail::tvec3<T> g101 = detail::tvec3<T>(gx1.y, gy1.y, gz1.y);
detail::tvec3<T> g011 = detail::tvec3<T>(gx1.z, gy1.z, gz1.z);
detail::tvec3<T> g111 = detail::tvec3<T>(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.yz));
T n010 = dot(g010, detail::tvec3<T>(Pf0.x, Pf1.y, Pf0.z));
T n110 = dot(g110, detail::tvec3<T>(Pf1.xy, Pf0.z));
T n001 = dot(g001, detail::tvec3<T>(Pf0.xy, 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.yz));
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(n_z.xy, n_z.zw, 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>
inline T cnoise(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));
Pi1 = mod(Pi1, T(289));
detail::tvec4<T> Pf0 = fract(P); // Fractional part for interpolation
detail::tvec4<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(Pi0.yy, Pi1.yy);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> iw0(Pi0.w);
detail::tvec4<T> iw1(Pi1.w);
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> ixy00 = permute(ixy0 + iw0);
detail::tvec4<T> ixy01 = permute(ixy0 + iw1);
detail::tvec4<T> ixy10 = permute(ixy1 + iw0);
detail::tvec4<T> ixy11 = permute(ixy1 + iw1);
detail::tvec4<T> gx00 = ixy00 / T(7);
detail::tvec4<T> gy00 = floor(gx00) / T(7);
detail::tvec4<T> gz00 = floor(gy00) / T(6);
gx00 = fract(gx00) - T(0.5);
gy00 = fract(gy00) - T(0.5);
gz00 = fract(gz00) - T(0.5);
detail::tvec4<T> gw00 = vec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
detail::tvec4<T> sw00 = step(gw00, vec4(0.0));
gx00 -= sw00 * (step(T(0), gx00) - T(0.5));
gy00 -= sw00 * (step(T(0), gy00) - T(0.5));
detail::tvec4<T> gx01 = ixy01 / T(7);
detail::tvec4<T> gy01 = floor(gx01) / T(7);
detail::tvec4<T> gz01 = floor(gy01) / T(6);
gx01 = fract(gx01) - T(0.5);
gy01 = fract(gy01) - T(0.5);
gz01 = fract(gz01) - T(0.5);
detail::tvec4<T> gw01 = vec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
detail::tvec4<T> sw01 = step(gw01, vec4(0.0));
gx01 -= sw01 * (step(T(0), gx01) - T(0.5));
gy01 -= sw01 * (step(T(0), gy01) - T(0.5));
detail::tvec4<T> gx10 = ixy10 / T(7);
detail::tvec4<T> gy10 = floor(gx10) / T(7);
detail::tvec4<T> gz10 = floor(gy10) / T(6);
gx10 = fract(gx10) - T(0.5);
gy10 = fract(gy10) - T(0.5);
gz10 = fract(gz10) - T(0.5);
detail::tvec4<T> gw10 = detail::tvec4<T>(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
detail::tvec4<T> sw10 = step(gw10, detail::tvec4<T>(0));
gx10 -= sw10 * (step(T(0), gx10) - T(0.5));
gy10 -= sw10 * (step(T(0), gy10) - T(0.5));
detail::tvec4<T> gx11 = ixy11 / T(7);
detail::tvec4<T> gy11 = floor(gx11) / T(7);
detail::tvec4<T> gz11 = floor(gy11) / T(6);
gx11 = fract(gx11) - T(0.5);
gy11 = fract(gy11) - T(0.5);
gz11 = fract(gz11) - T(0.5);
detail::tvec4<T> gw11 = detail::tvec4<T>(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
detail::tvec4<T> sw11 = step(gw11, vec4(0.0));
gx11 -= sw11 * (step(T(0), gx11) - T(0.5));
gy11 -= sw11 * (step(T(0), gy11) - T(0.5));
detail::tvec4<T> g0000(gx00.x, gy00.x, gz00.x, gw00.x);
detail::tvec4<T> g1000(gx00.y, gy00.y, gz00.y, gw00.y);
detail::tvec4<T> g0100(gx00.z, gy00.z, gz00.z, gw00.z);
detail::tvec4<T> g1100(gx00.w, gy00.w, gz00.w, gw00.w);
detail::tvec4<T> g0010(gx10.x, gy10.x, gz10.x, gw10.x);
detail::tvec4<T> g1010(gx10.y, gy10.y, gz10.y, gw10.y);
detail::tvec4<T> g0110(gx10.z, gy10.z, gz10.z, gw10.z);
detail::tvec4<T> g1110(gx10.w, gy10.w, gz10.w, gw10.w);
detail::tvec4<T> g0001(gx01.x, gy01.x, gz01.x, gw01.x);
detail::tvec4<T> g1001(gx01.y, gy01.y, gz01.y, gw01.y);
detail::tvec4<T> g0101(gx01.z, gy01.z, gz01.z, gw01.z);
detail::tvec4<T> g1101(gx01.w, gy01.w, gz01.w, gw01.w);
detail::tvec4<T> g0011(gx11.x, gy11.x, gz11.x, gw11.x);
detail::tvec4<T> g1011(gx11.y, gy11.y, gz11.y, gw11.y);
detail::tvec4<T> g0111(gx11.z, gy11.z, gz11.z, gw11.z);
detail::tvec4<T> g1111(gx11.w, gy11.w, gz11.w, gw11.w);
detail::tvec4<T> norm00 = taylorInvSqrt(detail::tvec4<T>(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));
g0000 *= norm00.x;
g0100 *= norm00.y;
g1000 *= norm00.z;
g1100 *= norm00.w;
detail::tvec4<T> norm01 = taylorInvSqrt(detail::tvec4<T>(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));
g0001 *= norm01.x;
g0101 *= norm01.y;
g1001 *= norm01.z;
g1101 *= norm01.w;
detail::tvec4<T> norm10 = taylorInvSqrt(detail::tvec4<T>(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));
g0010 *= norm10.x;
g0110 *= norm10.y;
g1010 *= norm10.z;
g1110 *= norm10.w;
detail::tvec4<T> norm11 = taylorInvSqrt(detail::tvec4<T>(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));
g0011 *= norm11.x;
g0111 *= norm11.y;
g1011 *= norm11.z;
g1111 *= norm11.w;
T n0000 = dot(g0000, Pf0);
T n1000 = dot(g1000, detail::tvec4<T>(Pf1.x, Pf0.yzw));
T n0100 = dot(g0100, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.zw));
T n1100 = dot(g1100, detail::tvec4<T>(Pf1.xy, Pf0.zw));
T n0010 = dot(g0010, detail::tvec4<T>(Pf0.xy, Pf1.z, Pf0.w));
T n1010 = dot(g1010, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
T n0110 = dot(g0110, detail::tvec4<T>(Pf0.x, Pf1.yz, Pf0.w));
T n1110 = dot(g1110, detail::tvec4<T>(Pf1.xyz, Pf0.w));
T n0001 = dot(g0001, detail::tvec4<T>(Pf0.xyz, Pf1.w));
T n1001 = dot(g1001, detail::tvec4<T>(Pf1.x, Pf0.yz, Pf1.w));
T n0101 = dot(g0101, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
T n1101 = dot(g1101, detail::tvec4<T>(Pf1.xy, Pf0.z, Pf1.w));
T n0011 = dot(g0011, detail::tvec4<T>(Pf0.xy, Pf1.zw));
T n1011 = dot(g1011, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.zw));
T n0111 = dot(g0111, detail::tvec4<T>(Pf0.x, Pf1.yzw));
T n1111 = dot(g1111, Pf1);
detail::tvec4<T> fade_xyzw = fade(Pf0);
detail::tvec4<T> n_0w = mix(detail::tvec4<T>(n0000, n1000, n0100, n1100), detail::tvec4<T>(n0001, n1001, n0101, n1101), fade_xyzw.w);
detail::tvec4<T> n_1w = mix(detail::tvec4<T>(n0010, n1010, n0110, n1110), detail::tvec4<T>(n0011, n1011, n0111, n1111), fade_xyzw.w);
detail::tvec4<T> n_zw = mix(n_0w, n_1w, fade_xyzw.z);
detail::tvec4<T> n_yzw = mix(n_zw.xy, n_zw.zw, 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 version
template <typename T>
inline T pnoise(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
detail::tvec4<T> Pf1 = Pf0 - T(1); // Fractional part - 1.0
detail::tvec4<T> ix = detail::tvec4<T>(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
detail::tvec4<T> iy = detail::tvec4<T>(Pi0.yy, Pi1.yy);
detail::tvec4<T> iz0(Pi0.z);
detail::tvec4<T> iz1(Pi1.z);
detail::tvec4<T> iw0(Pi0.w);
detail::tvec4<T> iw1(Pi1.w);
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> ixy00 = permute(ixy0 + iw0);
detail::tvec4<T> ixy01 = permute(ixy0 + iw1);
detail::tvec4<T> ixy10 = permute(ixy1 + iw0);
detail::tvec4<T> ixy11 = permute(ixy1 + iw1);
detail::tvec4<T> gx00 = ixy00 / T(7);
detail::tvec4<T> gy00 = floor(gx00) / T(7);
detail::tvec4<T> gz00 = floor(gy00) / T(6);
gx00 = fract(gx00) - T(0.5);
gy00 = fract(gy00) - T(0.5);
gz00 = fract(gz00) - T(0.5);
detail::tvec4<T> gw00 = detail::tvec4<T>(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
detail::tvec4<T> sw00 = step(gw00, detail::tvec4<T>(0));
gx00 -= sw00 * (step(0.0, gx00) - T(0.5));
gy00 -= sw00 * (step(0.0, gy00) - T(0.5));
detail::tvec4<T> gx01 = ixy01 / T(7);
detail::tvec4<T> gy01 = floor(gx01) / T(7);
detail::tvec4<T> gz01 = floor(gy01) / T(6);
gx01 = fract(gx01) - T(0.5);
gy01 = fract(gy01) - T(0.5);
gz01 = fract(gz01) - T(0.5);
detail::tvec4<T> gw01 = detail::tvec4<T>(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
detail::tvec4<T> sw01 = step(gw01, detail::tvec4<T>(0.0));
gx01 -= sw01 * (step(0.0, gx01) - T(0.5));
gy01 -= sw01 * (step(0.0, gy01) - T(0.5));
detail::tvec4<T> gx10 = ixy10 / T(7);
detail::tvec4<T> gy10 = floor(gx10) / T(7);
detail::tvec4<T> gz10 = floor(gy10) / T(6);
gx10 = fract(gx10) - T(0.5);
gy10 = fract(gy10) - T(0.5);
gz10 = fract(gz10) - T(0.5);
detail::tvec4<T> gw10 = detail::tvec4<T>(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
detail::tvec4<T> sw10 = step(gw10, detail::tvec4<T>(0.0));
gx10 -= sw10 * (step(0.0, gx10) - T(0.5));
gy10 -= sw10 * (step(0.0, gy10) - T(0.5));
detail::tvec4<T> gx11 = ixy11 / T(7);
detail::tvec4<T> gy11 = floor(gx11) / T(7);
detail::tvec4<T> gz11 = floor(gy11) / T(6);
gx11 = fract(gx11) - T(0.5);
gy11 = fract(gy11) - T(0.5);
gz11 = fract(gz11) - T(0.5);
detail::tvec4<T> gw11 = detail::tvec4<T>(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
detail::tvec4<T> sw11 = step(gw11, detail::tvec4<T>(0.0));
gx11 -= sw11 * (step(0.0, gx11) - T(0.5));
gy11 -= sw11 * (step(0.0, gy11) - T(0.5));
detail::tvec4<T> g0000(gx00.x, gy00.x, gz00.x, gw00.x);
detail::tvec4<T> g1000(gx00.y, gy00.y, gz00.y, gw00.y);
detail::tvec4<T> g0100(gx00.z, gy00.z, gz00.z, gw00.z);
detail::tvec4<T> g1100(gx00.w, gy00.w, gz00.w, gw00.w);
detail::tvec4<T> g0010(gx10.x, gy10.x, gz10.x, gw10.x);
detail::tvec4<T> g1010(gx10.y, gy10.y, gz10.y, gw10.y);
detail::tvec4<T> g0110(gx10.z, gy10.z, gz10.z, gw10.z);
detail::tvec4<T> g1110(gx10.w, gy10.w, gz10.w, gw10.w);
detail::tvec4<T> g0001(gx01.x, gy01.x, gz01.x, gw01.x);
detail::tvec4<T> g1001(gx01.y, gy01.y, gz01.y, gw01.y);
detail::tvec4<T> g0101(gx01.z, gy01.z, gz01.z, gw01.z);
detail::tvec4<T> g1101(gx01.w, gy01.w, gz01.w, gw01.w);
detail::tvec4<T> g0011(gx11.x, gy11.x, gz11.x, gw11.x);
detail::tvec4<T> g1011(gx11.y, gy11.y, gz11.y, gw11.y);
detail::tvec4<T> g0111(gx11.z, gy11.z, gz11.z, gw11.z);
detail::tvec4<T> g1111(gx11.w, gy11.w, gz11.w, gw11.w);
detail::tvec4<T> norm00 = taylorInvSqrt(detail::tvec4<T>(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));
g0000 *= norm00.x;
g0100 *= norm00.y;
g1000 *= norm00.z;
g1100 *= norm00.w;
detail::tvec4<T> norm01 = taylorInvSqrt(detail::tvec4<T>(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));
g0001 *= norm01.x;
g0101 *= norm01.y;
g1001 *= norm01.z;
g1101 *= norm01.w;
detail::tvec4<T> norm10 = taylorInvSqrt(detail::tvec4<T>(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));
g0010 *= norm10.x;
g0110 *= norm10.y;
g1010 *= norm10.z;
g1110 *= norm10.w;
detail::tvec4<T> norm11 = taylorInvSqrt(detail::tvec4<T>(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));
g0011 *= norm11.x;
g0111 *= norm11.y;
g1011 *= norm11.z;
g1111 *= norm11.w;
T n0000 = dot(g0000, Pf0);
T n1000 = dot(g1000, detail::tvec4<T>(Pf1.x, Pf0.yzw));
T n0100 = dot(g0100, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.zw));
T n1100 = dot(g1100, detail::tvec4<T>(Pf1.xy, Pf0.zw));
T n0010 = dot(g0010, detail::tvec4<T>(Pf0.xy, Pf1.z, Pf0.w));
T n1010 = dot(g1010, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
T n0110 = dot(g0110, detail::tvec4<T>(Pf0.x, Pf1.yz, Pf0.w));
T n1110 = dot(g1110, detail::tvec4<T>(Pf1.xyz, Pf0.w));
T n0001 = dot(g0001, detail::tvec4<T>(Pf0.xyz, Pf1.w));
T n1001 = dot(g1001, detail::tvec4<T>(Pf1.x, Pf0.yz, Pf1.w));
T n0101 = dot(g0101, detail::tvec4<T>(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
T n1101 = dot(g1101, detail::tvec4<T>(Pf1.xy, Pf0.z, Pf1.w));
T n0011 = dot(g0011, detail::tvec4<T>(Pf0.xy, Pf1.zw));
T n1011 = dot(g1011, detail::tvec4<T>(Pf1.x, Pf0.y, Pf1.zw));
T n0111 = dot(g0111, detail::tvec4<T>(Pf0.x, Pf1.yzw));
T n1111 = dot(g1111, Pf1);
detail::tvec4<T> fade_xyzw = fade(Pf0);
detail::tvec4<T> n_0w = mix(detail::tvec4<T>(n0000, n1000, n0100, n1100), detail::tvec4<T>(n0001, n1001, n0101, n1101), fade_xyzw.w);
detail::tvec4<T> n_1w = mix(detail::tvec4<T>(n0010, n1010, n0110, n1110), detail::tvec4<T>(n0011, n1011, n0111, n1111), fade_xyzw.w);
detail::tvec4<T> n_zw = mix(n_0w, n_1w, fade_xyzw.z);
detail::tvec2<T> n_yzw = mix(n_zw.xy, n_zw.zw, fade_xyzw.y);
T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
return T(2.2) * n_xyzw;
}
}//namespace noise }//namespace noise
}//namespace gtx }//namespace gtx