Fractal Noise
[libbn (numerical functions)]

Collaboration diagram for Fractal Noise:


Files

file  noise.c

Data Structures

struct  str_ht
struct  fbm_spec
double bn_noise_perlin (point_t pt)
void bn_noise_vec (point_t point, point_t result)
double bn_noise_fbm (point_t point, double h_val, double lacunarity, double octaves)
double bn_noise_turb (point_t point, double h_val, double lacunarity, double octaves)
double bn_noise_mf (point_t point, double h_val, double lacunarity, double octaves, double offset)
double bn_noise_ridged (point_t point, double h_val, double lacunarity, double octaves, double offset)

Defines

#define SMOOTHSTEP(x)   ( (x) * (x) * (3 - 2*(x)) )
 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)
#define FLOOR(x)   ( (int)(x) - ( (x) < 0 && (x) != (int)(x) ) )
#define MAXSIZE   267
#define INCRSUM(m, s, x, y, z)
#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)
fbm_specfind_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)

Define Documentation

#define SMOOTHSTEP x   )     ( (x) * (x) * (3 - 2*(x)) )
 

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 75 of file noise.c.

Referenced by bn_noise_perlin(), bn_noise_vec(), and rt_dsp_norm().

#define FLOOR x   )     ( (int)(x) - ( (x) < 0 && (x) != (int)(x) ) )
 

Definition at line 80 of file noise.c.

#define MAXSIZE   267
 

Definition at line 126 of file noise.c.

#define INCRSUM m,
s,
x,
y,
 ) 
 

Value:

((s)*(RTable[m]*0.5             \
                                        + RTable[m+1]*(x)       \
                                        + RTable[m+2]*(y)       \
                                        + RTable[m+3]*(z)))

Definition at line 133 of file noise.c.

Referenced by bn_noise_perlin(), and bn_noise_vec().

#define MAGIC_STRHT1   1771561
 

Definition at line 157 of file noise.c.

Referenced by bn_noise_init().

#define MAGIC_STRHT2   1651771
 

Definition at line 158 of file noise.c.

Referenced by bn_noise_init().

#define MAGIC_TAB1   9823
 

Definition at line 159 of file noise.c.

Referenced by bn_noise_init().

#define MAGIC_TAB2   784642
 

Definition at line 160 of file noise.c.

Referenced by bn_noise_init().

 
#define CK_HT  ) 
 

Value:

{ \
        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 != (short *)&ht.hashTableMagic1[1] ) \
                bu_bomb("ht.hashTable changed rel ht.hashTableMagic1"); \
        if (ht.hashTableMagic2 != (long *)&ht.hashTable[4096] ) \
                bu_bomb("ht.hashTable changed rel ht.hashTableMagic2"); \
}

Definition at line 161 of file noise.c.

#define Hash3d a,
b,
 ) 
 

Value:

ht.hashTable[  \
                ht.hashTable[  \
                        ht.hashTable[(a) & 0xfff] ^ ((b) & 0xfff) \
                ]  ^ ((c) & 0xfff) \
        ]
Map integer point into repeatable random number [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 178 of file noise.c.

Referenced by bn_noise_perlin(), and bn_noise_vec().

#define MAGIC_fbm_spec_wgt   0x837592
 

Definition at line 458 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 464 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 465 of file noise.c.

Referenced by bn_noise_fbm(), bn_noise_mf(), bn_noise_ridged(), and bn_noise_turb().


Function Documentation

void bn_noise_init void   ) 
 

Definition at line 187 of file noise.c.

References BN_RAND_TABSIZE, BN_RANDOM, BN_RANDSEED, bu_malloc(), BU_SEM_BN_NOISE, bu_semaphore_acquire(), bu_semaphore_release(), 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, and MAGIC_TAB2.

Referenced by bn_noise_perlin(), and bn_noise_vec().

Here is the call graph for this function:

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 253 of file noise.c.

References bn_noise_init(), Hash3d, str_ht::hashTableValid, INCRSUM, SMOOTHSTEP, X, Y, and Z.

Here is the call graph for this function:

void bn_noise_vec fastf_t point,
fastf_t result
 

Vector-valued "Noise"

Definition at line 334 of file noise.c.

References bn_noise_init(), Hash3d, str_ht::hashTableValid, INCRSUM, SMOOTHSTEP, X, Y, and Z.

Here is the call graph for this function:

struct fbm_spec* find_spec_wgt double  h,
double  l,
double  o
 

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 524 of file noise.c.

References bu_bomb(), fbm_spec::h_val, fbm_spec::lacunarity, fbm_spec::magic, MAGIC_fbm_spec_wgt, and fbm_spec::octaves.

Referenced by bn_noise_fbm(), bn_noise_mf(), bn_noise_ridged(), and bn_noise_turb().

Here is the call graph for this function:

double bn_noise_fbm fastf_t point,
double  h_val,
double  lacunarity,
double  octaves
 

Procedural fBm evaluated at "point"; returns value stored in "value".

Parameters:
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:

  • Min -1.15246
  • Max 1.23146
  • Mean -0.0138744
  • s.d. 0.306642
  • Var 0.0940295
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 585 of file noise.c.

References bn_noise_perlin(), find_spec_wgt(), int, PCOPY, PSCALE, fbm_spec::remainder, fbm_spec::spec_wgts, and value.

Here is the call graph for this function:

double bn_noise_turb fastf_t point,
double  h_val,
double  lacunarity,
double  octaves
 

Procedural turbulence evaluated at "point";.

Returns:
turbulence value for point
Parameters:
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:
 Min         0.00857137
 Max            1.26712
 Mean          0.395122
 s.d.          0.174796
 Var          0.0305536
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 655 of file noise.c.

References bn_noise_perlin(), find_spec_wgt(), int, PCOPY, PSCALE, fbm_spec::spec_wgts, and value.

Here is the call graph for this function:

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 730 of file noise.c.

References bn_noise_perlin(), find_spec_wgt(), PCOPY, PSCALE, and fbm_spec::spec_wgts.

Here is the call graph for this function:

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 789 of file noise.c.

References bn_noise_perlin(), find_spec_wgt(), PCOPY, PSCALE, and fbm_spec::spec_wgts.

Here is the call graph for this function:

double bn_noise_perlin point_t  pt  ) 
 

Referenced by bn_cmd_noise_perlin(), bn_noise_fbm(), bn_noise_mf(), bn_noise_ridged(), and bn_noise_turb().

void bn_noise_vec point_t  point,
point_t  result
 

double bn_noise_fbm point_t  point,
double  h_val,
double  lacunarity,
double  octaves
 

Referenced by bn_cmd_noise(), and bn_cmd_noise_slice().

double bn_noise_turb point_t  point,
double  h_val,
double  lacunarity,
double  octaves
 

Referenced by bn_cmd_noise().

double bn_noise_mf point_t  point,
double  h_val,
double  lacunarity,
double  octaves,
double  offset
 

double bn_noise_ridged point_t  point,
double  h_val,
double  lacunarity,
double  octaves,
double  offset
 


Generated on Mon Sep 18 01:25:23 2006 for BRL-CAD by  doxygen 1.4.6