]> git.localhorst.tv Git - tacos.git/blobdiff - src/rand/OctaveNoise.hpp
basic floor idea
[tacos.git] / src / rand / OctaveNoise.hpp
diff --git a/src/rand/OctaveNoise.hpp b/src/rand/OctaveNoise.hpp
new file mode 100644 (file)
index 0000000..bcd872e
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef TACOS_RAND_OCTAVENOISE_HPP_
+#define TACOS_RAND_OCTAVENOISE_HPP_
+
+#include <glm/glm.hpp>
+
+
+namespace tacos {
+
+template<class Noise>
+float OctaveNoise(
+       const Noise &noise,
+       const glm::vec3 &in,
+       int num,
+       float persistence,
+       float frequency = 1.0f,
+       float amplitude = 1.0f,
+       float growth = 2.0f
+) {
+       float total = 0.0f;
+       float max = 0.0f;
+       for (int i = 0; i < num; ++i) {
+               total += noise(in * frequency) * amplitude;
+               max += amplitude;
+               amplitude *= persistence;
+               frequency *= growth;
+       }
+
+       return total / max;
+}
+
+}
+
+#endif