A curated list of common 2D noises and patterns in computer graphics. Mostly taken from implementations on Shadertoy. All implementations are under the MIT or similar.
This library is intended for users who need access to raw, unprocessed noise values in Rust. This is not intended to be an effect or post processing library. All returned values are between [0..1].
Noise classes support both raw noises as well as smooth FBM variants.
This library is mostly a port of GPU noise and pattern implementations indended for computer graphics applications and games. If you need highest quality noise implementations you may have to look elsewhere.
This library uses the nalgebra-glm crate as the math library (and is also its only dependency). The API however has no external dependencies.
Precision
By default the library compiles to f32 via a type definition of FP in lib.rs, you can change the type as instructed and compile the library to f64 if needed.
The Traits
The traits for noises and patterns are very simple.
Noises
Value Noise
Based on 1D, 2D & 3D Value Noise
let mut pixels = vec!;
let value = new;
for y in 0..height
VoronoiBasic
Based on Voronoi Basic
let mut pixels = vec!;
let noise = new;
for y in 0..height
Patterns
Bricks
Based on Bricks and Tiles. Used here with permission from Fabrice under the MIT.
let mut pixels = vec!;
let mut bricks = new;
bricks.set_property;
for y in 0..height
Supported properties:
// The ratio of width / height of the bricks. 1.0 means they are square, larger values increases the width, default 2.0.
bricks.set_property;
// A value of 1.0 (default) offsets every second line, otherwise aligns the bricks vertically.
bricks.set_property;
// The cell size, a global scaling factor, default 16.0
bricks.set_property;
// The gap between bricks, default 0.08.
bricks.set_property;
// The bevel of the brick, larger values provide a smoother transition, by default 0.07.
bricks.set_property;
// The roundness of the brick, 0.0 creates square bricks, 1.0 circular ones. Default is 0.25.
bricks.set_property;