thebookofshaders/12/README.md

62 lines
2.2 KiB
Markdown
Raw Normal View History

2015-03-19 21:06:41 +00:00
## Fractal Brownian Motion
2015-03-15 15:35:14 +00:00
At the end of previus chapter we were thinking on noise as random smooth waves. This *wavely* nature of noise is what makes it such an interdisciplinary concept. In fact, in acustics, sound is constructed by the manipulation of the amplitud and frecuency of a sine waves.
2015-03-19 21:06:41 +00:00
```glsl
y = amplitud + sin( frequency );
```
2015-03-22 23:12:07 +00:00
An interesting property of waves is that they can be add up. The following graph shows what happen if you add sine waves of different frequencies and amplituds.
2015-03-19 21:06:41 +00:00
<div class="simpleFunction" data="
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.1;
"></div>
2015-03-22 23:12:07 +00:00
Think on the surface of the ocean. Massive amount of water propagating waves across it surface. Waves of diferent amplitud and frequencies coliding together.
On other side if those sine waves are harmonics produce interesting patterns. Try the following code on the previus graph. As you can see in each iteration the frequency increase, while the amplitud decrese.
```glsl
y = 0.;
for( int i = 0; i < 5; ++i) {
y += sin(PI*x*float(i))/float(i);
}
y *= 0.6;
```
2015-03-19 21:06:41 +00:00
2015-03-22 17:31:59 +00:00
## Fractal Brownian Motion
2015-03-19 21:06:41 +00:00
2015-03-22 17:31:59 +00:00
By adding different octaves of increasing frequencies and decreasing amplitudes of noise we can gain some extra granularity. This technique is call Fractal Brownian Motion and is very well documented in [this](http://www.iquilezles.org/www/articles/warp/warp.htm) [two](http://www.iquilezles.org/www/articles/morenoise/morenoise.htm) articles of Iñigo Quilez.
2015-03-19 21:06:41 +00:00
2015-03-22 17:31:59 +00:00
Take a look to the following example and progresively change the for loop to do 2,3,4,5,6,7 and 8 iterations. See how incrisinly fragmented this wave function becomes.
2015-03-19 21:06:41 +00:00
<div class="simpleFunction" data="
float a = 0.5;
for( int i = 0; i < 1; ++i) {
y += a * noise(x);
x = x * 2.0;
a *= 0.5;
}"></div>
2015-03-22 17:31:59 +00:00
If we apply this to 2D will look like the following code:
2015-03-19 21:06:41 +00:00
<div class="codeAndCanvas" data="2d-fbm.frag"></div>
2015-03-19 21:15:23 +00:00
## Using Fractal Braownian Motion
http://www.iquilezles.org/www/articles/warp/warp.htm
2015-03-19 21:17:43 +00:00
http://www.iquilezles.org/www/articles/morenoise/morenoise.htm
http://www.iquilezles.org/www/articles/dynclouds/dynclouds.htm
2015-03-19 21:06:41 +00:00
<div class="codeAndCanvas" data="clouds.frag"></div>
great!
2015-03-15 15:35:14 +00:00