mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-01-03 14:22:30 +00:00
Noise
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
/**
|
||||
* Base class for all noise generators
|
||||
*/
|
||||
public abstract class NoiseGenerator
|
||||
public abstract class BaseNoiseGenerator
|
||||
{
|
||||
protected final int perm[] = new int[512];
|
||||
protected double offsetX;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.Random;
|
||||
* @see SimplexNoiseC "Improved" and faster version with slighly
|
||||
* different results
|
||||
*/
|
||||
public class BasePerlinNoiseGenerator extends NoiseGenerator
|
||||
public class BasePerlinNoiseGenerator extends BaseNoiseGenerator
|
||||
{
|
||||
protected static final int grad3[][] = {{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}};
|
||||
private static final BasePerlinNoiseGenerator instance = new BasePerlinNoiseGenerator();
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
import com.volmit.iris.util.IrisInterpolation;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.NoiseInjector;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
public class CNG
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
import com.volmit.iris.util.FastNoise.CellularDistanceFunction;
|
||||
import com.volmit.iris.util.FastNoise.CellularReturnType;
|
||||
import com.volmit.iris.util.FastNoise.NoiseType;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -29,13 +27,13 @@ public class CellGenerator
|
||||
RNG rx = rng.nextParallelRNG(8735652);
|
||||
int s = rx.nextInt();
|
||||
fn = new FastNoise(s);
|
||||
fn.SetNoiseType(NoiseType.Cellular);
|
||||
fn.SetCellularReturnType(CellularReturnType.CellValue);
|
||||
fn.SetCellularDistanceFunction(CellularDistanceFunction.Natural);
|
||||
fn.SetNoiseType(FastNoise.NoiseType.Cellular);
|
||||
fn.SetCellularReturnType(FastNoise.CellularReturnType.CellValue);
|
||||
fn.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
|
||||
fd = new FastNoise(s);
|
||||
fd.SetNoiseType(NoiseType.Cellular);
|
||||
fd.SetCellularReturnType(CellularReturnType.Distance2Sub);
|
||||
fd.SetCellularDistanceFunction(CellularDistanceFunction.Natural);
|
||||
fd.SetNoiseType(FastNoise.NoiseType.Cellular);
|
||||
fd.SetCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
|
||||
fd.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
public float getDistance(double x, double z)
|
||||
|
||||
31
src/main/java/com/volmit/iris/noise/CellHeightNoise.java
Normal file
31
src/main/java/com/volmit/iris/noise/CellHeightNoise.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
public class CellHeightNoise implements NoiseGenerator {
|
||||
private final FastNoise n;
|
||||
|
||||
public CellHeightNoise(long seed) {
|
||||
this.n = new FastNoise((int) seed);
|
||||
n.SetNoiseType(FastNoise.NoiseType.Cellular);
|
||||
n.SetCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
|
||||
n.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
private double filter(double noise) {
|
||||
return (noise / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return filter(n.GetCellular((float) x, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return filter(n.GetCellular((float) x, (float) z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return filter(n.GetCellular((float) x, (float) y, (float) z));
|
||||
}
|
||||
}
|
||||
27
src/main/java/com/volmit/iris/noise/CellularNoise.java
Normal file
27
src/main/java/com/volmit/iris/noise/CellularNoise.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
public class CellularNoise implements NoiseGenerator {
|
||||
private final FastNoise n;
|
||||
|
||||
public CellularNoise(long seed) {
|
||||
this.n = new FastNoise((int) seed);
|
||||
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, 0) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return (n.GetCellular((float) x, (float) z) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return (n.GetCellular((float) x, (float) y, (float) z) / 2D) + 0.5D;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
// The developer's email is jorzixdan.me2@gzixmail.com (for great email, take
|
||||
// off every 'zix'.)
|
||||
//
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
import javax.vecmath.Vector2f;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
7
src/main/java/com/volmit/iris/noise/NoiseFactory.java
Normal file
7
src/main/java/com/volmit/iris/noise/NoiseFactory.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface NoiseFactory
|
||||
{
|
||||
NoiseGenerator create(long seed);
|
||||
}
|
||||
10
src/main/java/com/volmit/iris/noise/NoiseGenerator.java
Normal file
10
src/main/java/com/volmit/iris/noise/NoiseGenerator.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
public interface NoiseGenerator
|
||||
{
|
||||
public double noise(double x);
|
||||
|
||||
public double noise(double x, double z);
|
||||
|
||||
public double noise(double x, double y, double z);
|
||||
}
|
||||
20
src/main/java/com/volmit/iris/noise/NoiseType.java
Normal file
20
src/main/java/com/volmit/iris/noise/NoiseType.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
public enum NoiseType {
|
||||
WHITE(seed -> new WhiteNoise(seed)),
|
||||
SIMPLEX(seed -> new SimplexNoise(seed)),
|
||||
CELLULAR(seed -> new CellularNoise(seed)),
|
||||
CELLULAR_HEIGHT(seed -> new CellHeightNoise(seed)),
|
||||
VASCULAR(seed -> new VascularNoise(seed));
|
||||
|
||||
private NoiseFactory f;
|
||||
|
||||
private NoiseType(NoiseFactory f) {
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
public NoiseGenerator create(long seed)
|
||||
{
|
||||
return f.create(seed);
|
||||
}
|
||||
}
|
||||
1014
src/main/java/com/volmit/iris/noise/OpenSimplex.java
Normal file
1014
src/main/java/com/volmit/iris/noise/OpenSimplex.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.M;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
public class PolygonGenerator
|
||||
{
|
||||
private double[] rarity;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
import com.volmit.iris.util.IRare;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
public class RarityCellGenerator<T extends IRare> extends CellGenerator
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
24
src/main/java/com/volmit/iris/noise/SimplexNoise.java
Normal file
24
src/main/java/com/volmit/iris/noise/SimplexNoise.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
public class SimplexNoise implements NoiseGenerator {
|
||||
private final OpenSimplex n;
|
||||
|
||||
public SimplexNoise(long seed) {
|
||||
this.n = new OpenSimplex(seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return (n.noise2(x, 0) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return (n.noise2(x, z) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return (n.noise3_XZBeforeY(x, y, z) / 2D) + 0.5D;
|
||||
}
|
||||
}
|
||||
17
src/main/java/com/volmit/iris/noise/Test.java
Normal file
17
src/main/java/com/volmit/iris/noise/Test.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
NoiseGenerator t = null;
|
||||
|
||||
for (NoiseType i : NoiseType.values()) {
|
||||
System.out.println("Test: " + i.name());
|
||||
t = i.create(0);
|
||||
for (int j = 0; j < 100; j++) {
|
||||
System.out.println(t.noise(j * 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
31
src/main/java/com/volmit/iris/noise/VascularNoise.java
Normal file
31
src/main/java/com/volmit/iris/noise/VascularNoise.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
public class VascularNoise implements NoiseGenerator {
|
||||
private final FastNoise n;
|
||||
|
||||
public VascularNoise(long seed) {
|
||||
this.n = new FastNoise((int) seed);
|
||||
n.SetNoiseType(FastNoise.NoiseType.Cellular);
|
||||
n.SetCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
|
||||
n.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
private double filter(double noise) {
|
||||
return 1D - ((noise / 2D) + 0.5D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return filter(n.GetCellular((float) x, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return filter(n.GetCellular((float) x, (float) z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return filter(n.GetCellular((float) x, (float) y, (float) z));
|
||||
}
|
||||
}
|
||||
25
src/main/java/com/volmit/iris/noise/WhiteNoise.java
Normal file
25
src/main/java/com/volmit/iris/noise/WhiteNoise.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.volmit.iris.noise;
|
||||
|
||||
public class WhiteNoise implements NoiseGenerator {
|
||||
private final FastNoise n;
|
||||
|
||||
public WhiteNoise(long seed) {
|
||||
n = new FastNoise((int) seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return (n.GetWhiteNoise((float) x, 0) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return (n.GetWhiteNoise((float) x, (float) z) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return (n.GetWhiteNoise((float) x, (float) y, (float) z) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user