Auto stash before revert of "Improve finding by allowing minimal distance & randomization"

This commit is contained in:
cyberpwn 2021-11-12 21:50:27 -05:00
parent 434e7f75fa
commit d7ad947cbb
6 changed files with 63 additions and 74 deletions

View File

@ -47,6 +47,13 @@ public class IrisGeneratorStyle {
private final transient AtomicCache<CNG> cng = new AtomicCache<>(); private final transient AtomicCache<CNG> cng = new AtomicCache<>();
@Desc("The chance is 1 in CHANCE per interval") @Desc("The chance is 1 in CHANCE per interval")
private NoiseStyle style = NoiseStyle.FLAT; private NoiseStyle style = NoiseStyle.FLAT;
@Desc("If set above 0, this style will be cellularized")
private double cellularFrequency = 0;
@Desc("Cell zooms")
private double cellularZoom = 1;
@MinNumber(0.00001) @MinNumber(0.00001)
@Desc("The zoom of this style") @Desc("The zoom of this style")
private double zoom = 1; private double zoom = 1;
@ -89,6 +96,11 @@ public class IrisGeneratorStyle {
cng.fractureWith(fracture.create(rng.nextParallelRNG(2934), data), fracture.getMultiplier()); cng.fractureWith(fracture.create(rng.nextParallelRNG(2934), data), fracture.getMultiplier());
} }
if(cellularFrequency > 0)
{
return cng.cellularize(rng.nextParallelRNG(884466), cellularFrequency).scale(1D/cellularZoom).bake();
}
return cng; return cng;
} }
} }
@ -102,6 +114,11 @@ public class IrisGeneratorStyle {
cng.fractureWith(fracture.create(rng.nextParallelRNG(2934), data), fracture.getMultiplier()); cng.fractureWith(fracture.create(rng.nextParallelRNG(2934), data), fracture.getMultiplier());
} }
if(cellularFrequency > 0)
{
return cng.cellularize(rng.nextParallelRNG(884466), cellularFrequency).scale(1D/cellularZoom).bake();
}
return cng; return cng;
} }
@ -112,6 +129,11 @@ public class IrisGeneratorStyle {
cng.fractureWith(fracture.create(rng.nextParallelRNG(2934), data), fracture.getMultiplier()); cng.fractureWith(fracture.create(rng.nextParallelRNG(2934), data), fracture.getMultiplier());
} }
if(cellularFrequency > 0)
{
return cng.cellularize(rng.nextParallelRNG(884466), cellularFrequency).scale(1D/cellularZoom).bake();
}
return cng; return cng;
} }

View File

@ -20,7 +20,6 @@ package com.volmit.iris.engine.object;
import com.volmit.iris.engine.object.annotations.Desc; import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.noise.BiasedCellularNoise;
import com.volmit.iris.util.noise.CNG; import com.volmit.iris.util.noise.CNG;
import com.volmit.iris.util.noise.CNGFactory; import com.volmit.iris.util.noise.CNGFactory;
import com.volmit.iris.util.noise.NoiseType; import com.volmit.iris.util.noise.NoiseType;
@ -447,23 +446,6 @@ public enum NoiseStyle {
@Desc("Vascular noise gets higher as the position nears a cell border. Cells are distorted using Iris styled wispy noise.") @Desc("Vascular noise gets higher as the position nears a cell border. Cells are distorted using Iris styled wispy noise.")
VASCULAR_IRIS_HALF(rng -> CNG.signatureHalf(rng, NoiseType.VASCULAR)), VASCULAR_IRIS_HALF(rng -> CNG.signatureHalf(rng, NoiseType.VASCULAR)),
@Desc("White Noise is like static. Useful for block scattering but not terrain.")
SIMPLEX_BIASED_CELLULAR(rng -> new CNG(rng, new BiasedCellularNoise(rng.lmax(),
SIMPLEX.stream(rng.nextParallelRNG(-23333666)).zoom(0.158)), 1D, 1)),
@Desc("White Noise is like static. Useful for block scattering but not terrain.")
NOWHERE_BIASED_CELLULAR(rng -> new CNG(rng, new BiasedCellularNoise(rng.lmax(),
NOWHERE.stream(rng.nextParallelRNG(-23333666)).zoom(0.158)), 1D, 1)),
@Desc("White Noise is like static. Useful for block scattering but not terrain.")
IRIS_BIASED_CELLULAR(rng -> new CNG(rng, new BiasedCellularNoise(rng.lmax(),
IRIS.stream(rng.nextParallelRNG(-23333666)).zoom(0.158)), 1D, 1)),
@Desc("White Noise is like static. Useful for block scattering but not terrain.")
VASCULAR_BIASED_CELLULAR(rng -> new CNG(rng, new BiasedCellularNoise(rng.lmax(),
VASCULAR.stream(rng.nextParallelRNG(-23333666)).zoom(0.158)), 1D, 1)),
; ;
private final CNGFactory f; private final CNGFactory f;

View File

@ -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;
}
}

View File

@ -19,6 +19,7 @@
package com.volmit.iris.util.noise; package com.volmit.iris.util.noise;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.object.IRare; import com.volmit.iris.engine.object.IRare;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.function.NoiseInjector; 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) { public static CNG signature(RNG rng) {
return signature(rng, NoiseType.SIMPLEX); return signature(rng, NoiseType.SIMPLEX);
} }

View File

@ -1729,7 +1729,7 @@ public class FastNoise {
return 0; 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; x *= m_frequency;
y *= m_frequency; y *= m_frequency;
@ -1737,7 +1737,7 @@ public class FastNoise {
case CellValue: case CellValue:
case NoiseLookup: case NoiseLookup:
case Distance: case Distance:
return SingleCellular(x, y, sourceNoise); return SingleCellular(x, y, sourceNoise, iscale);
default: default:
return SingleCellular2Edge(x, y); 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 xr = FastRound(x);
int yr = FastRound(y); int yr = FastRound(y);
@ -1904,7 +1904,7 @@ public class FastNoise {
switch (m_cellularReturnType) { switch (m_cellularReturnType) {
case CellValue: case CellValue:
return sourceNoise.get(xc, yc).floatValue(); return sourceNoise.get(xc * iscale, yc * iscale).floatValue();
case NoiseLookup: case NoiseLookup:
Float2 vec = CELL_2D[Hash2D(m_seed, xc, yc) & 255]; Float2 vec = CELL_2D[Hash2D(m_seed, xc, yc) & 255];

View File

@ -18,6 +18,9 @@
package com.volmit.iris.util.noise; package com.volmit.iris.util.noise;
import com.volmit.iris.util.stream.ProceduralStream;
import com.volmit.iris.util.stream.interpolation.Interpolated;
public interface NoiseGenerator { public interface NoiseGenerator {
double noise(double x); double noise(double x);
@ -32,4 +35,9 @@ public interface NoiseGenerator {
default boolean isNoScale() { default boolean isNoScale() {
return false; return false;
} }
default ProceduralStream<Double> stream()
{
return ProceduralStream.of(this::noise, this::noise, Interpolated.DOUBLE);
}
} }