diff --git a/src/main/java/com/volmit/iris/noise/CNG.java b/src/main/java/com/volmit/iris/noise/CNG.java index 1207b1ff4..109e4b4f6 100644 --- a/src/main/java/com/volmit/iris/noise/CNG.java +++ b/src/main/java/com/volmit/iris/noise/CNG.java @@ -31,6 +31,7 @@ public class CNG private final double opacity; private NoiseInjector injector; private RNG rng; + private boolean noscale; private int oct; private double patch; private double up; @@ -124,6 +125,7 @@ public class CNG public CNG(RNG random, NoiseType t, double opacity, int octaves) { creates++; + noscale = t.equals(NoiseType.WHITE); this.oct = octaves; this.rng = random; power = 1; @@ -332,8 +334,8 @@ public class CNG public double noise(double... dim) { - double scale = this.bakedScale * this.scale; - double f = (fracture != null ? (fracture.noise(dim) - 0.5) * fscale : 0D); + double scale = noscale ? 1 : this.bakedScale * this.scale; + double f = noscale ? 0 : (fracture != null ? (fracture.noise(dim) - 0.5) * fscale : 0D); double x = dim.length > 0 ? dim[0] + f : 0D; double y = dim.length > 1 ? dim[1] - f : 0D; double z = dim.length > 2 ? dim[2] - f : 0D; diff --git a/src/main/java/com/volmit/iris/noise/FastNoise.java b/src/main/java/com/volmit/iris/noise/FastNoise.java index 0841f2e88..464ceadfc 100644 --- a/src/main/java/com/volmit/iris/noise/FastNoise.java +++ b/src/main/java/com/volmit/iris/noise/FastNoise.java @@ -353,21 +353,21 @@ public class FastNoise private static double DValCoord2D(int seed, long x, long y) { - int n = seed; + long n = seed; n ^= X_PRIME_L * x; n ^= Y_PRIME_L * y; - return ((n * n * n * 604930000L) / 21474836480000D) % 2D; + return ((n * n * n * 60493L) / (double) Long.MAX_VALUE); } private static double DValCoord3D(int seed, long x, long y, long z) { - int n = seed; + long n = seed; n ^= X_PRIME_L * x; n ^= Y_PRIME_L * y; n ^= Z_PRIME_L * z; - return ((n * n * n * 604930000L) / 21474836480000D) % 2D; + return ((n * n * n * 60493L) / (double) Long.MAX_VALUE); } private static float ValCoord3D(int seed, int x, int y, int z) @@ -628,7 +628,7 @@ public class FastNoise { long i = Double.doubleToRawLongBits(f); - return i ^ (i >> 16); + return i ^ (i >> 32); } public float GetWhiteNoise(float x, float y, float z, float w) diff --git a/src/main/java/com/volmit/iris/noise/WhiteNoise.java b/src/main/java/com/volmit/iris/noise/WhiteNoise.java index 4d6bfd17a..869419e0d 100644 --- a/src/main/java/com/volmit/iris/noise/WhiteNoise.java +++ b/src/main/java/com/volmit/iris/noise/WhiteNoise.java @@ -9,21 +9,26 @@ public class WhiteNoise implements NoiseGenerator n = new FastNoise((int) seed); } + private double f(double m) + { + return m; + } + @Override public double noise(double x) { - return (n.GetWhiteNoise(Float.intBitsToFloat((int) Double.doubleToLongBits(x / 1000d)) % 1000000F, 0) / 2D) + 0.5D; + return (n.DGetWhiteNoise(f(x), 0d) / 2D) + 0.5D; } @Override public double noise(double x, double z) { - return (n.GetWhiteNoise(Float.intBitsToFloat((int) Double.doubleToLongBits(x / 1000d)) % 1000000F, Float.intBitsToFloat((int) Double.doubleToLongBits(z / 1000d)) % 1000000F) / 2D) + 0.5D; + return (n.DGetWhiteNoise(f(x), f(z)) / 2D) + 0.5D; } @Override public double noise(double x, double y, double z) { - return (n.GetWhiteNoise(Float.intBitsToFloat((int) Double.doubleToLongBits(x / 1000d)) % 1000000F, Float.intBitsToFloat((int) Double.doubleToLongBits(y / 1000d)) % 1000000F, Float.intBitsToFloat((int) Double.doubleToLongBits(z / 1000d)) % 1000000F) / 2D) + 0.5D; + return (n.DGetWhiteNoise(f(x), f(y), f(z)) / 2D) + 0.5D; } } diff --git a/src/main/java/com/volmit/iris/object/NoiseStyle.java b/src/main/java/com/volmit/iris/object/NoiseStyle.java index 88afc63c9..3826214eb 100644 --- a/src/main/java/com/volmit/iris/object/NoiseStyle.java +++ b/src/main/java/com/volmit/iris/object/NoiseStyle.java @@ -9,19 +9,12 @@ import com.volmit.iris.util.RNG; @Desc("Styles of noise") @DontObfuscate -public enum NoiseStyle { +public enum NoiseStyle +{ @Desc("White Noise is like static. Useful for block scattering but not terrain.") @DontObfuscate STATIC(rng -> new CNG(rng, NoiseType.WHITE, 1D, 1)), - @Desc("White Noise is like static. Useful for block scattering but not terrain. 4 Times finer.") - @DontObfuscate - STATIC_FINE(rng -> new CNG(rng, NoiseType.WHITE, 1D, 1).scale(4)), - - @Desc("White Noise is like static. Useful for block scattering but not terrain. 16 Times finer.") - @DontObfuscate - STATIC_ULTRA_FINE(rng -> new CNG(rng, NoiseType.WHITE, 1D, 1).scale(16)), - @Desc("Wispy Perlin-looking simplex noise. The 'iris' style noise.") @DontObfuscate IRIS(rng -> CNG.signature(rng).scale(1)), @@ -44,9 +37,7 @@ public enum NoiseStyle { @Desc("Very Detailed smoke using simplex fractured with fractal billow simplex at high octaves.") @DontObfuscate - FRACTAL_SMOKE(rng -> new CNG(rng, 1D, 1) - .fractureWith(new CNG(rng.nextParallelRNG(1), NoiseType.FRACTAL_BILLOW_SIMPLEX, 1D, 8).scale(0.2), 1000) - .scale(0.34)), + FRACTAL_SMOKE(rng -> new CNG(rng, 1D, 1).fractureWith(new CNG(rng.nextParallelRNG(1), NoiseType.FRACTAL_BILLOW_SIMPLEX, 1D, 8).scale(0.2), 1000).scale(0.34)), @Desc("Thinner Veins.") @DontObfuscate @@ -54,19 +45,15 @@ public enum NoiseStyle { @Desc("Cells of simplex noise") @DontObfuscate - SIMPLEX_CELLS(rng -> new CNG(rng.nextParallelRNG(1), NoiseType.SIMPLEX, 1D, 1).scale(1) - .fractureWith(new CNG(rng.nextParallelRNG(8), NoiseType.CELLULAR, 1D, 1).scale(1), 200)), + SIMPLEX_CELLS(rng -> new CNG(rng.nextParallelRNG(1), NoiseType.SIMPLEX, 1D, 1).scale(1).fractureWith(new CNG(rng.nextParallelRNG(8), NoiseType.CELLULAR, 1D, 1).scale(1), 200)), @Desc("Veins of simplex noise") @DontObfuscate - SIMPLEX_VASCULAR(rng -> new CNG(rng.nextParallelRNG(1), NoiseType.SIMPLEX, 1D, 1).scale(1) - .fractureWith(new CNG(rng.nextParallelRNG(8), NoiseType.VASCULAR, 1D, 1).scale(1), 200)), + SIMPLEX_VASCULAR(rng -> new CNG(rng.nextParallelRNG(1), NoiseType.SIMPLEX, 1D, 1).scale(1).fractureWith(new CNG(rng.nextParallelRNG(8), NoiseType.VASCULAR, 1D, 1).scale(1), 200)), @Desc("Very Detailed fluid using simplex fractured with fractal billow simplex at high octaves.") @DontObfuscate - FRACTAL_WATER(rng -> new CNG(rng, 1D, 1) - .fractureWith(new CNG(rng.nextParallelRNG(1), NoiseType.FRACTAL_FBM_SIMPLEX, 1D, 9).scale(0.03), 9900) - .scale(1.14)), + FRACTAL_WATER(rng -> new CNG(rng, 1D, 1).fractureWith(new CNG(rng.nextParallelRNG(1), NoiseType.FRACTAL_FBM_SIMPLEX, 1D, 9).scale(0.03), 9900).scale(1.14)), @Desc("Perlin. Like simplex but more natural") @DontObfuscate @@ -413,17 +400,21 @@ public enum NoiseStyle { VASCULAR_IRIS_HALF(rng -> CNG.signatureHalf(rng, NoiseType.VASCULAR)), ; + private CNGFactory f; - private NoiseStyle(CNGFactory f) { + private NoiseStyle(CNGFactory f) + { this.f = f; } - public CNG create(RNG seed) { + public CNG create(RNG seed) + { return f.create(seed).bake(); } - public IrisGeneratorStyle style() { + public IrisGeneratorStyle style() + { return new IrisGeneratorStyle(this); } }