Skip to main content

ImprovedNoise

Struct ImprovedNoise 

Source
pub struct ImprovedNoise {
    p: [u8; 256],
    pub xo: f64,
    pub yo: f64,
    pub zo: f64,
    yo_floor: i32,
    yo_fraction: f64,
    zo_floor: i32,
    zo_fraction: f64,
}
Expand description

Improved Perlin noise generator.

This implements the improved Perlin noise algorithm as used in Minecraft. Each instance has a permutation table and offset values initialized from a random source.

Fields§

§p: [u8; 256]

Permutation table (256 bytes)

§xo: f64

X offset for the noise coordinates

§yo: f64

Y offset for the noise coordinates

§zo: f64

Z offset for the noise coordinates

§yo_floor: i32§yo_fraction: f64§zo_floor: i32§zo_fraction: f64

Implementations§

Source§

impl ImprovedNoise

Source

pub fn new<R: Random>(random: &mut R) -> Self

Creates a new ImprovedNoise from a random source.

Initializes the permutation table using Fisher-Yates shuffle and sets random offsets.

Source

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

Sample noise at the given coordinates.

This is the standard 3D Perlin noise sampling without Y scaling.

Source

pub fn noise_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>> + Neg<Output = Simd<F, N>>,

Calculate Perlin noise using SIMD vectors.

Source

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

Sample noise at (x, 0.0, z).

Source

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

Sample noise at (x, y, 0.0).

Source

pub fn noise_with_derivative( &self, x: f64, y: f64, z: f64, derivative_out: &mut [f64; 3], ) -> f64

Sample noise at the given coordinates, accumulating partial derivatives.

Returns the noise value and adds the partial derivatives (dx, dy, dz) into derivative_out. Used by BlendedNoise for terrain generation.

Source

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

Sample noise with Y scale and fudge parameters.

The y_scale and y_fudge parameters are used for terrain generation where vertical noise needs special handling.

§Arguments
  • x, y, z - The coordinates to sample
  • y_scale - Y scaling factor (0.0 to disable)
  • y_fudge - Y fudge factor for floor snapping
Source

fn sample_and_lerp( &self, x: i32, y: i32, z: i32, xr: f64, yr: f64, zr: f64, yr_original: f64, ) -> f64

Sample noise at grid point and interpolate.

The 8 corner gradient-dot products are evaluated as 2 × f64x4 so the per-lane math stays identical to the scalar path (((gx*xr) + (gy*yr)) + (gz*zr)), which preserves bit-identical output. Inspired by C2ME’s c2me-opts-math flat-gradient SIMD form.

Source

fn p_simd<const N: usize>(&self, idx: Simd<u8, N>) -> Simd<u8, N>

Source

fn sample_and_lerp_simd<F, const N: usize>( &self, x: Simd<i32, N>, y: Simd<i32, N>, z: Simd<i32, N>, xr: Simd<F, N>, yr: Simd<F, N>, zr: Simd<F, N>, yr_original: Simd<F, N>, ) -> Simd<F, N>
where F: SimdElement + SimdCast, Simd<F, N>: Mul<Output = Simd<F, N>> + Add<Output = Simd<F, N>> + Sub<Output = Simd<F, N>> + Neg<Output = Simd<F, N>>,

Sample noise at grid point and interpolate.

Source

pub fn noise_with_y_scale_simd<const N: usize>( &self, x: f64, ys: Simd<f64, N>, z: f64, y_scale: f64, y_fudges: Simd<f64, N>, ) -> Simd<f64, N>

Generic N-lane form of [Self::noise_with_y_scale_4x]. Each lane runs the exact per-lane math of the scalar Self::noise_with_y_scale, so any supported lane width yields bit-identical per-lane results — only the SIMD batch size changes. f64x4noise_with_y_scale_simd::<4>.

Source

fn sample_and_lerp_y_simd<const N: usize>( &self, xf: i32, zf: i32, xr: f64, zr: f64, ys_floor: Simd<i32, N>, yrs: Simd<f64, N>, yrs_original: Simd<f64, N>, ) -> Simd<f64, N>

Vectorized sample-and-lerp for N Y values sharing x/z grid position. Generic counterpart of [Self::sample_and_lerp_4x].

Source

fn sample_with_derivative( &self, x: i32, y: i32, z: i32, xr: f64, yr: f64, zr: f64, derivative_out: &mut [f64; 3], ) -> f64

Sample noise at grid point, interpolate, and accumulate derivatives.

Trait Implementations§

Source§

impl Clone for ImprovedNoise

Source§

fn clone(&self) -> ImprovedNoise

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 ImprovedNoise

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