mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 23:47:21 +00:00
add offset to all noise types to prevent common value between seeds
This commit is contained in:
parent
5705caa1ba
commit
4387aa814b
@ -39,4 +39,8 @@ public interface NoiseGenerator {
|
||||
default ProceduralStream<Double> stream() {
|
||||
return ProceduralStream.of(this::noise, this::noise, Interpolated.DOUBLE);
|
||||
}
|
||||
|
||||
default OffsetNoiseGenerator offset(long seed) {
|
||||
return new OffsetNoiseGenerator(this, seed);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,9 @@
|
||||
|
||||
package com.volmit.iris.util.noise;
|
||||
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public enum NoiseType {
|
||||
WHITE(WhiteNoise::new),
|
||||
@ -77,6 +79,24 @@ public enum NoiseType {
|
||||
}
|
||||
|
||||
public NoiseGenerator create(long seed) {
|
||||
return f.create(seed);
|
||||
return f.create(seed).offset(seed);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
long[] seeds = new long[10000];
|
||||
for (int i = 0; i < seeds.length; i++) {
|
||||
seeds[i] = RNG.r.lmax();
|
||||
}
|
||||
|
||||
for (NoiseType t : NoiseType.values()) {
|
||||
KSet<Double> set = new KSet<>();
|
||||
for (long seed : seeds) {
|
||||
set.add(t.create(seed).noise(0, 0));
|
||||
}
|
||||
|
||||
if (set.size() == 1) {
|
||||
System.out.println(t + " " + set);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.volmit.iris.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class OffsetNoiseGenerator implements NoiseGenerator {
|
||||
private final NoiseGenerator base;
|
||||
private final double ox, oz;
|
||||
|
||||
public OffsetNoiseGenerator(NoiseGenerator base, long seed) {
|
||||
this.base = base;
|
||||
RNG rng = new RNG(seed);
|
||||
ox = rng.nextDouble(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
oz = rng.nextDouble(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return base.noise(x + ox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return base.noise(x + ox, z + oz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return base.noise(x + ox, y, z + oz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNoScale() {
|
||||
return base.isNoScale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatic() {
|
||||
return base.isStatic();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NoiseGenerator getBase() {
|
||||
return base;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user