BRL-CAD
noise.h
Go to the documentation of this file.
1/* N O I S E . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21
22/**
23 * @addtogroup bn_noise
24 *
25 * @brief
26 * These noise functions provide mostly random noise at the integer
27 * lattice points.
28 *
29 * The functions should be evaluated at non-integer
30 * locations for their nature to be realized.
31 *
32 * Contains contributed code from:
33 * F. Kenton Musgrave
34 * Robert Skinner
35 *
36 */
37/** @{ */
38/* @file noise.h */
39
40#ifndef BN_NOISE_H
41#define BN_NOISE_H
42
43#include "common.h"
44#include "vmath.h"
45#include "bn/defines.h"
46
47__BEGIN_DECLS
48
49/*
50 * fractal noise support
51 */
52
53BN_EXPORT extern void bn_noise_init(void);
54
55/**
56 *@brief
57 * Robert Skinner's Perlin-style "Noise" function
58 *
59 * Results are in the range [-0.5 .. 0.5]. Unlike many
60 * implementations, this function provides random noise at the integer
61 * lattice values. However this produces much poorer quality and
62 * should be avoided if possible.
63 *
64 * The power distribution of the result has no particular shape,
65 * though it isn't as flat as the literature would have one believe.
66 */
67BN_EXPORT extern double bn_noise_perlin(point_t pt);
68
69/* FIXME: Why isn't the result listed first? */
70
71/**
72 * Vector-valued "Noise"
73 */
74BN_EXPORT extern void bn_noise_vec(point_t point,
75 point_t result);
76
77/**
78 * @brief
79 * Procedural fBm evaluated at "point"; returns value stored in
80 * "value".
81 *
82 * @param point location to sample noise
83 * @param h_val fractal increment parameter
84 * @param lacunarity gap between successive frequencies
85 * @param octaves number of frequencies in the fBm
86 *
87 * The spectral properties of the result are in the APPROXIMATE range
88 * [-1..1] Depending upon the number of octaves computed, this range
89 * may be exceeded. Applications should clamp or scale the result to
90 * their needs. The results have a more-or-less gaussian
91 * distribution. Typical results for 1M samples include:
92 *
93 * @li Min -1.15246
94 * @li Max 1.23146
95 * @li Mean -0.0138744
96 * @li s.d. 0.306642
97 * @li Var 0.0940295
98 *
99 * The function call pow() is relatively expensive. Therefore, this
100 * function pre-computes and saves the spectral weights in a table for
101 * re-use in successive invocations.
102 */
103BN_EXPORT extern double bn_noise_fbm(point_t point,
104 double h_val,
105 double lacunarity,
106 double octaves);
107
108/**
109 * @brief
110 * Procedural turbulence evaluated at "point";
111 *
112 * @return turbulence value for point
113 *
114 * @param point location to sample noise at
115 * @param h_val fractal increment parameter
116 * @param lacunarity gap between successive frequencies
117 * @param octaves number of frequencies in the fBm
118 *
119 * The result is characterized by sharp, narrow trenches in low values
120 * and a more fbm-like quality in the mid-high values. Values are in
121 * the APPROXIMATE range [0 .. 1] depending upon the number of octaves
122 * evaluated. Typical results:
123 @code
124 * Min 0.00857137
125 * Max 1.26712
126 * Mean 0.395122
127 * s.d. 0.174796
128 * Var 0.0305536
129 @endcode
130 * The function call pow() is relatively expensive. Therefore, this
131 * function pre-computes and saves the spectral weights in a table for
132 * re-use in successive invocations.
133 */
134BN_EXPORT extern double bn_noise_turb(point_t point,
135 double h_val,
136 double lacunarity,
137 double octaves);
138
139/**
140 * From "Texturing and Modeling, A Procedural Approach" 2nd ed
141 */
142BN_EXPORT extern double bn_noise_mf(point_t point,
143 double h_val,
144 double lacunarity,
145 double octaves,
146 double offset);
147
148/**
149 *@brief
150 * A ridged noise pattern
151 *
152 * From "Texturing and Modeling, A Procedural Approach" 2nd ed p338
153 */
154BN_EXPORT extern double bn_noise_ridged(point_t point,
155 double h_val,
156 double lacunarity,
157 double octaves,
158 double offset);
159
160__END_DECLS
161
162#endif /* BN_NOISE_H */
163/** @} */
164/*
165 * Local Variables:
166 * mode: C
167 * tab-width: 8
168 * indent-tabs-mode: t
169 * c-file-style: "stroustrup"
170 * End:
171 * ex: shiftwidth=4 tabstop=8
172 */
Header file for the BRL-CAD common definitions.
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.
double bn_noise_turb(point_t point, double h_val, double lacunarity, double octaves)
Procedural turbulence evaluated at "point";.
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".
double bn_noise_perlin(point_t pt)
Robert Skinner's Perlin-style "Noise" function.
void bn_noise_init(void)
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition: vmath.h:351
fundamental vector, matrix, quaternion math macros