5.9. Noise Functions
Noise functions (see Table 5.9) are available to both fragment and vertex shaders. These stochastic functions, first described by Ken Perlin, increase visual complexity. Values returned by the following noise functions give the appearance of randomness, but they are not truly random. A more complete description of and motivation for the noise function can be found in Chapter 15.
Table 5.9. Noise FunctionsSyntax | Description |
---|
float noise1 (float x) float noise1 (vec2 x) float noise1 (vec3 x) float noise1 (vec4 x) | Returns a 1D noise value based on the input value x. | vec2 noise2 (float x) vec2 noise2 (vec2 x) vec2 noise2 (vec3 x) vec2 noise2 (vec4 x) | Returns a 2D noise value based on the input value x. | vec3 noise3 (float x) vec3 noise3 (vec2 x) vec3 noise3 (vec3 x) vec3 noise3 (vec4 x) | Returns a 3D noise value based on the input value x. | vec4 noise4 (float x) vec4 noise4 (vec2 x) vec4 noise4 (vec3 x) vec4 noise4 (vec4 x) | Returns a 4D noise value based on the input value x. |
The built-in noise functions are defined to have the following characteristics:
The return values are always in the range [1,1] and cover at least the range [0.6,0.6] with a Gaussian-like distribution. The return values have an overall average of 0. The functions are repeatable, in that a particular input value always produces the same return value. They are statistically invariant under rotation; that is, no matter how the domain is rotated, it has the same statistical character. They have a statistical invariance under translation; that is, no matter how the domain is translated, it has the same statistical character. They typically give different results under translation. The spatial frequency is narrowly concentrated, centered somewhere between 0.5 and 1.0. They are C1 continuous everywhere; that is the first derivative is continuous.
|