]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/noise.cpp
Wieldmesh: don't force anisotropic filtering on, instead disable mipmaps
[dragonfireclient.git] / src / noise.cpp
index 70aa6dbca6529f83358d0ef80f5d45a84a479004..c0249a4373678075bbe7575f1b12897f8a0d87ce 100644 (file)
@@ -1,22 +1,27 @@
 /*
-Minetest
-Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
-Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+ * Minetest
+ * Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
+ * Copyright (C) 2010-2014 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *  1. Redistributions of source code must retain the above copyright notice, this list of
+ *     conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *     of conditions and the following disclaimer in the documentation and/or other materials
+ *     provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
 #include <math.h>
 #include "noise.h"
@@ -210,7 +215,7 @@ float noise2d_gradient(float x, float y, int seed)
 }
 
 
-float noise3d_gradient(float x, float y, float z, int seed)
+float noise3d_gradient(float x, float y, float z, int seed, bool eased)
 {
        // Calculate the integer coordinates
        int x0 = myfloor(x);
@@ -230,10 +235,17 @@ float noise3d_gradient(float x, float y, float z, int seed)
        float v011 = noise3d(x0,     y0 + 1, z0 + 1, seed);
        float v111 = noise3d(x0 + 1, y0 + 1, z0 + 1, seed);
        // Interpolate
-       return triLinearInterpolationNoEase(
-               v000, v100, v010, v110,
-               v001, v101, v011, v111,
-               xl, yl, zl);
+       if (eased) {
+               return triLinearInterpolation(
+                       v000, v100, v010, v110,
+                       v001, v101, v011, v111,
+                       xl, yl, zl);
+       } else {
+               return triLinearInterpolationNoEase(
+                       v000, v100, v010, v110,
+                       v001, v101, v011, v111,
+                       xl, yl, zl);
+       }
 }
 
 
@@ -270,14 +282,14 @@ float noise2d_perlin_abs(float x, float y, int seed,
 
 
 float noise3d_perlin(float x, float y, float z, int seed,
-               int octaves, float persistence)
+               int octaves, float persistence, bool eased)
 {
        float a = 0;
        float f = 1.0;
        float g = 1.0;
        for (int i = 0; i < octaves; i++)
        {
-               a += g * noise3d_gradient(x * f, y * f, z * f, seed + i);
+               a += g * noise3d_gradient(x * f, y * f, z * f, seed + i, eased);
                f *= 2.0;
                g *= persistence;
        }
@@ -286,14 +298,14 @@ float noise3d_perlin(float x, float y, float z, int seed,
 
 
 float noise3d_perlin_abs(float x, float y, float z, int seed,
-               int octaves, float persistence)
+               int octaves, float persistence, bool eased)
 {
        float a = 0;
        float f = 1.0;
        float g = 1.0;
        for (int i = 0; i < octaves; i++)
        {
-               a += g * fabs(noise3d_gradient(x * f, y * f, z * f, seed + i));
+               a += g * fabs(noise3d_gradient(x * f, y * f, z * f, seed + i, eased));
                f *= 2.0;
                g *= persistence;
        }
@@ -301,7 +313,6 @@ float noise3d_perlin_abs(float x, float y, float z, int seed,
 }
 
 
-// -1->0, 0->1, 1->0
 float contour(float v)
 {
        v = fabs(v);
@@ -648,3 +659,4 @@ void Noise::transformNoiseMap()
                i++;
        }
 }
+