mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Noise boxing
This commit is contained in:
parent
24242db981
commit
377a4c2284
@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisDataManager;
|
||||
import com.volmit.iris.core.IrisProject;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.engine.noise.CNG;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
@ -25,6 +25,7 @@ import com.volmit.iris.engine.cache.Cache;
|
||||
import com.volmit.iris.engine.data.B;
|
||||
import com.volmit.iris.engine.data.DataProvider;
|
||||
import com.volmit.iris.engine.hunk.Hunk;
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.engine.jigsaw.PlannedStructure;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.engine.object.common.IObjectPlacer;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.engine.object;
|
||||
package com.volmit.iris.engine.interpolation;
|
||||
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
|
@ -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
|
||||
}
|
@ -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);
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
@ -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];
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import com.volmit.iris.core.IrisDataManager;
|
||||
import com.volmit.iris.engine.IrisWorlds;
|
||||
import com.volmit.iris.engine.framework.EngineParallaxManager;
|
||||
import com.volmit.iris.engine.framework.IrisAccess;
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.engine.object.common.IObjectPlacer;
|
||||
import com.volmit.iris.engine.parallax.ParallaxChunkMeta;
|
||||
|
@ -20,6 +20,7 @@ package com.volmit.iris.engine.object;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.engine.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.MaxNumber;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.MaxNumber;
|
||||
|
@ -19,7 +19,7 @@
|
||||
package com.volmit.iris.engine.stream.interpolation;
|
||||
|
||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.engine.object.InterpolationMethod;
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.engine.stream.BasicStream;
|
||||
import com.volmit.iris.engine.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.NoiseProvider;
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine.stream.interpolation;
|
||||
|
||||
import com.volmit.iris.engine.object.InterpolationMethod;
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.engine.stream.ProceduralStream;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
|
Loading…
x
Reference in New Issue
Block a user