Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Noise

  1. Object
  2. Noise

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.

Methods

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.
public static ShaderNode hash2(ShaderNode p)Two independent pseudo random values in [0, 1).
public static ShaderNode value(ShaderNode p)Smooth value noise in [0, 1], one feature per unit.
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.
public static ShaderNode ridged(ShaderNode p, int octaves)Ridged fractal noise: sharp creases where plain noise crosses its middle.
public static ShaderNode cellular(ShaderNode p)Cellular (Worley) noise: the distance to the nearest of one random point per cell.
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.
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.

Inherited methods

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 ShaderNode
a VEC2

Returns

a FLOAT

hash2

public static ShaderNode hash2(ShaderNode p)
Two independent pseudo random values in [0, 1).

Parameters

p ShaderNode
a VEC2

Returns

a VEC2

value

public static ShaderNode value(ShaderNode p)
Smooth value noise in [0, 1], one feature per unit.

Parameters

p ShaderNode
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 ShaderNode
a VEC2
octaves int
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 ShaderNode
a VEC2
octaves int
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 ShaderNode
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 ShaderNode
a VEC2
phase ShaderNode
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 ShaderNode
a VEC2
octaves int
1 to 6
strength float
how steep the bumps are

Returns

a VEC3