Fractional Brownian Motion
This commit is contained in:
parent
6823552ee7
commit
2afd89dbf3
2 changed files with 18 additions and 1 deletions
|
@ -44,7 +44,7 @@ PerlinNoise::PerlinNoise(unsigned int seed) : ImplicitSurface(Point(0,0,0)) {
|
|||
}
|
||||
|
||||
double PerlinNoise::operator() (double x, double y, double z) const {
|
||||
return z - noise(x, 0, y);
|
||||
return z - fBm(x, 0, y, 2, 0.3, 2.0);
|
||||
}
|
||||
|
||||
double PerlinNoise::noise(double _x, double _y, double _z) const {
|
||||
|
@ -111,6 +111,21 @@ double PerlinNoise::grad(int hash, double x, double y, double z) const {
|
|||
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
|
||||
}
|
||||
|
||||
double PerlinNoise::fBm(double x, double y, double z, int octaves, double
|
||||
lacunarity, double gain) const {
|
||||
double amplitude = 1.0;
|
||||
double frequency = 1.0;
|
||||
double sum = 0.0;
|
||||
for(int i = 0; i < octaves; ++i)
|
||||
{
|
||||
// sum += amplitude * (1-abs(noise(x * frequency, y * frequency, z * frequency)));
|
||||
sum += amplitude * noise(x * frequency, y * frequency, z * frequency);
|
||||
amplitude *= gain;
|
||||
frequency *= lacunarity;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
Point PerlinNoise::normal_vector(double x, double y) {
|
||||
double n_x_y = noise(x, y, 0);
|
||||
double n_dx_y = noise(x + 0.01, y, 0);
|
||||
|
|
|
@ -16,6 +16,8 @@ class PerlinNoise : public ImplicitSurface {
|
|||
double operator() (double _x, double _y, double _z) const;
|
||||
double noise(double x, double y) const;
|
||||
Point normal_vector(double x, double y);
|
||||
double fBm(double x, double y, double z, int octaves, double
|
||||
lacunarity, double gain) const;
|
||||
|
||||
virtual Point location_hint() const;
|
||||
Point location_hint(double x, double z) const;
|
||||
|
|
Loading…
Reference in a new issue