float turbulence_2d(int octaves, float lacunarity, float gain, float scale, float x, float y) { float total = 0.f; float amplitude = 1.f; float max = 0.f; for(int i = 0; i < octaves; ++i) { max += amplitude; total += fabs(raw_noise_2d(x * scale, y * scale)) * amplitude; scale *= lacunarity; amplitude *= gain; } return total / max; }
// 2D Multi-octave Simplex noise. // // For each octave, a higher frequency/lower amplitude function will be added to the original. // The higher the persistence [0-1], the more of each succeeding octave will be added. float octave_noise_2d( const float octaves, const float persistence, const float scale, const float x, const float y ) { float total = 0; float frequency = scale; float amplitude = 1; // We have to keep track of the largest possible amplitude, // because each octave adds more, and we need a value in [-1, 1]. float maxAmplitude = 0; for( int i = 0; i < octaves; i++ ) { total += raw_noise_2d( x * frequency, y * frequency ) * amplitude; frequency *= 2; maxAmplitude += amplitude; amplitude *= persistence; } return total / maxAmplitude; }
double Simplex::raw_2d(const double& x, const double& y) { return raw_noise_2d(x,y); }
// 2D Scaled Simplex raw noise. // // Returned value will be between loBound and hiBound. double scaled_raw_noise_2d( const double loBound, const double hiBound, const double x, const double y ) { return raw_noise_2d(x, y) * (hiBound - loBound) / 2 + (hiBound + loBound) / 2; }
// 2D Scaled Simplex raw noise. // // Returned value will be between loBound and hiBound. float scaled_raw_noise_2d( const float loBound, const float hiBound, const float x, const float y ) { return raw_noise_2d(x, y) * (hiBound - loBound) / 2 + (hiBound + loBound) / 2; }