Crate simdnoise

Source
Expand description

Fast, SIMD accelerated noise generation functions with optional runtime feature detection.

Github Link

§Features

  • SSE2, SSE41, and AVX2 instruction sets, along with non SIMD fallback
  • Runtime detection picks the best available instruction set
  • Simplex noise, fractal brownian motion, turbulence, and ridge
  • 1D, 2D, 3D, and 4D
  • Cellular / Voroni Noise 2D and 3D

§Benchmarks

See Github

§Todo

  • AVX512 support
  • ARM NEON support
  • Other noise types

§Examples

§Get a block of noise with runtime SIMD detection

The library will, at runtime, pick the fastest available options between SSE2, SSE41, and AVX2

use simdnoise::*;

// Get a block of 2d fbm noise with default settings, 100 x 100, with values scaled to the range [0,1]
let noise =  NoiseBuilder::fbm_2d(100, 100).generate_scaled(0.0,1.0);

// Get a block of 4d ridge noise, custom settings, 32x32x32x32 unscaled
let (noise,min,max) =  NoiseBuilder::ridge_4d(32,32,32,32)
       .with_freq(0.05)
       .with_octaves(5)
       .with_gain(2.0)
       .with_seed(1337)
       .with_lacunarity(0.5)
       .generate();

§Call noise functions directly

Sometimes you need something other than a block, like the points on the surface of a sphere. Sometimes you may want to use SSE41 even with AVX2 is available

use simdnoise::*;
use core::arch::x86_64::*;

let noise_setting =  NoiseBuilder::cellular2_3d(32,32,32)
        .with_freq(0.05)
        .with_return_type(Cell2ReturnType::Distance2Mul)
        .with_jitter(0.5)
        .wrap();
 
// get a block of noise with the sse41 version, using the above settings
unsafe {
    let (noise,min,max) = simdnoise::sse41::get_3d_noise(&noise_setting);
}

// send your own SIMD x,y values to the noise functions directly
unsafe {
  // sse2 simplex noise
  let x = _mm_set1_ps(5.0);
  let y = _mm_set1_ps(10.0);
  let f : __m128 = simdnoise::sse2::simplex_2d(x,y);
  
  // avx2 turbulence
  let x = _mm256_set1_ps(5.0);
  let y = _mm256_set1_ps(10.0);
  let lacunarity = _mm256_set1_ps(0.5);
  let gain = _mm256_set1_ps(2.0);
  let octaves = 3;
  let f_turbulence : __m256 = simdnoise::avx2::turbulence_2d(x,y,lacunarity,gain,octaves);
    
}

Modules§

avx2
AVX2 and FMA3 Accelerated noise functions. CPUs since ~2013 (Intel) and ~2015 (AMD) support this. It is about twice as fast as the SSE2 version.
cellular
scalar
simplex
sse2
SSE2 Accelerated noise functions.
sse41
SSE41 Accelerated noise functions.

Structs§

Cellular2Settings
CellularSettings
FbmSettings
GradientSettings
NoiseBuilder
NoiseDimensions
RidgeSettings
TurbulenceSettings

Enums§

Cell2ReturnType
Determines what final value is returned for the cell2 noise
CellDistanceFunction
The function to use to compute distance between cells
CellReturnType
Determines what final value is returned for the cell noise
NoiseType
Specifies what type of noise to generate and contains any relevant settings.