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