VoxelEngine
 
Loading...
Searching...
No Matches
PerlinNoise.h
1#pragma once
2
3#include <FastNoise/FastNoise.h>
4
5#include <glm/glm.hpp>
6
7#include <cstddef>
8#include <cstdint>
9
10namespace engine {
11
13 public:
14 using Seed = uint64_t;
16 Seed seed,
17 float scale,
18 float offset,
19 uint32_t octaves = 1,
20 float persistence = 0.5f,
21 float lacunarity = 2.0f
22 );
23
24 float get2D(float x, float y) const noexcept;
25 float get2DNormalized(float x, float y) const noexcept;
26 void genArea2D(float* out, glm::ivec2 start, glm::ivec2 dims) const noexcept;
27
28 float get3D(float x, float y, float z) const noexcept;
29 float get3DNormalized(float x, float y, float z) const noexcept;
30 void genArea3D(float* out, glm::ivec3 start, glm::ivec3 dims) const noexcept;
31
32 float get4D(float x, float y, float z, float w) const noexcept;
33 float get4DNormalized(float x, float y, float z, float w) const noexcept;
34 void genArea4D(float* out, glm::ivec4 start, glm::ivec4 dims) const noexcept;
35 void genPositions4D(
36 float* out,
37 const float* inX,
38 const float* inY,
39 const float* inZ,
40 const float* inW,
41 size_t count
42 ) const noexcept;
43
44 private:
45 FastNoise::SmartNode<FastNoise::FractalFBm> m_noise;
46 Seed m_seed;
47 float m_offset;
48 uint32_t m_octaves;
49
50 float m_maxAmplitude;
51
52 static constexpr float MaxAmplitude(
53 const uint32_t octaves, const float persistence
54 ) noexcept {
55 float result = 0;
56 float amplitude = 1;
57
58 for (uint32_t i = 0; i < octaves; ++i) {
59 result += amplitude;
60 amplitude *= persistence;
61 }
62
63 return result;
64 }
65 };
66
67} // namespace engine
Definition PerlinNoise.h:12