Razaekel / noise-rs

Procedural noise generation library for Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

the method get() of perlin's noise will always be 0 when x, y >=1

lishaoxia1985 opened this issue · comments

let perlin = Perlin::new(1000);
let x_size = 1024;
let y_size = 1024;
for y in 0..y_size {
        for x in 0..x_size {
            let p = [x as f64, y as f64];
            let perlin_value = perlin.get(p);
            dbg!(perlin_value);
       }
}

it will always print "perlin_value = 0.0". That means you should use this:

for y in 0..y_size {
        for x in 0..x_size {
            let p = [x as f64 / x_size as f64, y as f64 / y_size as f64];
            let perlin_value = perlin.get(p);
            dbg!(perlin_value);
       }
}

This is differernt with other noise (e.g. worley).
We should add some comment to describe this.

Thanks for commenting this, I was really confused why my code was just spitting out zeroes.

what if my use-case has x_size = infinity? (like for procedurally generating terrain)

You could probably just get away with adding an offset or just divide by 10000 or something. There isn't really anything special about dividing by your world size, you just need to avoid only sampling on whole numbers.

@amaranth hello, do you think my issue is a bug?
No I have find another problem:
RidgedMulti is only used in the Worley noise whose return type is Value, because you can't set return type when you use Worley noise in RidgedMulti.

The problem you are reporting is the normal behaviour of Perlin noise. Perlin noise returns 0 when sampled on whole numbers. Your second example works because all the samples are fractional numbers. More info here.

@PrinceOfBorgo Thank you😂
Do you think we should add some comment to describe this?