thebookofshaders/12
2015-08-05 08:39:27 -03:00
..
1d-fbm.frag optical toys 2015-05-05 10:19:16 -04:00
2d-fbm.frag optical toys 2015-05-05 10:19:16 -04:00
clouds.frag optical toys 2015-05-05 10:19:16 -04:00
index.php adding files and main README-JP.md 2015-08-05 08:39:27 -03:00
noise.frag optical toys 2015-05-05 10:19:16 -04:00
README.md readme 2015-04-01 17:18:14 -04:00

Fractal Brownian Motion

At the end of the previous chapter we were thinking about noise and discovering that in fact noise could be interpreted as audio signals. In fact sound can be constructed by the manipulation of the amplitud and frequency of a sine waves.

y = amplitud + sin( frequency );

An interesting property of waves in general is that they can be add up. The following graph shows what happen if you add sine waves of different frequencies and amplitudes.

Think on it as the surface of the ocean. Massive amount of water propagating waves across it surface. Waves of different heights (amplitud) and rhythms (frequencies) bouncing and interfering each other.

Musicians learn long time ago that there are sounds that play well with each other. Those sound, carried by waves of air, vibrate in such a particular way that the resultan sound seams to be bust and enhance. Those sounds are call harmonics.

Back to code, we can add harmonics together and see how the resultant looks like. Try the following code on the previous graph.

y = 0.;
for( int i = 0; i < 5; ++i) {
    y += sin(PI*x*float(i))/float(i);
}
y *= 0.6;

As you can see in the above code, on every iteration the frequency increase by the double. By augmenting the number of iterations (chaining the 5 for a 10, a 20 or 50) the wave tends to break into smaller fractions, with more details and sharper fluctuations.

Fractal Brownian Motion

So we try adding different waves together, and the result was chaotic, we add up harmonic waves and the result was a consistent fractal pattern. We can use the best of both worlds and add up harmonic noise waves to exacerbate a noise pattern.

By adding different octaves of increasing frequencies and decreasing amplitudes of noise we can obtain a bigger level of detail or granularity. This technique is call Fractal Brownian Motion and usually consist on a fractal sum of noise functions.

Take a look to the following example and progressively change the for loop to do 2,3,4,5,6,7 and 8 iterations. See want happens

If we apply this one dimensional example to a bidimentional space it will look like the following example:

Using Fractal Brownian Motion

In this article Iñigo Quilez describe an interesting use of fractal brownian motion constructing patterns by adding successive results of fractal brownian motions.

Take a look to the code and how it looks