Skip to content

akmonengine/noisy

Repository files navigation

Noisy

GitHub go.mod Go version License Go Reference Go Report Card Tests Codecov GitHub Issues or Pull Requests GitHub Issues or Pull Requests

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

Basic Usage

Note that the returned values are always contained between [-1;1].

Sources

Multiple Sources are available, and you can create your own if you implement the SourceInterface.

Constant

Constant has a defined Value, and returns this value whatever is the position x,y,z.

source := noisy.Constant{1.0}

Sphere

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

White Noise returns a completely random value between [-1;1].

source := noisy.WhiteNoise{}

Perlin Noise

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

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

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.

Operators

Add

The Add operator sums two Sources.

Multiply

The Multiply operator multiply the values from two Sources.

Divide

The Divide operator divides the value from a Source A by the value from a Source B.

Invert

The Invert operator inverts the value. i.e. 1 => -1 and -1 => 1.

Max

The Max operator returns the highest value between two Sources.

Min

The Min operator returns the lowest value between two Sources.

Clamp

The Clamp operator returns the value from a Source, clamped between the Sources [Min;Max].

Abs

The Abs operator returns the absolute value from a Source, limiting it to [0;1].

Power

The Power operator returns the value from a Source A, powered by the value from a Source B.

Displace

The Displace operator uses the three input Sources to displace the coordinates of the Source, to compute the final value.

Turbulence

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

Turbulence1D

The Turbulence1D operator is similar to the Turbulence, except it uses only one Perlin Noise. This allows some different effect, more wave shaped.

Result

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())
}

Complex Example

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},
    },
}

What's next ?

Sources

  • Checkboard source
  • Cylinder source
  • Sine source
  • Voronoi source

Operators

  • Terrace

Processes

  • Gaussian Blur
  • Erosion

Sources

Contributing Guidelines

See how to contribute.

Licence

This project is distributed under the Apache 2.0 licence.

About

Go tool for noise generation based on Perlin Noise

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages