]> git.localhorst.tv Git - blobs.git/blob - src/math/OctaveNoise.hpp
randomize creature properties a bit
[blobs.git] / src / math / OctaveNoise.hpp
1 #ifndef BLOBS_MATH_OCTAVENOISE_HPP_
2 #define BLOBS_MATH_OCTAVENOISE_HPP_
3
4 #include "glm.hpp"
5
6
7 namespace blobs {
8 namespace math {
9
10 template<class Noise>
11 float OctaveNoise(
12         const Noise &noise,
13         const glm::vec3 &in,
14         int num,
15         float persistence,
16         float frequency = 1.0f,
17         float amplitude = 1.0f,
18         float growth = 2.0f
19 ) {
20         float total = 0.0f;
21         float max = 0.0f;
22         for (int i = 0; i < num; ++i) {
23                 total += noise(in * frequency) * amplitude;
24                 max += amplitude;
25                 amplitude *= persistence;
26                 frequency *= growth;
27         }
28
29         return total / max;
30 }
31
32 }
33 }
34
35 #endif