bracket-lib icon indicating copy to clipboard operation
bracket-lib copied to clipboard

Fractal noise scaling

Open gwafotapa opened this issue 2 years ago • 0 comments

When computing a fractal noise, the sum of all octaves is normalized by dividing it by the sum of the amplitudes of the octaves. Here's the code of the function which computes the normalizing factor amp_fractal:

    fn calculate_fractal_bounding(&mut self) {
        let mut amp: f32 = self.gain;
        let mut amp_fractal: f32 = 1.0;
        for _ in 0..self.octaves {
            amp_fractal += amp;
            amp *= self.gain;
        }
        self.fractal_bounding = 1.0 / amp_fractal;
    }

The computed sum amp_fractal has one more term than the number of octaves. I believe this is wrong. For example, in the particular case where you have one octave only, it ends up rescaling the noise by dividing it by (1 + gain) as if we had two octaves when it should divide by 1 instead (i.e. no normalization needed since there's only one octave). This can be confirmed by looking at Auburn's original code.

gwafotapa avatar Feb 02 '23 21:02 gwafotapa