FastNoiseLite Documentation
repository·master·Indexed 25 days ago
https://github.com/auburn/fastnoiseliteA highly portable, high-performance noise generation library supporting multiple algorithms including Perlin, Simplex, and Cellular noise. Designed for easy integration across various languages and platforms, it provides 2D and 3D sampling and is available for C, C++, C#, Fortran, GLSL, Go, Haxe, HLSL, Java, JavaScript/TypeScript, Odin, Pascal, and PowerShell.
What's inside FastNoiseLite
- FastNoise Lite is a highly portable, open-source noise generation library designed for high performance across various platforms and languages. It provides a wide selection of noise algorithms and supports both 2D and 3D sampling. It is an evolution of the original FastNoise library, optimized for easy integration and modern noise generation requirements.
Use the FastNoise Lite Web Preview App for testing
masterA compact web-based testing application is available to visually represent and test all features included in FastNoise Lite. You can use this app for:
- Testing different noise settings.
- Visualizing noise generation.
- Generating noise textures for export.
Setup FastNoiseLite in C
masterTo use FastNoiseLite in a C project, you must defineFNL_IMPLin exactly one source file before including theFastNoiseLite.hheader. Failing to do this will result in linker errors.Integrate FastNoiseLite into an Odin project
masterTo use FastNoiseLite in an Odin project, copy theFastNoiseLite.odinfile into your project structure. You can place it in either a localfast_noise_litedirectory within your project or in the globalodin/shareddirectory.Import FastNoiseLite
masterDepending on your module system, import FastNoiseLite as follows:
ESM:
import FastNoiseLite from "fastnoise-lite";CommonJS:
const FastNoiseLite = require("fastnoise-lite").default;// using ESM import FastNoiseLite from "fastnoise-lite"; // using CJS const FastNoiseLite = require("fastnoise-lite").default; let noise = new FastNoiseLite();Generate noise in GLSL using FastNoiseLite
masterTo generate noise in a GLSL shader, you must first create and configure a noise state using
fnlCreateState(). You can then sample noise at specific coordinates usingfnlGetNoise2D().Common configuration involves setting the
noise_typeproperty (e.g.,FNL_NOISE_OPENSIMPLEX2) on the state object.// Create and configure noise state fnl_state noise = fnlCreateState(); noise.noise_type = FNL_NOISE_OPENSIMPLEX2; // Gather noise data float noiseData[128 * 128]; int index = 0; for (int y = 0; y < 128; y++) { for (int x = 0; x < 128; x++) { noiseData[index++] = fnlGetNoise2D(noise, x, y); } } // Do something with this data...Install fastnoise-lite via npm
masterTo use FastNoise Lite in a JavaScript or TypeScript project, install the
fastnoise-litepackage using npm.npm install fastnoise-liteInstall FastNoiseLite for Zig
masterTo use FastNoiseLite in a Zig project, simply copy thefastnoise.zigfile directly into your project directory.Generate noise with FastNoiseLite
masterTo generate noise, follow these steps:
- Initialize: Create a
FastNoiseLiteinstance usingFastNoiseLite::new()orFastNoiseLite::with_seed(seed). - Configure: Use setter functions to adjust noise settings (e.g.,
set_noise_type). - Domain Warp (Optional): Use
domain_warp_2d(x, y)ordomain_warp_3d(x, y, z)to transform coordinates before sampling. - Sample: Call
get_noise_2d(x, y)orget_noise_3d(x, y, z)to retrieve the noise value.
Note: Noise values are returned in the range
-1..1. You may need to remap this to a different range (e.g.,0..1).use fastnoise_lite::*; // Create and configure the FastNoise object let mut noise = FastNoiseLite::new(); noise.set_noise_type(Some(NoiseType::OpenSimplex2)); const WIDTH: usize = 128; const HEIGHT: usize = 128; let mut noise_data = [[0.; HEIGHT]; WIDTH]; // Sample noise pixels for x in 0..WIDTH { for y in 0..HEIGHT { // Domain warp can optionally be employed to transform the coordinates before sampling: // let (x, y) = noise.domain_warp_2d(x as f32, y as f32); let negative_1_to_1 = noise.get_noise_2d(x as f32, y as f32); // You may want to remap the -1..1 range data to the 0..1 range: noise_data[x][y] = (negative_1_to_1 + 1.) / 2.; // (Uses of `as f32` above should become `as f64` if you're using FNL with the "f64" feature flag) } }- Initialize: Create a
Generate 2D noise in Go
masterTo generate 2D noise in Go, import the
fastnoisepackage. You can create a noise state using generics to specify eitherfloat32orfloat64. Once initialized, configure theNoiseType(e.g.,fastnoise.OpenSimplex2) and use theNoise2D(x, y)method to sample noise values at specific coordinates.import "fastnoise" // Create and configure noise state (either float32 or float64) var noise = fastnoise.New[float32]() noise.NoiseType(fastnoise.OpenSimplex2) // Gather noise data var noiseData [128][128]float32 for x := 0; x < 128; x++ { for y := 0; y < 128; y++ { noiseData[x][y] = noise.Noise2D(x, y) } }Integrate FastNoiseLite in C++
masterTo use FastNoiseLite in a C++ project, you must include the header file. Crucially, you must add#define FNL_IMPLbefore includingFastNoiseLite.hin exactly one source file to generate the implementation. Failure to do this will result in linker errors.Integrate FastNoise Lite in C++
masterTo use the C++ version of FastNoise Lite, include the header file. Note that for the single-header implementation, you must defineFNL_IMPLin exactly one source file to avoid linker errors.