5个版本

0.2.4 2024年4月6日
0.2.3 2024年4月4日
0.2.1 2024年4月4日
0.2.0 2024年4月4日
0.1.0 2024年4月4日

#360 in 算法

Download history 27/week @ 2024-04-14 2/week @ 2024-04-21 25/week @ 2024-04-28 1/week @ 2024-05-05 9/week @ 2024-05-12 16/week @ 2024-05-19 5/week @ 2024-05-26 16/week @ 2024-06-02 24/week @ 2024-06-09 24/week @ 2024-06-16 15/week @ 2024-06-23 21/week @ 2024-06-30 24/week @ 2024-07-07 24/week @ 2024-07-14 19/week @ 2024-07-21 53/week @ 2024-07-28

123 每月下载次数

MIT 许可证

1MB
1.5K SLoC

这是一个程序噪声的集合,用于CPU射线追踪以及作为程序艺术和纹理的构建模块。

噪声针对速度进行了优化。大多数噪声都可用在所有四个维度(1D、2D、3D、4D),一些噪声仅在特定维度可用(或仍在开发中)。

所有噪声都有相同的签名,以便可以将它们作为参数传递给提供的分形函数。所有函数返回的值在-1.0和1.0之间。

此库没有外部依赖。

这些图像由lib.rs文件中的测试生成。您可以在那里看到每个噪声的示例。

例如,Perlin噪声图像是通过以下方式生成的

fn generate_perlin_image() {
    let seed = 1;
    let mut rng = UniformRandomGen::new(seed);

    let width = 256;
    let height = 256;
    let img = ImageBuffer::from_fn(width, height, |x, y| {
        let noise_val = perlin_noise_2d(
            &mut rng,
            x as f32 / width as f32 * 10.0,
            y as f32 / height as f32 * 10.0,
            seed,
        );
        let normalized_val = ((noise_val + 1.0) / 2.0 * 255.0) as u8;
        Luma([normalized_val])
    });

    img.save("images/perlin.png").expect("Failed to save image");
}

此库目前正在开发中。更多噪声和分形函数正在开发中。

噪声函数

随机

Random

pub fn random_noise_1d(rng: &mut UniformRandomGen, x: f32, seed: u32) -> f32;

pub fn random_noise_2d(rng: &mut UniformRandomGen, x: f32, y: f32, seed: u32) -> f32;

pub fn random_noise_3d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, seed: u32) -> f32;

pub fn random_noise_4d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, t: f32, seed: u32) -> f32;

随机过滤

Random Filtered

pub fn random_noise_filtered_1d(rng: &mut UniformRandomGen, x: f32, seed: u32) -> f32;

pub fn random_noise_filtered_2d(rng: &mut UniformRandomGen, x: f32, y: f32, seed: u32) -> f32;

pub fn random_noise_filtered_3d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, seed: u32) -> f32;

pub fn random_noise_filtered_4d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, t: f32, seed: u32) -> f32;

Perlin

Perlin

pub fn perlin_noise_1d(rng: &mut UniformRandomGen, x: f32, seed: u32) -> f32;

pub fn perlin_noise_2d(rng: &mut UniformRandomGen, x: f32, y: f32, seed: u32) -> f32;

pub fn perlin_noise_3d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, seed: u32) -> f32;

pub fn perlin_noise_4d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, t: f32, seed: u32) -> f32;

Musgrave

Musgrave

pub fn musgrave_noise_1d(rng: &mut UniformRandomGen, x: f32, seed: u32) -> f32;

pub fn musgrave_noise_2d(rng: &mut UniformRandomGen, x: f32, y: f32, seed: u32) -> f32;

pub fn musgrave_noise_3d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, seed: u32) -> f32;

pub fn musgrave_noise_4d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, t: f32, seed: u32) -> f32;

Simplex

Musgrave

pub fn simplex_noise_1d(rng: &mut UniformRandomGen, x: f32, seed: u32) -> f32;

pub fn simplex_noise_2d(rng: &mut UniformRandomGen, x: f32, y: f32, seed: u32) -> f32;

pub fn simplex_noise_3d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, seed: u32) -> f32;

pub fn simplex_noise_4d(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, t: f32, seed: u32) -> f32;

Worley F1

Musgrave

pub fn worley_f1_noise_2d(rng: &mut UniformRandomGen, x: f32, y: f32, seed: u32) -> f32;

分形函数

分形加

PerlinAdd Perlin

MusgraveAdd Musgrave

SimplexAdd Simplex

WorleyF1Add Worley F1

pub fn fractal_noise_add_1d<F: Fn(&mut UniformRandomGen, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, seed: u32) -> f32

pub fn fractal_noise_add_2d<F: Fn(&mut UniformRandomGen, f32, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, y: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, seed: u32) -> f32;

pub fn fractal_noise_add_3d<F: Fn(&mut UniformRandomGen, f32, f32, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, seed: u32) -> f32;

pub fn fractal_noise_add_4d<F: Fn(&mut UniformRandomGen, f32, f32, f32, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, t: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, seed: u32) -> f32;

分形加绝对值

PerlinAddAbs Perlin

MusgraveAddAbs Musgrave

SimplexAddAbs Simplex

WorleyF1AddAbs Worley F1

pub fn fractal_noise_add_abs_1d<F: Fn(&mut UniformRandomGen, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, seed: u32) -> f32

pub fn fractal_noise_add_abs_2d<F: Fn(&mut UniformRandomGen, f32, f32, u32) -> f32>( rng: &mut UniformRandomGen, x: f32, y: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, seed: u32) -> f32;

pub fn fractal_noise_add_abs_3d<F: Fn(&mut UniformRandomGen, f32, f32, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, seed: u32) -> f32;

pub fn fractal_noise_add_abs_4d<F: Fn(&mut UniformRandomGen, f32, f32, f32, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, t: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, seed: u32) -> f32;

分形乘

PerlinMul Perlin

MusgraveMul Musgrave

SimplexMul Simplex

WorleyF1Mul Worley F1

pub fn fractal_noise_mul_1d<F: Fn(&mut UniformRandomGen, f32, u32) -> f32>( rng: &mut UniformRandomGen, x: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, offset: f32, seed: u32) -> f32

pub fn fractal_noise_mul_2d<F: Fn(&mut UniformRandomGen, f32, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, y: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, offset: f32, seed: u32) -> f32;

pub fn fractal_noise_mul_3d<F: Fn(&mut UniformRandomGen, f32, f32, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, offset: f32, seed: u32) -> f32;

pub fn fractal_noise_mul_4d<F: Fn(&mut UniformRandomGen, f32, f32, f32, f32, u32) -> f32>(rng: &mut UniformRandomGen, x: f32, y: f32, z: f32, t: f32, noise_func: F, octaves: i32, freq_falloff: f32, lacunarity: f32, offset: f32, seed: u32) -> f32;

无运行时依赖