From 78eebc255ee16c4b818582a7b5a263a812fb0f94 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Sat, 2 Jan 2021 12:26:21 -0500 Subject: [PATCH] FX Zones --- .../volmit/iris/generator/IrisComplex.java | 12 +- .../com/volmit/iris/object/IrisDimension.java | 5 + .../volmit/iris/object/NoiseEffectZone.java | 112 ++++++++++++++++++ 3 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/volmit/iris/object/NoiseEffectZone.java diff --git a/src/main/java/com/volmit/iris/generator/IrisComplex.java b/src/main/java/com/volmit/iris/generator/IrisComplex.java index 6c0c01b13..cf338dc24 100644 --- a/src/main/java/com/volmit/iris/generator/IrisComplex.java +++ b/src/main/java/com/volmit/iris/generator/IrisComplex.java @@ -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) diff --git a/src/main/java/com/volmit/iris/object/IrisDimension.java b/src/main/java/com/volmit/iris/object/IrisDimension.java index 1fdb110fd..0d9a6bb4c 100644 --- a/src/main/java/com/volmit/iris/object/IrisDimension.java +++ b/src/main/java/com/volmit/iris/object/IrisDimension.java @@ -56,6 +56,11 @@ public class IrisDimension extends IrisRegistrant @ArrayType(min = 1, type = IrisEntitySpawnOverride.class) private KList entitySpawnOverrides = new KList<>(); + @DontObfuscate + @Desc("Add spatial effects to iris noise") + @ArrayType(min = 1, type = NoiseEffectZone.class) + private KList noiseEffectZones = new KList<>(); + @DontObfuscate @Desc("Entity spawns during generation") @ArrayType(min = 1, type = IrisEntityInitialSpawn.class) diff --git a/src/main/java/com/volmit/iris/object/NoiseEffectZone.java b/src/main/java/com/volmit/iris/object/NoiseEffectZone.java new file mode 100644 index 000000000..3365e172a --- /dev/null +++ b/src/main/java/com/volmit/iris/object/NoiseEffectZone.java @@ -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 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; + } +}