ChaosPro Home
Introduction
What's New
Palettes
Using Formulas
Layering in ChaosPro
Rendering
Fractal Parameter Windows
Windows
Menu
3D Transformations
Animations
Formula Compiler
Writing Formulas
Language Reference
Introduction
Basic Syntax
Datatypes
Constants
Variables
Expressions
Operators
Functions
Arithmetic
Conversion
Color
Trigonometric
Miscellaneous
ident
isFinite
isNaN
oldz
perlinNoise
perlinNoise3
random
random.real
srand
trafoHistory
ubound
zero
Control Structures
Compiler Directives
Functions
Interface to ChaosPro
Special Features, Notes...
Compatibility
Fractal Type Reference
Tutorials
Appendix
CHAOSPRO 4.0
Release 4.0
.

Predefined Functions - perlinNoise3

Function name:perlinNoise3 - Return perlin noise vector for the given vector
Synopsis:perlinNoise3(v)

Input data type Output data type
vector vector


Description:

The perlinNoise3 function creates some kind of a "random noise" vector. Perlin noise is called after Ken Perlin who invented it.
Perlin noise in ChaosPro is implemented as a function of (x,y,z) which uses interpolation between a set of pre-calculated gradient vectors to construct a value that varies pseudo-randomly over space.
In other words: The base perlin noise returns a random value between -1 and 1 which smoothly changes with the input values x, y and z. perlinNoise3 itself actually calls perlin noise three times and thus returns a vector which smoothly changes with the input values x, y and z.

Using some further processing you can apply displacements or color changes to a base value. "Further processing" actually means that calling the function will only return a random number which needs to be scaled. You then need to call the function again and scale again, and so on. The resulting value then can directly be used as an index into a color table in order to apply some kind of texture coloring like cloud effects.

The standard algorithm for using perlin noise is as follows:

real stepInv;
real kCnt;
vector noiseResult,noiseSum;
vector noisePos;
real freq,octaveMult;

// external parameters following...
parameter real scaleStart;
parameter real octaves;
parameter double step;

	// at first, initialize the position according to "z",
	// we thus want to receive a random value for this position.
	noisePos=z;
	
	// we repeatedly call perlinNoise and scale each result
	// according to freq
	freq= scaleStart;
	// The result will be put into noiseSum
	noiseSum = vector(0,0,0);
	// octaves specifies how often we want to call perlinNoise.
	// The more often we call and scale the function, the more
	// "wild" the random pattern will be
	kCnt=octaves;
	stepInv=1/step;
	
	while (kCnt>0) {
		
		noiseResult=freq*perlinNoise3(partx(noisePos),
		                             party(noisePos),
		                             partz(noisePos));
		if (kCnt<1) {
			octaveMult=kCnt;
		} else {
			octaveMult=1;
		}
		
		noiseSum = noiseSum + octaveMult*noiseResult;

		// next time we call perlinNoise we scale the resulting
		// noise by freq, so let's change it to have different scales!
		freq = freq * step;
		// of course we must adjust noisePos to a new position
		// according to the scale factor: If we do not change
		// noisePos, perlinNoise will return exactly the same number...
		noisePos = stepInv*noisePos;
		kCnt=kCnt-1;
	}

In order to see what this is all about, have a look at the images below: Here we use the above algorithm in order to perform a displacement of a pixel:

The base image Octaves=1
   
Octaves=4 Octaves=8
   
Octaves=8, scale=0.5

As you can see, octaves=1 means: perlinNoise3 has been called once: The result is that the sphere is slightly distorted, almost unnoticeable. It's smooth in all three input directions, i.e. the values smoothly change in each direction. In fact, it's almost too smooth...

And that's the reason why one needs to call perlinNoise3 several times and add different scales of the noise: octaves=4 looks better, and octaves=8 actually calls perlinNoise 8 times, adds up the 8 differently scaled values, and the result is interesting...the final image increases the overall scale of the noise, which results in even more displacement. Such an easy displacement can be applied to all objects using the perlinNoise3 function.

By the way, perlinNoise does almost the same, the only exception is that it does not return a vector, but a real number. perlinNoise is ideal if you want to retrieve a single real value (for example for coloring), perlinNoise3 is ideal if you need three random values, for example if you want to displace a value.