This commit is contained in:
Daniel Mills 2021-01-02 12:26:21 -05:00
parent 5e6ec3b217
commit 78eebc255e
3 changed files with 126 additions and 3 deletions

View File

@ -145,7 +145,7 @@ public class IrisComplex implements DataProvider
.convertAware2D(this::implode).cache2D(cacheSize);
heightStream = ProceduralStream.of((x, z) -> {
IrisBiome b = baseBiomeStream.get(x, z);
return getHeight(b, x, z, engine.getWorld().getSeed());
return getHeight(engine, b, x, z, engine.getWorld().getSeed());
}, Interpolated.DOUBLE).cache2D(cacheSize);
slopeStream = heightStream.slope(3).interpolate().bilinear(3, 3).cache2D(cacheSize);
trueBiomeStream = heightStream
@ -289,7 +289,7 @@ public class IrisComplex implements DataProvider
return biome;
}
private double getHeight(IrisBiome b, double x, double z, long seed)
private double getHeight(Engine engine, IrisBiome b, double x, double z, long seed)
{
double h = 0;
@ -332,7 +332,13 @@ public class IrisComplex implements DataProvider
h += M.lerp(lo, hi, gen.getHeight(x, z, seed + 239945));
}
return h + fluidHeight + overlayStream.get(x,z);
double noise = h + fluidHeight + overlayStream.get(x,z);
for(NoiseEffectZone i : engine.getDimension().getNoiseEffectZones())
{
noise = i.filter(x, z, noise);
}
return Math.min(engine.getHeight(), Math.max(noise, 0));
}
private void registerGenerator(IrisGenerator cachedGenerator)

View File

@ -56,6 +56,11 @@ public class IrisDimension extends IrisRegistrant
@ArrayType(min = 1, type = IrisEntitySpawnOverride.class)
private KList<IrisEntitySpawnOverride> entitySpawnOverrides = new KList<>();
@DontObfuscate
@Desc("Add spatial effects to iris noise")
@ArrayType(min = 1, type = NoiseEffectZone.class)
private KList<NoiseEffectZone> noiseEffectZones = new KList<>();
@DontObfuscate
@Desc("Entity spawns during generation")
@ArrayType(min = 1, type = IrisEntityInitialSpawn.class)

View File

@ -0,0 +1,112 @@
package com.volmit.iris.object;
import com.volmit.iris.scaffold.cache.AtomicCache;
import com.volmit.iris.util.*;
import lombok.Data;
@Data
@DontObfuscate
@Desc("Represents a flat zone")
public class NoiseEffectZone {
@Required
@DontObfuscate
@Desc("The x coordinate of this zone")
private int x;
@Required
@DontObfuscate
@Desc("The z coordinate of this zone")
private int z;
@Required
@DontObfuscate
@Desc("The block radius of this zone")
private double blockRadius = 32;
@Required
@DontObfuscate
@Desc("The interpolation radius of this zone")
private double interpolationRadius = 7;
@Required
@DontObfuscate
@MaxNumber(1)
@MinNumber(0)
@Desc("The strength of this effect")
private double strength = 0.75;
@Required
@DontObfuscate
@Desc("The interpolator to use for smoothing the strength")
private InterpolationMethod interpolator = InterpolationMethod.BILINEAR_STARCAST_9;
@Required
@DontObfuscate
@Desc("If set, this will shift the terrain height in blocks (up or down)")
private double shiftHeight = 0;
@Required
@DontObfuscate
@Desc("If set, this will force the terrain closer to the specified height.")
private double convergeToHeight = -1;
@Required
@DontObfuscate
@Desc("Multiplies the input noise")
private double multiplyHeight = 1;
@Required
@DontObfuscate
@Desc("Invert the zone so that anything outside this zone is affected.")
private boolean invertZone = false;
@Required
@DontObfuscate
@Desc("Add additional noise to this spot")
private IrisGeneratorStyle addNoise = NoiseStyle.FLAT.style();
private transient AtomicCache<NoiseProvider> provider = new AtomicCache<>();
private static double BLOCK = 1D / 256D;
public double filter(double x, double z, double noise)
{
if(invertZone ? distance2(x, z) < (blockRadius + (interpolationRadius * 5)) * (blockRadius + + (interpolationRadius * 5)) : distance2(x, z) > (blockRadius + interpolationRadius) * (blockRadius + interpolationRadius))
{
return noise;
}
NoiseProvider d = provider.aquire(this::getNoiseProvider);
double s = IrisInterpolation.getNoise(interpolator, (int)x, (int)z, interpolationRadius, d);
if(s <= 0)
{
return noise;
}
double fx = noise;
if(convergeToHeight >= 0)
{
fx = convergeToHeight;
}
fx *= multiplyHeight;
fx += shiftHeight;
return M.lerp(noise, fx, strength * s);
}
public double distance(double x, double z) {
return Math.sqrt(Math.pow(this.x - x, 2) + Math.pow(this.z - z, 2));
}
public double distance2(double x, double z) {
return Math.pow(this.x - x, 2) + Math.pow(this.z - z, 2);
}
private NoiseProvider getNoiseProvider() {
return (x, z) -> distance(x, z) < blockRadius ? invertZone ? 0D : 1d : invertZone ? 1D : 0d;
}
}