- Notifications
You must be signed in to change notification settings - Fork2
SIMD-accelerated noise generation.
License
guzba/noisy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
nimble install noisy
Noisy is a SIMD-accelerated Nim implementation of Simplex (Perlin) noise. The goal of this library is to be easy to use, performant and dependency-free.
Noisy works well using Nim's relatively new--gc:arc
and--gc:orc
as well as the default garbage collector. This library also works using bothnim c
andnim cpp
, in addition to--cc:vcc
on Windows.
I have also verified that Noisy builds with--experimental:strictFuncs
on Nim 1.4.0.
import noisy, strformatvar simplex=initSimplex(1988)simplex.frequency=0.1# Starting at (0, 0) generate a 16x16 grid of 2D noise values.let values= simplex.grid((0,0), (16,16))for xin0..<16:for yin0..<16:let value= values[x, y]echo&"({x},{y}):{value}"
Benchmarks can be run comparing methods for generating noise values. Check the performance yourself by runningtests/benchmark.nim.
nim c -d:release -r .\tests\benchmark.nim
(256 x 256 x 256 cube of 3D simplex noise with 3 octaves, lower time is better)
Method | Time |
---|---|
Point by point usingvalue(x, y, z) | 1.6066s |
Usinggrid() (SIMD accelerated, GCC default) | 1.0281s |
Usinggrid() (SIMD accelerated,--passC:"-mavx" ) | 0.7476s |
nimble test
import noisy
Simplex=object octaves*:int amplitude*, frequency*, lacunarity*, gain*:float32
Grid=refobject width*, height*, depth*:int values*:seq[float32]
NoisyError=objectofValueError
funcinitSimplex(seed:int):Simplex
Returns the noise value at (x, y) or (x, y, z).
func`[]`(g:Grid; x, y:int; z=0):float32 {.inline.}
Generates the 2D noise value at (x, y) based on the Simplex parameters.
funcvalue(simplex:Simplex; x, y:float32):float32 {.raises: [NoisyError],tags: [].}
Generates the 3D noise value at (x, y, z) based on the Simplex parameters.
funcvalue(simplex:Simplex; x, y, z:float32):float32 {.raises: [NoisyError],tags: [].}
Helper for working with ints.
funcvalue(simplex:Simplex; x, y:int):float32 {.inline,raises: [NoisyError],tags: [].}
Helper for working with ints
funcvalue(simplex:Simplex; x, y, z:int):float32 {.inline,raises: [NoisyError].}
Beginning at position start, generate a grid of 2D noise based on the Simplex parameters. The width and height of the grid is set by the dimens parameter.
funcgrid(simplex:Simplex; start: (float32,float32); dimens: (int,int)):Grid {.raises: [NoisyError].}
Helper for working with ints.
funcgrid(simplex:Simplex; start: (int,int); dimens: (int,int)):Grid {.inline,raises: [NoisyError].}
Beginning at position start, generate a grid of 3D noise based on the Simplex parameters. The width, depth, and height of the grid is set by the dimens parameter.
funcgrid(simplex:Simplex; start: (float32,float32,float32); dimens: (int,int,int)):Grid {.raises: [NoisyError].}
Helper for working with ints.
funcgrid(simplex:Simplex; start: (int,int,int); dimens: (int,int,int)):Grid {.inline,raises: [NoisyError].}
About
SIMD-accelerated noise generation.