Class NoiseUtils

java.lang.Object
com.github.tommyettinger.textra.utils.NoiseUtils

public class NoiseUtils extends Object
Some 1D noise methods to be used when an effect needs smooth but random changes.
  • Constructor Details

    • NoiseUtils

      public NoiseUtils()
  • Method Details

    • noise1D

      public static float noise1D(float x, int seed)
      Quilez' 1D noise, with some changes to work on the CPU. Takes a distance x and any int seed, and produces a smoothly-changing value as x goes up or down and seed stays the same. Uses a quartic curve. You will often want to prefer octaveNoise1D(float, int), which uses this method, instead of directly calling noise1D(), because octaveNoise1D() looks much more natural.
      The distance (x) should be between -8192 and 1073733631 for this to return correct results. Because floats incur precision loss earlier than 1073733631, the actual upper bound is lower. The limit of -8192 comes from how this uses MathUtils.floor(float) internally on x + x.
      Credit to Inigo Quilez, who posted this ShaderToy in 2019 under the MIT license. There are changes here in the way it uses a seed and gets the h value, but the core idea is the same, using a symmetrical curve to minimize the number of hashes needed per point.
      Parameters:
      x - should go up and/or down steadily and by small amounts (less than 1.0, certainly)
      seed - should stay the same for a given curve
      Returns:
      a noise value between -1.0 and 1.0
    • octaveNoise1D

      public static float octaveNoise1D(float x, int seed)
      A more natural 1D noise that uses two octaves of noise1D(float, int); still has a range of -1 to 1.
      Because this uses a higher frequency for one octave of noise1D(), the limit on x is more restricting; x should be no less than -4096 here, though there may be precision quirks for other inputs near that range, and excessively large inputs will naturally lose some precision due to how floats work.
      Parameters:
      x - should go up and/or down steadily and by small amounts (less than 1.0, certainly)
      seed - should stay the same for a given curve
      Returns:
      a noise value between -1.0 and 1.0