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.
| 348 | // For each octave, a higher frequency/lower amplitude function will be added to the original. |
| 349 | // The higher the persistence [0-1], the more of each succeeding octave will be added. |
| 350 | float SimplexNoise(const int octaves, const float persistence, const float scale, const float2 &v) { |
| 351 | float total = 0; |
| 352 | float frequency = scale; |
| 353 | float amplitude = 1; |
| 354 | // We have to keep track of the largest possible amplitude, |
| 355 | // because each octave adds more, and we need a value in [-1, 1]. |
| 356 | float maxAmplitude = 0; |
| 357 | for( int i=0; i < octaves; i++ ) { |
| 358 | total += SimplexRawNoise(v.x * frequency, v.y * frequency) * amplitude; |
| 359 | frequency *= 2; |
| 360 | maxAmplitude += amplitude; |
| 361 | amplitude *= persistence; |
| 362 | } |
| 363 | return total / maxAmplitude; |
| 364 | } |
| 365 | |
| 366 | // 3D Multi-octave Simplex noise. |
| 367 | // |
no test coverage detected