Skip to content

Commit

Permalink
Surfaces API: add updated open simplex noise generators by K.jpg.
Browse files Browse the repository at this point in the history
* Uprev to 7.0.0-alpha.2
- Deprecate OpenSimplexNoise (not for removal)
- Add OpenSimplexNoise2 (K.jpg's OpenSimplex2(F)
- Add OpenSimplexNoise2S (K.jpg's OpenSimplex2S
- Instances w/ seed and utility generate() methods added to new noises
  • Loading branch information
gniftygnome committed Apr 17, 2023
1 parent 4e63b9a commit e5be5c3
Show file tree
Hide file tree
Showing 5 changed files with 2,026 additions and 10 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ org.gradle.jvmargs=-Xmx2G
fabric.loom.multiProjectOptimisation=true

maven_group=com.terraformersmc.terraform-api
version=7.0.0-alpha.1
version=7.0.0-alpha.2

minecraft_version=23w14a
yarn_mappings=23w14a+build.3
yarn_mappings=23w14a+build.6
loader_version=0.14.19
fabric_version=0.77.2+1.20
fabric_version=0.78.0+1.20

mixin_extras_version=0.2.0-beta.5
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@
* will be the same when ported to other languages.
*/

/**
* <p>OpenSimplexNoise is deprecated (without present intent to remove)
* because we have added faster, smoother implementations by K.jpg:</p>
*
* <p>OpenSimplexNoise2 (a.k.a. OpenSimplex2F) gives a result similar to Simplex noise.</p>
*
* <p>OpenSimplexNoise2S (a.k.a. OpenSimplex2S) gives a result similar to this noise,
* but it is faster and distributed across more of the range (-1,1).</p>
*
* <p>For more info, see <a href="https://github.com/KdotJPG/OpenSimplex2">K.jpg's OpenSimplex2 repo</a>.</p>
*/
@Deprecated
@SuppressWarnings({"UnnecessaryLocalVariable", "unused"})
public class OpenSimplexNoise {

private static final double STRETCH_CONSTANT_2D = -0.211324865405187; //(1/Math.sqrt(2+1)-1)/2;
private static final double SQUISH_CONSTANT_2D = 0.366025403784439; //(Math.sqrt(2+1)-1)/2;
private static final double STRETCH_CONSTANT_3D = -1.0 / 6; //(1/Math.sqrt(3+1)-1)/3;
Expand All @@ -28,8 +40,8 @@ public class OpenSimplexNoise {

private static final long DEFAULT_SEED = 0;

private short[] perm;
private short[] permGradIndex3D;
private final short[] perm;
private final short[] permGradIndex3D;

public OpenSimplexNoise() {
this(DEFAULT_SEED);
Expand Down Expand Up @@ -776,7 +788,7 @@ private static int fastFloor(double x) {

//Gradients for 2D. They approximate the directions to the
//vertices of an octagon from the center.
private static byte[] gradients2D = new byte[]{
private static final byte[] gradients2D = new byte[]{
5, 2, 2, 5,
-5, 2, -2, 5,
5, -2, 2, -5,
Expand All @@ -787,7 +799,7 @@ private static int fastFloor(double x) {
//vertices of a rhombicuboctahedron from the center, skewed so
//that the triangular and square facets can be inscribed inside
//circles of the same radius.
private static byte[] gradients3D = new byte[]{
private static final byte[] gradients3D = new byte[]{
-11, 4, 4, -4, 11, 4, -4, 4, 11,
11, 4, 4, 4, 11, 4, 4, 4, 11,
-11, -4, 4, -4, -11, 4, -4, -4, 11,
Expand All @@ -797,4 +809,4 @@ private static int fastFloor(double x) {
-11, -4, -4, -4, -11, -4, -4, -4, -11,
11, -4, -4, 4, -11, -4, 4, -4, -11,
};
}
}
Loading

0 comments on commit e5be5c3

Please sign in to comment.