core/math/noise
math_noise
Types
3Constants
28FALLBACK_ROTATE_3D
FALLBACK_ROTATE_3D :: f64 = f64(2.0) / f64(3.0)SourceHASH_MULTIPLIER
HASH_MULTIPLIER :: i64 = i64(0x53A3F72DEEC546F5)SourceLATTICE_STEP_4D
LATTICE_STEP_4D :: f32 = f32(0.2)SourceNORMALIZER_2D
NORMALIZER_2D :: f64 = f64(0.01001634121365712)SourceNORMALIZER_3D
NORMALIZER_3D :: f64 = f64(0.07969837668935331)SourceNORMALIZER_4D
NORMALIZER_4D :: f64 = f64(0.0220065933241897)SourceN_GRADS_2D
N_GRADS_2D :: 1 << N_GRADS_2D_EXPONENTSourceN_GRADS_2D_EXPONENT
N_GRADS_2D_EXPONENT :: 7SourceN_GRADS_3D
N_GRADS_3D :: 1 << N_GRADS_3D_EXPONENTSourceN_GRADS_3D_EXPONENT
N_GRADS_3D_EXPONENT :: 8SourceN_GRADS_4D
N_GRADS_4D :: 1 << N_GRADS_4D_EXPONENTSourceN_GRADS_4D_EXPONENT
N_GRADS_4D_EXPONENT :: 9SourcePRIME_W
PRIME_W :: i64 = i64(0x56CC5227E58F554B)SourcePRIME_X
PRIME_X :: i64 = i64(0x5205402B9270C86F)SourceOpenSimplex2 noise implementation.
Ported from https://github.com/KdotJPG/OpenSimplex2.
Copyright 2022 Yuki2 (https://github.com/NoahR02)
Private implementation details follow.PRIME_Y
PRIME_Y :: i64 = i64(0x598CD327003817B5)SourcePRIME_Z
PRIME_Z :: i64 = i64(0x5BCC226E9FA0BACB)SourceROOT_2_OVER_2
ROOT_2_OVER_2 :: f64 = f64(0.7071067811865476)SourceROOT_3_OVER_3
ROOT_3_OVER_3 :: f64 = f64(0.577350269189626)SourceROTATE_3D_ORTHOGONALIZER
ROTATE_3D_ORTHOGONALIZER :: f64 = f64(UNSKEW_2D)SourceRSQUARED_2D
RSQUARED_2D :: f32 = f32(0.5)SourceRSQUARED_3D
RSQUARED_3D :: f32 = f32(0.6)SourceRSQUARED_4D
RSQUARED_4D :: f32 = f32(0.6)SourceSEED_FLIP_3D
SEED_FLIP_3D :: i64 = i64(-0x52D547B2E96ED629)SourceSEED_OFFSET_4D
SEED_OFFSET_4D :: i64 = i64(0xE83DC3E0DA7164D)SourceSKEW_2D
SKEW_2D :: f64 = f64(0.366025403784439)SourceSKEW_4D
SKEW_4D :: f32 = f32(0hbe0d8369)SourceUNSKEW_2D
UNSKEW_2D :: f64 = f64(-0.21132486540518713)SourceUNSKEW_4D
UNSKEW_4D :: f32 = f32(0.309016994374947)SourceVariables
3GRADIENTS_2D
GRADIENTS_2D :: [N_GRADS_2D * 2]f32 = [N_GRADS_2D * 2]f32{
0h4218d2da, 0h42b87975, 0h42b87975, 0h4218d2da, 0h42b87975, 0hc218d2da, 0h4218d2da, 0hc2b87975,
0hc218d2da, 0hc2b87975, 0hc2b87975, 0hc218d2da, 0hc2b87975, 0h4218d2da, 0hc218d2da, 0h42b87975,
0h4150804d, 0h42c5f72a, 0h42731b78, 0hSourceGRADIENTS_3D
GRADIENTS_3D :: [N_GRADS_3D * 4]f32 = [N_GRADS_3D * 4]f32{
0h41df5103, 0h41df5103, 0hc148c1c5, 0h00000000, 0h41df5103, 0h41df5103, 0h4148c1c5, 0h00000000,
0h421ae5b8, 0h416b5146, 0h00000000, 0h00000000, 0h416b5146, 0h421ae5b8, 0h00000000, 0h00000000,
0hc1df5103, 0h41df5103, 0hc148c1c5, 0hSourceGRADIENTS_4D
GRADIENTS_4D :: [N_GRADS_4D * 4]f32 = [N_GRADS_4D * 4]f32{
0hc1f50507, 0hc16b8e00, 0hc16b8e00, 0h41d2a716, 0hc208695c, 0hc19194b0, 0h40de6d7d, 0h41b6d966,
0hc208695c, 0h40de6d7d, 0hc19194b0, 0h41b6d966, 0hc22076c5, 0h406d72bf, 0h406d72bf, 0h41a58418,
0hc1a58418, 0hc06d72bf, 0hc06d72bf, 0h42SourceProcedures
17_internal_noise_2d_unskewed_base
_internal_noise_2d_unskewed_base :: proc(seed: i64, coord: Vec2) -> (value: f32)Source2D Simplex noise base.
_internal_noise_3d_unrotated_base
_internal_noise_3d_unrotated_base :: proc(seed: i64, coord: Vec3) -> (value: f32)SourceGenerate overlapping cubic lattices for 3D OpenSimplex2 noise.
_internal_noise_4d_unskewed_base
_internal_noise_4d_unskewed_base :: proc(seed: i64, coord: Vec4) -> (value: f32)Source4D OpenSimplex2 noise base.
fast_floor
fast_floor :: proc(x: f64) -> (floored: i64)Sourcefast_round
fast_round :: proc(x: f64) -> (rounded: i64)Sourcegrad_2d
grad_2d :: proc(seed: i64, svp: [2]i64, delta: [2]f32) -> (value: f32)SourceUtility functions
grad_3d
grad_3d :: proc(seed: i64, rvp: [3]i64, delta: [3]f32) -> (value: f32)Sourcegrad_4d
grad_4d :: proc(seed: i64, svp: [4]i64, delta: [4]f32) -> (value: f32)Sourcenoise_2d
noise_2d :: proc(seed: i64, coord: Vec2) -> (value: f32)SourceNoise Evaluators 2D Simplex noise, standard lattice orientation.
noise_2d_improve_x
noise_2d_improve_x :: proc(seed: i64, coord: Vec2) -> (value: f32)Source2D Simplex noise, with Y pointing down the main diagonal.
Might be better for a 2D sandbox style game, where Y is vertical.
Probably slightly less optimal for heightmaps or continent maps,
unless your map is centered around an equator. It's a subtle
difference, but the option is here to make it an easy choice.noise_3d_fallback
noise_3d_fallback :: proc(seed: i64, coord: Vec3) -> (value: f32)Source3D OpenSimplex2 noise, fallback rotation option
Use `noise_3d_improve_xy` or `noise_3d_improve_xz` instead, wherever appropriate.
They have less diagonal bias. This function's best use is as a fallback.noise_3d_improve_xy
noise_3d_improve_xy :: proc(seed: i64, coord: Vec3) -> (value: f32)Source3D OpenSimplex2 noise, with better visual isotropy in (X, Y).
Recommended for 3D terrain and time-varied animations.
The Z coordinate should always be the "different" coordinate in whatever your use case is.
If Y is vertical in world coordinates, call `noise_3d_improve_xz(x, z, Y)` or use `noise_3d_xz_before_y`.
If Z is vertical in world coordinates, call `noise_3d_improve_xz(x, y, Z)`.
For a time varied animation, call `noise_3d_improve_xz(x, y, T)`.noise_3d_improve_xz
noise_3d_improve_xz :: proc(seed: i64, coord: Vec3) -> (value: f32)Source3D OpenSimplex2 noise, with better visual isotropy in (X, Z).
Recommended for 3D terrain and time-varied animations.
The Y coordinate should always be the "different" coordinate in whatever your use case is.
If Y is vertical in world coordinates, call `noise_3d_improve_xz(x, Y, z)`.
If Z is vertical in world coordinates, call `noise_3d_improve_xz(x, Z, y)` or use `noise_3d_improve_xy`.
For a time varied animation, call `noise_3d_improve_xz(x, T, y)` or use `noise_3d_improve_xy`.noise_4d_fallback
noise_4d_fallback :: proc(seed: i64, coord: Vec4) -> (value: f32)Source4D OpenSimplex2 noise, fallback lattice orientation.
noise_4d_improve_xyz
noise_4d_improve_xyz :: proc(seed: i64, coord: Vec4) -> (value: f32)Source4D OpenSimplex2 noise, with XYZ oriented like noise_3d_fallback
and W for an extra degree of freedom. W repeats eventually.
Recommended for time-varied animations which texture a 3D object (W=time)
where there isn't a clear distinction between horizontal and verticalnoise_4d_improve_xyz_improve_xy
noise_4d_improve_xyz_improve_xy :: proc(seed: i64, coord: Vec4) -> (value: f32)Source4D OpenSimplex2 noise, with XYZ oriented like noise_3d_improve_xy
and W for an extra degree of freedom. W repeats eventually.
Recommended for time-varied animations which texture a 3D object (W=time)
in a space where Z is vertical.noise_4d_improve_xyz_improve_xz
noise_4d_improve_xyz_improve_xz :: proc(seed: i64, coord: Vec4) -> (value: f32)Source4D OpenSimplex2 noise, with XYZ oriented like noise_3d_improve_xz
and W for an extra degree of freedom. W repeats eventually.
Recommended for time-varied animations which texture a 3D object (W=time)
in a space where Y is vertical.