BRL-CAD
Collaboration diagram for Fractal Noise:

Files

file  noise.c
 

Data Structures

struct  str_ht
 
struct  fbm_spec
 

Macros

#define SMOOTHSTEP(x)   ((x) * (x) * (3 - 2*(x)))
 interpolate smoothly from 0 .. 1 More...
 
#define MAXSIZE   267 /* 255 + 3 * (4 values) */
 
#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)
 These noise functions provide mostly random noise at the integer lattice points. The functions should be evaluated at non-integer locations for their nature to be realized. More...
 
double bn_noise_perlin (point_t pt)
 Robert Skinner's Perlin-style "Noise" function. More...
 
void bn_noise_vec (point_t point, point_t result)
 
double bn_noise_fbm (point_t point, double h_val, double lacunarity, double octaves)
 Procedural fBm evaluated at "point"; returns value stored in "value". More...
 
double bn_noise_turb (point_t point, double h_val, double lacunarity, double octaves)
 Procedural turbulence evaluated at "point";. More...
 
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)
 A ridged noise pattern. More...
 
double bn_noise_perlin (fastf_t *point)
 
void bn_noise_vec (fastf_t *point, fastf_t *result)
 
struct fbm_specfind_spec_wgt (double h, double l, double o)
 
double bn_noise_fbm (fastf_t *point, double h_val, double lacunarity, double octaves)
 
double bn_noise_turb (fastf_t *point, double h_val, double lacunarity, double octaves)
 
double bn_noise_ridged (fastf_t *point, double h_val, double lacunarity, double octaves, double offset)
 
double bn_noise_mf (fastf_t *point, double h_val, double lacunarity, double octaves, double offset)
 

Detailed Description

Macro Definition 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 55 of file noise.c.

Referenced by bn_noise_perlin(), and bn_noise_vec().

#define MAXSIZE   267 /* 255 + 3 * (4 values) */

Definition at line 109 of file noise.c.

Referenced by bn_noise_init().

#define INCRSUM (   m,
  s,
  x,
  y,
 
)
Value:
((s)*(RTable[m]*0.5 \
+ RTable[m+1]*(x) \
+ RTable[m+2]*(y) \
+ RTable[m+3]*(z)))
if lu s
Definition: nmg_mod.c:3860

Definition at line 116 of file noise.c.

Referenced by bn_noise_perlin(), and bn_noise_vec().

#define TABLE_SIZE   4096

Definition at line 139 of file noise.c.

Referenced by bn_noise_init().

#define MAGIC_STRHT1   1771561

Definition at line 141 of file noise.c.

Referenced by bn_noise_init().

#define MAGIC_STRHT2   1651771

Definition at line 142 of file noise.c.

Referenced by bn_noise_init().

#define MAGIC_TAB1   9823

Definition at line 143 of file noise.c.

Referenced by bn_noise_init().

#define MAGIC_TAB2   784642

Definition at line 144 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"); \
bu_bomb("ht.hashTable changed rel ht.hashTableMagic1"); \
bu_bomb("ht.hashTable changed rel ht.hashTableMagic2"); \
}
uint32_t magic_end
Definition: noise.c:134
#define MAGIC_STRHT1
Definition: noise.c:141
#define BU_CKMAG(_ptr, _magic, _str)
Definition: magic.h:233
#define MAGIC_STRHT2
Definition: noise.c:142
uint32_t magic
Definition: noise.c:129
if(share_geom)
Definition: nmg_mod.c:3829
#define MAGIC_TAB1
Definition: noise.c:143
uint32_t * hashTableMagic1
Definition: noise.c:131
#define MAGIC_TAB2
Definition: noise.c:144
uint32_t * hashTable
Definition: noise.c:132
#define TABLE_SIZE
Definition: noise.c:139
uint32_t * hashTableMagic2
Definition: noise.c:133
void bu_bomb(const char *str) _BU_ATTR_NORETURN
Definition: bomb.c:91

Definition at line 145 of file noise.c.

Referenced by bn_noise_init().

#define Hash3d (   a,
  b,
 
)
Value:
ht.hashTable[ \
ht.hashTable[ \
ht.hashTable[(a) & 0xfff] ^ ((b) & 0xfff) \
] ^ ((c) & 0xfff) \
]
uint32_t * hashTable
Definition: noise.c:132

Map integer point into repeatable random number 0..TABLE_SIZE-1. 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 164 of file noise.c.

Referenced by bn_noise_perlin(), and bn_noise_vec().

#define MAGIC_fbm_spec_wgt   0x837592

Definition at line 422 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 428 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 429 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  )

These noise functions provide mostly random noise at the integer lattice points. The functions should be evaluated at non-integer locations for their nature to be realized.

Contains contributed code from: F. Kenton Musgrave Robert Skinner

Definition at line 173 of file noise.c.

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

Here is the call graph for this function:

double bn_noise_perlin ( point_t  pt)

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.

Referenced by bn_cmd_noise_perlin().

void bn_noise_vec ( point_t  point,
point_t  result 
)

Vector-valued "Noise"

Referenced by fbm_render().

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

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

Parameters
pointlocation to sample noise
<tt>h_val''fractal increment parameter @paramlacunarity'' 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. Therefore, this function pre-computes and saves the spectral weights in a table for re-use in successive invocations.

Referenced by bn_cmd_noise(), bn_cmd_noise_slice(), camo_render(), fractal_render(), and tsplat_render().

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

Procedural turbulence evaluated at "point";.

Returns
turbulence value for point
Parameters
pointlocation to sample noise at
<tt>h_val''fractal increment parameter @paramlacunarity'' 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:

1 Min 0.00857137
2 Max 1.26712
3 Mean 0.395122
4 s.d. 0.174796
5 Var 0.0305536

The function call pow() is relatively expensive. Therefore, this function pre-computes and saves the spectral weights in a table for re-use in successive invocations.

Referenced by bn_cmd_noise(), bn_cmd_noise_slice(), fire_render(), fractal_render(), marble_render(), and scloud_render().

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

From "Texturing and Modeling, A Procedural Approach" 2nd ed

double bn_noise_ridged ( point_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

double bn_noise_perlin ( fastf_t point)

Definition at line 225 of file noise.c.

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

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

Here is the call graph for this function:

void bn_noise_vec ( fastf_t point,
fastf_t result 
)

Definition at line 302 of file noise.c.

References bn_noise_init(), Hash3d, str_ht::hashTableValid, INCRSUM, s, 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, then we compute them and save them for possible future use

Definition at line 487 of file noise.c.

References bu_bomb(), BU_SEM_BN_NOISE, bu_semaphore_acquire(), bu_semaphore_release(), 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 
)

Definition at line 535 of file noise.c.

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

Here is the call graph for this function:

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

Definition at line 579 of file noise.c.

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

Here is the call graph for this function:

double bn_noise_ridged ( fastf_t point,
double  h_val,
double  lacunarity,
double  octaves,
double  offset 
)

Definition at line 632 of file noise.c.

References bn_noise_perlin(), find_spec_wgt(), fbm_spec::octaves, 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 
)

Definition at line 687 of file noise.c.

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

Here is the call graph for this function: