Class VroomNoise

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

public class VroomNoise extends Object implements INoise
A type of continuous noise that is meant to look "similar in character" regardless of dimension. This is closely based on FoamNoise, but doesn't do any domain warping between results. This lowers the quality of single-octave noise somewhat, but may improve the appearance of noise using 3 or more octaves of FBM noise. Like FoamNoise in D dimensions, this makes D+1 calls to D-dimensional value noise with different rotations, averages them, and sharpens the result. Unlike FoamNoise, the grid structure of the value noise is noticeable in 4D and up. The grid quickly disappears if multiple octaves are used.
This may be somewhat faster than FoamNoise, while maintaining similar traits when multiple octaves are used. It isn't exactly clear why generating planets using 5D VroomNoise is 10-20% faster than 5D FoamNoise (with non-noise steps taking much of that time). One possibility is that VroomNoise is faster because it doesn't have any data dependency between noise calls, so those calls could potentially be executed with instruction-level parallelism. Another possibility is that the measurement was flawed, and they're about the same speed. In any case, VroomNoise shouldn't ever be slower than FoamNoise, and it may look better with multiple octaves.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface INoise

    INoise.Serializer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final VroomNoise
     
    protected long
    Use the same seed for any noise that should be continuous (smooth) across calls to nearby points.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    VroomNoise(long seed)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy of this INoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions.
    boolean
     
    int
    Gets the maximum dimension supported by this generator, which is 7.
    int
    Gets the minimum dimension supported by this generator, which is 2.
    float
    getNoise(float x, float y)
    Gets 2D noise using getSeed().
    float
    getNoise(float x, float y, float z)
    Gets 3D noise using getSeed().
    float
    getNoise(float x, float y, float z, float w)
    Gets 4D foam noise using getSeed().
    float
    getNoise(float x, float y, float z, float w, float u)
    Gets 5D noise with getSeed().
    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
    getNoise(float x, float y, float z, float w, float u, float v, float m)
    Gets 7D noise with a default or pre-set seed.
    float
    getNoiseWithSeed(float x, float y, float z, float w, float u, float v, float m, long seed)
    Gets 7D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, float w, float u, float v, long seed)
    Gets 6D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, float w, float u, long seed)
    Gets 5D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, float w, long seed)
    Gets 4D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, float z, long seed)
    Gets 3D noise with a specific seed.
    float
    getNoiseWithSeed(float x, float y, long seed)
    Gets 2D noise with a specific seed.
    long
    Gets the current seed of the generator, as a long even if the seed is stored internally as an int.
    Returns the String "VroN", to be used as a unique tag for this generator.
    boolean
    Returns true because this generator can be seeded with setSeed(long) and retrieved with getSeed().
    int
     
    static VroomNoise
     
    void
    setSeed(long seed)
    Sets the seed to the given long, if long seeds are supported, or (int)seed if only int seeds are supported.
    Given a serialized String produced by INoise.stringSerialize(), reassigns this INoise to have the described state from the given String.
    Produces a String that describes everything needed to recreate this INoise in full.
     
    static float
    valueNoise(float x, float y, float z, float w, float u, float v, float m, long seed)
     
    static float
    valueNoise(float x, float y, float z, float w, float u, float v, long seed)
     
    static float
    valueNoise(float x, float y, float z, float w, float u, long seed)
    Gets 5D value noise with the lowest, fastest level of detail.
    static float
    valueNoise(float x, float y, float z, float w, long seed)
    Gets 4D value noise with the lowest, fastest level of detail.
    static float
    valueNoise(float x, float y, float z, long seed)
    Gets value noise with the lowest, fastest level of detail.
    static float
    valueNoise(float x, float y, long seed)
    Gets 2D value noise with the lowest, fastest level of detail.

    Methods inherited from class Object

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

    Methods inherited from interface INoise

    readExternal, writeExternal
  • Field Details

    • seed

      protected long seed
      Use the same seed for any noise that should be continuous (smooth) across calls to nearby points.
    • instance

      public static final VroomNoise instance
  • Constructor Details

    • VroomNoise

      public VroomNoise()
    • VroomNoise

      public VroomNoise(long seed)
  • Method Details

    • getNoise

      public float getNoise(float x, float y)
      Gets 2D noise using getSeed().
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x coordinate
      y - y coordinate
      Returns:
      noise between -1 and 1, inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, long seed)
      Gets 2D noise with a specific seed.
      Specified by:
      getNoiseWithSeed in interface INoise
      Parameters:
      x - x position; can be any finite float
      y - y position; can be any finite float
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • valueNoise

      public static float valueNoise(float x, float y, long seed)
      Gets 2D value noise with the lowest, fastest level of detail. Uses the given seed and does not change x or y. This has a different output range (0 to 1) than foam noise.
      Parameters:
      x - x coordinate
      y - y coordinate
      seed - the seed to use for the noise (used in place of getSeed())
      Returns:
      noise between 0 and 1
    • getNoise

      public float getNoise(float x, float y, float z)
      Gets 3D noise using getSeed().
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      Returns:
      noise between -1 and 1, inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, long seed)
      Gets 3D noise with a specific seed.
      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
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • valueNoise

      public static float valueNoise(float x, float y, float z, long seed)
      Gets value noise with the lowest, fastest level of detail. Uses the given seed and does not change x, y, or z. This has a different output range (0 to 1) than foam noise.
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      seed - the seed to use for the noise (used in place of getSeed())
      Returns:
      noise between 0 and 1
    • getNoise

      public float getNoise(float x, float y, float z, float w)
      Gets 4D foam noise using getSeed().
      Specified by:
      getNoise in interface INoise
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      w - w coordinate
      Returns:
      noise between -1 and 1, inclusive
    • getNoiseWithSeed

      public float getNoiseWithSeed(float x, float y, float z, float w, long seed)
      Gets 4D noise with a specific seed.
      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
      seed - can be any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • valueNoise

      public static float valueNoise(float x, float y, float z, float w, long seed)
      Gets 4D value noise with the lowest, fastest level of detail. Uses the given seed and does not change x, y, z, or w. This has a different output range (0 to 1) than foam noise.
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      w - w coordinate
      seed - the seed to use for the noise (used in place of getSeed())
      Returns:
      noise between 0 and 1
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u)
      Gets 5D noise with getSeed().
      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 seed)
      Gets 5D noise with a specific seed.
      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
      seed - any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • valueNoise

      public static float valueNoise(float x, float y, float z, float w, float u, long seed)
      Gets 5D value noise with the lowest, fastest level of detail. Uses the given seed and does not change x, y, z, w, or u. This has a different output range (0 to 1) than foam noise.
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      w - w coordinate
      u - u coordinate
      seed - the seed to use for the noise (used in place of getSeed())
      Returns:
      noise between 0 and 1
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u, float v)
      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 seed)
      Gets 6D noise with a specific seed.
      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
      seed - any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • valueNoise

      public static float valueNoise(float x, float y, float z, float w, float u, float v, long seed)
    • getNoise

      public float getNoise(float x, float y, float z, float w, float u, float v, float m)
      Gets 7D 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
      m - m 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, float m, long seed)
      Gets 7D noise with a specific seed.
      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
      m - m position; can be any finite float
      seed - any long
      Returns:
      a noise value between -1.0f and 1.0f, both inclusive
    • valueNoise

      public static float valueNoise(float x, float y, float z, float w, float u, float v, float m, long seed)
    • getTag

      public String getTag()
      Returns the String "VroN", to be used as a unique tag for this generator.
      Specified by:
      getTag in interface INoise
      Returns:
      the String "VroN"
    • 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, which is 2 inclusive
    • getMaxDimension

      public int getMaxDimension()
      Gets the maximum dimension supported by this generator, which is 7.
      Specified by:
      getMaxDimension in interface INoise
      Returns:
      the maximum supported dimension, which is 7
    • 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)
      Description copied from interface: INoise
      Sets the seed to the given long, if long seeds are supported, or (int)seed if only int seeds are supported. If this generator cannot be seeded, this should do nothing, and should not throw an exception. If this operation allocates or is time-intensive, then INoise.hasEfficientSetSeed() should return false. That method is checked in INoise.getNoiseWithSeed(float, float, long), and if it returns false, the noise call will avoid calling setSeed(). You can always at least try to set the seed, even if it does nothing or is heavy on performance, and doing it a few times each frame should typically be fine for any generator. In the case this is called thousands of times each frame, check INoise.hasEfficientSetSeed().
      Specified by:
      setSeed in interface INoise
      Parameters:
      seed - a long or int seed, with no restrictions unless otherwise documented
    • getSeed

      public long getSeed()
      Description copied from interface: INoise
      Gets the current seed of the generator, as a long even if the seed is stored internally as an int. This must be implemented, but if the generator doesn't have a seed that can be expressed as a long (potentially using BitConversion.floatToIntBits(float)), this can just return 0.
      Specified by:
      getSeed in interface INoise
      Returns:
      the current seed, as a long
    • stringSerialize

      public String stringSerialize()
      Description copied from interface: INoise
      Produces a String that describes everything needed to recreate this INoise in full. This String can be read back in by INoise.stringDeserialize(String) to reassign the described state to another INoise. The syntax here should always start and end with the ` character, which is used by INoise.stringDeserialize(String) to identify the portion of a String that can be read back. The ` character should not be otherwise used unless to serialize another INoise that this uses.
      If you use Base to produce String representations for numeric fields in an INoise, Base.BASE10 is strongly recommended; in most cases, you can just use string concatenation with the fields separated by the tilde character, "~". For printing a float field with Base to a StringBuilder sb, use Base.BASE10.appendGeneral(sb, field).
      The default implementation throws an UnsupportedOperationException only. INoise classes do not have to implement any serialization methods, but they aren't serializable by the methods in this class or in INoise.Serializer unless they do implement this, INoise.getTag(), INoise.stringDeserialize(String), and INoise.copy().
      Specified by:
      stringSerialize in interface INoise
      Returns:
      a String that describes this INoise for serialization
    • stringDeserialize

      public VroomNoise stringDeserialize(String data)
      Description copied from interface: INoise
      Given a serialized String produced by INoise.stringSerialize(), reassigns this INoise to have the described state from the given String. The serialized String must have been produced by the same class as this object is.
      Any class that implements INoise.stringSerialize() should also implement this method in a compatible way. Using base-10 is expected for most uses. Using Base.BASE10.readFloat(data, start, end) may be useful to parse only the part of data between start and end.
      The default implementation throws an UnsupportedOperationException only. INoise classes do not have to implement any serialization methods, but they aren't serializable by the methods in this class or in INoise.Serializer unless they do implement this, INoise.getTag(), INoise.stringSerialize(), and INoise.copy().
      Specified by:
      stringDeserialize in interface INoise
      Parameters:
      data - a serialized String, typically produced by INoise.stringSerialize()
      Returns:
      this INoise, after being modified (if possible)
    • recreateFromString

      public static VroomNoise recreateFromString(String data)
    • copy

      public VroomNoise copy()
      Description copied from interface: INoise
      Creates a copy of this INoise, 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.
      The default implementation throws an UnsupportedOperationException only. Implementors are strongly encouraged to implement this in general, and that is required to use an INoise class with INoise.Serializer.
      Specified by:
      copy in interface INoise
      Returns:
      a copy of this INoise
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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