Hydrology climate zones

- Hydrology climate splits the land into wet and dry zones with a noise style
- Dry zones keep only the dryRainfall share of rainfall and pond density
- Zone edges ease across the transition band
- Policy climateZones exempts an area from the dry zones
- Policy fluid also fills streams and rivers that flow through the area
- Bank steepness reads the steepest natural ground between the bank and the water
- Bank edges roughen with smooth noise
- Natural ground heights reach the rasterizer at full precision
- Settings reject climate values outside 0..1
- Hydrology probes read the full precision natural heights
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-31 19:23:25 -04:00
1 parent 304e66b74b
commit c2eca3e6bd
26 files changed
+427 -73

No files matched your search

@@ -22,6 +22,9 @@ public class IrisHydrology {
@Description("Fraction of eligible water features to keep after local placement probabilities. 0.5 keeps half the candidate river sources, ponds, lakes and underground water features without changing their configured sizes.")
private double density = 1D;
@Description("Wet and dry zones that decide where streams and ponds gather. Within a wet zone the configured density applies unchanged.")
private IrisHydrologyClimate climate = new IrisHydrologyClimate();
@Description("How water drains across the terrain before rivers and ponds are placed.")
private IrisHydrologyDrainage drainage = new IrisHydrologyDrainage();
@@ -0,0 +1,37 @@
package art.arcane.iris.generation.hydrology.config;
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
import art.arcane.iris.generation.noise.NoiseStyle;
import art.arcane.iris.pack.schema.annotation.MaxNumber;
import art.arcane.iris.pack.schema.annotation.MinNumber;
import art.arcane.volmlib.util.documentation.Description;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Accessors(chain = true)
@NoArgsConstructor
@Description("Wet and dry zones across the dimension. A noise field splits the land into zones: wet zones keep the rainfall and pond density of their biome, dry zones lose them. Streams and ponds then cluster in the wet zones instead of reaching every hill, and a river that rises in a wet zone still flows on through dry land.")
@Data
public class IrisHydrologyClimate {
@Description("Turns wet and dry zones on. When off, rainfall and pond density follow the hydrology policies alone.")
private boolean enabled = false;
@Description("Noise that lays out the zones. Land where its value is below dryness is dry. A larger zoom makes larger zones.")
private IrisGeneratorStyle style = NoiseStyle.SIMPLEX.style().zoomed(24D);
@MinNumber(0)
@MaxNumber(1)
@Description("Noise value below which land is dry. 0 keeps all land wet, and higher values dry out more of it.")
private double dryness = 0.5D;
@MinNumber(0)
@MaxNumber(1)
@Description("Width of the noise band over which rainfall fades from dry to wet. 0 gives sharp zone edges.")
private double transition = 0.1D;
@MinNumber(0)
@MaxNumber(1)
@Description("Share of the area's rainfall and pond density kept in dry zones. 0 lets dry zones start no streams or ponds of their own.")
private double dryRainfall = 0D;
}
@@ -24,12 +24,12 @@ public class IrisHydrologyDeformation {
@MinNumber(0)
@MaxNumber(16)
@Description("How much steeper banks become on steep terrain.")
@Description("How much steeper a bank stays where the natural ground between it and the water is steep.")
private double bankSteepFactor = 3.5D;
@MinNumber(0)
@MaxNumber(2)
@Description("Strength of the noise that roughens bank edges.")
@Description("Strength of the smooth noise that roughens bank edges.")
private double bankNoise = 0.2D;
@Description("Keeps caves from opening under water, so rivers and ponds never drain into them.")
@@ -31,13 +31,16 @@ public class IrisHydrologyPolicy {
@Description("Multiplier on how many ponds form in this area. With no value set anywhere it is 1.")
private Double pondDensity = null;
@Description("Whether the dimension's wet and dry zones apply in this area. false keeps this area's full rainfall and pond density even inside a dry zone. With no value set anywhere they apply.")
private Boolean climateZones = null;
@Description("Whether streams and rivers may form in this area. With no value set anywhere they are allowed.")
private IrisHydrologyPermission streams = null;
@Description("Whether ponds may form in this area. With no value set anywhere they are allowed.")
private IrisHydrologyPermission ponds = null;
@Description("Name of a fluid profile that fills ponds and lakes whose floor lies in this area, instead of the ponds' own fluid. Channels always use the fluid of their tier.")
@Description("Name of a fluid profile that fills the water in this area instead of its usual fluid: ponds and lakes whose floor lies here, and every stretch of stream or river that flows through here.")
private String fluid = null;
@RegistryListResource(IrisBiome.class)
@@ -14,8 +14,10 @@ import art.arcane.iris.generation.hydrology.plan.WindowKey;
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureQuery;
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureRef;
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
import art.arcane.iris.generation.hydrology.raster.ChannelFluids;
import art.arcane.iris.generation.hydrology.raster.ChunkRasterizer;
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
import art.arcane.iris.generation.hydrology.raster.NaturalHeights;
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
@@ -51,7 +53,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.LongSupplier;
import java.util.function.Predicate;
import java.util.function.Supplier;
@@ -68,7 +69,7 @@ public final class HydrologyRuntime {
private final HydrologySettings settings;
private final HydrologyPlanCache cache;
private final ChunkRasterizer rasterizer;
private final IntBinaryOperator naturalHeight;
private final NaturalHeights naturalHeight;
private final BooleanSupplier mainThread;
private final RasterLru rasters;
private final ThreadLocal<LastRaster> last;
@@ -109,17 +110,17 @@ public final class HydrologyRuntime {
this.caveFluidPolicies = false;
}
public HydrologyRuntime(HydrologySettings settings, HydrologyPlanCache cache, IntBinaryOperator naturalHeight,
public HydrologyRuntime(HydrologySettings settings, HydrologyPlanCache cache, NaturalHeights naturalHeight,
BooleanSupplier mainThread, LongSupplier ticker) {
this(settings, cache, naturalHeight, mainThread, ticker, HydrologyBinding.UNBOUND, identity -> null, false);
this(settings, cache, naturalHeight, ChannelFluids.TIER, mainThread, ticker, HydrologyBinding.UNBOUND, identity -> null, false);
}
private HydrologyRuntime(HydrologySettings settings, HydrologyPlanCache cache, IntBinaryOperator naturalHeight,
BooleanSupplier mainThread, LongSupplier ticker, HydrologyBinding binding,
private HydrologyRuntime(HydrologySettings settings, HydrologyPlanCache cache, NaturalHeights naturalHeight,
ChannelFluids channelFluids, BooleanSupplier mainThread, LongSupplier ticker, HydrologyBinding binding,
Function<PreparedHydrologyCacheIdentity, HydrologyPlanStore> stores, boolean caveFluidPolicies) {
this.settings = Objects.requireNonNull(settings, "settings");
this.cache = Objects.requireNonNull(cache, "cache");
this.rasterizer = new ChunkRasterizer(settings);
this.rasterizer = new ChunkRasterizer(settings, channelFluids);
this.naturalHeight = Objects.requireNonNull(naturalHeight, "naturalHeight");
this.mainThread = Objects.requireNonNull(mainThread, "mainThread");
this.rasters = new RasterLru();
@@ -160,7 +161,7 @@ public final class HydrologyRuntime {
HydrologyPlanCache cache = HydrologyPlanCache.create(settings, planners.regions(), planners.windows(), MultiBurst.hydrology, mainThread);
String dimensionKey = dimension.getLoadKey();
IrisWorld world = engine.getWorld();
return new HydrologyRuntime(settings, cache, source::naturalHeight, mainThread, System::nanoTime, binding,
return new HydrologyRuntime(settings, cache, source::naturalSurface, source, mainThread, System::nanoTime, binding,
identity -> store(world, dimensionKey, settings, identity), caveFluidPolicies);
}
@@ -7,11 +7,13 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
import art.arcane.iris.generation.hydrology.grid.HydrologyTerrainSource;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.raster.ChannelFluids;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.generation.terrain.InferredType;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.generation.terrain.IrisRegion;
import art.arcane.iris.studio.generation.BiomeBuffetLayout;
import art.arcane.volmlib.util.noise.CNG;
import art.arcane.volmlib.util.stream.ProceduralStream;
import java.util.ArrayList;
@@ -25,9 +27,10 @@ import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource {
public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource, ChannelFluids {
private static final int MINIMUM_SLICE = 256;
private static final int POLICY_CAPACITY = 4096;
private static final long SALT_CLIMATE = 0x434c494d415445L;
private final IrisComplex complex;
private final IrisDimension dimension;
@@ -40,6 +43,8 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource
private final BiomeBuffetLayout buffet;
private final IrisBiome focus;
private final HydrologyBinding binding;
private final HydrologySettings.Climate climate;
private final CNG wetness;
private final ConcurrentHashMap<PolicyKey, Policy> policies = new ConcurrentHashMap<>();
public IrisHydrologyTerrainSource(IrisComplex complex, IrisDimension dimension, HydrologySettings settings, ExecutorService pool,
@@ -55,6 +60,8 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource
this.buffet = complex.getBiomeBuffet();
this.focus = complex.getFocusBiome();
this.binding = Objects.requireNonNull(binding, "binding");
this.climate = settings.climate();
this.wetness = climate.enabled() ? climate.style().create(settings.seed() ^ SALT_CLIMATE, complex.getData()) : null;
}
@Override
@@ -73,8 +80,13 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource
}
}
public int naturalHeight(int x, int z) {
return complex.naturalTrueHeight(x, z);
public double naturalSurface(int x, int z) {
return complex.naturalHeight(x, z);
}
@Override
public String channelFluid(int x, int z) {
return policy(biomes.get(x, z), regions.get(x, z)).fluid();
}
@Override
@@ -150,12 +162,17 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource
Policy policy = policy(biomes.get(x, z), regions.get(x, z));
out.height()[index] = (float) height;
out.ocean()[index] = StrictMath.round(height) < settings.seaLevel() && oceanIntent(x, z);
out.rainfall()[index] = policy.rainfall();
out.pondDensity()[index] = policy.pondDensity();
float wet = policy.climateZones() ? wetness(x, z) : 1f;
out.rainfall()[index] = policy.rainfall() * wet;
out.pondDensity()[index] = policy.pondDensity() * wet;
out.permission()[index] = policy.permission();
out.fluidProfile()[index] = policy.fluid();
}
private float wetness(int x, int z) {
return wetness == null ? 1f : (float) climate.wetness(wetness.noise(x, z));
}
private boolean oceanIntent(int x, int z) {
BiomeBuffetLayout.Cell cell = buffet == null ? null : buffet.terrain(x, z);
IrisBiome focused = cell == null ? focus : cell.biome();
@@ -183,13 +200,14 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource
IrisHydrologyPermission streams = inherited(biome, region, IrisHydrologyPolicy::getStreams, IrisHydrologyPermission.ALLOW);
IrisHydrologyPermission ponds = inherited(biome, region, IrisHydrologyPolicy::getPonds, IrisHydrologyPermission.ALLOW);
String fluid = inherited(biome, region, IrisHydrologyPolicy::getFluid, null);
boolean climateZones = inherited(biome, region, IrisHydrologyPolicy::getClimateZones, Boolean.TRUE);
requireMultiplier("rainfall", rainfall, biome, region);
requireMultiplier("pondDensity", pondDensity, biome, region);
if (fluid != null && !settings.fluids().containsKey(fluid)) {
throw new IllegalArgumentException("Hydrology policy for " + where(biome, region) + " names fluid '" + fluid
+ "', which is not one of the hydrology fluids " + settings.fluids().keySet());
}
return new Policy((float) rainfall, (float) pondDensity, permission(streams, ponds), fluid);
return new Policy((float) rainfall, (float) pondDensity, permission(streams, ponds), fluid, climateZones);
}
private <T> T inherited(IrisBiome biome, IrisRegion region, Function<IrisHydrologyPolicy, T> field, T fallback) {
@@ -214,7 +232,7 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource
return "biome " + (biome == null ? "none" : biome.getLoadKey()) + " in region " + (region == null ? "none" : region.getLoadKey());
}
private record Policy(float rainfall, float pondDensity, byte permission, String fluid) {
private record Policy(float rainfall, float pondDensity, byte permission, String fluid, boolean climateZones) {
}
private record PolicyKey(IrisBiome biome, IrisRegion region) {
@@ -5,6 +5,7 @@ import art.arcane.iris.generation.decoration.IrisDecorationPart;
import art.arcane.iris.generation.decoration.IrisDecorator;
import art.arcane.iris.generation.hydrology.config.IrisCavePools;
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyClimate;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyDeformation;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyDrainage;
@@ -20,6 +21,7 @@ import art.arcane.iris.generation.hydrology.config.IrisPondShore;
import art.arcane.iris.generation.hydrology.config.IrisSeaInlets;
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
import com.google.gson.Gson;
@@ -51,6 +53,7 @@ public final class HydrologySettings {
private final int maxY;
private final boolean enabled;
private final float density;
private final Climate climate;
private final Drainage drainage;
private final List<HydrologyTier> tiers;
private final Ponds ponds;
@@ -72,6 +75,7 @@ public final class HydrologySettings {
throw new IllegalArgumentException("Hydrology density must be within 0..1, got " + config.getDensity());
}
this.density = (float) config.getDensity();
this.climate = climate(config.getClimate());
this.drainage = drainage(config.getDrainage());
this.tiers = tiers(config.getTiers());
this.ponds = ponds(config.getPonds());
@@ -135,6 +139,10 @@ public final class HydrologySettings {
return density;
}
public Climate climate() {
return climate;
}
public Drainage drainage() {
return drainage;
}
@@ -167,6 +175,22 @@ public final class HydrologySettings {
return persist;
}
private static Climate climate(IrisHydrologyClimate config) {
Objects.requireNonNull(config, "Hydrology climate is missing");
IrisGeneratorStyle style = Objects.requireNonNull(config.getStyle(), "Hydrology climate.style is missing");
float dryness = unit(config.getDryness(), "climate.dryness");
float transition = unit(config.getTransition(), "climate.transition");
float dryRainfall = unit(config.getDryRainfall(), "climate.dryRainfall");
return new Climate(config.isEnabled(), style, dryness, transition, dryRainfall);
}
private static float unit(double value, String field) {
if (!Double.isFinite(value) || value < 0D || value > 1D) {
throw new IllegalArgumentException("Hydrology " + field + " must be within 0..1, got " + value);
}
return (float) value;
}
private static Drainage drainage(IrisHydrologyDrainage config) {
return new Drainage((float) config.getFillEpsilon(), config.getBreachDepth(), config.isWetnessThinning(),
(float) config.getMinimumHeadKeep(), (float) config.getHeadRelief(), (float) config.getSaturationCatchment());
@@ -468,6 +492,7 @@ public final class HydrologySettings {
private long computeFingerprint() {
Fingerprint hash = new Fingerprint().add(seed).add(seaLevel).add(minY).add(maxY).add(enabled)
.add(density).add(prefetchRings).add(persist);
addClimate(hash);
addDrainage(hash);
addTiers(hash);
addPonds(hash);
@@ -477,6 +502,12 @@ public final class HydrologySettings {
return hash.value();
}
private void addClimate(Fingerprint hash) {
if (climate.enabled()) {
hash.add(true).add(PALETTE_JSON.toJson(climate.style())).add(climate.dryness()).add(climate.transition()).add(climate.dryRainfall());
}
}
private void addDrainage(Fingerprint hash) {
hash.add(drainage.fillEpsilon()).add(drainage.breachDepth()).add(drainage.wetnessThinning())
.add(drainage.minimumHeadKeep()).add(drainage.headRelief()).add(drainage.saturationCatchment());
@@ -535,6 +566,23 @@ public final class HydrologySettings {
public record IntRange(int min, int max) {
}
public record Climate(boolean enabled, IrisGeneratorStyle style, float dryness, float transition, float dryRainfall) {
public double wetness(double noise) {
if (!enabled || dryness <= 0f) {
return 1D;
}
double half = 0.5D * transition;
double share;
if (half <= 0D) {
share = noise < dryness ? 0D : 1D;
} else {
double t = Math.clamp((noise - dryness + half) / transition, 0D, 1D);
share = t * t * (3D - 2D * t);
}
return dryRainfall + (1D - dryRainfall) * share;
}
}
public record Drainage(float fillEpsilon, int breachDepth, boolean wetnessThinning, float minimumHeadKeep, float headRelief,
float saturationCatchment) {
}
@@ -6,6 +6,7 @@ final class BedProfile {
private static final long SALT_BROAD = 0x42454442524f4144L;
private static final long SALT_DETAIL = 0x4245444445544149L;
private static final long SALT_TEXTURE = 0x4245445445585455L;
private static final long SALT_ROUGHNESS = 0x42414e4b524f5547L;
private BedProfile() {
}
@@ -18,6 +19,10 @@ final class BedProfile {
return 0.35D * noise(seed, SALT_TEXTURE, x, z, 2);
}
static double roughness(long seed, int x, int z) {
return noise(seed, SALT_ROUGHNESS, x, z, 4) - 0.5D;
}
static double position(double u, double variation) {
double bounded = Math.clamp(u, 0D, 1D);
return bounded + 0.8D * variation * bounded * (1D - bounded);
@@ -0,0 +1,8 @@
package art.arcane.iris.generation.hydrology.raster;
@FunctionalInterface
public interface ChannelFluids {
ChannelFluids TIER = (x, z) -> null;
String channelFluid(int x, int z);
}
@@ -8,17 +8,18 @@ import art.arcane.iris.generation.hydrology.water.HydrologyTier;
import java.util.List;
import java.util.Objects;
import java.util.function.IntBinaryOperator;
public final class ChunkRasterizer {
private static final int CHUNK = 16;
private static final int CANDIDATE_HALO = 48;
private final HydrologySettings settings;
private final ChannelFluids channelFluids;
private final int halo;
public ChunkRasterizer(HydrologySettings settings) {
public ChunkRasterizer(HydrologySettings settings, ChannelFluids channelFluids) {
this.settings = Objects.requireNonNull(settings, "settings");
this.channelFluids = Objects.requireNonNull(channelFluids, "channelFluids");
float widest = 0f;
for (HydrologyTier tier : settings.tiers()) {
widest = Math.max(widest, tier.maxHalfWidth());
@@ -33,13 +34,13 @@ public final class ChunkRasterizer {
chunkX * CHUNK + CHUNK - 1 + halo, chunkZ * CHUNK + CHUNK - 1 + halo);
}
public ChunkWaterRaster rasterize(int chunkX, int chunkZ, IntBinaryOperator naturalHeight, List<IndexedWindow> windows,
public ChunkWaterRaster rasterize(int chunkX, int chunkZ, NaturalHeights naturalHeight, List<IndexedWindow> windows,
List<RegionPlan> lakeRegionPlans) {
Objects.requireNonNull(naturalHeight, "naturalHeight");
ChunkFeatures features = ChunkFeatures.gather(settings, chunkX, chunkZ, halo, windows, lakeRegionPlans, lakeRegions(chunkX, chunkZ));
if (features.inert()) {
return ChunkWaterRaster.EMPTY;
}
return new RasterComposer(settings, features, chunkX, chunkZ).compose(naturalHeight);
return new RasterComposer(settings, features, channelFluids, chunkX, chunkZ).compose(naturalHeight);
}
}
@@ -0,0 +1,6 @@
package art.arcane.iris.generation.hydrology.raster;
@FunctionalInterface
public interface NaturalHeights {
double height(int x, int z);
}
@@ -2,7 +2,6 @@ package art.arcane.iris.generation.hydrology.raster;
import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.hydrology.grid.CellHash;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
@@ -11,7 +10,6 @@ import art.arcane.iris.generation.hydrology.water.Reach;
import art.arcane.iris.generation.hydrology.water.ReachStyle;
import java.util.Arrays;
import java.util.function.IntBinaryOperator;
final class RasterComposer {
private static final int CHUNK = 16;
@@ -22,12 +20,15 @@ final class RasterComposer {
private static final double MAX_CONE_SLOPE = 2D;
private static final double CONE_EXPONENT = 0.8D;
private static final double ROUNDING = 1e-6D;
private static final long SALT_BANK = 0x42414e4b4e5aL;
private static final int SLOPE_REACH = 2;
private static final int RAY_STEP = 4;
private final HydrologySettings settings;
private final ChunkFeatures features;
private final ChannelFluids channelFluids;
private final int originX;
private final int originZ;
private final double[] exact = new double[CELLS];
private final int[] natural = new int[CELLS];
private final int[] terrain = new int[CELLS];
private final int[] head = new int[CELLS];
@@ -41,11 +42,12 @@ final class RasterComposer {
private final HydrologyTier[] nearTier = new HydrologyTier[CELLS];
private final ReachCursor cursor = new ReachCursor();
private final int[] inletColumn = new int[2];
private IntBinaryOperator naturalHeight;
private NaturalHeights naturalHeight;
RasterComposer(HydrologySettings settings, ChunkFeatures features, int chunkX, int chunkZ) {
RasterComposer(HydrologySettings settings, ChunkFeatures features, ChannelFluids channelFluids, int chunkX, int chunkZ) {
this.settings = settings;
this.features = features;
this.channelFluids = channelFluids;
this.originX = chunkX * CHUNK - 1;
this.originZ = chunkZ * CHUNK - 1;
Arrays.fill(head, Integer.MIN_VALUE);
@@ -54,11 +56,12 @@ final class RasterComposer {
Arrays.fill(distance, Double.POSITIVE_INFINITY);
}
ChunkWaterRaster compose(IntBinaryOperator naturalHeight) {
ChunkWaterRaster compose(NaturalHeights naturalHeight) {
this.naturalHeight = naturalHeight;
for (int cell = 0; cell < CELLS; cell++) {
if (!corner(cell)) {
natural[cell] = naturalHeight.applyAsInt(originX + cell % GRID, originZ + cell / GRID);
exact[cell] = naturalHeight.height(originX + cell % GRID, originZ + cell / GRID);
natural[cell] = (int) Math.round(exact[cell]);
terrain[cell] = natural[cell];
}
}
@@ -107,7 +110,7 @@ final class RasterComposer {
return;
}
if (cursor.channel.reach != null) {
channel(cell, ground, variation, BedProfile.detail(settings.seed(), x, z));
channel(cell, x, z, ground, variation);
} else if (interior(cell)) {
dry(cell, x, z, ground, variation);
}
@@ -129,16 +132,17 @@ final class RasterComposer {
return Math.min(floor, bed(hit, Math.min(level, level(hit.reach.grade()[hit.point()])), ground, variation, detail));
}
private void channel(int cell, int ground, double variation, double detail) {
private void channel(int cell, int x, int z, int ground, double variation) {
ReachCursor.Choice hit = cursor.channel;
Reach reach = hit.reach;
int point = hit.point();
String area = channelFluids.channelFluid(x, z);
head[cell] = level(reach.grade()[point]);
terrain[cell] = bed(hit, head[cell], ground, variation, detail);
terrain[cell] = bed(hit, head[cell], ground, variation, BedProfile.detail(settings.seed(), x, z));
role[cell] = role(reach.style()[point]);
feature[cell] = reach.id();
tier[cell] = reach.tier();
fluid[cell] = reach.tier().fluid();
fluid[cell] = area != null ? area : reach.tier().fluid();
}
private static int bed(ReachCursor.Choice hit, int surface, int ground, double variation, double detail) {
@@ -162,7 +166,8 @@ final class RasterComposer {
u = BedProfile.position(u, -variation);
}
if (ground >= surface) {
cut = BankProfile.cut(bankTier.bankStyle(), surface, ground, u, coneSlope(cell) * u * bankTier.bankBand(), noise(x, z));
double cone = coneSlope(steepestToWater(x, z, bank, bankEdge)) * u * bankTier.bankBand();
cut = BankProfile.cut(bankTier.bankStyle(), surface, ground, u, cone, noise(x, z));
} else {
raise = BankProfile.levee(bankTier.bankStyle(), surface, ground, u, noise(x, z), settings.deformation().maxFill());
}
@@ -205,15 +210,47 @@ final class RasterComposer {
distance[cell] = best;
}
private double coneSlope(int cell) {
double slope = Math.max(Math.abs(natural[cell + 1] - natural[cell - 1]), Math.abs(natural[cell + GRID] - natural[cell - GRID])) / 2D;
private double coneSlope(double slope) {
HydrologySettings.Deformation deformation = settings.deformation();
return Math.min(MAX_CONE_SLOPE, deformation.bankSlope() + deformation.bankSteepFactor() * Math.pow(slope, CONE_EXPONENT));
}
private double steepestToWater(int x, int z, ReachCursor.Choice bank, double bankEdge) {
Reach reach = bank.reach;
int next = Math.min(bank.segment + 1, reach.xs().length - 1);
double centreX = reach.xs()[bank.segment] + (reach.xs()[next] - reach.xs()[bank.segment]) * bank.t;
double centreZ = reach.zs()[bank.segment] + (reach.zs()[next] - reach.zs()[bank.segment]) * bank.t;
double steepest = slopeAt(x, z);
double length = Math.hypot(centreX - x, centreZ - z);
if (length <= 0D) {
return steepest;
}
double towardX = (centreX - x) / length;
double towardZ = (centreZ - z) / length;
for (double edge = 0D; edge < bankEdge; edge += RAY_STEP) {
double back = bankEdge - edge;
steepest = Math.max(steepest, slopeAt((int) Math.floor(x + towardX * back + 0.5D), (int) Math.floor(z + towardZ * back + 0.5D)));
}
return steepest;
}
private double slopeAt(int x, int z) {
return Math.max(Math.abs(exactAt(x + SLOPE_REACH, z) - exactAt(x - SLOPE_REACH, z)),
Math.abs(exactAt(x, z + SLOPE_REACH) - exactAt(x, z - SLOPE_REACH))) / (2D * SLOPE_REACH);
}
private double exactAt(int x, int z) {
int gx = x - originX;
int gz = z - originZ;
if (gx >= 0 && gz >= 0 && gx < GRID && gz < GRID && !corner(gz * GRID + gx)) {
return exact[gz * GRID + gx];
}
return naturalHeight.height(x, z);
}
private double noise(int x, int z) {
float strength = settings.deformation().bankNoise();
return strength == 0f ? 0D : (CellHash.unit(CellHash.mix(settings.seed(), SALT_BANK, x, z)) - 0.5D) * strength;
return strength == 0f ? 0D : BedProfile.roughness(settings.seed(), x, z) * strength;
}
private static int taperCut(int level, int ground, double u) {
@@ -349,7 +386,7 @@ final class RasterComposer {
if (gx >= 0 && gz >= 0 && gx < GRID && gz < GRID && !corner(gz * GRID + gx)) {
return natural[gz * GRID + gx];
}
return naturalHeight.applyAsInt(x, z);
return (int) Math.round(naturalHeight.height(x, z));
}
private void nameShores() {
@@ -1680,7 +1680,11 @@ public class IrisComplex implements DataProvider {
/** The natural terrain height of a column, from the natural height stream only: never touches hydrology or its caches. */
public int naturalTrueHeight(int x, int z) {
return (int) Math.round(naturalHeightStream.getDouble(x, z));
return (int) Math.round(naturalHeight(x, z));
}
public double naturalHeight(int x, int z) {
return naturalHeightStream.getDouble(x, z);
}
/** The terrain slope of a column from the natural height stream only: never touches hydrology or its caches. */