A Unity package that contains a collection of functions for generating various kinds of noise both on the CPU and GPU.
Type | 1D | 2D | 3D | 4D |
---|---|---|---|---|
Perlin | ✔️ | ✔️ | ✔️ | ✔️ |
Simplex | ✔️ | ✔️ | ✔️ | ✔️ |
Voronoi | ✔️ | ✔️ | ✔️ | ✔️ |
Cellular | ✔️ | ✔️ | ✔️ | ✔️ |
All noise generators also include functions for generating a fractal version.
Open the Package Manager window, click on "Add Package from Git URL ...", then enter the following:
https://github.com/u-plus-one/unitynoise.git
Add the following line to your project's Packages/manifest.json
:
"com.github.u-plus-one.unitynoise": "https://github.com/u-plus-one/unitynoise.git"
You can also download this repository and extract the ZIP file anywhere inside your project's Assets folder.
All noise generators are found inside the UnityNoise
namespace.
Example:
using UnityNoise;
-----
Vector3 pos = new Vector3(0.5f, 1.0f, 2.0f);
//Simple 3D Perlin
float noise = PerlinNoise.Instance.GetNoise3D(pos);
//Fractal 3D Perlin (parameters: octaves, lacunarity, persistence, scale)
FractalSettings fractal = new FractalSettings(4, 2f, 0.5f, 1);
float noise = PerlinNoise.Instance.GetNoise3D(pos, fractal);
Add a reference to the Include file you want to use, e.g:
#include "Packages/com.github.u-plus-one.unitynoise/Shaders/PerlinNoise.cginc"
Example:
//Simple 3D Perlin
float noise = GetPerlinNoise3D(position.xyz);
//Fractal 3D Perlin
FractalSettings settings;
settings.octaves = 4;
settings.persistence = 0.5;
settings.lacunarity = 2.0;
float noise = ComputePerlinNoise3D(position.xyz, settings);
Noise Textures can be generated as procedural assets and can be used just like regular 2D textures.
To create a new noise texture, go to Assets/Create/Texture/Noise Texture
Noise Textures come with the following settings:
Parameter | Description |
---|---|
Resolution | Texture width / height |
Use 3D Noise | Whether to sample from 3D noise to generate the 2D texture |
Scale | Number of noise "cells" in both axes, higher numbers generate more noise |
Seed | Random seed to use for noise generation |
Depth | General contrast of the genreated noise |
Tiled | Generates a texture that can repeat seamlessly |
Fractal Settings | Various settings releated to fractal noise generation |
Mapping Settings | Various settings related to remapping input values or mapping to a color gradient |
Texture Settings | Common Texture Importer settings |
A histogram view is also provided to see the distribution of noise values across the entire texture.