Noises

Cubiomes.NoisesModule
Warning

Working over raw noise functions is very low-level and should only be used as a last resort or for performance reasons.

Noises is a module to generate and sample various types of noise functions used in the procedural generation of Minecraft worlds. The result are always floating, but the input can be any type of number.

A noise object can be quite big in memory, so we can create an undefined noise object and initialize it without copying it with the setrng!🎲 function, saving time and memory.

The main uses are with the functions:

  • Noise : create an undefined noise object.
  • setrng!🎲 : initialize the noise object.
  • Noise🎲 : create and initialize the noise object in one step.
  • sample_noise : sample the noise at a given point.

The noises implemented are:

  • Perlin : a Perlin noise.
  • Octaves : a sum of N Perlin noises.
  • DoublePerlin : a sum of two independent and identically distributed Octaves noises.
source

Index

API

Cubiomes.Noises.DoublePerlinType
DoublePerlin{N} <: Noise

A double Perlin noise implementation. It's a sum of two independent and identically distributed (iid) Octaves{N} noise.

source
Cubiomes.Noises.Noise🎲Method
Noise🎲(::Type{T}, rng::AbstractJavaRNG, args...) where {N, T<:Noise}

Create a noise of type T and initialize it with the given random number generator rng. Other arguments are used to initialize the noise. They depend on the noise type and they are the same as the arguments of the setrng!🎲 function.

Strictly equivalent to

julia> noise = Noise(T, undef) # or Noise(T, undef, args[1]) for DoublePerlin
T(...)

julia> setrng!🎲(noise, rng, args...)`.

See also: Noise, setrng!🎲

source
Cubiomes.Noises.sample_noiseFunction
sample_noise(noise::Perlin, x, z, y=missing, yamp=0, ymin=0)
sample_noise(noise::Octaves, x, z, y=missing, yamp=missing, ymin=missing)
sample_noise(noise::DoublePerlin, x, z, y=missing, [move_factor,])

Sample the given noise at the specified coordinates.

See also: sample_simplex, Noise, Noise🎲

source
Cubiomes.Noises.setrng!🎲Function
setrng!🎲(noise::Perlin, rng)
setrng!🎲(noise::Octaves{N}, rng::JavaRandom, octave_min) where N
setrng!🎲(noise::Octaves{N}, rng::JavaXoroshiro128PlusPlus, amplitudes, octave_min) where N
setrng!🎲(noise::DoublePerlin{N}, rng, octave_min) where N
setrng!🎲(noise::DoublePerlin{N}, rng, amplitudes, octave_min) where N

` Initialize the noise in place with the given random number generator (of type AbstractJavaRNG).

Warning

N represents the number of octaves, each associated with a non-zero amplitude. Therefore, N MUST be equal to the number of non-zero values in amplitudes. This number can be obtained with Cubiomes.length_filter(!iszero, amplitudes). For performance reasons, it is possible to lower N and completely ignore the last amplitudes using unsafe_setrng!🎲.

Tip

Since the last amplitudes are ignored if they are set to zero, replace the tuple of amplitudes with the trimmed version without the last zeros can save a very small amount of memory / time. However, only do this if the trimmed amplitudes are already known. Computing them only for this function call will not save any time.

See also: unsafe_setrng!🎲, Noise, Noise🎲

source
Cubiomes.Noises.unsafe_setrng!🎲Function
unsafe_setrng!🎲(noise, rng::JavaXoroshiro128PlusPlus, amplitudes, octave_min)

Same as setrng!🎲 but allows to skip some octaves for performance reasons, i.e. N can be less than the number of non-zero values in amplitudes, and the last octaves are completely ignored. If instead N is greater, the behavior is undefined.

See also: setrng!🎲, Noise, Noise🎲

source

Private API

Click to see
Cubiomes.Noises.indexed_lerpMethod
indexed_lerp(idx::Integer, x, y, z)

Use the lower 4 bits of idx as a simple hash to combine the x, y, and z values into a single number (a new index), to be used in the Perlin noise interpolation.

source
Cubiomes.Noises.interpolate_perlinMethod
interpolate_perlin(
            idx::PermsType,
            d1, d2, d3,
            h1, h2, h3,
            t1, t2, t3
        ) -> Real

Interpolate the Perlin noise at the given coordinates.

Arguments

  • The idx parameter is the permutations array.
  • The d1, d2, and d3 parameters are the fractional parts of the x, y, and z

coordinates.

  • The h1, h2, and h3 parameters are the integer parts of the x, y, and z

coordinates. They MUST be between 0 and 255.

  • The t1, t2, and t3 parameters are the smoothstep values of the fractional parts

of the x, y, and z coordinates.

See also: init_coord_values, sample_noise, Perlin

source
Cubiomes.Noises.next_perlin🎲Function
next_perlin🎲(rng::JavaRandom, ::Type{Int32}; start=0, stop) -> Int32
next_perlin🎲(rng::JavaXoroshiro128PlusPlus, ::Type{Int32}; start=0, stop) -> Int3

Same as next🎲 but with a different implementation specific for the perlin noise. Don't ask why this is different, it's just how Minecraft does it.

See also: next🎲

source
Cubiomes.Noises.simplex_gradientMethod
simplex_gradient(idx, x, y, z, d)

Compute the gradient of the simplex noise at the given coordinates.

Arguments

  • idx: Index used for interpolation.
  • x, y, z: Coordinates in the simplex grid.
  • d: Constant used to determine the influence of the point in the grid.

See also: sample_simplex

source
Cubiomes.Noises.smoothstep_perlin_unsafeMethod
smoothstep_perlin_unsafe(x)

Compute $6x^5 - 15x^4 + 10x^3$, the smoothstep function used in Perlin noise. See https://en.wikipedia.org/wiki/Smoothstep#Variations for more details.

This function is unsafe because it is assuming that $0 \leq x \leq 1$ (it does not clamp the input).

source