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: f64Factor applied to output values for the lowest frequency octave.
Used by Self::max_broken_value which recomputes the edge value.
max_value: f64Maximum possible output value
Implementations§
Source§impl PerlinNoise
impl PerlinNoise
Sourcepub fn create(
splitter: &RandomSplitter,
first_octave: i32,
amplitudes: &[f64],
) -> Self
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.
Sourcepub fn create_from_random(
random: &mut RandomSource,
first_octave: i32,
amplitudes: &[f64],
) -> Self
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]:
- Consume 262 values from the random (to advance state)
- Fork a new positional random from the current state
- 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.
Sourcepub fn create_legacy_for_nether(
random: &mut RandomSource,
first_octave: i32,
amplitudes: &[f64],
) -> Self
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).
Sourcefn from_parts(
noise_levels: Vec<Option<ImprovedNoise>>,
amplitudes: &[f64],
zero_octave_index: usize,
) -> Self
fn from_parts( noise_levels: Vec<Option<ImprovedNoise>>, amplitudes: &[f64], zero_octave_index: usize, ) -> Self
Build a PerlinNoise from pre-computed noise levels.
Sourcefn edge_value(
amplitudes: &[f64],
lowest_freq_value_factor: f64,
noise_value: f64,
) -> f64
fn edge_value( amplitudes: &[f64], lowest_freq_value_factor: f64, noise_value: f64, ) -> f64
Calculate the theoretical maximum value for the given amplitudes.
Sourcepub fn get_value(&self, x: f64, y: f64, z: f64) -> f64
pub fn get_value(&self, x: f64, y: f64, z: f64) -> f64
Sample the noise at the given coordinates.
Sourcepub fn get_value_xz(&self, x: f64, z: f64) -> f64
pub fn get_value_xz(&self, x: f64, z: f64) -> f64
Sample the noise at (x, 0.0, z).
Sourcepub fn get_value_xy(&self, x: f64, y: f64) -> f64
pub fn get_value_xy(&self, x: f64, y: f64) -> f64
Sample the noise at (x, y, 0.0).
Sourcepub 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,
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.
Sourcepub fn get_value_with_y_params(
&self,
x: f64,
y: f64,
z: f64,
y_scale: f64,
y_fudge: f64,
y_flat_hack: bool,
) -> f64
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 sampley_scale- Y scaling factor for terrainy_fudge- Y fudge factor for floor snappingy_flat_hack- If true, use-yoinstead of wrapped y (for legacy biomes)
Sourcepub 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
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.
Sourcepub 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>
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.
Sourcepub fn max_broken_value(&self, y_scale: f64) -> f64
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)
Sourcepub fn get_octave_noise(&self, i: usize) -> Option<&ImprovedNoise>
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
impl Clone for PerlinNoise
Source§fn clone(&self) -> PerlinNoise
fn clone(&self) -> PerlinNoise
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PerlinNoise
impl RefUnwindSafe for PerlinNoise
impl Send for PerlinNoise
impl Sync for PerlinNoise
impl Unpin for PerlinNoise
impl UnsafeUnpin for PerlinNoise
impl UnwindSafe for PerlinNoise
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreArc<SyncMutex<>>