Skip to main content

PerlinNoise

Struct PerlinNoise 

Source
pub struct PerlinNoise {
    noise_levels: Vec<Option<ImprovedNoise>>,
    amplitudes: Vec<f64>,
    active_octaves: Vec<ActiveOctave>,
    lowest_freq_value_factor: f64,
    max_value: f64,
}
Expand description

Octave-based Perlin noise generator.

Combines multiple ImprovedNoise instances at different frequencies to create noise with detail at multiple scales.

Fields§

§noise_levels: Vec<Option<ImprovedNoise>>

Noise generators for each octave (None if amplitude is 0). Kept for Self::get_octave_noise which is indexed by original octave order.

§amplitudes: Vec<f64>

Amplitude multipliers for each octave. Kept for Self::max_broken_value which recomputes the edge value.

§active_octaves: Vec<ActiveOctave>

Pre-computed per-octave data for the hot sampling loop. Only contains entries with non-zero amplitude, in original (low → high frequency) order so that floating-point accumulation matches the legacy iteration.

§lowest_freq_value_factor: f64

Factor applied to output values for the lowest frequency octave. Used by Self::max_broken_value which recomputes the edge value.

§max_value: f64

Maximum possible output value

Implementations§

Source§

impl PerlinNoise

Source

pub fn create( splitter: &RandomSplitter, first_octave: i32, amplitudes: &[f64], ) -> Self

Create a new PerlinNoise from a positional random splitter (hash-based seeding).

Each octave gets its seed from splitter.with_hash_of("octave_{level}"). This is a convenience method; for vanilla-matching behavior within [NormalNoise], use create_from_random instead.

Source

pub fn create_from_random( random: &mut RandomSource, first_octave: i32, amplitudes: &[f64], ) -> Self

Create a new PerlinNoise from a mutable sequential random source.

This matches vanilla’s PerlinNoise constructor for [XoroshiroRandomSource]:

  1. Consume 262 values from the random (to advance state)
  2. Fork a new positional random from the current state
  3. Use hash-based seeding for each octave from the forked positional

This is critical for [NormalNoise] where the first and second PerlinNoise must get different seeds from the same sequential random source.

Source

pub fn create_legacy_for_nether( random: &mut RandomSource, first_octave: i32, amplitudes: &[f64], ) -> Self

Create a PerlinNoise using the legacy nether biome initialization path.

Unlike create_from_random which uses positional/hash-based seeding, this creates ImprovedNoise instances directly from a sequential random source. Matches vanilla’s PerlinNoise(random, pair, useNewInitialization=false).

Source

fn from_parts( noise_levels: Vec<Option<ImprovedNoise>>, amplitudes: &[f64], zero_octave_index: usize, ) -> Self

Build a PerlinNoise from pre-computed noise levels.

Source

fn edge_value( amplitudes: &[f64], lowest_freq_value_factor: f64, noise_value: f64, ) -> f64

Calculate the theoretical maximum value for the given amplitudes.

Source

pub fn get_value(&self, x: f64, y: f64, z: f64) -> f64

Sample the noise at the given coordinates.

Source

pub fn get_value_xz(&self, x: f64, z: f64) -> f64

Sample the noise at (x, 0.0, z).

Source

pub fn get_value_xy(&self, x: f64, y: f64) -> f64

Sample the noise at (x, y, 0.0).

Source

pub fn get_value_simd<F, const N: usize>( &self, x: Simd<F, N>, y: Simd<F, N>, z: Simd<F, N>, ) -> Simd<F, N>
where F: SimdElement + SimdCast, Simd<F, N>: SimdFloat<Cast<i32> = Simd<i32, N>> + SimdPartialOrd + SimdPartialEq<Mask = Mask<<F as SimdElement>::Mask, N>> + Add<Output = Simd<F, N>> + Sub<Output = Simd<F, N>> + Mul<Output = Simd<F, N>> + Div<Output = Simd<F, N>> + Neg<Output = Simd<F, N>> + StdFloat,

Calculate Perlin noise value using SIMD vectors.

Source

pub fn get_value_with_y_params( &self, x: f64, y: f64, z: f64, y_scale: f64, y_fudge: f64, y_flat_hack: bool, ) -> f64

Sample the noise with Y scaling parameters.

§Arguments
  • x, y, z - Coordinates to sample
  • y_scale - Y scaling factor for terrain
  • y_fudge - Y fudge factor for floor snapping
  • y_flat_hack - If true, use -yo instead of wrapped y (for legacy biomes)
Source

pub fn get_value_with_y_params_4x( &self, x: f64, ys: f64x4, z: f64, y_scale: f64, y_fudge: f64, y_flat_hack: bool, ) -> f64x4

SIMD form of Self::get_value_with_y_params that processes 4 Y values at a fixed (x, z) per call. Used by transpiled density-function trees that batch 4 cell-corner Ys in one pass.

Per-lane math is identical to the scalar path — same operation order, same wrapping, same octave loop — so the 4 returned lanes are bit-identical to four scalar calls at the same Y values.

Source

pub fn get_value_with_y_params_simd<const N: usize>( &self, x: f64, ys: Simd<f64, N>, z: f64, y_scale: f64, y_fudge: f64, y_flat_hack: bool, ) -> Simd<f64, N>

Generic N-lane form of Self::get_value_with_y_params_4x. Per-lane math is identical to the scalar path at any supported width.

Source

pub const fn max_value(&self) -> f64

Get the maximum possible output value.

Source

pub fn max_broken_value(&self, y_scale: f64) -> f64

Calculate the maximum “broken” value for BlendedNoise.

Used by BlendedNoise to determine the theoretical max output. Java reference: PerlinNoise.maxBrokenValue(double)

Source

pub fn get_octave_noise(&self, i: usize) -> Option<&ImprovedNoise>

Get the noise generator for a specific octave (by index from highest frequency).

Index 0 is the highest frequency octave.

Trait Implementations§

Source§

impl Clone for PerlinNoise

Source§

fn clone(&self) -> PerlinNoise

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PerlinNoise

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoShared for T

§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more