diff options
Diffstat (limited to 'src/noise.cpp')
-rw-r--r-- | src/noise.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/noise.cpp b/src/noise.cpp index 63682e1e4..bc5148545 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -92,8 +92,7 @@ double noise3d(int x, int y, int z, int seed) return 1.0 - (double)n/1073741824; } -#if 0 -// This is too slow +#if 1 double noise2d_gradient(double x, double y, int seed) { // Calculate the integer coordinates @@ -118,7 +117,7 @@ double noise2d_gradient(double x, double y, int seed) } #endif -#if 1 +#if 0 double noise2d_gradient(double x, double y, int seed) { // Calculate the integer coordinates @@ -175,6 +174,21 @@ double noise2d_perlin(double x, double y, int seed, return a; } +double noise2d_perlin_abs(double x, double y, int seed, + int octaves, double persistence) +{ + double a = 0; + double f = 1.0; + double g = 1.0; + for(int i=0; i<octaves; i++) + { + a += g * fabs(noise2d_gradient(x*f, y*f, seed+i)); + f *= 2.0; + g *= persistence; + } + return a; +} + double noise3d_perlin(double x, double y, double z, int seed, int octaves, double persistence) { @@ -190,3 +204,18 @@ double noise3d_perlin(double x, double y, double z, int seed, return a; } +double noise3d_perlin_abs(double x, double y, double z, int seed, + int octaves, double persistence) +{ + double a = 0; + double f = 1.0; + double g = 1.0; + for(int i=0; i<octaves; i++) + { + a += g * fabs(noise3d_gradient(x*f, y*f, z*f, seed+i)); + f *= 2.0; + g *= persistence; + } + return a; +} + |