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
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)
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]));
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 &);
{ 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];
}
}
};
+
/// (3D only) adaptation of Stefan Gustavson's SimplexNoise java class
class SimplexNoise {
};
+
+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