NoiseTools Utility
advanced scriptingVoxel Play 4 · Scripting / API
Overview
The NoiseTools class provides utilities for managing noise textures and heightmaps, designed for terrain generation and procedural content creation.
Fields
static Vector3 seedOffset- Random seeded offsets for terrain sampling
Methods
LoadNoiseTexture
Loads noise values from a texture:
float[] noiseValues = NoiseTools.LoadNoiseTexture(texture, out int textureSize);
LoadHeightmapFromTerrainData
Loads heightmap values from Unity TerrainData:
float[] heightmap = NoiseTools.LoadHeightmapFromTerrainData(terrainData, out int size);
GetNoiseValue
Samples noise texture at a specific position:
NoiseTools.GetNoiseValue(noiseArray, textureSize, x, z)- 2D noise samplingNoiseTools.GetNoiseValue(noiseArray, textureSize, x, z, ridgeNoise: true)- 2D with ridge noise (inverted effect for ridges/peaks)NoiseTools.GetNoiseValue(noiseArray, textureSize, x, y, z)- 3D noise sampling
GetNoiseValueBilinear
Samples 2D noise texture using bilinear filtering for smoother results:
float value = NoiseTools.GetNoiseValueBilinear(noiseArray, textureSize, x, z);
Also accepts an optional ridgeNoise parameter.
GetFractalNoiseValue
Procedural fractal Perlin noise, no texture required. This is the sampler behind the Sample Height Map Fractal and Ridge Noise Fractal graph nodes. Thread-safe, so it can be called from a mesher or generator thread.
float value = NoiseTools.GetFractalNoiseValue(x, z, frequency, octaves, persistence, lacunarity);
float value3D = NoiseTools.GetFractalNoiseValue3D(x, y, z, frequency, octaves, persistence, lacunarity);
frequency: base frequency. Lower values produce larger features.octaves: number of layers combined (1-8).persistence: amplitude multiplier from one octave to the next.lacunarity: frequency multiplier from one octave to the next.
Both return a 0-1 value. To turn either into ridge noise, invert it around its midpoint: 1 - 2 * abs(value - 0.5).
PerlinNoise3D
Single-octave 3D Perlin noise at a world position, returned in the 0-1 range. Use it when you want raw noise without the fractal loop.
float value = NoiseTools.PerlinNoise3D(x, y, z);
GetCellularNoiseValue
Procedural cellular (Worley) noise, no texture required. Space is divided into cells around scattered feature points; the method returns either the distance to the nearest feature point or a mask of the borders between cells. Thread-safe. This is the sampler behind the Cellular Noise graph node.
// 2D: cells at (x, z)
float value = NoiseTools.GetCellularNoiseValue(x, z, frequency, jitter, edges);
// 3D: cells at (x, y, z), so the pattern varies with altitude
float value3D = NoiseTools.GetCellularNoiseValue3D(x, y, z, frequency, jitter, edges);
frequency: base frequency of the pattern. Higher values pack more cells into the same area.jitter: how far cell centres wander from the regular grid, clamped to 0-1. 0 is a perfect grid, 1 is fully scattered.edges:falsereturns the distance to the nearest cell centre (regions and plateaus in 2D, blobs and pockets in 3D).truereturns the borders between cells (cracks, rivers and biome frontiers in 2D, cave-like walls in 3D).
Both return a 0-1 value and both honour seedOffset, so a new world seed shifts the pattern.
ApplyTerraces
Quantizes a 0-1 value into stepped bands, the operation behind the Terraces graph node.
float terraced = NoiseTools.ApplyTerraces(value, terraceCount, smoothness);
terraceCount: number of bands, clamped to a minimum of 2.smoothness: 0-1. Each band is a flat plateau covering1 - smoothnessof its range, followed by a smoothstep ramp into the next step. 0 gives hard steps with no ramp at all; 1 removes the plateau entirely and the result ramps continuously.
Suggest an improvement
Help us improve this documentation page.