26个稳定版本
3.1.6 | 2020年5月30日 |
---|---|
3.1.4 | 2019年11月30日 |
3.0.1 | 2019年7月14日 |
3.0.0 | 2019年3月5日 |
1.0.2 | 2018年6月17日 |
#98 in 游戏开发
每月511次下载
用于 2 crates
160KB
4K SLoC

SIMDNoise
为Rust设计的超快SIMD噪声库。欢迎PR!
特性
- 梯度噪声(Simplex即Perlin)1D、2D、3D、4D
- 分形布朗运动、脊和湍流
- 细胞噪声(即Voronoi)2D、3D
- SSE2、SSE41和AVX2指令集,以及非SIMD回退
- AVX2版本还利用了FMA3
- 运行时检测选择最佳可用的指令集
- 提供一个种子值以随机化噪声结果
基准测试
Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz 单线程 使用 Criterion.rs
2D 4k(3840×2160)Fbm噪声,3次谐波
SIMD集 | 时间 |
---|---|
标量 | 888毫秒 |
sse2 | 225毫秒 |
sse41 | 186毫秒 |
avx2 | 108毫秒 |
3D 128×128×128细胞噪声
SIMD集 | 时间 |
---|---|
标量 | 1,400毫秒 |
sse2 | 128毫秒 |
sse41 | 94毫秒 |
avx2 | 47毫秒 |
待办事项
- AVX512支持
- ARM NEON支持
- 其他噪声类型
使用运行时SIMD检测获取噪声块
库将在运行时选择SSE2、SSE41和AVX2之间最快的可用选项。
// 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 3d ridge noise, custom settings, 32x32x32 unscaled
let (noise, min, max) = NoiseBuilder::ridge_3d(32, 32, 32)
.with_freq(0.05)
.with_octaves(5)
.with_gain(2.0)
.with_seed(1337)
.with_lacunarity(0.5)
.generate();
直接调用噪声函数
有时你需要一些不同于块的东西,比如球面上的点。有时即使有AVX2可用,你可能也想使用SSE41。
let noise_setting = NoiseBuilder::ridge_3d(32, 32, 32)
.with_freq(0.05)
.with_octaves(5)
.with_gain(2.0)
.with_lacunarity(0.5)
.wrap();
// get a block of noise with the sse41 version, using the above settings
let (noise, min, max) = unsafe { simdnoise::sse41::get_2d_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 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, lacunarity, gain, octaves);
};
依赖关系
~465KB
~13K SLoC