aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-02-27 00:59:56 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-02-27 00:59:56 +0200
commitd9d0efdeedffbef90361886b1f8b0877a4fde1f2 (patch)
tree92bfc4ec45644d6eafd6f9b02d95c738733b7ba3
parent48a772b3c6388cbe7f9003557f27cc2cf51b8fe8 (diff)
downloadminetest-d9d0efdeedffbef90361886b1f8b0877a4fde1f2.tar.gz
minetest-d9d0efdeedffbef90361886b1f8b0877a4fde1f2.tar.bz2
minetest-d9d0efdeedffbef90361886b1f8b0877a4fde1f2.zip
fixed 3d noise and made 2d noise faster
-rw-r--r--src/noise.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/noise.cpp b/src/noise.cpp
index 7b651dbb3..63682e1e4 100644
--- a/src/noise.cpp
+++ b/src/noise.cpp
@@ -92,6 +92,8 @@ double noise3d(int x, int y, int z, int seed)
return 1.0 - (double)n/1073741824;
}
+#if 0
+// This is too slow
double noise2d_gradient(double x, double y, int seed)
{
// Calculate the integer coordinates
@@ -114,6 +116,26 @@ double noise2d_gradient(double x, double y, int seed)
// Interpolate between the values
return biLinearInterpolation(s,u,v,w,xl,yl);
}
+#endif
+
+#if 1
+double noise2d_gradient(double x, double y, int seed)
+{
+ // Calculate the integer coordinates
+ int x0 = (x > 0.0 ? (int)x : (int)x - 1);
+ int y0 = (y > 0.0 ? (int)y : (int)y - 1);
+ // Calculate the remaining part of the coordinates
+ double xl = x - (double)x0;
+ double yl = y - (double)y0;
+ // Get values for corners of cube
+ double v00 = noise2d(x0, y0, seed);
+ double v10 = noise2d(x0+1, y0, seed);
+ double v01 = noise2d(x0, y0+1, seed);
+ double v11 = noise2d(x0+1, y0+1, seed);
+ // Interpolate
+ return biLinearInterpolation(v00,v10,v01,v11,xl,yl);
+}
+#endif
double noise3d_gradient(double x, double y, double z, int seed)
{
@@ -124,7 +146,7 @@ double noise3d_gradient(double x, double y, double z, int seed)
// Calculate the remaining part of the coordinates
double xl = x - (double)x0;
double yl = y - (double)y0;
- double zl = y - (double)z0;
+ double zl = z - (double)z0;
// Get values for corners of cube
double v000 = noise3d(x0, y0, z0, seed);
double v100 = noise3d(x0+1, y0, z0, seed);