Qubit Noise Library
Introduction
Hello devforum! This will be one of my first community resources I have made, and I hope it's a useful module that many of you will use. The initial usecase of this module was to help me generate terrain for one of my games but that projects was recently scrapped so the module has been unused for a while. I believed others would probably find use in this module so here I am today.
Information
This noise module contains many features, such as persistence, lacunarity and octaves. These features are commonly used on other game engines to produce more realistic looking noise, or to customise it further (it's entirely up to you).
Usage
Generate Partial2DNoiseMap
Generate Partial2DNoiseMap
Usage:
noise.generate2DPartialMap(width, height, [optional] seed, scale,[optional] octaves, persistence, lacunarity, [optional] offset, normalise)returns BindableEvent, noiseAddedor:
noise.generate2DPartialMap(noiseSettings)
returns BindableEvent, noiseAdded
Example Code:
-- Generating noise using individual parameters
local noiseEvent = QubitNoise.generate2DPartialMap(15, 15, os.clock(), 25, 1, 0.5, 1, Vector2.new(0, 0))
-- Generating noise using noiseSettings
local noiseSettings = {width = 15, height = 15, scale = 25, persistence = 0.5, lacunarity = 1}
local noiseEvent = QubitNoise.generate2DPartialMap(noiseSettings)
noiseEvent:Connect(function(x, y, noise)
print(string.format("%d, %d = %f", x, y, noise))
end)
Generate 2DNoiseMap
Generate 2DNoiseMap
This function internally calls noise.generate2DPartialMap function, but instead will run synchronuosly and will yield the thread until all the noise values have been generated and returned. (this is typically the one you will be most likely to use)Usage:
noise.generate2DNoiseMap(width, height, [optional] seed, scale,[optional] octaves, persistence, lacunarity, [optional] offset, normalise)returns 2D Table, noiseValuesor:
noise.generate2DNoiseMap(noiseSettings)
returns 2D Table, noiseValues
Example Code:
-- Generating noise using individual parameters
local noise = QubitNoise.generate2DNoiseMap(15, 15, os.clock(), 25, 1, 0.5, 1, Vector2.new(0, 0))
-- Generating noise using noiseSettings
local noiseSettings = {width = 15, height = 15, scale = 25, persistence = 0.5, lacunarity = 1}
local noiseEvent = QubitNoise.generate2DNoiseMap(noiseSettings)
print(string.format("1, 1 = %f", noise[1][1]))
Generate Circular Gradient
Generate Circular Gradient
This function is more or less a utility function if you want to use this in generation, I originally added it so I could create a circle gradient around a generated map so I could construct denser land masses towards the center of the circle and fade out outside. It may still be useful so I have decided to leave it in the module, it functions almost identically to the noise generation.Usage:
noise.generateRadialGradient(width, length, shouldNormalise)returns 2D Table, gradient
Example Code:
-- Generating gradient
local gradient = QubitNoise.generateRadialGradient(25, 25, true)
print(string.format("min = %d, max = %d", gradient.min, gradient.max))
print(string.format("1, 1 = %d", gradient[1][1]))
Showcase
Here are a few images/videos of the noise map being used with my terrain generator, to generate landmasses. The entire system uses the noise values from the Noise Generator and just instances new blocks into the world - offsetting the y position by the noise value - and setting the material depending on the noise value (e.g sand if the noise value < 0.75)
Beach Island
Noise Settings
- Seed: 18764.7645253
- Octaves: 35
- Persistence: 1
- Lacunarity: 0.25