]> git.localhorst.tv Git - blank.git/commitdiff
use 3 octaves for solid generation noise
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 23 Mar 2015 22:28:41 +0000 (23:28 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 23 Mar 2015 22:28:41 +0000 (23:28 +0100)
also, that other perlin implementation sucked noodles

TODO
src/generator.cpp
src/generator.hpp
src/noise.cpp
src/noise.hpp

diff --git a/TODO b/TODO
index 244e938c259c8283cafa73b09be54cbeba6fb3db..363c635551cfa384065abbd85e03f87b86e79f9e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -79,5 +79,3 @@ entity/world collision
 better noise
 
        current simplex noise implementation repeats itself pretty quickly
-       also there seems to be a (imo) better implementation here:
-       http://flafla2.github.io/2014/08/09/perlinnoise.html
index 43d932cceae421473bc391820370c36dccc1fac7..dc83b89b7c681a541aef9374595967501592f8f7 100644 (file)
@@ -8,7 +8,7 @@ namespace blank {
 Generator::Generator(const Config &config)
 : solidNoise(config.solid_seed)
 , typeNoise(config.type_seed)
-, stretch(config.stretch)
+, stretch(1.0f/config.stretch)
 , solid_threshold(config.solid_threshold)
 , space(0)
 , light(0)
@@ -25,8 +25,8 @@ void Generator::operator ()(Chunk &chunk) const {
                for (int y = 0; y < Chunk::Height(); ++y) {
                        for (int x = 0; x < Chunk::Width(); ++x) {
                                Block::Pos block_pos(x, y, z);
-                               glm::vec3 gen_pos = (coords + block_pos) / stretch;
-                               float val = solidNoise(gen_pos);
+                               glm::vec3 gen_pos = (coords + block_pos) * stretch;
+                               float val = OctaveNoise(solidNoise, coords + block_pos, 3, 0.5f, stretch, 2.0f);
                                if (val > solid_threshold) {
                                        int type_val = int((typeNoise(gen_pos) + 1.0f) * solids.size()) % solids.size();
                                        chunk.SetBlock(block_pos, Block(solids[type_val]));
index 3d7ceaff801d82bc2d16e011b4e4d844d4a4a801..70c38f59941e517e62de8a9a6920db9610c235f4 100644 (file)
@@ -17,7 +17,7 @@ public:
                unsigned int solid_seed = 0;
                unsigned int type_seed = 0;
                float stretch = 64.0f;
-               float solid_threshold = 0.8f;
+               float solid_threshold = 0.5f;
        };
 
        explicit Generator(const Config &);
index 6d59224c2f41f4de89ae982627387fcacd7235a2..8b716140e78c5b301fbd00a383778eb482e9166f 100644 (file)
@@ -45,10 +45,9 @@ SimplexNoise::SimplexNoise(unsigned int seed)
        {  0.0f,  1.0f, -1.0f },
        {  0.0f, -1.0f, -1.0f },
 }) {
-       unsigned int val = seed;
+       GaloisLFSR random(seed ^ 0x0123456789ACBDEF);
        for (size_t i = 0; i < 256; ++i) {
-               val = 2346765 * val + 6446345;
-               perm[i] = val % 256;
+               random(perm[i]);
                perm[i + 256] = perm[i];
        }
 }
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