pure-noise: Performant, modern noise generation for Haskell with minimal dependencies. Based on FastNoiseLite.

[ bsd3, library, math, noise, numeric ] [ Propose Tags ]
Versions [RSS] 0.1.0.0, 0.1.0.1
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), vector (<=0.14) [details]
License BSD-3-Clause
Copyright 2024 Jeremy Nuttall
Author Jeremy Nuttall
Maintainer jeremy@jeremy-nuttall.com
Category Math, Numeric, Noise
Home page https://github.com/jtnuttall/pure-noise#readme
Bug tracker https://github.com/jtnuttall/pure-noise/issues
Source repo head: git clone https://github.com/jtnuttall/pure-noise
Uploaded by jtnuttall at 2024-10-15T19:32:06Z
Distributions
Downloads 23 total (23 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for pure-noise-0.1.0.1

[back to package description]

pure-noise

Performant, modern noise generation for Haskell with a minimal dependency footprint.

The algorithms used in this library are ported from FastNoiseLite. The library structure has been retuned to fit better with Haskell semantics.

The public interface for this library is unlikely to change much, although the implementations (noiseBaseN functions and anything in Numeric.Noise.Internal) are subject to change and may change between minor versions.

Usage

The library exports newtypes for N-dimensional noise. Currently, these are just functions that accept a seed and a point in N-dimensional space. They can be arbitrarily unwrapped by with the noiseNAt family of functions. Since they abstract over the given seed and parameters, they can be composed with Num or Fractional methods at will with little-to-no performance cost.

Noise values are generally clamped to [-1, 1], although some noise functions may occasionally produce values slightly outside this range.

import Numeric.Noise qualified as Noise

myNoise2 :: (RealFrac a) => Seed -> a -> a -> a
myNoise2 =
  let fractalConfig = Noise.defaultFractalConfig
  in Noise.noise2At $
      Noise.fractal2 fractalConfig ((perlin2 + superSimplex2) / 2)

More examples can be found in bench and demo.

Performance notes

  • This library benefits considerably from compilation with the LLVM backend (-fllvm). Benchmarks suggest a ~50-80% difference depending on the kind of noise.

Benchmarks

Results

Measured by values / second generated by the noise functions. These results come from a benchmark with -fllvm enabled.

All results are for Floats.

There's inevitably some noise in the measurements because all of the results are forced into an unboxed vector.

2D

name values / second
value2 157_347_680
perlin2 129_541_747
openSimplex2 64_758_006
superSimplex2 64_072_639
valueCubic2 52_110_819
cellular2 15_743_434

3D

name values / second
value3 85_438_023
perlin3 56_830_482
valueCubic3 15_559_523

Examples

There's an interactive demo app in the demo directory.

OpenSimplex2

OpenSimplex2 OpenSimplex2 ridged

Perlin

Perlin fBm

Cellular

value distance2add