Noisy is a Go tool to generate textures and heightmaps with noises algorithm (up to 3 dimensions). This is useful for procedural generation, for example in game development. Using Perlin Noise (https://mrl.cs.nyu.edu/~perlin/noise/), it allows to combine different Sources (perlin noise, ridged multifractal) using Operators (e.g. add, multiply, clamps).
Note that the returned values are always contained between [-1;1].
Multiple Sources are available, and you can create your own if you implement the SourceInterface.
Constant has a defined Value, and returns this value whatever is the position x,y,z.
source := noisy.Constant{1.0}Sphere has a Frequency setting the number of inner spheres, and an Offset to translate it.
source := noisy.Sphere{
Frequency: 1.0,
OffsetX: -0.5,
OffsetY: -0.5,
OffsetZ: -0.5,
}White Noise returns a completely random value between [-1;1].
source := noisy.WhiteNoise{}Perlin Noise is a standard for noise generation.
source := noisy.Perlin{
Frequency: 5.0,
Lacunarity: 2.0,
Persistence: 0.5,
OctaveCount: 6,
Seed: 42,
}The parameters allow to custom the generated result:
- Frequency sets the first (biggest) Octave.
- Lacunarity sets the multiplier to the frequency for each successive Octave.
- Persistence sets the amplitude for each successive Octave.
- OctaveCount sets the number of Octaves to generate and blend.
- Seed sets the random seed, useful to regenerate the same image if required.
Billow Noise is similar to Perlin Noise, except it returns only absolute values. So the resulted content would be between [0;1].
source := noisy.Billow{
Frequency: 5.0,
Lacunarity: 2.0,
Persistence: 0.5,
OctaveCount: 6,
Seed: 42,
}Ridged Multifractal is based on the Perlin Noise, but allows visual effects similar to mountains.
source := noisy.RidgedMulti{
Frequency: 5.0,
Lacunarity: 2.0,
Persistence: 0.5,
Offset: 0.4,
Gain: 0.6,
OctaveCount: 6,
Seed: 42,
}The new parameters define the ridges:
- Offset is added for each successive Octave, enabling more ridges, a rougher result.
- Gain sets the factor for the high-frequency ridges, enabling more detailed noises in high Octaves.
The Add operator sums two Sources.
The Multiply operator multiply the values from two Sources.
The Divide operator divides the value from a Source A by the value from a Source B.
The Invert operator inverts the value. i.e. 1 => -1 and -1 => 1.
The Max operator returns the highest value between two Sources.
The Min operator returns the lowest value between two Sources.
The Clamp operator returns the value from a Source, clamped between the Sources [Min;Max].
The Abs operator returns the absolute value from a Source, limiting it to [0;1].
The Power operator returns the value from a Source A, powered by the value from a Source B.
The Displace operator uses the three input Sources to displace the coordinates of the Source, to compute the final value.
The Turbulence operator uses 3 internal Perlin Noise to generate random displacement. It takes a Source, and three properties used to generate the noise:
- Frequency
- Roughness, the number of Octaves of the 3 Perlin Noise
- Power, the scaling factor of the displacement
The Turbulence1D operator is similar to the Turbulence, except it uses only one Perlin Noise. This allows some different effect, more wave shaped.
Once your generator is built, you can either fetch the value for one position:
value := generator.GetValue(0.0, 0.0, 0.0)This value is contained between [-1;1].
You can also generate an image, stored on the filesystem:
err := RenderImg(generator, map[float64]color.RGBA{
-1.0: {0, 0, 0, 255},
1.0: {255, 255, 255, 255},
}, "noise.png", 1024, 1024)
if err != nil {
fmt.Println(err.Error())
}Let's create a volcanic island for a game. For the base of our island, we can use a circle (a Sphere source).
seed := 876310720398733142
generator := Multiply{
Sphere{
Frequency: 2.0,
OffsetX: -1.0,
OffsetY: -1.0,
OffsetZ: -1.0,
},
Clamp{
SourceA: Add{
Perlin{
Frequency: 1.1,
Lacunarity: 2.0,
Persistence: 0.5,
OctaveCount: 6,
Seed: seed,
},
RidgedMulti{
Frequency: 3.0,
Lacunarity: 2.0,
Persistence: 0.5,
Offset: 0.5,
Gain: 0.8,
OctaveCount: 5,
Seed: seed,
},
},
Min: Constant{0.0},
Max: Constant{1.0},
},
}- Checkboard source
- Cylinder source
- Sine source
- Voronoi source
- Terrace
- Gaussian Blur
- Erosion
See how to contribute.
This project is distributed under the Apache 2.0 licence.