Xonotic
noise.qh
Go to the documentation of this file.
1 #pragma once
2 
3 // noises "usually" start in the range -1..1
4 entityclass(Noise);
5 classfield(Noise).float noise_baccum;
6 classfield(Noise).float noise_paccum;
7 classfield(Noise).float noise_paccum2;
8 classfield(Noise).float noise_paccum3;
9 classfield(Noise).float noise_bstate;
10 
12 float Noise_Brown(entity e, float dt)
13 {
14  e.noise_baccum += random() * sqrt(dt); // same stddev for all dt
15  return e.noise_baccum;
16 }
18 float Noise_Pink(entity e, float dt)
19 {
20  float f;
21  f = dt * 60;
22  // http://home.earthlink.net/~ltrammell/tech/pinkalg.htm
23  if (random() > (0.3190 ** f)) e.noise_paccum = 0.34848 * (2 * random() - 1);
24  if (random() > (0.7756 ** f)) e.noise_paccum2 = 0.28768 * (2 * random() - 1);
25  if (random() > (0.9613 ** f)) e.noise_paccum3 = 0.43488 * (2 * random() - 1);
26  return e.noise_paccum + e.noise_paccum2 + e.noise_paccum3;
27 }
29 float Noise_White(entity e, float dt)
30 {
31  return random() * 2 - 1;
32 }
35 float Noise_Burst(entity e, float dt, float p)
36 {
37  if (random() > (p ** dt)) e.noise_bstate = !e.noise_bstate;
38  return 2 * e.noise_bstate - 1;
39 }
entity() spawn
ERASEABLE float Noise_Brown(entity e, float dt)
Definition: noise.qh:12
#define ERASEABLE
Definition: _all.inc:35
ERASEABLE float Noise_Burst(entity e, float dt, float p)
+1 or -1
Definition: noise.qh:35
entityclass(Noise)
ERASEABLE float Noise_White(entity e, float dt)
Definition: noise.qh:29
classfield(Noise).float noise_baccum
ERASEABLE float Noise_Pink(entity e, float dt)
Definition: noise.qh:18