#simplex-noise #simplex #procedural-generation #perlin-noise #noise #simd #procedural

fastnoise2

A safe Rust wrapper for FastNoise2, a node-based noise generation library optimized with SIMD

4 releases (2 breaking)

0.3.0 Sep 22, 2024
0.2.0 Aug 18, 2024
0.1.1 Aug 14, 2024
0.1.0 Aug 14, 2024

#240 in Hardware support

Download history 365/week @ 2024-08-13 14/week @ 2024-08-20 4/week @ 2024-09-10 196/week @ 2024-09-17 23/week @ 2024-09-24 11/week @ 2024-10-01 3/week @ 2024-10-08

237 downloads per month

MIT license

470KB
6.5K SLoC

C++ 4K SLoC // 0.0% comments Rust 2.5K SLoC // 0.0% comments GLSL 101 SLoC // 0.1% comments Bitbake 9 SLoC

fastnoise2

Crates.io License Crates.io Version docs.rs

fastnoise2 provides an easy-to-use and mostly safe interface for the FastNoise2 C++ library, which provides modular node graph-based noise generation using SIMD.

NoiseTool Node Tree

This crate acts as a wrapper around fastnoise2-sys, the unsafe bindings for FastNoise2.

Examples

Here is an example of a encoded node tree, exported by FastNoise2's NoiseTool.

use fastnoise2::SafeNode;

let (x_size, y_size) = (1000, 1000);
let encoded_node_tree = "EQACAAAAAAAgQBAAAAAAQBkAEwDD9Sg/DQAEAAAAAAAgQAkAAGZmJj8AAAAAPwEEAAAAAAAAAEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM3MTD4AMzMzPwAAAAA/";
let node = SafeNode::from_encoded_node_tree(encoded_node_tree).unwrap();

// Allocate a buffer of enough size to hold all output data.
let mut noise_out = vec![0.0; (x_size * y_size) as usize];

let min_max = node.gen_uniform_grid_2d(
    &mut noise_out,
    -x_size / 2, // x offset
    -y_size / 2, // y offset
    x_size,
    y_size,
    0.01, // frequency
    1337, // seed
);

// use `noise_out`!

You can also manually code a node tree using FastNoise2's metadata system, either with Node, or by combining generators, see SafeNode.

Take a look at examples to find out more.

Setup

fastnoise2-sys, the underlying bindings for fastnoise2, uses a build script that follows a specific order of preference for compiling and/or linking the FastNoise2 library:

  1. Building from source, if the build-from-source feature is enabled.
  2. If the FASTNOISE2_LIB_DIR environment variable is set to /path/to/lib/, that path will be searched for static FastNoise library.
  3. If not set, it falls back to building from source.

Building from Source

To build FastNoise2 from source using fastnoise2-sys, ensure you have:

Notes

  • If you prefer not to build from source, precompiled binaries are available for download from the FastNoise2 Releases.
  • The FASTNOISE2_SOURCE_DIR environment variable is generally not needed as fastnoise2-sys includes the FastNoise2 source code as a Git submodule. If you need to use a different source directory, set FASTNOISE2_SOURCE_DIR to point to the root of the FastNoise2 source code.

Dependencies

~0.3–3MB
~59K SLoC