13 个版本
0.1.26 | 2024 年 7 月 25 日 |
---|---|
0.1.25 | 2024 年 7 月 24 日 |
0.1.24 | 2024 年 3 月 13 日 |
0.1.17 | 2023 年 12 月 27 日 |
#281 in 数学
264 每月下载量
16KB
354 行
noise-algebra
使用普通的代数构建自定义噪声函数,并按您喜欢的任何方式进行采样!
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!
}
专为程序生成设计,API 专注于使噪声构建代码易于阅读和编写,同时保持高性能。
非常感谢 Chris Janaqi 在实现过程中给予我的帮助!
基准测试
使用 simd::simplex (来自 simdnoise) 和仅输出常量的假噪声函数构建相同的噪声。我们评估了这些函数在 32x32 点网格上的采样速度。
在我 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]
当前的性能可能更好,simd 还未用于噪声上的操作。目标是使用 simd 在所有地方,但我还没有实现它。
待办事项
进行中
- 扩展到 1、3 和 4 维度的支持
- 在所有地方使用 simd
- 添加更多类型的噪声(细胞、梯度等)
依赖关系
~3MB
~63K SLoC