Class Noise

java.lang.Object
com.codename1.gpu.shaders.Noise

public final class Noise extends Object

Procedural noise built from ShaderNode math, so it runs in either stage on every backend and needs no texture. Every function takes a VEC2 coordinate; scale it to set the feature size.

The hashes avoid sin, whose precision differs between GPUs, and use only additions, multiplications and fract.

  • Method Details

    • hash

      public static ShaderNode hash(ShaderNode p)

      A pseudo random FLOAT in [0, 1) for each point, constant over no region: feed it floor of a coordinate for one value per cell.

      Parameters
      • p: a VEC2
      Returns

      a FLOAT

    • hash2

      public static ShaderNode hash2(ShaderNode p)

      Two independent pseudo random values in [0, 1).

      Parameters
      • p: a VEC2
      Returns

      a VEC2

    • value

      public static ShaderNode value(ShaderNode p)

      Smooth value noise in [0, 1], one feature per unit.

      Parameters
      • p: a VEC2
      Returns

      a FLOAT

    • fbm

      public static ShaderNode fbm(ShaderNode p, int octaves)

      Fractal value noise: octaves layers, each twice the frequency and half the weight of the one before. Clouds, terrain, dirt.

      Parameters
      • p: a VEC2

      • octaves: 1 to 6

      Returns

      a FLOAT in about [0, 1]

    • ridged

      public static ShaderNode ridged(ShaderNode p, int octaves)

      Ridged fractal noise: sharp creases where plain noise crosses its middle. Mountain ridges, lightning, cracks.

      Parameters
      • p: a VEC2

      • octaves: 1 to 6

      Returns

      a FLOAT in [0, 1]

    • cellular

      public static ShaderNode cellular(ShaderNode p)

      Cellular (Worley) noise: the distance to the nearest of one random point per cell. Foam, caustics, scales, cobbles, lava crust.

      Parameters
      • p: a VEC2
      Returns

      a FLOAT, 0 at a feature point and about 1 at most

    • cellular

      public static ShaderNode cellular(ShaderNode p, ShaderNode phase)

      Cellular noise whose feature points drift in circles over time, for moving water light and bubbling surfaces.

      Parameters
      • p: a VEC2

      • phase: a FLOAT that animates the points, such as time(), or null for still points

      Returns

      a FLOAT

    • bumpNormal

      public static ShaderNode bumpNormal(ShaderNode p, int octaves, float strength)

      The slope of fractal noise, as a tangent space normal for ShaderNode.perturbNormal: bumps without a normal map.

      Parameters
      • p: a VEC2

      • octaves: 1 to 6

      • strength: how steep the bumps are

      Returns

      a VEC3