mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
Merge branch 'ver/6.6.0' into dev/7.0-2
This commit is contained in:
@@ -12,4 +12,14 @@ public class AdditionSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return left + right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operated(double[] left, double[] right) {
|
||||
int dimensions = left.length;
|
||||
double[] out = new double[dimensions];
|
||||
for(int i = 0; i < dimensions; i++) {
|
||||
out[i] = left[i] + right[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.arithmetic;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public abstract class BinaryArithmeticSampler implements NoiseSampler {
|
||||
public abstract class BinaryArithmeticSampler implements DerivativeNoiseSampler {
|
||||
private final NoiseSampler left;
|
||||
private final NoiseSampler right;
|
||||
|
||||
@@ -12,6 +13,11 @@ public abstract class BinaryArithmeticSampler implements NoiseSampler {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return DerivativeNoiseSampler.isDifferentiable(left) && DerivativeNoiseSampler.isDifferentiable(right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
return operate(left.noise(seed, x, y), right.noise(seed, x, y));
|
||||
@@ -22,5 +28,17 @@ public abstract class BinaryArithmeticSampler implements NoiseSampler {
|
||||
return operate(left.noise(seed, x, y, z), right.noise(seed, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y) {
|
||||
return operated(((DerivativeNoiseSampler)left).noised(seed, x, y), ((DerivativeNoiseSampler)right).noised(seed, x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y, double z) {
|
||||
return operated(((DerivativeNoiseSampler)left).noised(seed, x, y, z), ((DerivativeNoiseSampler)right).noised(seed, x, y, z));
|
||||
}
|
||||
|
||||
public abstract double operate(double left, double right);
|
||||
|
||||
public abstract double[] operated(double[] left, double[] right);
|
||||
}
|
||||
|
||||
@@ -12,4 +12,15 @@ public class DivisionSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return left / right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operated(double[] left, double[] right) {
|
||||
int dimensions = left.length;
|
||||
double[] out = new double[dimensions];
|
||||
out[0] = left[0] / right[0];
|
||||
for(int i = 1; i < dimensions; i++) {
|
||||
out[i] = (left[i] * right[0] - left[0] * right[i]) / (right[0] * right[0]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,11 @@ public class MaxSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return Math.max(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operated(double[] left, double[] right) {
|
||||
double leftValue = left[0];
|
||||
double rightValue = right[0];
|
||||
return leftValue > rightValue ? left : right;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,11 @@ public class MinSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return Math.min(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operated(double[] left, double[] right) {
|
||||
double leftValue = left[0];
|
||||
double rightValue = right[0];
|
||||
return leftValue < rightValue ? left : right;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,15 @@ public class MultiplicationSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return left * right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operated(double[] left, double[] right) {
|
||||
int dimensions = left.length;
|
||||
double[] out = new double[dimensions];
|
||||
out[0] = left[0] * right[0];
|
||||
for(int i = 1; i < dimensions; i++) {
|
||||
out[i] = left[i] * right[0] + left[0] * right[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,14 @@ public class SubtractionSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return left - right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operated(double[] left, double[] right) {
|
||||
int dimensions = left.length;
|
||||
double[] out = new double[dimensions];
|
||||
for(int i = 0; i < dimensions; i++) {
|
||||
out[i] = left[i] - right[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
@@ -52,4 +53,60 @@ public class BrownianMotionSampler extends FractalNoiseFunction {
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return DerivativeNoiseSampler.isDifferentiable(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y) {
|
||||
double[] sum = {0, 0, 0};
|
||||
double amp = fractalBounding;
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
// This should only be called after `input` is verified as a `DerivativeNoiseSampler`
|
||||
// so this should be a safe cast
|
||||
double[] noise = ((DerivativeNoiseSampler) input).noised(seed++, x, y);
|
||||
sum[0] += noise[0] * amp;
|
||||
|
||||
// Directional derivative of each octave can be subject to the same addition and product
|
||||
// as per derivative sum and product rules in order to produce the correct final derivative
|
||||
sum[1] += noise[1] * amp;
|
||||
sum[2] += noise[2] * amp;
|
||||
|
||||
amp *= MathUtil.lerp(weightedStrength, 1.0, Math.min(noise[0] + 1, 2) * 0.5);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
amp *= gain;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y, double z) {
|
||||
double[] sum = {0, 0, 0, 0};
|
||||
double amp = fractalBounding;
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double[] noise = ((DerivativeNoiseSampler) input).noised(seed++, x, y, z);
|
||||
sum[0] += noise[0] * amp;
|
||||
|
||||
// See comment in 2D version
|
||||
sum[1] += noise[1] * amp;
|
||||
sum[2] += noise[2] * amp;
|
||||
sum[3] += noise[3] * amp;
|
||||
|
||||
amp *= MathUtil.lerp(weightedStrength, 1.0, (noise[0] + 1) * 0.5);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
z *= lacunarity;
|
||||
amp *= gain;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.NoiseFunction;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.DerivativeNoiseFunction;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public abstract class FractalNoiseFunction extends NoiseFunction {
|
||||
public abstract class FractalNoiseFunction extends DerivativeNoiseFunction {
|
||||
protected final NoiseSampler input;
|
||||
protected double fractalBounding = 1 / 1.75;
|
||||
protected int octaves = 3;
|
||||
@@ -52,4 +52,19 @@ public abstract class FractalNoiseFunction extends NoiseFunction {
|
||||
public void setWeightedStrength(double weightedStrength) {
|
||||
this.weightedStrength = weightedStrength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y) {
|
||||
throw new UnsupportedOperationException("Implementation failed to check or set isDifferentiable correctly");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y, double z) {
|
||||
throw new UnsupportedOperationException("Implementation failed to check or set isDifferentiable correctly");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,12 +116,12 @@ public abstract class SimplexStyleSampler extends DerivativeNoiseFunction {
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y) {
|
||||
return new double[]{ 0, 0, 0 };
|
||||
throw new UnsupportedOperationException("Implementation failed to check or set isDifferentiable correctly");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y, double z) {
|
||||
return new double[]{ 0, 0, 0, 0 };
|
||||
throw new UnsupportedOperationException("Implementation failed to check or set isDifferentiable correctly");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,10 +6,7 @@ package com.dfsek.terra.api.noise;
|
||||
public interface DerivativeNoiseSampler extends NoiseSampler {
|
||||
|
||||
static boolean isDifferentiable(NoiseSampler sampler) {
|
||||
if(sampler instanceof DerivativeNoiseSampler dSampler) {
|
||||
return dSampler.isDifferentiable();
|
||||
}
|
||||
return false;
|
||||
return sampler instanceof DerivativeNoiseSampler dSampler && dSampler.isDifferentiable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user