mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-08 16:56:25 +00:00
Auto stash before revert of "Improve finding by allowing minimal distance & randomization"
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.noise;
|
||||
|
||||
import com.volmit.iris.engine.object.NoiseStyle;
|
||||
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
|
||||
public class BiasedCellularNoise implements NoiseGenerator {
|
||||
private final FastNoise n;
|
||||
private final ProceduralStream<Double> biasShape;
|
||||
|
||||
public BiasedCellularNoise(long seed, ProceduralStream<Double> biasShape) {
|
||||
this.biasShape = biasShape.subtract(0.5).multiply(2);
|
||||
this.n = new FastNoise(new RNG(seed).imax());
|
||||
n.SetNoiseType(FastNoise.NoiseType.Cellular);
|
||||
n.SetCellularReturnType(FastNoise.CellularReturnType.CellValue);
|
||||
n.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return (n.GetCellular((float) x, (float) 0, biasShape) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return (n.GetCellular((float) x, (float) z, biasShape) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return (n.GetCellular((float) x, (float) y, biasShape) / 2D) + 0.5D;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.util.noise;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.IRare;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.NoiseInjector;
|
||||
@@ -102,6 +103,34 @@ public class CNG {
|
||||
}
|
||||
}
|
||||
|
||||
public CNG cellularize(RNG seed, double freq)
|
||||
{
|
||||
FastNoise cellularFilter = new FastNoise(seed.imax());
|
||||
cellularFilter.SetNoiseType(FastNoise.NoiseType.Cellular);
|
||||
cellularFilter.SetCellularReturnType(FastNoise.CellularReturnType.CellValue);
|
||||
cellularFilter.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Manhattan);
|
||||
cellularFilter.SetFrequency((float) freq * 0.01f);
|
||||
|
||||
ProceduralStream<Double> str = stream();
|
||||
|
||||
return new CNG(seed, new NoiseGenerator() {
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return noise(x, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return (cellularFilter.GetCellular((float)x, (float)z, str, 1) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, y + z);
|
||||
}
|
||||
}, 1D, 1);
|
||||
}
|
||||
|
||||
public static CNG signature(RNG rng) {
|
||||
return signature(rng, NoiseType.SIMPLEX);
|
||||
}
|
||||
|
||||
@@ -1729,7 +1729,7 @@ public class FastNoise {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public float GetCellular(float x, float y, ProceduralStream<Double> sourceNoise) {
|
||||
public float GetCellular(float x, float y, ProceduralStream<Double> sourceNoise, double iscale) {
|
||||
x *= m_frequency;
|
||||
y *= m_frequency;
|
||||
|
||||
@@ -1737,7 +1737,7 @@ public class FastNoise {
|
||||
case CellValue:
|
||||
case NoiseLookup:
|
||||
case Distance:
|
||||
return SingleCellular(x, y, sourceNoise);
|
||||
return SingleCellular(x, y, sourceNoise, iscale);
|
||||
default:
|
||||
return SingleCellular2Edge(x, y);
|
||||
}
|
||||
@@ -1837,7 +1837,7 @@ public class FastNoise {
|
||||
}
|
||||
}
|
||||
|
||||
private float SingleCellular(float x, float y, ProceduralStream<Double> sourceNoise) {
|
||||
private float SingleCellular(float x, float y, ProceduralStream<Double> sourceNoise, double iscale) {
|
||||
int xr = FastRound(x);
|
||||
int yr = FastRound(y);
|
||||
|
||||
@@ -1904,7 +1904,7 @@ public class FastNoise {
|
||||
|
||||
switch (m_cellularReturnType) {
|
||||
case CellValue:
|
||||
return sourceNoise.get(xc, yc).floatValue();
|
||||
return sourceNoise.get(xc * iscale, yc * iscale).floatValue();
|
||||
|
||||
case NoiseLookup:
|
||||
Float2 vec = CELL_2D[Hash2D(m_seed, xc, yc) & 255];
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
|
||||
package com.volmit.iris.util.noise;
|
||||
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||
|
||||
public interface NoiseGenerator {
|
||||
double noise(double x);
|
||||
|
||||
@@ -32,4 +35,9 @@ public interface NoiseGenerator {
|
||||
default boolean isNoScale() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default ProceduralStream<Double> stream()
|
||||
{
|
||||
return ProceduralStream.of(this::noise, this::noise, Interpolated.DOUBLE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user