Crate simdnoise[−][src]
Fast, SIMD accelerated noise generation functions with optional runtime feature detection.
Features
- SSE2, SSE41, and AVX2 instruction sets, along with non SIMD fallback
- AVX2 version also leverages FMA3
- 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::*; // Set your noise type let noise_type = simdnoise::NoiseType::Fbm { freq: 0.04, lacunarity: 0.5, gain: 2.0, octaves: 3, }; // Get a block of 2d 100x100 noise, with no scaling of resulting values // min and max values are returned so you can apply your own scaling let (an_f32_vec,min,max) = simdnoise::get_2d_noise(0.0, 100, 0.0, 100, noise_type); // Get a block of 20x20x20 3d noise let (an_f32_vec,min,max) = simdnoise::get_3d_noise(0.0, 20, 0.0, 20,0.0, 20,noise_type); // Get a block of noise scaled between -1 and 1 let an_f32_vec = simdnoise::get_2d_scaled_noise(0.0, 100, 0.0, 100, noise_type,-1.0,1.0);
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 std::arch::x86_64::*; // Set your noise type let noise_type = simdnoise::NoiseType::Fbm { freq: 0.04, lacunarity: 0.5, gain: 2.0, octaves: 3, }; // get a block of 100x100 sse41 noise, skip runtime detection let (noise,min,max) = unsafe {simdnoise::sse41::get_2d_noise(0.0,100,0.0,100,noise_type)}; // 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 = simdnoise::sse2::simplex_2d(x,y); // avx2 turbulence let x = _mm256_set1_ps(5.0); let y = _mm256_set1_ps(10.0); let freq = _mm256_set1_ps(1.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,freq,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. |
scalar |
Non SIMD accelerated versions of noise functions, guaranteed to work wherever rust works. Simplex noise implementations here are ports of Stefan Gustavson's C implementations at: https://github.com/stegu/perlin-noise |
sse2 |
SSE2 Accelerated noise functions. All 64bit intel/amd CPUs support this. save for one obscure server cpu |
sse41 |
SSE41 Accelerated noise functions. The vast majority of Intel/AMD cpus running support this. It is only a few % faster than SSE2 though. |
Enums
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. |
Functions
get_1d_noise |
Gets a width X height sized block of 2d noise, unscaled,
using runtime CPU feature detection to pick the fastest method
between scalar, SSE2, SSE41, and AVX2
|
get_1d_scaled_noise |
Gets a width X height sized block of scaled 2d noise
using runtime CPU feature detection to pick the fastest method
between scalar, SSE2, SSE41, and AVX2
|
get_2d_noise |
Gets a width X height sized block of 2d noise, unscaled,
using runtime CPU feature detection to pick the fastest method
between scalar, SSE2, SSE41, and AVX2
|
get_2d_scaled_noise |
Gets a width X height sized block of scaled 2d noise
using runtime CPU feature detection to pick the fastest method
between scalar, SSE2, SSE41, and AVX2
|
get_3d_noise |
Gets a width X height X depth sized block of 3d noise, unscaled,
using runtime CPU feature detection to pick the fastest method
between scalar, SSE2, SSE41, and AVX2
|
get_3d_scaled_noise |
Gets a width X height X depth sized block of scaled 3d noise
using runtime CPU feature detection to pick the fastest method
between scalar, SSE2, SSE41, and AVX2
|
get_4d_noise |
Gets a width X height X depth X time sized block of rd noise, unscaled,
using runtime CPU feature detection to pick the fastest method
between scalar, SSE2, SSE41, and AVX2
|
get_4d_scaled_noise |
Gets a width X height X depth X time sized block of scaled 4d noise
using runtime CPU feature detection to pick the fastest method
between scalar, SSE2, SSE41, and AVX2
|