Class PerlueNoise

java.lang.Object
com.github.yellowstonegames.grid.PerlueNoise
All Implemented Interfaces:
INoise, Externalizable, Serializable

public class PerlueNoise extends Object implements INoise
A mix of "Classic" PerlinNoise, written by Ken Perlin before he created Simplex Noise, with ValueNoise calculated at the same time. This uses quintic interpolation throughout (which was an improvement found in Simplex Noise), and has a single int seed. Perlue Noise can have significant grid-aligned and 45-degree-diagonal artifacts when too few octaves are used, but sometimes this is irrelevant, such as when sampling 3D noise on the surface of a sphere. These artifacts sometimes manifest as "waves" of quickly-changing and then slowly-changing noise, when 3D noise uses time as the z axis.
This tends to look fairly different from vanilla PerlinNoise or ValueNoise; it is capable of more chaotic arrangements of high and low values than either of those, but it still tends to have clusters of values of a specific size more often than clusters with very different sizes. In higher dimensions (4 and up, mainly), the value noise artifacts are more readily apparent. Using more octaves tends to improve the appearance of both this and PerlinNoise. In the highest dimensions this supports, PerlinNoise may have less-noticeable artifacts when compared to PerlueNoise.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface INoise

    INoise.Serializer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    static final PerlueNoise
     
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    static final float
     
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    PerlueNoise(int seed)
     
    PerlueNoise(long seed)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy of this PerlueNoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions.
    static float
    equalize(float x, float add, float mul)
    Given inputs as x in the range -1.0 to 1.0 that are too biased towards 0.0, this "squashes" the range softly to widen it and spread it away from 0.0 without increasing bias anywhere else.
    boolean
     
    int
    Gets the maximum dimension supported by this generator, which is 6.
    int
    Gets the minimum dimension supported by this generator, which is 2.
    float
    getNoise(float x, float y)
    Gets 2D noise with a default or pre-set seed.
    float
    getNoise(float x, float y, float z)
    Gets 3D noise with a default or pre-set seed.
    float
    getNoise(float x, float y, float z, float w)
    Gets 4D noise with a default or pre-set seed.
    float
    getNoise(float x, float y, float z, float w, float u)
    Gets 5D noise with a default or pre-set seed.
    float
    getNoise(float x, float y, float z, float w, float u, float v)
    Gets 6D noise with a default or pre-set seed.
    float
    getNoiseWithSeed(float x, float y, float z, float w, float u, float v, long s)
    Gets 6D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, float w, float u, long s)
    Gets 5D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, float w, long s)
    Gets 4D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, long s)
    Gets 3D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, long s)
    Gets 2D noise with a specific seed.
    long
    Gets the current seed of the generator, as a long (it is really an int).
    Returns the constant String "PluN" that identifies this in serialized Strings.
    protected static float
    gradCoord2D(int seed, int x, int y, float xd, float yd)
     
    protected static float
    gradCoord3D(int seed, int x, int y, int z, float xd, float yd, float zd)
     
    protected static float
    gradCoord4D(int seed, int x, int y, int z, int w, float xd, float yd, float zd, float wd)
     
    protected static float
    gradCoord5D(int seed, int x, int y, int z, int w, int u, float xd, float yd, float zd, float wd, float ud)
     
    protected static float
    gradCoord6D(int seed, int x, int y, int z, int w, int u, int v, float xd, float yd, float zd, float wd, float ud, float vd)
     
    boolean
    Returns true because this generator can be seeded with setSeed(long) and retrieved with getSeed().
    int
     
     
    void
    setSeed(long seed)
    Sets the seed to the given int, or really the int portion of the given long.
    Given a serialized String produced by stringSerialize(), reassigns this PerlueNoise to have the described state from the given String.
    Produces a String that describes everything needed to recreate this RawNoise in full.
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface INoise

    getNoise, getNoiseWithSeed, readExternal, writeExternal
  • Field Details

  • Constructor Details

    • PerlueNoise

      public PerlueNoise()
    • PerlueNoise

      public PerlueNoise(int seed)
    • PerlueNoise

      public PerlueNoise(long seed)
    • PerlueNoise

      public PerlueNoise(PerlueNoise other)
  • Method Details

    • getMinDimension

      public int getMinDimension()
      Gets the minimum dimension supported by this generator, which is 2.
      Specified by:
      getMinDimension in interface INoise
      Returns:
      the minimum supported dimension, 2
    • getMaxDimension

      public int getMaxDimension()
      Gets the maximum dimension supported by this generator, which is 6.
      Specified by:
      getMaxDimension in interface INoise
      Returns:
      the maximum supported dimension, 6
    • hasEfficientSetSeed

      public boolean hasEfficientSetSeed()
      Returns true because this generator can be seeded with setSeed(long) and retrieved with getSeed().
      Specified by:
      hasEfficientSetSeed in interface INoise
      Returns:
      true
    • setSeed

      public void setSeed(long seed)
      Sets the seed to the given int, or really the int portion of the given long.
      Specified by:
      setSeed in interface INoise
      Parameters:
      seed - a long seed, but only the int portion will be used (it is cast to int)
    • getSeed

      public long getSeed()
      Gets the current seed of the generator, as a long (it is really an int).
      Specified by:
      getSeed in interface INoise
      Returns:
      the current seed, as a long
    • getTag

      public String getTag()
      Returns the constant String "PluN" that identifies this in serialized Strings.
      Specified by:
      getTag in interface INoise
      Returns:
      a short String constant that identifies this RawNoise type, "PluN"
    • copy

      public PerlueNoise copy()
      Creates a copy of this PerlueNoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions. This almost always just calls a copy constructor.
      Specified by:
      copy in interface INoise
      Returns:
      a copy of this PerlueNoise
    • gradCoord2D

      protected static float gradCoord2D(int seed, int x, int y, float xd, float yd)
    • gradCoord3D

      protected static float gradCoord3D(int seed, int x, int y, int z, float xd, float yd, float zd)
    • gradCoord4D

      protected static float gradCoord4D(int seed, int x, int y, int z, int w, float xd, float yd, float zd, float wd)
    • gradCoord5D

      protected static float gradCoord5D(int seed, int x, int y, int z, int w, int u, float xd, float yd, float zd, float wd, float ud)
    • gradCoord6D

      protected static float gradCoord6D(int seed, int x, int y, int z, int w, int u, int v, float xd, float yd, float zd, float wd, float ud, float vd)
    • equalize

      public static float equalize(float x, float add, float mul)
      Given inputs as x in the range -1.0 to 1.0 that are too biased towards 0.0, this "squashes" the range softly to widen it and spread it away from 0.0 without increasing bias anywhere else.
      This starts with a common sigmoid function, x / sqrt(x * x + add), but instead of approaching -1 and 1 but never reaching them, this multiplies the result so the line crosses -1 when x is -1, and crosses 1 when x is 1. It has a smooth derivative, if that matters to you.
      Parameters:
      x - a float between -1 and 1
      add - if greater than 1, this will have nearly no effect; the lower this goes below 1, the more this will separate results near the center of the range. This must be greater than or equal to 0.0
      mul - typically the result of calling (float) Math.sqrt(add + 1f)
      Returns:
      a float with a slightly different distribution from x, but still between -1 and 1
    • getNoise

      public float getNoise(float x, float y)
      Description copied from interface: INoise
      Gets 2D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, long s)
      Description copied from interface: INoise
      Gets 2D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      s - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z)
      Description copied from interface: INoise
      Gets 3D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, long s)
      Description copied from interface: INoise
      Gets 3D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      s - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w)
      Description copied from interface: INoise
      Gets 4D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, long s)
      Description copied from interface: INoise
      Gets 4D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      s - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u)
      Description copied from interface: INoise
      Gets 5D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, float u, long s)
      Description copied from interface: INoise
      Gets 5D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      s - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u, float v)
      Description copied from interface: INoise
      Gets 6D noise with a default or pre-set seed.
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      v - v position; can be any finite float
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, float u, float v, long s)
      Description copied from interface: INoise
      Gets 6D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen with INoise.hasEfficientSetSeed().
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      z - z position; can be any finite float
      w - w position; can be any finite float
      u - u position; can be any finite float
      v - v position; can be any finite float
      s - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • stringSerialize

      public String stringSerialize()
      Produces a String that describes everything needed to recreate this RawNoise in full. This String can be read back in by stringDeserialize(String) to reassign the described state to another RawNoise.
      Specified by:
      stringSerialize in interface INoise
      Returns:
      a String that describes this PerlueNoise for serialization
    • stringDeserialize

      public PerlueNoise stringDeserialize(String data)
      Given a serialized String produced by stringSerialize(), reassigns this PerlueNoise to have the described state from the given String. The serialized String must have been produced by a PerlueNoise.
      Specified by:
      stringDeserialize in interface INoise
      Parameters:
      data - a serialized String, typically produced by stringSerialize()
      Returns:
      this PerlueNoise, after being modified (if possible)
    • recreateFromString

      public static PerlueNoise recreateFromString(String data)
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface INoise
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object