Suppressed perlin1d, added perlin 2,3,4 and simplex 2 classes + minor
fixes/optimisations on noisemachine
This commit is contained in:
parent
57d9af6b56
commit
784787cd79
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PERLIN2D_H
|
||||
#define PERLIN2D_H
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
template <typename T> class NzPerlin2D : public NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzPerlin2D();
|
||||
T GetValue(T x, T y, T res);
|
||||
~NzPerlin2D() = default;
|
||||
protected:
|
||||
private:
|
||||
int x0, y0;
|
||||
int gi0,gi1,gi2,gi3;
|
||||
int ii, jj;
|
||||
T gradient2[8][2];
|
||||
T s,t,u,v;
|
||||
T Cx,Cy;
|
||||
T Li1, Li2;
|
||||
T nx, ny;
|
||||
T tmp;
|
||||
NzVector2<T> temp;
|
||||
};
|
||||
|
||||
typedef NzPerlin2D<float> NzPerlin2Df;
|
||||
typedef NzPerlin2D<double> NzPerlin2Dd;
|
||||
|
||||
#include <Nazara/Noise/Perlin2D.inl>
|
||||
|
||||
#endif // PERLIN2D_H
|
||||
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzPerlin2D<T>::NzPerlin2D()
|
||||
{
|
||||
T unit = 1.0/sqrt(2);
|
||||
T grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit},
|
||||
{1,0},{-1,0},{0,1},{0,-1}};
|
||||
|
||||
for(int i(0) ; i < 8 ; ++i)
|
||||
for(int j(0) ; j < 2 ; ++j)
|
||||
gradient2[i][j] = grad2Temp[i][j];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzPerlin2D<T>::GetValue(T x, T y, T res)
|
||||
{
|
||||
nx = x/res;
|
||||
ny = y/res;
|
||||
|
||||
x0 = static_cast<int>(nx);
|
||||
y0 = static_cast<int>(ny);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj]] & 7;
|
||||
gi1 = perm[ii + 1 + perm[jj]] & 7;
|
||||
gi2 = perm[ii + perm[jj + 1]] & 7;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1]] & 7;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-y0;
|
||||
s = gradient2[gi0][0]*temp.x + gradient2[gi0][1]*temp.y;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-y0;
|
||||
t = gradient2[gi1][0]*temp.x + gradient2[gi1][1]*temp.y;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-(y0+1);
|
||||
u = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-(y0+1);
|
||||
v = gradient2[gi3][0]*temp.x + gradient2[gi3][1]*temp.y;
|
||||
|
||||
tmp = nx-x0;
|
||||
Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
Li1 = s + Cx*(t-s);
|
||||
Li2 = u + Cx*(v-u);
|
||||
|
||||
tmp = ny - y0;
|
||||
Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
return Li1 + Cy*(Li2-Li1);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PERLIN3D_H
|
||||
#define PERLIN3D_H
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
template <typename T> class NzPerlin3D : public NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzPerlin3D();
|
||||
T GetValue(T x, T y, T z, T res);
|
||||
~NzPerlin3D() = default;
|
||||
protected:
|
||||
private:
|
||||
int x0,y0,z0;
|
||||
int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7;
|
||||
int ii,jj,kk;
|
||||
int gradient3[16][3];
|
||||
T Li1,Li2,Li3,Li4,Li5,Li6;
|
||||
T s[2],t[2],u[2],v[2];
|
||||
T Cx,Cy,Cz;
|
||||
T nx,ny,nz;
|
||||
T tmp;
|
||||
NzVector3<T> temp;
|
||||
|
||||
};
|
||||
|
||||
typedef NzPerlin3D<float> NzPerlin3Df;
|
||||
typedef NzPerlin3D<double> NzPerlin3Dd;
|
||||
|
||||
#include <Nazara/Noise/Perlin3D.inl>
|
||||
|
||||
#endif // PERLIN3D_H
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzPerlin3D<T>::NzPerlin3D()
|
||||
{
|
||||
int grad3Temp[][3] = {
|
||||
{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0},
|
||||
{1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1},
|
||||
{0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1},
|
||||
{1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 16 ; ++i)
|
||||
for(int j(0) ; j < 3 ; ++j)
|
||||
gradient3[i][j] = grad3Temp[i][j];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzPerlin3D<T>::GetValue(T x, T y, T z, T res)
|
||||
{
|
||||
nx = x/res;
|
||||
ny = y/res;
|
||||
nz = z/res;
|
||||
|
||||
x0 = static_cast<int>(nx);
|
||||
y0 = static_cast<int>(ny);
|
||||
z0 = static_cast<int>(nz);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
kk = z0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk]]] % 16;
|
||||
gi1 = perm[ii + 1 + perm[jj + perm[kk]]] % 16;
|
||||
gi2 = perm[ii + perm[jj + 1 + perm[kk]]] % 16;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] % 16;
|
||||
|
||||
gi4 = perm[ii + perm[jj + perm[kk + 1]]] % 16;
|
||||
gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] % 16;
|
||||
gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] % 16;
|
||||
gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 16;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-y0;
|
||||
temp.z = nz-z0;
|
||||
s[0] = gradient3[gi0][0]*temp.x + gradient3[gi0][1]*temp.y + gradient3[gi0][2]*temp.z;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-y0;
|
||||
t[0] = gradient3[gi1][0]*temp.x + gradient3[gi1][1]*temp.y + gradient3[gi1][2]*temp.z;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-(y0+1);
|
||||
u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-(y0+1);
|
||||
v[0] = gradient3[gi3][0]*temp.x + gradient3[gi3][1]*temp.y + gradient3[gi3][2]*temp.z;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-y0;
|
||||
temp.z = nz-(z0+1);
|
||||
s[1] = gradient3[gi4][0]*temp.x + gradient3[gi4][1]*temp.y + gradient3[gi4][2]*temp.z;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-y0;
|
||||
t[1] = gradient3[gi5][0]*temp.x + gradient3[gi5][1]*temp.y + gradient3[gi5][2]*temp.z;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-(y0+1);
|
||||
u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-(y0+1);
|
||||
v[1] = gradient3[gi7][0]*temp.x + gradient3[gi7][1]*temp.y + gradient3[gi7][2]*temp.z;
|
||||
|
||||
tmp = nx-x0;
|
||||
Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
Li1 = s[0] + Cx*(t[0]-s[0]);
|
||||
Li2 = u[0] + Cx*(v[0]-u[0]);
|
||||
Li3 = s[1] + Cx*(t[1]-s[1]);
|
||||
Li4 = u[1] + Cx*(v[1]-u[1]);
|
||||
|
||||
tmp = ny-y0;
|
||||
Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
Li5 = Li1 + Cy*(Li2-Li1);
|
||||
Li6 = Li3 + Cy*(Li4-Li3);
|
||||
|
||||
tmp = nz-z0;
|
||||
Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
return Li5 + Cz*(Li6-Li5);
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef PERLIN4D_H
|
||||
#define PERLIN4D_H
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
template <typename T> class NzPerlin4D : public NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzPerlin4D();
|
||||
T GetValue(T x, T y, T z, T w, T res);
|
||||
~NzPerlin4D() = default;
|
||||
protected:
|
||||
private:
|
||||
int x0,y0,z0,w0;
|
||||
int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15;
|
||||
int ii,jj,kk,ll;
|
||||
int gradient4[32][4];
|
||||
T Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14;
|
||||
T s[4],t[4],u[4],v[4];
|
||||
T Cx,Cy,Cz,Cw;
|
||||
T nx,ny,nz,nw;
|
||||
T tmp;
|
||||
NzVector4<T> temp;
|
||||
|
||||
};
|
||||
|
||||
typedef NzPerlin4D<float> NzPerlin4Df;
|
||||
typedef NzPerlin4D<double> NzPerlin4Dd;
|
||||
|
||||
#include <Nazara/Noise/Perlin4D.inl>
|
||||
|
||||
#endif // PERLIN4D_H
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzPerlin4D<T>::NzPerlin4D()
|
||||
{
|
||||
int grad4Temp[][4] =
|
||||
{
|
||||
{0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1},
|
||||
{0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1},
|
||||
{1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1},
|
||||
{-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1},
|
||||
{1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1},
|
||||
{-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1},
|
||||
{1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0},
|
||||
{-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 32 ; ++i)
|
||||
for(int j(0) ; j < 4 ; ++j)
|
||||
gradient4[i][j] = grad4Temp[i][j];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzPerlin4D<T>::GetValue(T x, T y, T z, T w, T res)
|
||||
{
|
||||
nx = x/res;
|
||||
ny = y/res;
|
||||
nz = z/res;
|
||||
nw = w/res;
|
||||
|
||||
x0 = static_cast<int>(nx);
|
||||
y0 = static_cast<int>(ny);
|
||||
z0 = static_cast<int>(nz);
|
||||
w0 = static_cast<int>(nw);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
kk = z0 & 255;
|
||||
ll = w0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk + perm[ll ]]]] % 32;
|
||||
gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll ]]]] % 32;
|
||||
gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32;
|
||||
|
||||
gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32;
|
||||
gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32;
|
||||
gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32;
|
||||
gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32;
|
||||
|
||||
gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] % 32;
|
||||
gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] % 32;
|
||||
gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32;
|
||||
gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32;
|
||||
|
||||
gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32;
|
||||
gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32;
|
||||
gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32;
|
||||
gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-y0;
|
||||
temp.z = nz-z0;
|
||||
temp.w = nw-w0;
|
||||
s[0] = gradient4[gi0][0]*temp.x + gradient4[gi0][1]*temp.y + gradient4[gi0][2]*temp.z + gradient4[gi0][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-y0;
|
||||
t[0] = gradient4[gi1][0]*temp.x + gradient4[gi1][1]*temp.y + gradient4[gi1][2]*temp.z + gradient4[gi1][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-(y0+1);
|
||||
u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-(y0+1);
|
||||
v[0] = gradient4[gi3][0]*temp.x + gradient4[gi3][1]*temp.y + gradient4[gi3][2]*temp.z + gradient4[gi3][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-y0;
|
||||
temp.z = nz-(z0+1);
|
||||
s[1] = gradient4[gi4][0]*temp.x + gradient4[gi4][1]*temp.y + gradient4[gi4][2]*temp.z + gradient4[gi4][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-y0;
|
||||
t[1] = gradient4[gi5][0]*temp.x + gradient4[gi5][1]*temp.y + gradient4[gi5][2]*temp.z + gradient4[gi5][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-(y0+1);
|
||||
u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-(y0+1);
|
||||
v[1] = gradient4[gi7][0]*temp.x + gradient4[gi7][1]*temp.y + gradient4[gi7][2]*temp.z + gradient4[gi7][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-y0;
|
||||
temp.z = nz-z0;
|
||||
temp.w = nw-(w0+1);
|
||||
s[2] = gradient4[gi8][0]*temp.x + gradient4[gi8][1]*temp.y + gradient4[gi8][2]*temp.z + gradient4[gi8][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-y0;
|
||||
t[2] = gradient4[gi9][0]*temp.x + gradient4[gi9][1]*temp.y + gradient4[gi9][2]*temp.z + gradient4[gi9][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-(y0+1);
|
||||
u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-(y0+1);
|
||||
v[2] = gradient4[gi11][0]*temp.x + gradient4[gi11][1]*temp.y + gradient4[gi11][2]*temp.z + gradient4[gi11][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-y0;
|
||||
temp.z = nz-(z0+1);
|
||||
s[3] = gradient4[gi12][0]*temp.x + gradient4[gi12][1]*temp.y + gradient4[gi12][2]*temp.z + gradient4[gi12][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-y0;
|
||||
t[3] = gradient4[gi13][0]*temp.x + gradient4[gi13][1]*temp.y + gradient4[gi13][2]*temp.z + gradient4[gi13][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.y = ny-(y0+1);
|
||||
u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.y = ny-(y0+1);
|
||||
v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w;
|
||||
|
||||
tmp = nx-x0;
|
||||
Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
Li1 = s[0] + Cx*(t[0]-s[0]);
|
||||
Li2 = u[0] + Cx*(v[0]-u[0]);
|
||||
Li3 = s[1] + Cx*(t[1]-s[1]);
|
||||
Li4 = u[1] + Cx*(v[1]-u[1]);
|
||||
Li5 = s[2] + Cx*(t[2]-s[2]);
|
||||
Li6 = u[2] + Cx*(v[2]-u[2]);
|
||||
Li7 = s[3] + Cx*(t[3]-s[3]);
|
||||
Li8 = u[3] + Cx*(v[3]-u[3]);
|
||||
|
||||
tmp = ny-y0;
|
||||
Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
Li9 = Li1 + Cy*(Li2-Li1);
|
||||
Li10 = Li3 + Cy*(Li4-Li3);
|
||||
Li11 = Li5 + Cy*(Li6-Li5);
|
||||
Li12 = Li7 + Cy*(Li8-Li7);
|
||||
|
||||
tmp = nz-z0;
|
||||
Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
Li13 = Li9 + Cz*(Li10-Li9);
|
||||
Li14 = Li11 + Cz*(Li12-Li11);
|
||||
|
||||
tmp = nw-w0;
|
||||
Cw = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10);
|
||||
|
||||
return Li13 + Cw*(Li14-Li13);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef SIMPLEX2D_H
|
||||
#define SIMPLEX2D_H
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
|
||||
template <typename T> class NzSimplex2D : public NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzSimplex2D();
|
||||
T GetValue(T x, T y, T res);
|
||||
~NzSimplex2D() = default;
|
||||
protected:
|
||||
private:
|
||||
int ii,jj;
|
||||
int gi0,gi1,gi2;
|
||||
NzVector2i Origin,off1;
|
||||
T n1,n2,n3;
|
||||
T c1,c2,c3;
|
||||
T gradient2[8][2];
|
||||
T UnskewCoeff2D;
|
||||
T SkewCoeff2D;
|
||||
NzVector2<T> A, IsoOriginDist;
|
||||
NzVector2<T> d1,d2,d3;
|
||||
|
||||
|
||||
};
|
||||
|
||||
typedef NzSimplex2D<float> NzSimplex2Df;
|
||||
typedef NzSimplex2D<double> NzSimplex2Dd;
|
||||
|
||||
#include <Nazara/Noise/Simplex2D.inl>
|
||||
|
||||
#endif // SIMPLEX2D_H
|
||||
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzSimplex2D<T>::NzSimplex2D()
|
||||
{
|
||||
|
||||
T unit = 1.0/sqrt(2);
|
||||
T grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit},
|
||||
{1,0},{-1,0},{0,1},{0,-1}};
|
||||
|
||||
for(int i(0) ; i < 8 ; ++i)
|
||||
for(int j(0) ; j < 2 ; ++j)
|
||||
gradient2[i][j] = grad2Temp[i][j];
|
||||
|
||||
SkewCoeff2D = 0.5*(sqrt(3.0) - 1.0);
|
||||
UnskewCoeff2D = (3.0-sqrt(3.0))/6;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzSimplex2D<T>::GetValue(T x, T y, T res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
|
||||
Origin.x = fastfloor(x + (x + y) * SkewCoeff2D);
|
||||
Origin.y = fastfloor(y + (x + y) * SkewCoeff2D);
|
||||
|
||||
A.x = Origin.x - (Origin.x + Origin.y) * UnskewCoeff2D;
|
||||
A.y = Origin.y - (Origin.x + Origin.y) * UnskewCoeff2D;
|
||||
|
||||
IsoOriginDist.x = x - A.x;
|
||||
IsoOriginDist.y = y - A.y;
|
||||
|
||||
if(IsoOriginDist.x > IsoOriginDist.y)
|
||||
{
|
||||
off1.x = 1;
|
||||
off1.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 1;
|
||||
}
|
||||
|
||||
d1.x = A.x - x;
|
||||
d1.y = A.y - y;
|
||||
|
||||
d2.x = d1.x + off1.x - UnskewCoeff2D;
|
||||
d2.y = d1.y + off1.y - UnskewCoeff2D;
|
||||
|
||||
d3.x = d1.x + 1.0 - 2 * UnskewCoeff2D;
|
||||
d3.y = d1.y + 1.0 - 2 * UnskewCoeff2D;
|
||||
|
||||
ii = Origin.x & 255;
|
||||
jj = Origin.y & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj]] % 8;
|
||||
gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 8;
|
||||
gi2 = perm[ii + 1 + perm[jj + 1]] % 8;
|
||||
|
||||
n1 = gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y;
|
||||
n2 = gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y;
|
||||
n3 = gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y;
|
||||
|
||||
c1 = 0.5 - d1.x * d1.x - d1.y * d1.y;
|
||||
c2 = 0.5 - d2.x * d2.x - d2.y * d2.y;
|
||||
c3 = 0.5 - d3.x * d3.x - d3.y * d3.y;
|
||||
|
||||
if(c1 < 0)
|
||||
c1 = 0;
|
||||
if(c2 < 0)
|
||||
c2 = 0;
|
||||
if(c3 < 0)
|
||||
c3 = 0;
|
||||
|
||||
n1 = c1*c1*c1*n1;
|
||||
n2 = c2*c2*c2*n2;
|
||||
n3 = c3*c3*c3*n3;
|
||||
|
||||
return (n1+n2+n3)*23.2;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue