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: f64X offset for the noise coordinates
yo: f64Y offset for the noise coordinates
zo: f64Z offset for the noise coordinates
yo_floor: i32§yo_fraction: f64§zo_floor: i32§zo_fraction: f64Implementations§
Source§impl ImprovedNoise
impl ImprovedNoise
Sourcepub fn new<R: Random>(random: &mut R) -> Self
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.
Sourcepub fn noise(&self, x: f64, y: f64, z: f64) -> f64
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.
Sourcepub 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>>,
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.
Sourcepub fn noise_with_derivative(
&self,
x: f64,
y: f64,
z: f64,
derivative_out: &mut [f64; 3],
) -> f64
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.
Sourcepub fn noise_with_y_scale(
&self,
x: f64,
y: f64,
z: f64,
y_scale: f64,
y_fudge: f64,
) -> f64
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 sampley_scale- Y scaling factor (0.0 to disable)y_fudge- Y fudge factor for floor snapping
Sourcefn sample_and_lerp(
&self,
x: i32,
y: i32,
z: i32,
xr: f64,
yr: f64,
zr: f64,
yr_original: f64,
) -> f64
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.
fn p_simd<const N: usize>(&self, idx: Simd<u8, N>) -> Simd<u8, N>
Sourcefn 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>
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>
Sample noise at grid point and interpolate.
Sourcepub 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>
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. f64x4 ≡ noise_with_y_scale_simd::<4>.
Trait Implementations§
Source§impl Clone for ImprovedNoise
impl Clone for ImprovedNoise
Source§fn clone(&self) -> ImprovedNoise
fn clone(&self) -> ImprovedNoise
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 ImprovedNoise
impl RefUnwindSafe for ImprovedNoise
impl Send for ImprovedNoise
impl Sync for ImprovedNoise
impl Unpin for ImprovedNoise
impl UnsafeUnpin for ImprovedNoise
impl UnwindSafe for ImprovedNoise
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<>>