]> git.localhorst.tv Git - blank.git/blobdiff - src/noise.hpp
use 3 octaves for solid generation noise
[blank.git] / src / noise.hpp
index 166a60a71058b998d60df732f752259b993beea4..26e37668b00f609fdfd2747a2ed6a3e044031729 100644 (file)
@@ -35,6 +35,7 @@ private:
 
 };
 
+
 /// (3D only) adaptation of Stefan Gustavson's SimplexNoise java class
 class SimplexNoise {
 
@@ -68,6 +69,29 @@ private:
 
 };
 
+
+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