Calculate derivative for slant palettes

This commit is contained in:
dfsek
2020-11-29 00:01:21 -07:00
parent 6eb5c0e0ec
commit 67ff426894
5 changed files with 57 additions and 35 deletions

View File

@@ -165,6 +165,7 @@ public class ConfigPack {
biomeTemplates.forEach(biome -> {
biomeRegistry.add(biome.getID(), biomeFactory.build(biome));
Debug.info("Loaded biome " + biome.getID());
Debug.info("Threshold: " + biome.getSlantThreshold());
});
List<BiomeGridTemplate> biomeGridTemplates = new ArrayList<>();

View File

@@ -65,14 +65,7 @@ public class BiomeTemplate implements ConfigTemplate {
@Abstractable
@Default
private Palette<BlockData> oceanPalette = new SinglePalette<>(Material.WATER.createBlockData());
@Value("slant.y-offset.top")
@Abstractable
@Default
private double slantOffsetTop = 0.5D;
@Value("slant.y-offset-bottom")
@Abstractable
@Default
private double slantOffsetBottom = 0.25;
@Value("elevation.equation")
@Default
@Abstractable
@@ -103,6 +96,15 @@ public class BiomeTemplate implements ConfigTemplate {
@Default
private Map<Material, Palette<BlockData>> stairPalettes;
@Value("slant.threshold")
@Abstractable
@Default
private double slantThreshold = 0.1;
public double getSlantThreshold() {
return slantThreshold;
}
public double getSlabThreshold() {
return slabThreshold;
}
@@ -178,12 +180,4 @@ public class BiomeTemplate implements ConfigTemplate {
public Map<Ore, OreConfig> getOres() {
return ores;
}
public double getSlantOffsetTop() {
return slantOffsetTop;
}
public double getSlantOffsetBottom() {
return slantOffsetBottom;
}
}

View File

@@ -0,0 +1,18 @@
package com.dfsek.terra.generation;
import net.jafama.FastMath;
import org.polydev.gaea.math.ChunkInterpolator;
public class Sampler {
private final ChunkInterpolator interpolator;
private final ElevationInterpolator elevationInterpolator;
public Sampler(ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) {
this.interpolator = interpolator;
this.elevationInterpolator = elevationInterpolator;
}
public double sample(double x, double y, double z) {
return interpolator.getNoise(x, y - elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z)), z);
}
}

View File

@@ -9,6 +9,7 @@ import com.dfsek.terra.biome.palette.PaletteHolder;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.math.MathUtil;
import com.dfsek.terra.population.CavePopulator;
import com.dfsek.terra.population.FloraPopulator;
import com.dfsek.terra.population.OrePopulator;
@@ -78,22 +79,10 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
}
private static Palette<BlockData> getPalette(int x, int y, int z, BiomeTemplate c, ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) {
private static Palette<BlockData> getPalette(int x, int y, int z, BiomeTemplate c, Sampler sampler) {
PaletteHolder slant = c.getSlantPalette();
if(slant != null) {
double ySlantOffsetTop = c.getSlantOffsetTop();
double ySlantOffsetBottom = c.getSlantOffsetBottom();
boolean top = interpolator.getNoise(x, y + ySlantOffsetTop - elevationInterpolator.getElevation(x, z), z) > 0;
boolean bottom = interpolator.getNoise(x, y - ySlantOffsetBottom - elevationInterpolator.getElevation(x, z), z) > 0;
if(top && bottom) {
boolean north = interpolator.getNoise(x, y - elevationInterpolator.getElevation(x, z + 1), z + 1) > 0;
boolean south = interpolator.getNoise(x, y - elevationInterpolator.getElevation(x, z - 1), z - 1) > 0;
boolean east = interpolator.getNoise(x + 1, y - elevationInterpolator.getElevation(x + 1, z), z) > 0;
boolean west = interpolator.getNoise(x - 1, y - elevationInterpolator.getElevation(x - 1, z), z) > 0;
if((north || south || east || west) && (!(north && south && east && west))) return slant.getPalette(y);
}
if(slant != null && MathUtil.derivative(sampler, x, y, z) > c.getSlantThreshold()) {
return slant.getPalette(y);
}
return c.getPalette().getPalette(y);
}
@@ -157,6 +146,8 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
elevationInterpolator = new ElevationInterpolator(chunkX, chunkZ, tw.getGrid());
}
Sampler sampler = new Sampler(interpolator, elevationInterpolator);
for(byte x = 0; x < 16; x++) {
for(byte z = 0; z < 16; z++) {
int paletteLevel = 0;
@@ -167,13 +158,11 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
Biome b = grid.getBiome(xOrig + x, zOrig + z, GenerationPhase.PALETTE_APPLY);
BiomeTemplate c = ((UserDefinedBiome) b).getConfig();
double elevate = elevationInterpolator.getElevation(x, z);
int sea = c.getSeaLevel();
Palette<BlockData> seaPalette = c.getOceanPalette();
for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
if(interpolator.getNoise(x, y - elevate, z) > 0) {
BlockData data = getPalette(x, y, z, c, interpolator, elevationInterpolator).get(paletteLevel, cx, cz);
if(sampler.sample(x, y, z) > 0) {
BlockData data = getPalette(x, y, z, c, sampler).get(paletteLevel, cx, cz);
chunk.setBlock(x, y, z, data);
if(paletteLevel == 0 && c.doSlabs() && y < 255) {
prepareBlockPart(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector(x, y + 1, z), c.getSlabPalettes(),

View File

@@ -0,0 +1,20 @@
package com.dfsek.terra.math;
import com.dfsek.terra.generation.Sampler;
public final class MathUtil {
private static final double CONST = 1;
public static double derivative(Sampler sampler, double x, double y, double z) {
double baseSample = sampler.sample(x, y, z);
double xVal1 = (sampler.sample(x + CONST, y, z) - baseSample) / CONST;
double xVal2 = (sampler.sample(x - CONST, y, z) - baseSample) / CONST;
double zVal1 = (sampler.sample(x, y, z + CONST) - baseSample) / CONST;
double zVal2 = (sampler.sample(x, y, z - CONST) - baseSample) / CONST;
double yVal1 = (sampler.sample(x, y + CONST, z) - baseSample) / CONST;
double yVal2 = (sampler.sample(x, y - CONST, z) - baseSample) / CONST;
return Math.sqrt(((xVal2 - xVal1) * (xVal2 - xVal1)) + ((zVal2 - zVal1) * (zVal2 - zVal1)) + ((yVal2 - yVal1) * (yVal2 - yVal1)));
}
}