Blender V4.3
noise.cc File Reference
#include <algorithm>
#include <cmath>
#include <cstdint>
#include "BLI_math_base.hh"
#include "BLI_math_base_safe.h"
#include "BLI_math_matrix_types.hh"
#include "BLI_math_numbers.hh"
#include "BLI_math_vector.hh"
#include "BLI_noise.hh"
#include "BLI_utildefines.h"

Go to the source code of this file.

Namespaces

namespace  blender
 
namespace  blender::noise
 

Functions

Jenkins Lookup3 Hash Functions
BLI_INLINE uint32_t blender::noise::hash_bit_rotate (uint32_t x, uint32_t k)
 
BLI_INLINE void blender::noise::hash_bit_mix (uint32_t &a, uint32_t &b, uint32_t &c)
 
BLI_INLINE void blender::noise::hash_bit_final (uint32_t &a, uint32_t &b, uint32_t &c)
 
BLI_INLINE uint32_t blender::noise::float_as_uint (float f)
 
BLI_INLINE float blender::noise::uint_to_float_01 (uint32_t k)
 
Hash Functions

Create a randomized hash from the given inputs. Contrary to hash functions in BLI_hash.hh these functions produce better randomness but are more expensive to compute.

uint32_t blender::noise::hash (uint32_t kx)
 
uint32_t blender::noise::hash (uint32_t kx, uint32_t ky)
 
uint32_t blender::noise::hash (uint32_t kx, uint32_t ky, uint32_t kz)
 
uint32_t blender::noise::hash (uint32_t kx, uint32_t ky, uint32_t kz, uint32_t kw)
 
uint32_t blender::noise::hash_float (float kx)
 
uint32_t blender::noise::hash_float (float2 k)
 
uint32_t blender::noise::hash_float (float3 k)
 
uint32_t blender::noise::hash_float (float4 k)
 
uint32_t blender::noise::hash_float (const float4x4 &k)
 
float blender::noise::hash_to_float (uint32_t kx)
 
float blender::noise::hash_to_float (uint32_t kx, uint32_t ky)
 
float blender::noise::hash_to_float (uint32_t kx, uint32_t ky, uint32_t kz)
 
float blender::noise::hash_to_float (uint32_t kx, uint32_t ky, uint32_t kz, uint32_t kw)
 
float blender::noise::hash_float_to_float (float k)
 
float blender::noise::hash_float_to_float (float2 k)
 
float blender::noise::hash_float_to_float (float3 k)
 
float blender::noise::hash_float_to_float (float4 k)
 
float2 blender::noise::hash_float_to_float2 (float2 k)
 
float2 blender::noise::hash_float_to_float2 (float3 k)
 
float2 blender::noise::hash_float_to_float2 (float4 k)
 
float3 blender::noise::hash_float_to_float3 (float k)
 
float3 blender::noise::hash_float_to_float3 (float2 k)
 
float3 blender::noise::hash_float_to_float3 (float3 k)
 
float3 blender::noise::hash_float_to_float3 (float4 k)
 
float4 blender::noise::hash_float_to_float4 (float4 k)
 

Perlin Noise

Perlin, Ken. "Improving noise." Proceedings of the 29th annual conference on Computer graphics and interactive techniques. 2002.

This implementation is functionally identical to the implementations in EEVEE, OSL, and SVM. So any changes should be applied in all relevant implementations.

enum  {
  blender::noise::NOISE_SHD_PERLIN_MULTIFRACTAL = 0 , blender::noise::NOISE_SHD_PERLIN_FBM = 1 , blender::noise::NOISE_SHD_PERLIN_HYBRID_MULTIFRACTAL = 2 , blender::noise::NOISE_SHD_PERLIN_RIDGED_MULTIFRACTAL = 3 ,
  blender::noise::NOISE_SHD_PERLIN_HETERO_TERRAIN = 4
}
 
template<typename T >
static T blender::noise::mix (T v0, T v1, float x)
 
BLI_INLINE float blender::noise::mix (float v0, float v1, float v2, float v3, float x, float y)
 
BLI_INLINE float blender::noise::mix (float v0, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float x, float y, float z)
 
BLI_INLINE float blender::noise::mix (float v0, float v1, float v2, float v3, float v4, float v5, float v6, float v7, float v8, float v9, float v10, float v11, float v12, float v13, float v14, float v15, float x, float y, float z, float w)
 
BLI_INLINE float blender::noise::fade (float t)
 
BLI_INLINE float blender::noise::negate_if (float value, uint32_t condition)
 
BLI_INLINE float blender::noise::noise_grad (uint32_t hash, float x)
 
BLI_INLINE float blender::noise::noise_grad (uint32_t hash, float x, float y)
 
BLI_INLINE float blender::noise::noise_grad (uint32_t hash, float x, float y, float z)
 
BLI_INLINE float blender::noise::noise_grad (uint32_t hash, float x, float y, float z, float w)
 
BLI_INLINE float blender::noise::floor_fraction (float x, int &i)
 
BLI_INLINE float blender::noise::perlin_noise (float position)
 
BLI_INLINE float blender::noise::perlin_noise (float2 position)
 
BLI_INLINE float blender::noise::perlin_noise (float3 position)
 
BLI_INLINE float blender::noise::perlin_noise (float4 position)
 
float blender::noise::perlin_signed (float position)
 
float blender::noise::perlin_signed (float2 position)
 
float blender::noise::perlin_signed (float3 position)
 
float blender::noise::perlin_signed (float4 position)
 
float blender::noise::perlin (float position)
 
float blender::noise::perlin (float2 position)
 
float blender::noise::perlin (float3 position)
 
float blender::noise::perlin (float4 position)
 
template<typename T >
float blender::noise::perlin_fbm (T p, float detail, float roughness, float lacunarity, bool normalize)
 
template float blender::noise::perlin_fbm< float3 > (float3 p, const float detail, const float roughness, const float lacunarity, const bool normalize)
 
template<typename T >
float blender::noise::perlin_multi_fractal (T p, const float detail, const float roughness, const float lacunarity)
 
template<typename T >
float blender::noise::perlin_hetero_terrain (T p, const float detail, const float roughness, const float lacunarity, const float offset)
 
template<typename T >
float blender::noise::perlin_hybrid_multi_fractal (T p, const float detail, const float roughness, const float lacunarity, const float offset, const float gain)
 
template<typename T >
float blender::noise::perlin_ridged_multi_fractal (T p, const float detail, const float roughness, const float lacunarity, const float offset, const float gain)
 
template<typename T >
float blender::noise::perlin_select (T p, float detail, float roughness, float lacunarity, float offset, float gain, int type, bool normalize)
 
BLI_INLINE float blender::noise::random_float_offset (float seed)
 
BLI_INLINE float2 blender::noise::random_float2_offset (float seed)
 
BLI_INLINE float3 blender::noise::random_float3_offset (float seed)
 
BLI_INLINE float4 blender::noise::random_float4_offset (float seed)
 
BLI_INLINE float blender::noise::perlin_distortion (float position, float strength)
 
BLI_INLINE float2 blender::noise::perlin_distortion (float2 position, float strength)
 
BLI_INLINE float3 blender::noise::perlin_distortion (float3 position, float strength)
 
BLI_INLINE float4 blender::noise::perlin_distortion (float4 position, float strength)
 
template<typename T >
float blender::noise::perlin_fractal_distorted (T position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 
template float blender::noise::perlin_fractal_distorted< float > (float position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 
template float blender::noise::perlin_fractal_distorted< float2 > (float2 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 
template float blender::noise::perlin_fractal_distorted< float3 > (float3 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 
template float blender::noise::perlin_fractal_distorted< float4 > (float4 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 
float3 blender::noise::perlin_float3_fractal_distorted (float position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 
float3 blender::noise::perlin_float3_fractal_distorted (float2 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 
float3 blender::noise::perlin_float3_fractal_distorted (float3 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 
float3 blender::noise::perlin_float3_fractal_distorted (float4 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
 

Voronoi Noise

Note
Ported from Cycles code.

Original code is under the MIT License, Copyright (c) 2013 Inigo Quilez.

Smooth Voronoi:

Distance To Edge based on:

With optimization to change -2..2 scan window to -1..1 for better performance, as explained in https://www.shadertoy.com/view/llG3zy.

enum  { blender::noise::NOISE_SHD_VORONOI_EUCLIDEAN = 0 , blender::noise::NOISE_SHD_VORONOI_MANHATTAN = 1 , blender::noise::NOISE_SHD_VORONOI_CHEBYCHEV = 2 , blender::noise::NOISE_SHD_VORONOI_MINKOWSKI = 3 }
 
enum  {
  blender::noise::NOISE_SHD_VORONOI_F1 = 0 , blender::noise::NOISE_SHD_VORONOI_F2 = 1 , blender::noise::NOISE_SHD_VORONOI_SMOOTH_F1 = 2 , blender::noise::NOISE_SHD_VORONOI_DISTANCE_TO_EDGE = 3 ,
  blender::noise::NOISE_SHD_VORONOI_N_SPHERE_RADIUS = 4
}
 
float blender::noise::voronoi_distance (const float a, const float b)
 
float blender::noise::voronoi_distance (const float2 a, const float2 b, const VoronoiParams &params)
 
float blender::noise::voronoi_distance (const float3 a, const float3 b, const VoronoiParams &params)
 
float blender::noise::voronoi_distance (const float4 a, const float4 b, const VoronoiParams &params)
 
float4 blender::noise::voronoi_position (const float coord)
 
VoronoiOutput blender::noise::voronoi_f1 (const VoronoiParams &params, const float coord)
 
VoronoiOutput blender::noise::voronoi_smooth_f1 (const VoronoiParams &params, const float coord, const bool calc_color)
 
VoronoiOutput blender::noise::voronoi_f2 (const VoronoiParams &params, const float coord)
 
float blender::noise::voronoi_distance_to_edge (const VoronoiParams &params, const float coord)
 
float blender::noise::voronoi_n_sphere_radius (const VoronoiParams &params, const float coord)
 
float4 blender::noise::voronoi_position (const float2 coord)
 
VoronoiOutput blender::noise::voronoi_f1 (const VoronoiParams &params, const float2 coord)
 
VoronoiOutput blender::noise::voronoi_smooth_f1 (const VoronoiParams &params, const float2 coord, const bool calc_color)
 
VoronoiOutput blender::noise::voronoi_f2 (const VoronoiParams &params, const float2 coord)
 
float blender::noise::voronoi_distance_to_edge (const VoronoiParams &params, const float2 coord)
 
float blender::noise::voronoi_n_sphere_radius (const VoronoiParams &params, const float2 coord)
 
float4 blender::noise::voronoi_position (const float3 coord)
 
VoronoiOutput blender::noise::voronoi_f1 (const VoronoiParams &params, const float3 coord)
 
VoronoiOutput blender::noise::voronoi_smooth_f1 (const VoronoiParams &params, const float3 coord, const bool calc_color)
 
VoronoiOutput blender::noise::voronoi_f2 (const VoronoiParams &params, const float3 coord)
 
float blender::noise::voronoi_distance_to_edge (const VoronoiParams &params, const float3 coord)
 
float blender::noise::voronoi_n_sphere_radius (const VoronoiParams &params, const float3 coord)
 
float4 blender::noise::voronoi_position (const float4 coord)
 
VoronoiOutput blender::noise::voronoi_f1 (const VoronoiParams &params, const float4 coord)
 
VoronoiOutput blender::noise::voronoi_smooth_f1 (const VoronoiParams &params, const float4 coord, const bool calc_color)
 
VoronoiOutput blender::noise::voronoi_f2 (const VoronoiParams &params, const float4 coord)
 
float blender::noise::voronoi_distance_to_edge (const VoronoiParams &params, const float4 coord)
 
float blender::noise::voronoi_n_sphere_radius (const VoronoiParams &params, const float4 coord)
 
template<typename T >
VoronoiOutput blender::noise::fractal_voronoi_x_fx (const VoronoiParams &params, const T coord, const bool calc_color)
 
template<typename T >
float blender::noise::fractal_voronoi_distance_to_edge (const VoronoiParams &params, const T coord)
 
template VoronoiOutput blender::noise::fractal_voronoi_x_fx< float > (const VoronoiParams &params, const float coord, const bool calc_color)
 
template VoronoiOutput blender::noise::fractal_voronoi_x_fx< float2 > (const VoronoiParams &params, const float2 coord, const bool calc_color)
 
template VoronoiOutput blender::noise::fractal_voronoi_x_fx< float3 > (const VoronoiParams &params, const float3 coord, const bool calc_color)
 
template VoronoiOutput blender::noise::fractal_voronoi_x_fx< float4 > (const VoronoiParams &params, const float4 coord, const bool calc_color)
 
template float blender::noise::fractal_voronoi_distance_to_edge< float > (const VoronoiParams &params, const float coord)
 
template float blender::noise::fractal_voronoi_distance_to_edge< float2 > (const VoronoiParams &params, const float2 coord)
 
template float blender::noise::fractal_voronoi_distance_to_edge< float3 > (const VoronoiParams &params, const float3 coord)
 
template float blender::noise::fractal_voronoi_distance_to_edge< float4 > (const VoronoiParams &params, const float4 coord)
 

Gabor Noise

Implements Gabor noise based on the paper:

Lagae, Ares, et al. "Procedural noise using sparse Gabor convolution." ACM Transactions on Graphics (TOG) 28.3 (2009): 1-10.

But with the improvements from the paper:

Tavernier, Vincent, et al. "Making gabor noise fast and normalized." Eurographics 2019-40th Annual Conference of the European Association for Computer Graphics. 2019.

And compute the Phase and Intensity of the Gabor based on the paper:

Tricard, Thibault, et al. "Procedural phasor noise." ACM Transactions on Graphics (TOG) 38.4 (2019): 1-13.

static constexpr int blender::noise::gabor_impulses_count = 8
 
static float2 blender::noise::compute_2d_gabor_kernel (const float2 position, const float frequency, const float orientation)
 
static float blender::noise::compute_2d_gabor_standard_deviation ()
 
static float2 blender::noise::compute_2d_gabor_noise_cell (const float2 cell, const float2 position, const float frequency, const float isotropy, const float base_orientation)
 
static float2 blender::noise::compute_2d_gabor_noise (const float2 coordinates, const float frequency, const float isotropy, const float base_orientation)
 
static float2 blender::noise::compute_3d_gabor_kernel (const float3 position, const float frequency, const float3 orientation)
 
static float blender::noise::compute_3d_gabor_standard_deviation ()
 
static float3 blender::noise::compute_3d_orientation (const float3 orientation, const float isotropy, const float4 seed)
 
static float2 blender::noise::compute_3d_gabor_noise_cell (const float3 cell, const float3 position, const float frequency, const float isotropy, const float3 base_orientation)
 
static float2 blender::noise::compute_3d_gabor_noise (const float3 coordinates, const float frequency, const float isotropy, const float3 base_orientation)
 
void blender::noise::gabor (const float2 coordinates, const float scale, const float frequency, const float anisotropy, const float orientation, float *r_value, float *r_phase, float *r_intensity)
 
void blender::noise::gabor (const float3 coordinates, const float scale, const float frequency, const float anisotropy, const float3 orientation, float *r_value, float *r_phase, float *r_intensity)