Beautiful Interpolation

This commit is contained in:
Daniel Mills 2020-08-29 18:01:00 -04:00
parent 20b715f7cb
commit 9880248e49
7 changed files with 214 additions and 49 deletions

View File

@ -7,11 +7,12 @@ import org.bukkit.entity.Player;
import com.volmit.iris.util.ChronoLatch;
import com.volmit.iris.util.FolderWatcher;
import com.volmit.iris.util.J;
public class IrisHotloadManager
{
private ChronoLatch latch;
private volatile boolean busy = false;
private FolderWatcher w;
public IrisHotloadManager()
@ -27,7 +28,13 @@ public class IrisHotloadManager
return;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () ->
if(busy)
{
return;
}
busy = true;
J.attemptAsync(() ->
{
boolean modified = false;
int c = 0;
@ -123,10 +130,12 @@ public class IrisHotloadManager
{
}
int cc = c;
if(modified)
{
String m = "Hotloaded " + c + " File" + (c == 1 ? "" : "s");
J.s(() ->
{
String m = "Hotloaded " + cc + " File" + (cc == 1 ? "" : "s");
for(Player i : Bukkit.getOnlinePlayers())
{
@ -136,6 +145,13 @@ public class IrisHotloadManager
Bukkit.getConsoleSender().sendMessage(Iris.instance.getTag("Studio") + m);
Iris.globaldata.hotloaded();
ch.onHotloaded();
busy = false;
});
}
else
{
busy = false;
}
});
}

View File

@ -527,8 +527,6 @@ public class ProjectManager
dimension.setLandZoom(1.5);
IrisGenerator gen = new IrisGenerator();
IrisNoiseGenerator gg = new IrisNoiseGenerator(true);
gen.setInterpolationFunction(InterpolationMethod.HERMITE);
gen.setInterpolationScale(185);
gen.getComposite().add(gg);
gen.setLoadKey("example-generator");
IrisBiomeGeneratorLink b1 = new IrisBiomeGeneratorLink();

View File

@ -29,7 +29,6 @@ import com.volmit.iris.util.BiomeResult;
import com.volmit.iris.util.CaveResult;
import com.volmit.iris.util.ChronoLatch;
import com.volmit.iris.util.HeightMap;
import com.volmit.iris.util.IrisInterpolation;
import com.volmit.iris.util.IrisLock;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
@ -689,7 +688,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
protected double interpolateGenerator(double rx, double rz, IrisGenerator gen)
{
double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) ->
double hi = gen.getInterpolator().interpolate(rx, rz, (xx, zz) ->
{
try
{
@ -712,7 +711,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
return 0;
});
double lo = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) ->
double lo = gen.getInterpolator().interpolate(rx, rz, (xx, zz) ->
{
try
{

View File

@ -10,6 +10,42 @@ public enum InterpolationMethod
@DontObfuscate
BILINEAR,
@DontObfuscate
STARCAST_3,
@DontObfuscate
STARCAST_6,
@DontObfuscate
STARCAST_9,
@DontObfuscate
STARCAST_12,
@DontObfuscate
BILINEAR_STARCAST_3,
@DontObfuscate
BILINEAR_STARCAST_6,
@DontObfuscate
BILINEAR_STARCAST_9,
@DontObfuscate
BILINEAR_STARCAST_12,
@DontObfuscate
HERMITE_STARCAST_3,
@DontObfuscate
HERMITE_STARCAST_6,
@DontObfuscate
HERMITE_STARCAST_9,
@DontObfuscate
HERMITE_STARCAST_12,
@DontObfuscate
BILINEAR_BEZIER,

View File

@ -69,15 +69,8 @@ public class IrisGenerator extends IrisRegistrant
@Required
@DontObfuscate
@Desc("The interpolation method when two biomes use different heights but this same generator")
private InterpolationMethod interpolationFunction = InterpolationMethod.BICUBIC;
@Required
@MinNumber(1)
@MaxNumber(8192)
@DontObfuscate
@Desc("The interpolation distance scale (blocks) when two biomes use different heights but this same generator")
private double interpolationScale = 7;
@Desc("The interpolator to use when smoothing this generator into other regions & generators")
private IrisInterpolator interpolator = new IrisInterpolator();
@MinNumber(0)
@MaxNumber(8192)
@ -255,7 +248,7 @@ public class IrisGenerator extends IrisRegistrant
return 0;
}
int hc = (int) ((cliffHeightMin * 10) + 10 + cliffHeightMax + interpolationScale * seed + offsetX + offsetZ);
int hc = (int) ((cliffHeightMin * 10) + 10 + cliffHeightMax * seed + offsetX + offsetZ);
double h = 0;
double tp = 0;
@ -291,7 +284,7 @@ public class IrisGenerator extends IrisRegistrant
public double getCliffHeight(double rx, double rz, double superSeed)
{
int hc = (int) ((cliffHeightMin * 10) + 10 + cliffHeightMax + interpolationScale * seed + offsetX + offsetZ);
int hc = (int) ((cliffHeightMin * 10) + 10 + cliffHeightMax * seed + offsetX + offsetZ);
double h = cliffHeightGenerator.getNoise((long) (seed + superSeed + hc), (rx + offsetX) / zoom, (rz + offsetZ) / zoom);
return IrisInterpolation.lerp(cliffHeightMin, cliffHeightMax, h);
}

View File

@ -0,0 +1,43 @@
package com.volmit.iris.object;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
import com.volmit.iris.util.IrisInterpolation;
import com.volmit.iris.util.MaxNumber;
import com.volmit.iris.util.MinNumber;
import com.volmit.iris.util.NoiseProvider;
import com.volmit.iris.util.Required;
import lombok.Data;
@Desc("Configures rotation for iris")
@Data
public class IrisInterpolator
{
@Required
@DontObfuscate
@Desc("The interpolation method when two biomes use different heights but this same generator")
private InterpolationMethod function = InterpolationMethod.BICUBIC;
@Required
@MinNumber(1)
@MaxNumber(8192)
@DontObfuscate
@Desc("The range checked horizontally. Smaller ranges yeild more detail but are not as smooth.")
private double horizontalScale = 3;
public IrisInterpolator()
{
}
public double interpolate(double x, double z, NoiseProvider provider)
{
return interpolate((int) Math.round(x), (int) Math.round(z), provider);
}
public double interpolate(int x, int z, NoiseProvider provider)
{
return IrisInterpolation.getNoise(getFunction(), x, z, getHorizontalScale(), provider);
}
}

View File

@ -1,6 +1,8 @@
package com.volmit.iris.util;
import com.volmit.iris.noise.CNG;
import com.volmit.iris.object.InterpolationMethod;
import com.volmit.iris.object.NoiseStyle;
public class IrisInterpolation
{
@ -221,11 +223,11 @@ public class IrisInterpolation
public static double trilerp(double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, double x, double y, double z)
{
double s = blerp(v1, v2, v3, v4, x, y);
double t = blerp(v5, v6, v7, v8, x, y);
return lerp(s, t, z);
return lerp(blerp(v1, v2, v3, v4, x, y), blerp(v5, v6, v7, v8, x, y), z);
}
public static CNG cng = NoiseStyle.SIMPLEX.create(new RNG());
public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n)
{
int fx = (int) Math.floor(x / rad);
@ -234,6 +236,7 @@ public class IrisInterpolation
int z1 = (int) Math.round(fz * rad);
int x2 = (int) Math.round((fx + 1) * rad);
int z2 = (int) Math.round((fz + 1) * rad);
double px = rangeScale(0, 1, x1, x2, x);
double pz = rangeScale(0, 1, z1, z2, z);
//@builder
@ -246,6 +249,23 @@ public class IrisInterpolation
//@done
}
public static double getStarcast(int x, int z, double rad, double checks, NoiseProvider n)
{
double m = (360 / checks);
double v = 0;
for(int i = 0; i < 360; i += m)
{
double sin = Math.sin(Math.toRadians(i));
double cos = Math.cos(Math.toRadians(i));
double cx = x + ((rad * cos) - (rad * sin));
double cz = z + ((rad * sin) + (rad * cos));
v += n.noise(cx, cz);
}
return v / checks;
}
public static double getBilinearBezierNoise(int x, int z, double rad, NoiseProvider n)
{
int fx = (int) Math.floor(x / rad);
@ -537,81 +557,141 @@ public class IrisInterpolation
//@done
}
public static double getNoise(InterpolationMethod method, int x, int z, double rad, NoiseProvider n)
public static double getNoise(InterpolationMethod method, int x, int z, double h, NoiseProvider n)
{
if(method.equals(InterpolationMethod.BILINEAR))
{
return getBilinearNoise(x, z, rad, n);
return getBilinearNoise(x, z, h, n);
}
else if(method.equals(InterpolationMethod.STARCAST_3))
{
return getStarcast(x, z, h, 3D, n);
}
else if(method.equals(InterpolationMethod.STARCAST_6))
{
return getStarcast(x, z, h, 6D, n);
}
else if(method.equals(InterpolationMethod.STARCAST_9))
{
return getStarcast(x, z, h, 9D, n);
}
else if(method.equals(InterpolationMethod.STARCAST_12))
{
return getStarcast(x, z, h, 12D, n);
}
else if(method.equals(InterpolationMethod.BILINEAR_STARCAST_3))
{
return getStarcast(x, z, h, 3D, (xx, zz) -> getBilinearNoise((int) xx, (int) zz, h, n));
}
else if(method.equals(InterpolationMethod.BILINEAR_STARCAST_6))
{
return getStarcast(x, z, h, 6D, (xx, zz) -> getBilinearNoise((int) xx, (int) zz, h, n));
}
else if(method.equals(InterpolationMethod.BILINEAR_STARCAST_9))
{
return getStarcast(x, z, h, 9D, (xx, zz) -> getBilinearNoise((int) xx, (int) zz, h, n));
}
else if(method.equals(InterpolationMethod.BILINEAR_STARCAST_12))
{
return getStarcast(x, z, h, 12D, (xx, zz) -> getBilinearNoise((int) xx, (int) zz, h, n));
}
else if(method.equals(InterpolationMethod.HERMITE_STARCAST_3))
{
return getStarcast(x, z, h, 3D, (xx, zz) -> getHermiteNoise((int) xx, (int) zz, h, n, 0D, 0D));
}
else if(method.equals(InterpolationMethod.HERMITE_STARCAST_6))
{
return getStarcast(x, z, h, 6D, (xx, zz) -> getHermiteNoise((int) xx, (int) zz, h, n, 0D, 0D));
}
else if(method.equals(InterpolationMethod.HERMITE_STARCAST_9))
{
return getStarcast(x, z, h, 9D, (xx, zz) -> getHermiteNoise((int) xx, (int) zz, h, n, 0D, 0D));
}
else if(method.equals(InterpolationMethod.HERMITE_STARCAST_12))
{
return getStarcast(x, z, h, 12D, (xx, zz) -> getHermiteNoise((int) xx, (int) zz, h, n, 0D, 0D));
}
else if(method.equals(InterpolationMethod.BICUBIC))
{
return getBicubicNoise(x, z, rad, n);
return getBicubicNoise(x, z, h, n);
}
else if(method.equals(InterpolationMethod.BILINEAR_BEZIER))
{
return getBilinearBezierNoise(x, z, rad, n);
return getBilinearBezierNoise(x, z, h, n);
}
else if(method.equals(InterpolationMethod.BILINEAR_PARAMETRIC_2))
{
return getBilinearParametricNoise(x, z, rad, n, 2);
return getBilinearParametricNoise(x, z, h, n, 2);
}
else if(method.equals(InterpolationMethod.BILINEAR_PARAMETRIC_4))
{
return getBilinearParametricNoise(x, z, rad, n, 4);
return getBilinearParametricNoise(x, z, h, n, 4);
}
else if(method.equals(InterpolationMethod.BILINEAR_PARAMETRIC_1_5))
{
return getBilinearParametricNoise(x, z, rad, n, 1.5);
return getBilinearParametricNoise(x, z, h, n, 1.5);
}
else if(method.equals(InterpolationMethod.BICUBIC))
{
return getBilinearNoise(x, z, rad, n);
return getBilinearNoise(x, z, h, n);
}
else if(method.equals(InterpolationMethod.HERMITE))
{
return getHermiteNoise(x, z, rad, n);
return getHermiteNoise(x, z, h, n);
}
else if(method.equals(InterpolationMethod.HERMITE_TENSE))
{
return getHermiteNoise(x, z, rad, n, 0.8D, 0D);
return getHermiteNoise(x, z, h, n, 0.8D, 0D);
}
else if(method.equals(InterpolationMethod.CATMULL_ROM_SPLINE))
{
return getHermiteNoise(x, z, rad, n, 1D, 0D);
return getHermiteNoise(x, z, h, n, 1D, 0D);
}
else if(method.equals(InterpolationMethod.HERMITE_LOOSE))
{
return getHermiteNoise(x, z, rad, n, 0D, 0D);
return getHermiteNoise(x, z, h, n, 0D, 0D);
}
else if(method.equals(InterpolationMethod.HERMITE_LOOSE_HALF_NEGATIVE_BIAS))
{
return getHermiteNoise(x, z, rad, n, 0D, -0.5D);
return getHermiteNoise(x, z, h, n, 0D, -0.5D);
}
else if(method.equals(InterpolationMethod.HERMITE_LOOSE_HALF_POSITIVE_BIAS))
{
return getHermiteNoise(x, z, rad, n, 0D, 0.5D);
return getHermiteNoise(x, z, h, n, 0D, 0.5D);
}
else if(method.equals(InterpolationMethod.HERMITE_LOOSE_FULL_NEGATIVE_BIAS))
{
return getHermiteNoise(x, z, rad, n, 0D, -1D);
return getHermiteNoise(x, z, h, n, 0D, -1D);
}
else if(method.equals(InterpolationMethod.HERMITE_LOOSE_FULL_POSITIVE_BIAS))
{
return getHermiteNoise(x, z, rad, n, 0D, 1D);
return getHermiteNoise(x, z, h, n, 0D, 1D);
}
return n.noise(x, z);