Crates.io | noiselib |
lib.rs | noiselib |
version | 0.2.4 |
source | src |
created_at | 2024-04-04 02:15:13.566001 |
updated_at | 2024-04-06 08:11:37.962658 |
description | A library of procedural 1D, 2D, 3D and 4D noise and fractal functions. |
homepage | |
repository | https://github.com/markusmoenig/noiselib.git |
max_upload_size | |
id | 1195782 |
size | 949,659 |
This is a collection of procedural, seeded noises. Useful for CPU based raytracers and as building blocks for procedural art and textures.
The noises are optimized for speed. Most noises are available in all 4 dimensions (1D, 2D, 3D, 4D), some are only available in specific dimensions (or are still under development).
All noises have the same signature so that they can be passed as parameters to the supplied fractal functions. All return a value between -1.0 and 1.0.
This library has no external dependencies.
The images were generated by tests inside the lib.rs file. You can see examples for every noise there.
For example the Perlin noise image was generated with
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");
}
This library is currently work in progress. More noises and fractal functions are in development.
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;
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;
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;
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;
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;
pub fn worley_f1_noise_2d(rng: &mut UniformRandomGen, x: f32, y: f32, seed: u32) -> f32;
Perlin
Musgrave
Simplex
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;
Perlin
Musgrave
Simplex
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;
Perlin
Musgrave
Simplex
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;