thebookofshaders/13/README.md
Patricio Gonzalez Vivo 6aaba1705c voro
2016-05-02 17:19:51 -04:00

3.9 KiB

Fractal Brownian Motion

Noise tends to means different things for different people. Musicians will think it in disturbing sounds, communicators as interference and astrophysics as cosmic microwave background. In fact most of this concept have one things in common that bring as back to the begining of random. Waves and their properties. Audio or electromagnetical waves, fluctuation overtime of a signal. That change happens in amplitud and frequency. The ecuation for it looks like this:

  • Try changing the values of the frequency and amplitud to understand how they behave.
  • Using shaping functions try changing the amplitud overtime.
  • Using shaping function try changing the frequency overtime.

By doing the last to excersize you have manage to "modulate" a sine wave, and you just create AM (amplitud modulated) and FM (frequency modulated) waves. Congratulations!

Another interesting property of waves is their ability to add up. Add the following lines to the previus example and pay atention how the frequencies and amplitudes change conform we add different waves.

float t = 0.01*(-u_time*130.0);
y += sin(x*2.1 + t)*4.5;
y += sin(x*1.72 + t*1.121)*4.0;
y += sin(x*2.221 + t*0.437)*5.0;
y += sin(x*3.1122+ t*4.269)*2.5;
y *= 0.06;
  • Experiment by changing their values.
  • Is it possible to cancel two waves? how that will look like?
  • Is it possible to add waves in such a way that they will amplify each other?

In music, each note is asociated with specific a frequency. This frequencies seams to respond to a pattern where it self in what we call scale.

By adding different iterations of noise (octaves), where in each one increment the frequencies (Lacunarity) and decreasing amplitude (gain) of the noise we can obtain a bigger level of granularity on the noise. This technique is call Fractal Brownian Motion (fBM) and in it simplest form looks like the following code

  • Progressively change the number of octaves to iterate from 1 to 2, 4, 8 and 10. See want happens.
  • With over 4 octaves try changing the lacunarity value.
  • Also with over 4 octaves change the gain value and see what happens.

Note how each in each octave the noise seams to have more detail. Also note the self similarity while more octaves are added.

The following code is an example of how fBm could be implemented on two dimensions.

  • Reduce the numbers of octaves by changing the value on line 37
  • Modify the lacunarity of the fBm on line 47
  • Explore by changing the gain on line 48

This techniques is use commonly to construct procedural landscapes. The self similarity of the fBm is perfect for mountains, together with a close cassing known as turbulence. Esentially a fBm but constructed from the absolute value of a signed noise.

for (int i = 0; i < OCTAVES; i++) {
    value += amplitud * abs(snoise(st));
    st *= 2.;
    amplitud *= .5;
}

Another member of this family is the ridge. Constructed similarly to the turbolence but with some extra calculations:

    n = abs(n);     // create creases
    n = offset - n; // invert so creases are at top
    n = n * n;      // sharpen creases