Antkeeper  0.0.1
fbm.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_MATH_NOISE_FBM_HPP
21 #define ANTKEEPER_MATH_NOISE_FBM_HPP
22 
24 #include <engine/math/hash/pcg.hpp>
26 #include <engine/math/vector.hpp>
27 #include <cstdint>
28 
29 namespace math {
30 namespace noise {
31 
46 template <class T, std::size_t N>
47 [[nodiscard]] T fbm
48 (
50  std::size_t octaves,
51  T lacunarity,
52  T gain,
53  T (*noise)(const vector<T, N>&, vector<hash::make_uint_t<T>, N> (*)(const vector<T, N>&)) = &simplex<T, N>,
54  vector<hash::make_uint_t<T>, N> (*hash)(const vector<T, N>&) = &hash::pcg<T, N>
55 )
56 {
57  T amplitude{1};
58  T value{0};
59 
60  while (octaves--)
61  {
62  value += noise(position, hash) * amplitude;
63  position *= lacunarity;
64  amplitude *= gain;
65  }
66 
67  return value;
68 }
69 
70 } // namespace noise
71 } // namespace math
72 
73 #endif // ANTKEEPER_MATH_NOISE_FBM_HPP
Hash functions.
Definition: fnv1a.hpp:29
typename make_uint< T >::type make_uint_t
Helper type for make_uint.
Definition: make-uint.hpp:63
T fbm(vector< T, N > position, std::size_t octaves, T lacunarity, T gain, T(*noise)(const vector< T, N > &, vector< hash::make_uint_t< T >, N >(*)(const vector< T, N > &))=&simplex< T, N >, vector< hash::make_uint_t< T >, N >(*hash)(const vector< T, N > &)=&hash::pcg< T, N >)
Fractional Brownian motion (fBm).
Definition: fbm.hpp:48
Mathematical functions and data types.
Definition: angles.hpp:26
n-dimensional vector.
Definition: vector.hpp:44