Noise boxing

This commit is contained in:
Daniel Mills
2021-07-16 03:54:09 -04:00
parent 24242db981
commit 377a4c2284
12 changed files with 243 additions and 47 deletions

View File

@@ -0,0 +1,133 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.interpolation;
import com.volmit.iris.engine.object.annotations.Desc;
@Desc("An interpolation method (or function) is simply a method of smoothing a position based on surrounding points on a grid. Bicubic for example is smoother, but has 4 times the checks than Bilinear for example. Try using BILINEAR_STARCAST_9 for beautiful results.")
public enum InterpolationMethod {
@Desc("No interpolation. Nearest Neighbor (bad for terrain, great for performance).")
NONE,
@Desc("Uses 4 nearby points in a square to calculate a 2d slope. Very fast but creates square artifacts. See: https://en.wikipedia.org/wiki/Bilinear_interpolation")
BILINEAR,
@Desc("Starcast is Iris's own creation. It uses raytrace checks to find a horizontal boundary nearby. 3 Checks in a circle. Typically starcast is used with another interpolation method. See BILINEAR_STARCAST_9 For example. Starcast is meant to 'break up' large, abrupt cliffs to make cheap interpolation smoother.")
STARCAST_3,
@Desc("Starcast is Iris's own creation. It uses raytrace checks to find a horizontal boundary nearby. 6 Checks in a circle. Typically starcast is used with another interpolation method. See BILINEAR_STARCAST_9 For example. Starcast is meant to 'break up' large, abrupt cliffs to make cheap interpolation smoother.")
STARCAST_6,
@Desc("Starcast is Iris's own creation. It uses raytrace checks to find a horizontal boundary nearby. 9 Checks in a circle. Typically starcast is used with another interpolation method. See BILINEAR_STARCAST_9 For example. Starcast is meant to 'break up' large, abrupt cliffs to make cheap interpolation smoother.")
STARCAST_9,
@Desc("Starcast is Iris's own creation. It uses raytrace checks to find a horizontal boundary nearby. 12 Checks in a circle. Typically starcast is used with another interpolation method. See BILINEAR_STARCAST_9 For example. Starcast is meant to 'break up' large, abrupt cliffs to make cheap interpolation smoother.")
STARCAST_12,
@Desc("Uses starcast to break up the abrupt sharp cliffs, then smooths the rest out with bilinear.")
BILINEAR_STARCAST_3,
@Desc("Uses starcast to break up the abrupt sharp cliffs, then smooths the rest out with bilinear.")
BILINEAR_STARCAST_6,
@Desc("Uses starcast to break up the abrupt sharp cliffs, then smooths the rest out with bilinear.")
BILINEAR_STARCAST_9,
@Desc("Uses starcast to break up the abrupt sharp cliffs, then smooths the rest out with bilinear.")
BILINEAR_STARCAST_12,
@Desc("Uses starcast to break up the abrupt sharp cliffs, then smooths the rest out with hermite.")
HERMITE_STARCAST_3,
@Desc("Uses starcast to break up the abrupt sharp cliffs, then smooths the rest out with hermite.")
HERMITE_STARCAST_6,
@Desc("Uses starcast to break up the abrupt sharp cliffs, then smooths the rest out with hermite.")
HERMITE_STARCAST_9,
@Desc("Uses starcast to break up the abrupt sharp cliffs, then smooths the rest out with hermite.")
HERMITE_STARCAST_12,
@Desc("Uses bilinear but on a bezier curve. See: https://en.wikipedia.org/wiki/Bezier_curve")
BILINEAR_BEZIER,
@Desc("Uses Bilinear but with parametric curves alpha 2.")
BILINEAR_PARAMETRIC_2,
@Desc("Uses Bilinear but with parametric curves alpha 4.")
BILINEAR_PARAMETRIC_4,
@Desc("Uses Bilinear but with parametric curves alpha 1.5.")
BILINEAR_PARAMETRIC_1_5,
@Desc("Bicubic noise creates 4, 4-point splines for a total of 16 checks. Bcubic can go higher than expected and lower than expected right before a large change in slope.")
BICUBIC,
@Desc("Hermite is similar to bicubic, but faster and it can be tuned a little bit")
HERMITE,
@Desc("Essentially bicubic with zero tension")
CATMULL_ROM_SPLINE,
@Desc("Essentially bicubic with max tension")
HERMITE_TENSE,
@Desc("Hermite is similar to bicubic, this variant reduces the dimple artifacts of bicubic")
HERMITE_LOOSE,
@Desc("Hermite is similar to bicubic, this variant reduces the dimple artifacts of bicubic")
HERMITE_LOOSE_HALF_POSITIVE_BIAS,
@Desc("Hermite is similar to bicubic, this variant reduces the dimple artifacts of bicubic")
HERMITE_LOOSE_HALF_NEGATIVE_BIAS,
@Desc("Hermite is similar to bicubic, this variant reduces the dimple artifacts of bicubic")
HERMITE_LOOSE_FULL_POSITIVE_BIAS,
@Desc("Hermite is similar to bicubic, this variant reduces the dimple artifacts of bicubic")
HERMITE_LOOSE_FULL_NEGATIVE_BIAS,
}

View File

@@ -0,0 +1,28 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.interpolation;
import com.volmit.iris.engine.object.annotations.Desc;
@Desc("An interpolation method (or function) is simply a method of smoothing a position based on surrounding points on a grid. Bicubic for example is smoother, but has 4 times the checks than Bilinear for example. Try using BILINEAR_STARCAST_9 for beautiful results.")
public enum InterpolationMethod3D {
TRILINEAR,
TRICUBIC,
TRIHERMITE
}

View File

@@ -20,7 +20,6 @@ package com.volmit.iris.engine.interpolation;
import com.google.common.util.concurrent.AtomicDouble;
import com.volmit.iris.engine.noise.CNG;
import com.volmit.iris.engine.object.InterpolationMethod;
import com.volmit.iris.engine.object.NoiseStyle;
import com.volmit.iris.util.function.NoiseProvider;
import com.volmit.iris.util.function.NoiseProvider3;
@@ -355,16 +354,21 @@ public class IrisInterpolation {
//@done
}
public static double getTrilinear(int x, int y, int z, double rad, NoiseProvider3 n) {
int fx = (int) Math.floor(x / rad);
int fy = (int) Math.floor(y / rad);
int fz = (int) Math.floor(z / rad);
int x1 = (int) Math.round(fx * rad);
int y1 = (int) Math.round(fy * rad);
int z1 = (int) Math.round(fz * rad);
int x2 = (int) Math.round((fx + 1) * rad);
int y2 = (int) Math.round((fy + 1) * rad);
int z2 = (int) Math.round((fz + 1) * rad);
public static double getTrilinear(int x, int y, int z, double rad, NoiseProvider3 n)
{
return getTrilinear(x,y,z,rad,rad,rad,n);
}
public static double getTrilinear(int x, int y, int z, double radx, double rady, double radz, NoiseProvider3 n) {
int fx = (int) Math.floor(x / radx);
int fy = (int) Math.floor(y / rady);
int fz = (int) Math.floor(z / radz);
int x1 = (int) Math.round(fx * radx);
int y1 = (int) Math.round(fy * rady);
int z1 = (int) Math.round(fz * radz);
int x2 = (int) Math.round((fx + 1) * radx);
int y2 = (int) Math.round((fy + 1) * rady);
int z2 = (int) Math.round((fz + 1) * radz);
double px = rangeScale(0, 1, x1, x2, x);
double py = rangeScale(0, 1, y1, y2, y);
double pz = rangeScale(0, 1, z1, z2, z);
@@ -383,21 +387,25 @@ public class IrisInterpolation {
}
public static double getTricubic(int x, int y, int z, double rad, NoiseProvider3 n) {
int fx = (int) Math.floor(x / rad);
int fy = (int) Math.floor(y / rad);
int fz = (int) Math.floor(z / rad);
int x0 = (int) Math.round((fx - 1) * rad);
int y0 = (int) Math.round((fy - 1) * rad);
int z0 = (int) Math.round((fz - 1) * rad);
int x1 = (int) Math.round(fx * rad);
int y1 = (int) Math.round(fy * rad);
int z1 = (int) Math.round(fz * rad);
int x2 = (int) Math.round((fx + 1) * rad);
int y2 = (int) Math.round((fy + 1) * rad);
int z2 = (int) Math.round((fz + 1) * rad);
int x3 = (int) Math.round((fx + 2) * rad);
int y3 = (int) Math.round((fy + 2) * rad);
int z3 = (int) Math.round((fz + 2) * rad);
return getTricubic(x,y,z,rad,rad,rad,n);
}
public static double getTricubic(int x, int y, int z, double radx, double rady, double radz, NoiseProvider3 n) {
int fx = (int) Math.floor(x / radx);
int fy = (int) Math.floor(y / rady);
int fz = (int) Math.floor(z / radz);
int x0 = (int) Math.round((fx - 1) * radx);
int y0 = (int) Math.round((fy - 1) * rady);
int z0 = (int) Math.round((fz - 1) * radz);
int x1 = (int) Math.round(fx * radx);
int y1 = (int) Math.round(fy * rady);
int z1 = (int) Math.round(fz * radz);
int x2 = (int) Math.round((fx + 1) * radx);
int y2 = (int) Math.round((fy + 1) * rady);
int z2 = (int) Math.round((fz + 1) * radz);
int x3 = (int) Math.round((fx + 2) * radx);
int y3 = (int) Math.round((fy + 2) * rady);
int z3 = (int) Math.round((fz + 2) * radz);
double px = rangeScale(0, 1, x1, x2, x);
double py = rangeScale(0, 1, y1, y2, y);
double pz = rangeScale(0, 1, z1, z2, z);
@@ -473,26 +481,34 @@ public class IrisInterpolation {
//@done
}
public static double getTrihermite(int x, int y, int z, double rad, NoiseProvider3 n) {
return getTrihermite(x, y, z, rad, n, 0D, 0D);
public static double getTrihermite(int x, int y, int z, double rad, NoiseProvider3 n, double tension, double bias) {
return getTrihermite(x, y, z, rad, rad, rad, n, tension, bias);
}
public static double getTrihermite(int x, int y, int z, double rad, NoiseProvider3 n, double tension, double bias) {
int fx = (int) Math.floor(x / rad);
int fy = (int) Math.floor(y / rad);
int fz = (int) Math.floor(z / rad);
int x0 = (int) Math.round((fx - 1) * rad);
int y0 = (int) Math.round((fy - 1) * rad);
int z0 = (int) Math.round((fz - 1) * rad);
int x1 = (int) Math.round(fx * rad);
int y1 = (int) Math.round(fy * rad);
int z1 = (int) Math.round(fz * rad);
int x2 = (int) Math.round((fx + 1) * rad);
int y2 = (int) Math.round((fy + 1) * rad);
int z2 = (int) Math.round((fz + 1) * rad);
int x3 = (int) Math.round((fx + 2) * rad);
int y3 = (int) Math.round((fy + 2) * rad);
int z3 = (int) Math.round((fz + 2) * rad);
public static double getTrihermite(int x, int y, int z, double rad, NoiseProvider3 n) {
return getTrihermite(x, y, z, rad, rad, rad, n, 0D, 0D);
}
public static double getTrihermite(int x, int y, int z, double radx, double rady, double radz, NoiseProvider3 n) {
return getTrihermite(x, y, z, radx, rady, radz, n, 0D, 0D);
}
public static double getTrihermite(int x, int y, int z, double radx, double rady, double radz, NoiseProvider3 n, double tension, double bias) {
int fx = (int) Math.floor(x / radx);
int fy = (int) Math.floor(y / rady);
int fz = (int) Math.floor(z / radz);
int x0 = (int) Math.round((fx - 1) * radx);
int y0 = (int) Math.round((fy - 1) * rady);
int z0 = (int) Math.round((fz - 1) * radz);
int x1 = (int) Math.round(fx * radx);
int y1 = (int) Math.round(fy * rady);
int z1 = (int) Math.round(fz * radz);
int x2 = (int) Math.round((fx + 1) * radx);
int y2 = (int) Math.round((fy + 1) * rady);
int z2 = (int) Math.round((fz + 1) * radz);
int x3 = (int) Math.round((fx + 2) * radx);
int y3 = (int) Math.round((fy + 2) * rady);
int z3 = (int) Math.round((fz + 2) * radz);
double px = rangeScale(0, 1, x1, x2, x);
double py = rangeScale(0, 1, y1, y2, y);
double pz = rangeScale(0, 1, z1, z2, z);
@@ -824,6 +840,23 @@ public class IrisInterpolation {
return rad.get();
}
public static double getNoise3D(InterpolationMethod3D method, int x, int y, int z, double radx, double rady, double radz, NoiseProvider3 n) {
return switch (method){
case TRILINEAR -> getTrilinear(x,y,z,radx, rady, radz, n);
case TRICUBIC -> getTricubic(x,y,z,radx, rady, radz, n);
case TRIHERMITE -> getTrihermite(x,y,z,radx, rady, radz, n);
};
}
public static double getNoise3D(InterpolationMethod3D method, int x, int y, int z, double rad, NoiseProvider3 n) {
return switch (method){
case TRILINEAR -> getTrilinear(x,y,z,rad, rad, rad, n);
case TRICUBIC -> getTricubic(x,y,z,rad, rad, rad, n);
case TRIHERMITE -> getTrihermite(x,y,z,rad, rad, rad, n);
};
}
public static double getNoise(InterpolationMethod method, int x, int z, double h, NoiseProvider n) {
if (method.equals(InterpolationMethod.BILINEAR)) {
return getBilinearNoise(x, z, h, n);

View File

@@ -0,0 +1,59 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.interpolation;
import com.volmit.iris.util.function.NoiseProvider;
public class NoiseBox {
private final double[] noise;
private final int w;
public NoiseBox(int offsetX, int offsetZ, int w, int d, NoiseProvider provider, InterpolationMethod method, int rad)
{
final double[] realNoise;
this.w = w;
int wrad = w/rad;
int drad = d/rad;
noise = new double[w*d];
realNoise = new double[(wrad+1)*(drad+1)];
for(int i = 0; i <= wrad; i++)
{
for(int j = 0; j <= drad; j++)
{
realNoise[(j * wrad) + i] = provider.noise(i, j);
}
}
NoiseProvider p = (x, z) -> realNoise[(int) ((z * wrad) + x)];
for(int i = 0; i < w; i++)
{
for(int j = 0; j < d; j++)
{
noise[(j * w) + i] = IrisInterpolation.getNoise(method, offsetX + i, offsetZ + j, rad, p);
}
}
}
public double get(int x, int z)
{
return noise[(z * w) + x];
}
}

View File

@@ -0,0 +1,71 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.interpolation;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.engine.hunk.storage.ArrayHunk;
import com.volmit.iris.util.function.NoiseProvider;
import com.volmit.iris.util.function.NoiseProvider3;
public class NoiseCube {
private final double[] noise;
private final int w;
private final int h;
public NoiseCube(int offsetX, int offsetY, int offsetZ, int w, int h, int d, NoiseProvider3 provider, InterpolationMethod3D method, int rad)
{
final double[] realNoise;
this.w = w;
this.h = h;
int wrad = w/rad;
int hrad = h/rad;
int drad = d/rad;
noise = new double[w*h*d];
realNoise = new double[(wrad+1)*(hrad+1)*(drad+1)];
for(int i = 0; i <= wrad; i++)
{
for(int j = 0; j <= hrad; j++)
{
for(int k = 0; k <= drad; k++)
{
realNoise[(k * w * h) + (j * w) + i] = provider.noise(i, j, k);
}
}
}
NoiseProvider3 p = (x, y, z) -> realNoise[(int) ((z * w * h) + (y * w) + x)];
for(int i = 0; i < w; i++)
{
for(int j = 0; j < h; j++)
{
for(int k = 0; k < d; k++)
{
noise[(k * w * h) + (j * w) + i] = IrisInterpolation.getNoise3D(method, offsetX + i, offsetY + j,offsetZ + k, rad, p);
}
}
}
}
public double get(int x, int y, int z)
{
return noise[(z * w * h) + (y * w) + x];
}
}