Sample radii & Remove ridges

This commit is contained in:
Daniel Mills
2020-01-15 03:02:01 -05:00
parent ccf36f23c3
commit c4d2e16433
9 changed files with 72 additions and 256 deletions

View File

@@ -13,13 +13,11 @@ import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.controller.PackController;
import ninja.bytecode.iris.generator.genobject.GenObjectDecorator;
import ninja.bytecode.iris.generator.genobject.GenObjectGroup;
import ninja.bytecode.iris.generator.layer.GenLayerBase;
import ninja.bytecode.iris.generator.layer.GenLayerBiome;
import ninja.bytecode.iris.generator.layer.GenLayerCarving;
import ninja.bytecode.iris.generator.layer.GenLayerCaverns;
import ninja.bytecode.iris.generator.layer.GenLayerCaves;
import ninja.bytecode.iris.generator.layer.GenLayerLayeredNoise;
import ninja.bytecode.iris.generator.layer.GenLayerRidge;
import ninja.bytecode.iris.generator.layer.GenLayerSnow;
import ninja.bytecode.iris.pack.CompiledDimension;
import ninja.bytecode.iris.pack.IrisBiome;
@@ -54,14 +52,15 @@ public class IrisGenerator extends ParallelChunkGenerator
MB.of(Material.SMOOTH_BRICK, 2),
MB.of(Material.SMOOTH_BRICK, 3),
});
public GMap<String, IrisBiome> biomeCache = new GMap<>();
//@done
private double[][][] scatterCache;
private CNG scatter;
public GMap<String, IrisBiome> biomeCache = new GMap<>();
private MB WATER = new MB(Material.STATIONARY_WATER);
private MB BEDROCK = new MB(Material.BEDROCK);
private GList<IrisBiome> internal;
private GenLayerBase glBase;
private GenLayerLayeredNoise glLNoise;
private GenLayerRidge glRidge;
private GenLayerBiome glBiome;
private GenLayerCaves glCaves;
private GenLayerCarving glCarving;
@@ -104,6 +103,21 @@ public class IrisGenerator extends ParallelChunkGenerator
}
}
public int scatterInt(int x, int y, int z, int bound)
{
return (int) (scatter(x, y, z) * (double) (bound - 1));
}
public double scatter(int x, int y, int z)
{
return scatterCache[Math.abs(x) % 16][Math.abs(y) % 16][Math.abs(z) % 16];
}
public boolean scatterChance(int x, int y, int z, double chance)
{
return scatter(x, y, z) > chance;
}
public GList<IrisBiome> getLoadedBiomes()
{
return internal;
@@ -115,14 +129,29 @@ public class IrisGenerator extends ParallelChunkGenerator
this.world = world;
rTerrain = new RNG(world.getSeed() + 1024);
lerpf = new CNG(rTerrain.nextParallelRNG(-10000), 1D, 2).scale(Iris.settings.gen.linearSampleFractureScale);
glBase = new GenLayerBase(this, world, random, rTerrain.nextParallelRNG(1));
glLNoise = new GenLayerLayeredNoise(this, world, random, rTerrain.nextParallelRNG(2));
glRidge = new GenLayerRidge(this, world, random, rTerrain.nextParallelRNG(3));
glBiome = new GenLayerBiome(this, world, random, rTerrain.nextParallelRNG(4), dim.getBiomes());
glCaves = new GenLayerCaves(this, world, random, rTerrain.nextParallelRNG(-1));
glCarving = new GenLayerCarving(this, world, random, rTerrain.nextParallelRNG(-2));
glCaverns = new GenLayerCaverns(this, world, random, rTerrain.nextParallelRNG(-3));
glSnow = new GenLayerSnow(this, world, random, rTerrain.nextParallelRNG(5));
scatterCache = new double[16][][];
scatter = new CNG(rTerrain.nextParallelRNG(52), 1, 1).scale(10);
for(int i = 0; i < 16; i++)
{
scatterCache[i] = new double[16][];
for(int j = 0; j < 16; j++)
{
scatterCache[i][j] = new double[16];
for(int k = 0; k < 16; k++)
{
scatterCache[i][j][k] = scatter.noise(i, j, k);
}
}
}
}
@Override
@@ -133,8 +162,8 @@ public class IrisGenerator extends ParallelChunkGenerator
public IrisBiome getBiome(int wxx, int wzx)
{
double wx = Math.round((double) wxx * Iris.settings.gen.horizontalZoom);
double wz = Math.round((double) wzx * Iris.settings.gen.horizontalZoom);
double wx = Math.round((double) wxx * (Iris.settings.gen.horizontalZoom / 1.90476190476));
double wz = Math.round((double) wzx * (Iris.settings.gen.horizontalZoom / 1.90476190476));
return glBiome.getBiome(wx * Iris.settings.gen.biomeScale, wz * Iris.settings.gen.biomeScale);
}
@@ -149,17 +178,19 @@ public class IrisGenerator extends ParallelChunkGenerator
//@builder
int highest = 0;
int seaLevel = Iris.settings.gen.seaLevel;
double wx = Math.round((double) wxx * Iris.settings.gen.horizontalZoom);
double wz = Math.round((double) wzx * Iris.settings.gen.horizontalZoom);
double wx = Math.round((double) wxx * (Iris.settings.gen.horizontalZoom / 1.90476190476));
double wz = Math.round((double) wzx * (Iris.settings.gen.horizontalZoom / 1.90476190476));
IrisBiome biome = getBiome(wxx, wzx);
double hv = IrisInterpolation.getNoise(wxx, wzx,
Iris.settings.gen.linearSampleRadius,
Iris.settings.gen.bilinearSampleRadius,
Iris.settings.gen.trilinearSampleRadius,
(xf, zf) -> getBiomedHeight((int) Math.round(xf), (int) Math.round(zf), plan),
(a, b) -> lerpf.noise(a, b),
Iris.settings.gen.linearFunction,
Iris.settings.gen.bilinearFunction,
Iris.settings.gen.trilinearFunction);
hv += glLNoise.generateLayer(hv * Iris.settings.gen.roughness * 215, wxx * Iris.settings.gen.roughness * 0.82, wzx * Iris.settings.gen.roughness * 0.82) * (1.6918 * (hv * 2.35));
hv -= glRidge.generateLayer(hv, wxx, wzx);
int height = (int) Math.round(M.clip(hv, 0D, 1D) * 253);
int max = Math.max(height, seaLevel);
IrisBiome override = null;
@@ -190,7 +221,7 @@ public class IrisGenerator extends ParallelChunkGenerator
for(int i = 0; i < max; i++)
{
MB mb = ROCK.get(glBase.scatterInt(wzx, i, wxx, ROCK.size()));
MB mb = ROCK.get(scatterInt(wzx, i, wxx, ROCK.size()));
boolean underwater = i >= height && i < seaLevel;
boolean underground = i < height;
@@ -199,7 +230,7 @@ public class IrisGenerator extends ParallelChunkGenerator
mb = WATER;
}
if(underground && (height - 1) - i < glBase.scatterInt(x, i, z, 4) + 2)
if(underground && (height - 1) - i < scatterInt(x, i, z, 4) + 2)
{
mb = biome.getDirtRNG();
}
@@ -247,7 +278,7 @@ public class IrisGenerator extends ParallelChunkGenerator
mb = BEDROCK;
}
if(!Iris.settings.gen.flatBedrock ? i <= 2 : i < glBase.scatterInt(x, i, z, 3))
if(!Iris.settings.gen.flatBedrock ? i <= 2 : i < scatterInt(x, i, z, 3))
{
mb = BEDROCK;
}
@@ -294,11 +325,10 @@ public class IrisGenerator extends ParallelChunkGenerator
if(xh == -1)
{
int wx = (int) Math.round((double) x * Iris.settings.gen.horizontalZoom);
int wz = (int) Math.round((double) z * Iris.settings.gen.horizontalZoom);
int wx = (int) Math.round((double) x * (Iris.settings.gen.horizontalZoom / 1.90476190476));
int wz = (int) Math.round((double) z * (Iris.settings.gen.horizontalZoom / 1.90476190476));
IrisBiome biome = glBiome.getBiome(wx * Iris.settings.gen.biomeScale, wz * Iris.settings.gen.biomeScale);
double h = Iris.settings.gen.baseHeight + biome.getHeight();
h += (glBase.getHeight(wx, wz) * 0.5) - (0.33 * 0.5);
plan.setHeight(x, z, h);
return h;
@@ -327,11 +357,6 @@ public class IrisGenerator extends ParallelChunkGenerator
return rTerrain;
}
public GenLayerBase getGlBase()
{
return glBase;
}
public CompiledDimension getDimension()
{
return dim;

View File

@@ -1,101 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.World;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.M;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerBase extends GenLayer
{
private double[][][] scatterCache;
private CNG gen;
private CNG fracture;
private CNG hfracture;
private CNG height;
private CNG superheight;
public GenLayerBase(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
scatterCache = new double[16][][];
CNG scatter = new CNG(rng.nextParallelRNG(5), 1, 1)
.scale(10);
hfracture = new CNG(rng.nextParallelRNG(6), 1, 2)
.scale(0.0124);
gen = new CNG(rng.nextParallelRNG(7), 0.19D, 7)
.scale(0.012)
.amp(0.5)
.freq(1.1)
.fractureWith(new CNG(rng.nextParallelRNG(8), 1, 6)
.scale(0.018)
.injectWith(CNG.MULTIPLY)
.child(new CNG(rng.nextParallelRNG(9), 0.745, 2)
.scale(0.1)), 44);
height = new CNG(rng.nextParallelRNG(10), 1, 8)
.scale(0.0017601 * Iris.settings.gen.heightScale)
.fractureWith(new CNG(rng.nextParallelRNG(11), 1, 6)
.scale(0.0174)
.fractureWith(new CNG(rng.nextParallelRNG(12), 1, 1)
.scale(0.0034), 31)
.scale(0.066), 58);
superheight = new CNG(rng.nextParallelRNG(13), 1, 6)
.scale(0.0025 * Iris.settings.gen.superHeightScale)
.fractureWith(new CNG(rng.nextParallelRNG(14), 1, 1)
.scale(0.021), 250);
fracture = new CNG(rng.nextParallelRNG(15), 0.6D, 4)
.scale(0.118);
//@done
for(int i = 0; i < 16; i++)
{
scatterCache[i] = new double[16][];
for(int j = 0; j < 16; j++)
{
scatterCache[i][j] = new double[16];
for(int k = 0; k < 16; k++)
{
scatterCache[i][j][k] = scatter.noise(i, j, k);
}
}
}
}
public double getHeight(double x, double z)
{
return M.clip(Math.pow(height.noise(x + (hfracture.noise(x, z) * Iris.settings.gen.heightFracture), z + (hfracture.noise(z, x) * Iris.settings.gen.heightFracture)), Iris.settings.gen.heightExponentBase + (superheight.noise(x, z) * Iris.settings.gen.heightExponentMultiplier)) * Iris.settings.gen.heightMultiplier, 0D, 1D);
}
public int scatterInt(int x, int y, int z, int bound)
{
return (int) (scatter(x, y, z) * (double) (bound - 1));
}
public double scatter(int x, int y, int z)
{
return scatterCache[Math.abs(x) % 16][Math.abs(y) % 16][Math.abs(z) % 16];
}
public boolean scatterChance(int x, int y, int z, double chance)
{
return scatter(x, y, z) > chance;
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
double noise = gnoise + getHeight(dx, dz);
double fnoise = fracture.noise(dx, dz);
dx += (fnoise * 44);
dz -= (fnoise * 44);
return ((noise * 0.185) + (gen.noise(dx, dz) * (0.15 + (noise * 0.65))));
}
}

View File

@@ -146,7 +146,7 @@ public class GenLayerCarving extends GenLayer
}
}
else if(hit > 1 && hit < g.getGlBase().scatterInt(x, i, z, 4) + 3)
else if(hit > 1 && hit < g.scatterInt(x, i, z, 4) + 3)
{
if(!fail)
{

View File

@@ -146,7 +146,7 @@ public class GenLayerCaverns extends GenLayer
}
}
else if(hit > 1 && hit < g.getGlBase().scatterInt(x, i, z, 4) + 3)
else if(hit > 1 && hit < g.scatterInt(x, i, z, 4) + 3)
{
if(!fail)
{

View File

@@ -1,49 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.World;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.M;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerFracture extends GenLayer
{
private CNG gen;
private CNG cond;
private double shootHeight = 0.963;
public GenLayerFracture(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
gen = new CNG(rng.nextParallelRNG(40), 1D, 2)
.scale(0.023)
.fractureWith(new CNG(rng.nextParallelRNG(41), 1D, 1)
.scale(0.05), 333);
cond = new CNG(rng.nextParallelRNG(42), 1D, 2)
.scale(0.038)
.fractureWith(new CNG(rng.nextParallelRNG(43), 1D, 1)
.scale(0.025), 299);
//@done
}
@Override
public double generateLayer(double noise, double dx, double dz)
{
double shootHeight = this.shootHeight + (cond.noise(dx, dz) * 0.035);
if(noise >= shootHeight)
{
double multiplier = M.rangeScale(0, 0.055, this.shootHeight, 1D, cond.noise(-dx, -dz));
double on = gen.noise(dx, dz) * multiplier;
return noise + on;
}
return noise;
}
}

View File

@@ -1,56 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.World;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerRidge extends GenLayer
{
private CNG gen;
private CNG fract;
private CNG g;
private CNG q;
public GenLayerRidge(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
q = new CNG(rng.nextParallelRNG(21), 1D, 2).scale(0.0211);
g = new CNG(rng.nextParallelRNG(22), 1D, 2).scale(0.0011);
fract = new CNG(rng.nextParallelRNG(23), 1D, 5).scale(0.0011);
gen = new CNG(rng.nextParallelRNG(24), 0.19D, 16)
.scale(0.012)
.injectWith(CNG.MAX)
.amp(0.5)
.freq(1.1)
.fractureWith(new CNG(rng.nextParallelRNG(25), 1, 6)
.scale(0.018)
.child(new CNG(rng.nextParallelRNG(26), 0.745, 2)
.scale(0.1))
.fractureWith(new CNG(rng.nextParallelRNG(27), 1, 3)
.scale(0.15), 24), 44);
}
public double getHeight(double x, double z)
{
return gen.noise(x, z);
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
double d = gen.noise(gnoise, dx + (fract.noise(gnoise, dx, dz) * 1555), dz - (fract.noise(dz, dx, gnoise) * 1555));
if(d > g.noise(dx, dz) / 8D)
{
return q.noise(dx, dz, d) * (d / (7D * (g.noise(dz, dx, gnoise) + 0.1))) * (Math.PI / 2.78);
}
return 0;
}
}