mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 14:50:56 +00:00
WIP Seismic Integration
This commit is contained in:
+4
-4
@@ -5,20 +5,20 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.seismic.type.sampler.Sampler;
|
||||
|
||||
|
||||
public class BiomeNoiseConfigTemplate implements ObjectTemplate<BiomeNoiseProperties> {
|
||||
@Value("terrain.sampler")
|
||||
private @Meta NoiseSampler baseSampler;
|
||||
private @Meta Sampler baseSampler;
|
||||
|
||||
@Value("terrain.sampler-2d")
|
||||
@Default
|
||||
private @Meta NoiseSampler elevationSampler = NoiseSampler.zero();
|
||||
private @Meta Sampler elevationSampler = Sampler.zero();
|
||||
|
||||
@Value("carving.sampler")
|
||||
@Default
|
||||
private @Meta NoiseSampler carvingSampler = NoiseSampler.zero();
|
||||
private @Meta Sampler carvingSampler = Sampler.zero();
|
||||
|
||||
@Value("terrain.blend.distance")
|
||||
@Default
|
||||
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.config.noise;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.seismic.type.sampler.Sampler;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public record BiomeNoiseProperties(NoiseSampler base,
|
||||
NoiseSampler elevation,
|
||||
NoiseSampler carving,
|
||||
public record BiomeNoiseProperties(Sampler base,
|
||||
Sampler elevation,
|
||||
Sampler carving,
|
||||
int blendDistance,
|
||||
int blendStep,
|
||||
double blendWeight,
|
||||
|
||||
+3
-3
@@ -1,19 +1,19 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.config.noise;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.seismic.type.sampler.Sampler;
|
||||
|
||||
|
||||
public class ThreadLocalNoiseHolder {
|
||||
private final ThreadLocal<Holder> holder = ThreadLocal.withInitial(Holder::new);
|
||||
|
||||
public double getNoise(NoiseSampler sampler, int x, int y, int z, long seed) {
|
||||
public double getNoise(Sampler sampler, int x, int y, int z, long seed) {
|
||||
Holder holder = this.holder.get();
|
||||
|
||||
if(holder.init && holder.y == y && holder.z == z && holder.x == x && holder.seed == seed) {
|
||||
return holder.noise;
|
||||
}
|
||||
|
||||
double noise = sampler.noise(seed, x, y, z);
|
||||
double noise = sampler.getSample(seed, x, y, z);
|
||||
holder.noise = noise;
|
||||
holder.x = x;
|
||||
holder.y = y;
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.seismic.type.vector.Vector3;
|
||||
|
||||
|
||||
public enum SlantCalculationMethod {
|
||||
@@ -22,7 +22,7 @@ public enum SlantCalculationMethod {
|
||||
Vector3.Mutable normalApproximation = Vector3.Mutable.of(0, 0, 0);
|
||||
for(Vector3 point : DOT_PRODUCT_SAMPLE_POINTS) {
|
||||
var scalar = -sampler.sample(x + point.getX(), y + point.getY(), z + point.getZ());
|
||||
normalApproximation.add(point.mutable().multiply(scalar));
|
||||
normalApproximation.add(point.mutable().mulScalar(scalar));
|
||||
}
|
||||
return DOT_PRODUCT_DIRECTION.dot(normalApproximation.normalize());
|
||||
}
|
||||
|
||||
+2
-2
@@ -55,12 +55,12 @@ public class ElevationInterpolator {
|
||||
}
|
||||
|
||||
if(same) {
|
||||
values[x + 1][z + 1] = center.elevation().noise(seed, xOrigin + x, zOrigin + z); // no weighting needed!
|
||||
values[x + 1][z + 1] = center.elevation().getSample(seed, xOrigin + x, zOrigin + z); // no weighting needed!
|
||||
} else {
|
||||
for(int xi = -smooth; xi <= smooth; xi++) {
|
||||
for(int zi = -smooth; zi <= smooth; zi++) {
|
||||
BiomeNoiseProperties gen = gens[x + 1 + smooth + xi][z + 1 + smooth + zi];
|
||||
noise += gen.elevation().noise(seed, xOrigin + x, zOrigin + z) * gen.elevationWeight();
|
||||
noise += gen.elevation().getSample(seed, xOrigin + x, zOrigin + z) * gen.elevationWeight();
|
||||
div += gen.elevationWeight();
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -7,7 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
import com.dfsek.seismic.math.numericanalysis.interpolation.InterpolationFunctions;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,6 +32,7 @@ public class Interpolator {
|
||||
this.v3 = v3;
|
||||
}
|
||||
|
||||
//TODO this system is not very good, replace it wholesale
|
||||
/**
|
||||
* 2D Bilinear interpolation between 4 points on a unit square.
|
||||
*
|
||||
@@ -40,8 +42,8 @@ public class Interpolator {
|
||||
* @return double - The interpolated value.
|
||||
*/
|
||||
public double bilerp(double s, double t) {
|
||||
double v01 = MathUtil.lerp(s, v0, v1);
|
||||
double v23 = MathUtil.lerp(s, v2, v3);
|
||||
return MathUtil.lerp(t, v01, v23);
|
||||
double v01 = InterpolationFunctions.lerp(v0, v1, s);
|
||||
double v23 = InterpolationFunctions.lerp(v2, v3, s);
|
||||
return InterpolationFunctions.lerp(v01, v23, t);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -7,7 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
import com.dfsek.seismic.math.numericanalysis.interpolation.InterpolationFunctions;
|
||||
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,8 @@ public class Interpolator3 {
|
||||
this.bottom = new Interpolator(_100, _110, _101, _111);
|
||||
}
|
||||
|
||||
//TODO this system is not very good, replace it wholesale
|
||||
public double trilerp(double x, double y, double z) {
|
||||
return MathUtil.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z));
|
||||
return InterpolationFunctions.lerp(top.bilerp(y, z), bottom.bilerp(y, z), x);
|
||||
}
|
||||
}
|
||||
+10
-9
@@ -1,8 +1,9 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import com.dfsek.seismic.math.numericanalysis.interpolation.InterpolationFunctions;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
@@ -56,7 +57,7 @@ public class LazilyEvaluatedInterpolator {
|
||||
.getContext()
|
||||
.get(noisePropertiesKey)
|
||||
.carving()
|
||||
.noise(seed, xi, y, zi);
|
||||
.getSample(seed, xi, y, zi);
|
||||
samples[index] = sample;
|
||||
}
|
||||
return sample;
|
||||
@@ -81,10 +82,10 @@ public class LazilyEvaluatedInterpolator {
|
||||
|
||||
double xFrac = (double) (x % horizontalRes) / horizontalRes;
|
||||
double zFrac = (double) (z % horizontalRes) / horizontalRes;
|
||||
double lerp_bottom_0 = MathUtil.lerp(zFrac, sample_0_0_0, sample_0_0_1);
|
||||
double lerp_bottom_1 = MathUtil.lerp(zFrac, sample_1_0_0, sample_1_0_1);
|
||||
double lerp_bottom_0 = InterpolationFunctions.lerp(sample_0_0_0, sample_0_0_1, zFrac);
|
||||
double lerp_bottom_1 = InterpolationFunctions.lerp(sample_1_0_0, sample_1_0_1, zFrac);
|
||||
|
||||
double lerp_bottom = MathUtil.lerp(xFrac, lerp_bottom_0, lerp_bottom_1);
|
||||
double lerp_bottom = InterpolationFunctions.lerp(lerp_bottom_0, lerp_bottom_1, xFrac);
|
||||
|
||||
if(yRange) { // we can do bilerp
|
||||
return lerp_bottom;
|
||||
@@ -100,11 +101,11 @@ public class LazilyEvaluatedInterpolator {
|
||||
double sample_1_1_0 = sample(xIndex + 1, yIndex + 1, zIndex, x + horizontalRes, y + verticalRes, z);
|
||||
double sample_1_1_1 = sample(xIndex + 1, yIndex + 1, zIndex + 1, x + horizontalRes, y + verticalRes, z + horizontalRes);
|
||||
|
||||
double lerp_top_0 = MathUtil.lerp(zFrac, sample_0_1_0, sample_0_1_1);
|
||||
double lerp_top_1 = MathUtil.lerp(zFrac, sample_1_1_0, sample_1_1_1);
|
||||
double lerp_top_0 = InterpolationFunctions.lerp(sample_0_1_0, sample_0_1_1, zFrac);
|
||||
double lerp_top_1 = InterpolationFunctions.lerp(sample_1_1_0, sample_1_1_1, zFrac);
|
||||
|
||||
double lerp_top = MathUtil.lerp(xFrac, lerp_top_0, lerp_top_1);
|
||||
double lerp_top = InterpolationFunctions.lerp(lerp_top_0, lerp_top_1, xFrac);
|
||||
|
||||
return MathUtil.lerp(yFrac, lerp_bottom, lerp_top);
|
||||
return InterpolationFunctions.lerp(lerp_bottom, lerp_top, yFrac);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user