Razaekel / noise-rs

Procedural noise generation library for Rust.
Apache License 2.0
843 stars 119 forks source link

Perlin noise generator returns only 0 #248

Closed fenjalien closed 3 years ago

fenjalien commented 3 years ago

The following code for me prints 0 for each value

use noise::{NoiseFn, Perlin, Seedable};

fn main() {
    let perlin = Perlin::new().set_seed(100);

    for x in 0..10 {
        for y in 0..10 {
            println!("({}, {}) = {}", x, y, perlin.get([x as f64, y as f64]));
        }
    }
}

The active toolchain is stable-x86_64-unknown-linux-gnu with rustc at version 1.52.1 Other generators like Value and OpenSimplex don't have this behaviour. Changing the seed and version of noise-rs doesn't help.

Razaekel commented 3 years ago

Perlin noise produces zero values when sampled along lattice coordinates, i.e. at integer values for x or y. To resolve this, you could add an offset to the sampled coordinates, something like:

perlin.get([x as f64 + 0.5, y as f64 + 0.5]);

I'll have to add a note stating this zero result at lattice coordinates for the future.