Skip to content

u-plus-one/UnityNoise

Repository files navigation

UnityNoise

Unity License

Description

A Unity package that contains a collection of functions for generating various kinds of noise both on the CPU and GPU.

Available Noise Functions

Type 1D 2D 3D 4D
Perlin ✔️ ✔️ ✔️ ✔️
Simplex ✔️ ✔️ ✔️ ✔️
Voronoi ✔️ ✔️ ✔️ ✔️
Cellular ✔️ ✔️ ✔️ ✔️

All noise generators also include functions for generating a fractal version.

Installation

Option 1: Unity Package Manager

Open the Package Manager window, click on "Add Package from Git URL ...", then enter the following:

https://github.com/u-plus-one/unitynoise.git

Option 2: Manually Editing packages.json

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"

Option 3: Manual Installation (not recommended)

You can also download this repository and extract the ZIP file anywhere inside your project's Assets folder.

Usage

In Scripts

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);

In Shaders

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);

Texture Assets

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.

About

Collection of various noise functions for both scripts and shaders

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published