noise-algebra

Crates.ionoise-algebra
lib.rsnoise-algebra
version0.1.28
sourcesrc
created_at2023-12-27 20:20:45.14855
updated_at2024-11-08 12:59:26.126816
descriptionEasy manipulation of noise functions
homepage
repositoryhttps://github.com/Inspirateur/noise-algebra
max_upload_size
id1081851
size19,994
Téo Orthlieb (Inspirateur)

documentation

README

noise-algebra

Build your custom noise functions using plain algebra, and sample them however you like!

use noise_algebra::*;

fn main() {
    // prepare a noise source object;
    // it will yield samples for a 200x200 square centered on 0 with half precision (step_by = 2)
    let step_by = 2;
    let seed = 42;
    let n = NoiseSource::new([-100..=100, -100..=100], seed, step_by)
    // Easily compose your noise
    let ocean_threshold = 0.3;
    let elevation = (n.simplex(0.1) + n.simplex(0.5)*0.5 + n.simplex(1.)*0.1).normalize();
    // make temperature decrease with altitude
    let temperature = (n.simplex(0.2) - elevation.clone()*0.3).normalize();
    // make humidity sharply increase with proximity to ocean and decrease with temperature
    let humidity = temperature.clone() * (n.simplex(0.1) + elevation.clone().mask(ocean_threshold)).normalize();
    // All the individual noises used in the functions are given a different seed to avoid weird artefacts;
    // and the noise samples keep track of their range so that normalize magically works!
}

Designed for procedural generation, the API is focused on making noise building code easy to read and write while still being performant.

Big thanks to Chris Janaqi for helping me with the implementation!

Benchmark

The same noise is constructed using simd::simplex (from simdnoise) and a fake-noise function that just outputs a constant. We evaluate the sample speed of these functions for a grid of 32x32 points.

Results on my Intel(R) Xeon(R) CPU E5-1650 v3 (3.50GHz):

simplex-generate-32^2      time:   [93.603 µs 94.057 µs 94.697 µs]
const-generate-32^2     time:   [42.411 µs 43.501 µs 44.717 µs]

The current performances could be better, simd is not yet used for operations applied on the noises. The goal is to use simd everywhere but I haven't implemented it yet.

Todo

Work in progress:

  • extend support to dimensions 1, 3 and 4
  • use simd everywhere
  • add more types of noise (cellular, gradient, etc.)
Commit count: 60

cargo fmt