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) -> f32
pub fn noise(&self, x: f64, y: f64, z: f64) -> f32
Samples the 26.3 float-based PerlinNoise implementation.
Vanilla keeps coordinates and offsets as doubles, then converts the
fractional coordinates and every interpolation operation to float.
Sourcepub fn noise_y_simd<const N: usize>(
&self,
x: f64,
ys: Simd<f64, N>,
z: f64,
) -> Simd<f32, N>
pub fn noise_y_simd<const N: usize>( &self, x: f64, ys: Simd<f64, N>, z: f64, ) -> Simd<f32, N>
samples one X/Z column of the floatvalued Perlin noise impl
Sourcepub fn smeared_noise(
&self,
original_x: f64,
original_y: f64,
original_z: f64,
fudge_y_scale: f64,
) -> f32
pub fn smeared_noise( &self, original_x: f64, original_y: f64, original_z: f64, fudge_y_scale: f64, ) -> f32
Samples the float-based SmearedPerlinNoise used by 26.3’s blended
terrain noise.
Sourcepub fn smeared_noise_xz(&self, x: f64, z: f64, fudge_y_scale: f64) -> f32
pub fn smeared_noise_xz(&self, x: f64, z: f64, fudge_y_scale: f64) -> f32
Samples smeared noise at (x, 0.0, z).
Sourcepub fn smeared_noise_xy(&self, x: f64, y: f64, fudge_y_scale: f64) -> f32
pub fn smeared_noise_xy(&self, x: f64, y: f64, fudge_y_scale: f64) -> f32
Samples smeared noise at (x, y, 0.0).
Sourcepub fn smeared_noise_y_simd<const N: usize>(
&self,
original_x: f64,
original_ys: Simd<f64, N>,
original_z: f64,
fudge_y_scale: f64,
) -> Simd<f32, N>
pub fn smeared_noise_y_simd<const N: usize>( &self, original_x: f64, original_ys: Simd<f64, N>, original_z: f64, fudge_y_scale: f64, ) -> Simd<f32, N>
Samples an X/Z column of float-based SmearedPerlinNoise values.
Coordinates and the vertical fudge stay in f64, as in vanilla. The
gradients and interpolation remain in f32 lanes.
fn sample_and_lerp( &self, x: i32, y: i32, z: i32, relative_x: f32, relative_y: f32, relative_z: f32, original_relative_y: f32, ) -> f32
fn column_corner_hashes(&self, x0: u8, x1: u8, y: u8, z: u8) -> [usize; 8]
fn sample_and_lerp_y_simd<const N: usize>( &self, x: i32, ys: Simd<i32, N>, z: i32, relative_x: f32, relative_ys: Simd<f32, N>, relative_z: f32, original_relative_ys: Simd<f32, N>, ) -> Simd<f32, N>
fn sample_and_lerp_y_simd_kernel<const N: usize, const SHARED_Y: bool>( &self, x: i32, ys: Simd<i32, N>, z: i32, relative_x: f32, relative_ys: Simd<f32, N>, relative_z: f32, original_relative_ys: Simd<f32, N>, ) -> Simd<f32, N>
Sourcepub fn noise_simd<const N: usize>(
&self,
x: Simd<f32, N>,
y: Simd<f32, N>,
z: Simd<f32, N>,
) -> Simd<f32, N>
pub fn noise_simd<const N: usize>( &self, x: Simd<f32, N>, y: Simd<f32, N>, z: Simd<f32, N>, ) -> Simd<f32, N>
Calculate Perlin noise using SIMD vectors.
Sourcepub fn noise_with_derivative(
&self,
x: f64,
y: f64,
z: f64,
derivative_out: &mut [f32; 3],
) -> f32
pub fn noise_with_derivative( &self, x: f64, y: f64, z: f64, derivative_out: &mut [f32; 3], ) -> f32
Sample noise at the given coordinates, accumulating partial derivatives.
Returns the float noise value and adds the partial derivatives (dx, dy, dz)
into derivative_out. Matches vanilla’s PerlinNoise.noiseWithDerivative.
Sourcepub fn noise_with_y_scale(
&self,
x: f64,
y: f64,
z: f64,
y_scale: f64,
y_fudge: f64,
) -> f32
pub fn noise_with_y_scale( &self, x: f64, y: f64, z: f64, y_scale: f64, y_fudge: f64, ) -> f32
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
fn p_simd<const N: usize>(&self, idx: Simd<u8, N>) -> Simd<u8, N>
Sourcefn sample_and_lerp_simd<const N: usize>(
&self,
x: Simd<i32, N>,
y: Simd<i32, N>,
z: Simd<i32, N>,
xr: Simd<f32, N>,
yr: Simd<f32, N>,
zr: Simd<f32, N>,
yr_original: Simd<f32, N>,
) -> Simd<f32, N>
fn sample_and_lerp_simd<const N: usize>( &self, x: Simd<i32, N>, y: Simd<i32, N>, z: Simd<i32, N>, xr: Simd<f32, N>, yr: Simd<f32, N>, zr: Simd<f32, N>, yr_original: Simd<f32, N>, ) -> Simd<f32, 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<f32, 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<f32, N>
Generic N-lane form of the Y-scaled float sampler. 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.
Trait Implementations§
Source§impl Clone for ImprovedNoise
impl Clone for ImprovedNoise
Auto 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<>>