rust-simd-noise icon indicating copy to clipboard operation
rust-simd-noise copied to clipboard

Grid-like artifacts in turbulence_3d.

Open virtualritz opened this issue 5 years ago • 9 comments
trafficstars

Below is a screenshot from a slice of turbulence_3d using default parameters except octaves, which is set to 8. There are some pretty obvious grid-like artifacts at 45 deg angles. This is not what turbulence is supposed to look like. Call generating the attached image:

let z_offset = 10; // will be animated later
...
let noise = simdnoise::NoiseBuilder::turbulence_3d_offset(
        z_offset,
        1,
        0.0,
        1920,
        0.0,
        1080,
    )
    .with_octaves(8)
    .generate_scaled(0.0, 255.0);

Screen Shot 2020-05-09 at 04 27 38

virtualritz avatar May 09 '20 02:05 virtualritz

interesting, I'll double check the turbulence code. Have you taken a look, any ideas?

jackmott avatar May 09 '20 16:05 jackmott

Well it doesn't happen in 2d, but does in 3d or 4d, so that is a clue.

jackmott avatar May 09 '20 21:05 jackmott

It looks like a bug in the simplex3d/4d itself

jackmott avatar May 09 '20 21:05 jackmott

probably related to how I am hashing in grad3d/4d, looking into it

jackmott avatar May 09 '20 22:05 jackmott

I like how you update the ticket while debugging. People should make this a habit.

virtualritz avatar May 10 '20 00:05 virtualritz

Any findings?

virtualritz avatar May 26 '20 23:05 virtualritz

I've made some progress, just slow, because life.

jackmott avatar May 27 '20 00:05 jackmott

Ok this should be fixed in the 3d case in the latest version and master branch. Let me know how it looks for you, if all is well I'll apply the same process to the 4d case.

jackmott avatar May 30 '20 18:05 jackmott

This still happens, but it becomes more pronounced with slightly higher frequency and lower octaves.

diagonals

Code that produces the image
use minifb::{Key, Window, WindowOptions};

const WIDTH: usize = 2048;
const HEIGHT: usize = 1024;

const FREQ: f32 = 0.125;
const OCTAVES: u8 = 6;

fn get_buffer() -> Vec<u32> {
    let noise = simdnoise::NoiseBuilder::turbulence_3d_offset(0.0, WIDTH, 0.0, HEIGHT, 0.0, 1)
        .with_freq(FREQ)
        .with_octaves(OCTAVES)
        .generate_scaled(0.0, 255.0);

    noise.iter().map(|x| *x as u32 * 0x00010101).collect()
}

fn main() {
    let buffer = get_buffer();

    let mut window = Window::new(
        "Test - ESC to exit",
        WIDTH,
        HEIGHT,
        WindowOptions::default(),
    )
    .unwrap_or_else(|e| {
        panic!("{}", e);
    });

    // Limit to max ~60 fps update rate
    window.limit_update_rate(Some(std::time::Duration::from_micros(16600)));

    while window.is_open() && !window.is_key_down(Key::Escape) {
        // We unwrap here as we want this code to exit if it fails. Real applications may want to handle this in a different way
        window.update_with_buffer(&buffer, WIDTH, HEIGHT).unwrap();
    }
}

parasyte avatar Jan 30 '22 05:01 parasyte