]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/noise.qc
Merge remote-tracking branch 'origin/master' into terencehill/menu_remove_tab_title
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / noise.qc
1 #include "noise.qh"
2 #include "_all.qh"
3
4 entityclass(Noise);
5 class(Noise) .float noise_baccum;
6 class(Noise) .float noise_paccum;
7 class(Noise) .float noise_paccum2;
8 class(Noise) .float noise_paccum3;
9 class(Noise) .float noise_bstate;
10
11 float Noise_Brown(entity e, float dt)
12 {
13         e.noise_baccum += random() * sqrt(dt); // same stddev for all dt
14         return e.noise_baccum;
15 }
16 float Noise_Pink(entity e, float dt)
17 {
18         float f;
19         f = dt * 60;
20         // http://home.earthlink.net/~ltrammell/tech/pinkalg.htm
21         if(random() > pow(0.3190, f))
22                 e.noise_paccum = 0.34848 * (2 * random() - 1);
23         if(random() > pow(0.7756, f))
24                 e.noise_paccum2 = 0.28768 * (2 * random() - 1);
25         if(random() > pow(0.9613, f))
26                 e.noise_paccum3 = 0.43488 * (2 * random() - 1);
27         return e.noise_paccum + e.noise_paccum2 + e.noise_paccum3;
28 }
29 float Noise_White(entity e, float dt)
30 {
31         return random() * 2 - 1;
32 }
33 float Noise_Burst(entity e, float dt, float p)
34 {
35         if(random() > pow(p, dt))
36                 e.noise_bstate = !e.noise_bstate;
37         return 2 * e.noise_bstate - 1;
38 }