Perlin Noise Functions - sinisterchipmunk/jax GitHub Wiki

Import: //= require "shaders/functions/noise"

NOTE: By default, the Perlin noise functions supported by Jax will attempt to perform texture lookups, since this is the fastest approach. If used in the vertex shader, and if the graphics card does not support vertex texture lookups, then Jax will fall back to non-VTL noise functions, which are slower. This is done automatically and silently. The following API is identical for both types of noise:

float cnoise(in vec2 P)
float cnoise(in vec3 P)
float cnoise(in vec4 P)

Calculates "classic" Perlin noise values for the given 2D, 3D or 4D point.

float snoise(in vec2 P)
float snoise(in vec3 P)
float snoise(in vec4 P)

Calculates simplex ("improved") Perlin noise for the given 2D, 3D or 4D point. See above paragraph for differences.

Notes:

2D noise is the fastest, but the least useful.

2D classic noise is somewhat faster than 2D simplex noise.

3D classic noise is about the same speed as 3D simplex noise (but simplex noise looks better).

4D classic noise is considerably slower and worse-looking than 4D simplex noise.

For the 4D noise values, the fourth component is often used as a random seed or time offset for animation.

For turbulence-based effects, try taking the absolute value of the return value of a noise function.

For believable clouds, try tweaking the following algorithm:

float t = TIME * 0.025;
float cloudThickness = snoise(vec4(vPos, t)) +
                       0.5 * snoise(vec4(vPos*2.0, t)) +
                       0.25 * snoise(vec4(vPos*4.0, t)) +
                       0.125 * snoise(vec4(vPos*8.0, t)) +
                       0.0625 * snoise(vec4(vPos*16.0, t));
cloudThickness = (cloudThickness+1.0)/2.0;
diffuse.rgb = mix(diffuse.rgb, cloudColor, cloudThickness);