Data Structures | |
struct | str_ht |
struct | fbm_spec |
Files | |
file | noise.c |
Defines | |
#define | SMOOTHSTEP(x) ((x) * (x) * (3 - 2*(x))) |
interpolate smoothly from 0 .. 1 | |
#define | MAXSIZE 267 |
#define | INCRSUM(m, s, x, y, z) |
#define | TABLE_SIZE 4096 |
#define | MAGIC_STRHT1 1771561 |
#define | MAGIC_STRHT2 1651771 |
#define | MAGIC_TAB1 9823 |
#define | MAGIC_TAB2 784642 |
#define | CK_HT() |
#define | Hash3d(a, b, c) |
#define | MAGIC_fbm_spec_wgt 0x837592 |
#define | PSCALE(_p, _s) _p[0] *= _s; _p[1] *= _s; _p[2] *= _s |
#define | PCOPY(_d, _s) _d[0] = _s[0]; _d[1] = _s[1]; _d[2] = _s[2] |
Functions | |
void | bn_noise_init (void) |
double | bn_noise_perlin (fastf_t *point) |
Robert Skinner's Perlin-style "Noise" function. | |
void | bn_noise_vec (fastf_t *point, fastf_t *result) |
struct fbm_spec * | find_spec_wgt (double h, double l, double o) |
double | bn_noise_fbm (fastf_t *point, double h_val, double lacunarity, double octaves) |
Procedural fBm evaluated at "point"; returns value stored in "value". | |
double | bn_noise_turb (fastf_t *point, double h_val, double lacunarity, double octaves) |
Procedural turbulence evaluated at "point";. | |
double | bn_noise_ridged (fastf_t *point, double h_val, double lacunarity, double octaves, double offset) |
A ridged noise pattern. | |
double | bn_noise_mf (fastf_t *point, double h_val, double lacunarity, double octaves, double offset) |
interpolate smoothly from 0 .. 1
SMOOTHSTEP() takes a value in the range [0:1] and provides a number in the same range indicating the amount of (a) present in a smooth interpolation transition between (a) and (b)
Definition at line 51 of file noise.c.
Referenced by bn_noise_perlin(), and bn_noise_vec().
#define MAXSIZE 267 |
Definition at line 107 of file noise.c.
Referenced by bn_noise_init().
Definition at line 114 of file noise.c.
Referenced by bn_noise_perlin(), and bn_noise_vec().
#define TABLE_SIZE 4096 |
Definition at line 137 of file noise.c.
Referenced by bn_noise_init().
#define MAGIC_STRHT1 1771561 |
Definition at line 139 of file noise.c.
Referenced by bn_noise_init().
#define MAGIC_STRHT2 1651771 |
Definition at line 140 of file noise.c.
Referenced by bn_noise_init().
#define MAGIC_TAB1 9823 |
Definition at line 141 of file noise.c.
Referenced by bn_noise_init().
#define MAGIC_TAB2 784642 |
Definition at line 142 of file noise.c.
Referenced by bn_noise_init().
#define CK_HT | ( | ) |
{ \ BU_CKMAG(&ht.magic, MAGIC_STRHT1, "struct str_ht ht 1"); \ BU_CKMAG(&ht.magic_end, MAGIC_STRHT2, "struct str_ht ht 2"); \ BU_CKMAG(ht.hashTableMagic1, MAGIC_TAB1, "hashTable Magic 1"); \ BU_CKMAG(ht.hashTableMagic2, MAGIC_TAB2, "hashTable Magic 2"); \ if (ht.hashTable != &ht.hashTableMagic1[1]) \ bu_bomb("ht.hashTable changed rel ht.hashTableMagic1"); \ if (ht.hashTableMagic2 != &ht.hashTable[TABLE_SIZE]) \ bu_bomb("ht.hashTable changed rel ht.hashTableMagic2"); \ }
Definition at line 143 of file noise.c.
Referenced by bn_noise_init().
#define Hash3d | ( | a, | |||
b, | |||||
c | ) |
ht.hashTable[ \ ht.hashTable[ \ ht.hashTable[(a) & 0xfff] ^ ((b) & 0xfff) \ ] ^ ((c) & 0xfff) \ ]
Map integer point into repeatable random number [0..TABLE_SIZE-1] (i.e., [0-4095]). We actually only use the first 8 bits of the final value extracted from this table. It's not quite clear that we really need this big a table. The extra size does provide some extra randomness for intermediate results.
Definition at line 161 of file noise.c.
Referenced by bn_noise_perlin(), and bn_noise_vec().
#define MAGIC_fbm_spec_wgt 0x837592 |
Definition at line 437 of file noise.c.
Referenced by find_spec_wgt().
#define PSCALE | ( | _p, | |||
_s | ) | _p[0] *= _s; _p[1] *= _s; _p[2] *= _s |
Definition at line 443 of file noise.c.
Referenced by bn_noise_fbm(), bn_noise_mf(), bn_noise_ridged(), and bn_noise_turb().
#define PCOPY | ( | _d, | |||
_s | ) | _d[0] = _s[0]; _d[1] = _s[1]; _d[2] = _s[2] |
Definition at line 444 of file noise.c.
Referenced by bn_noise_fbm(), bn_noise_mf(), bn_noise_ridged(), and bn_noise_turb().
void bn_noise_init | ( | ) |
Definition at line 170 of file noise.c.
References BN_RAND_TABSIZE, BN_RANDOM, BN_RANDSEED, CK_HT, str_ht::hashTable, str_ht::hashTableMagic1, str_ht::hashTableMagic2, str_ht::hashTableValid, str_ht::magic, str_ht::magic_end, MAGIC_STRHT1, MAGIC_STRHT2, MAGIC_TAB1, MAGIC_TAB2, MAXSIZE, and TABLE_SIZE.
Referenced by bn_noise_perlin(), and bn_noise_vec().
double bn_noise_perlin | ( | fastf_t * | point | ) |
Robert Skinner's Perlin-style "Noise" function.
Results are in the range [-0.5 .. 0.5]. Unlike many implementations, this function provides random noise at the integer lattice values. However this produces much poorer quality and should be avoided if possible.
The power distribution of the result has no particular shape, though it isn't as flat as the literature would have one believe.
Definition at line 234 of file noise.c.
References bn_noise_init(), Hash3d, str_ht::hashTableValid, INCRSUM, SMOOTHSTEP, X, x, Y, y, Z, and z.
void bn_noise_vec | ( | fastf_t * | point, | |
fastf_t * | result | |||
) |
Vector-valued "Noise"
Definition at line 313 of file noise.c.
References bn_noise_init(), Hash3d, str_ht::hashTableValid, INCRSUM, SMOOTHSTEP, X, x, Y, y, Z, and z.
struct fbm_spec* find_spec_wgt | ( | double | h, | |
double | l, | |||
double | o | |||
) | [read] |
The first order of business is to see if we have pre-computed the spectral weights table for these parameters in a previous invocation. If not, the we compute them and save them for possible future use
Definition at line 500 of file noise.c.
References fbm_spec::h_val, fbm_spec::lacunarity, fbm_spec::magic, MAGIC_fbm_spec_wgt, fbm_spec::octaves, and ZERO.
Referenced by bn_noise_fbm(), bn_noise_mf(), bn_noise_ridged(), and bn_noise_turb().
double bn_noise_fbm | ( | fastf_t * | point, | |
double | h_val, | |||
double | lacunarity, | |||
double | octaves | |||
) |
Procedural fBm evaluated at "point"; returns value stored in "value".
point | location to sample noise | |
``h_val'' | fractal increment parameter | |
``lacunarity'' | gap between successive frequencies | |
``octaves'' | number of frequencies in the fBm |
The spectral properties of the result are in the APPROXIMATE range [-1..1] Depending upon the number of octaves computed, this range may be exceeded. Applications should clamp or scale the result to their needs. The results have a more-or-less gaussian distribution. Typical results for 1M samples include:
The function call pow() is relatively expensive. Therfore, this function pre-computes and saves the spectral weights in a table for re-use in successive invocations.
Definition at line 568 of file noise.c.
References bn_noise_perlin(), find_spec_wgt(), PCOPY, PSCALE, fbm_spec::spec_wgts, and ZERO.
double bn_noise_turb | ( | fastf_t * | point, | |
double | h_val, | |||
double | lacunarity, | |||
double | octaves | |||
) |
Procedural turbulence evaluated at "point";.
point | location to sample noise at | |
``h_val'' | fractal increment parameter | |
``lacunarity'' | gap between successive frequencies | |
``octaves'' | number of frequencies in the fBm |
The result is characterized by sharp, narrow trenches in low values and a more fbm-like quality in the mid-high values. Values are in the APPROXIMATE range [0 .. 1] depending upon the number of octaves evaluated. Typical results:
The function call pow() is relatively expensive. Therfore, this function pre-computes and saves the spectral weights in a table for re-use in successive invocations.
Definition at line 638 of file noise.c.
References bn_noise_perlin(), find_spec_wgt(), PCOPY, PSCALE, fbm_spec::spec_wgts, and ZERO.
double bn_noise_ridged | ( | fastf_t * | point, | |
double | h_val, | |||
double | lacunarity, | |||
double | octaves, | |||
double | offset | |||
) |
A ridged noise pattern.
From "Texturing and Modeling, A Procedural Approach" 2nd ed p338
Definition at line 713 of file noise.c.
References bn_noise_perlin(), find_spec_wgt(), PCOPY, PSCALE, and fbm_spec::spec_wgts.
double bn_noise_mf | ( | fastf_t * | point, | |
double | h_val, | |||
double | lacunarity, | |||
double | octaves, | |||
double | offset | |||
) |
From "Texturing and Modeling, A Procedural Approach" 2nd ed
Definition at line 771 of file noise.c.
References bn_noise_perlin(), find_spec_wgt(), PCOPY, PSCALE, and fbm_spec::spec_wgts.